kind of able to select more than 1.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.subs
|
(ns auto-ap.subs
|
||||||
(:require [re-frame.core :as re-frame]
|
(:require [re-frame.core :as re-frame]
|
||||||
|
[auto-ap.utils :refer [by]]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[goog.crypt.base64 :as base64]))
|
[goog.crypt.base64 :as base64]))
|
||||||
|
|
||||||
@@ -33,6 +34,11 @@
|
|||||||
(fn [db client]
|
(fn [db client]
|
||||||
(:accounts db)))
|
(:accounts db)))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::accounts-for-client-by-id
|
||||||
|
(fn [db client]
|
||||||
|
(by :id (:accounts db))))
|
||||||
|
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::accounts-for-current-client
|
::accounts-for-current-client
|
||||||
(fn [db]
|
(fn [db]
|
||||||
|
|||||||
@@ -109,7 +109,7 @@
|
|||||||
|
|
||||||
(defn appearing-side-bar [{:keys [visible?]} & children ]
|
(defn appearing-side-bar [{:keys [visible?]} & children ]
|
||||||
[appearing {:visible? visible? :enter-class "slide-in-right" :exit-class "slide-out-right" :timeout 500}
|
[appearing {:visible? visible? :enter-class "slide-in-right" :exit-class "slide-out-right" :timeout 500}
|
||||||
[:aside {:class "column is-3 aside menu" :style {:height "calc(100vh - 46px)" :overflow "auto"}}
|
[:aside {:class "column is-4 aside menu" :style {:height "calc(100vh - 46px)" :overflow "auto"}}
|
||||||
[:div.sub-main {} children ]]])
|
[:div.sub-main {} children ]]])
|
||||||
|
|
||||||
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}]
|
(defn side-bar-layout [{:keys [side-bar main ap bottom right-side-bar]}]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
(ns auto-ap.views.pages.invoices.form
|
(ns auto-ap.views.pages.invoices.form
|
||||||
(:require [auto-ap.entities.invoice :as invoice]
|
(:require [auto-ap.entities.invoice :as invoice]
|
||||||
|
[auto-ap.utils :refer [by]]
|
||||||
[auto-ap.events :as events]
|
[auto-ap.events :as events]
|
||||||
[auto-ap.forms :as forms]
|
[auto-ap.forms :as forms]
|
||||||
[auto-ap.subs :as subs]
|
[auto-ap.subs :as subs]
|
||||||
@@ -12,12 +13,31 @@
|
|||||||
[cljs-time.core :as c]
|
[cljs-time.core :as c]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
[re-frame.core :as re-frame]
|
[re-frame.core :as re-frame]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]
|
||||||
|
[goog.string :as gstring]))
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
(re-frame/reg-sub
|
(re-frame/reg-sub
|
||||||
::can-submit-edit-invoice
|
::form
|
||||||
:<- [::forms/form ::form]
|
:<- [::forms/form ::form]
|
||||||
|
:<- [::subs/accounts-for-client-by-id]
|
||||||
|
(fn [[form accounts]]
|
||||||
|
(update-in form [:data :expense-accounts] (fn [expense-accounts]
|
||||||
|
(mapv
|
||||||
|
(fn [ea]
|
||||||
|
(let [account (accounts (:id (:account ea)))]
|
||||||
|
(cond-> ea
|
||||||
|
(:location account) (assoc ea :location (:location account))
|
||||||
|
(:amount ea) (assoc :title (str (:name account) " - "
|
||||||
|
(or (:location account)
|
||||||
|
(:location ea)) ": "
|
||||||
|
(gstring/format "$%.2f" (:amount ea 0) )))
|
||||||
|
(not account) (assoc :title "New expense account"))))
|
||||||
|
expense-accounts)))))
|
||||||
|
|
||||||
|
(re-frame/reg-sub
|
||||||
|
::can-submit-edit-invoice
|
||||||
|
:<- [::form]
|
||||||
(fn [{:keys [data status]} _]
|
(fn [{:keys [data status]} _]
|
||||||
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
(let [min-total (if (= (:total (:original data)) (:outstanding-balance (:original data)))
|
||||||
nil
|
nil
|
||||||
@@ -32,7 +52,7 @@
|
|||||||
command))
|
command))
|
||||||
|
|
||||||
(defmethod submit-query :create [db]
|
(defmethod submit-query :create [db]
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::form])]
|
||||||
{:venia/operation {:operation/type :mutation
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "AddInvoice"}
|
:operation/name "AddInvoice"}
|
||||||
:venia/queries [{:query/data [:add-invoice
|
:venia/queries [{:query/data [:add-invoice
|
||||||
@@ -52,7 +72,7 @@
|
|||||||
invoice-read]}]}))
|
invoice-read]}]}))
|
||||||
|
|
||||||
(defmethod submit-query :edit [db]
|
(defmethod submit-query :edit [db]
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::form])]
|
||||||
{:venia/operation {:operation/type :mutation
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "EditInvoice"}
|
:operation/name "EditInvoice"}
|
||||||
:venia/queries [{:query/data [:edit-invoice
|
:venia/queries [{:query/data [:edit-invoice
|
||||||
@@ -70,7 +90,7 @@
|
|||||||
invoice-read]}]}))
|
invoice-read]}]}))
|
||||||
|
|
||||||
(defmethod submit-query :add-and-print [db [_ _ bank-account-id type]]
|
(defmethod submit-query :add-and-print [db [_ _ bank-account-id type]]
|
||||||
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::form])]
|
||||||
{:venia/operation {:operation/type :mutation
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "AddAndPrintInvoice"}
|
:operation/name "AddAndPrintInvoice"}
|
||||||
:venia/queries [{:query/data [:add-and-print-invoice
|
:venia/queries [{:query/data [:add-and-print-invoice
|
||||||
@@ -152,7 +172,7 @@
|
|||||||
::submitted
|
::submitted
|
||||||
(fn [{:keys [db]} [_ params command bank-account-id type]]
|
(fn [{:keys [db]} [_ params command bank-account-id type]]
|
||||||
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
(when @(re-frame/subscribe [::can-submit-edit-invoice])
|
||||||
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
|
(let [{:keys [data]} @(re-frame/subscribe [::form])]
|
||||||
{:db (forms/loading db ::form)
|
{:db (forms/loading db ::form)
|
||||||
:graphql
|
:graphql
|
||||||
{:token (-> db :user)
|
{:token (-> db :user)
|
||||||
@@ -187,7 +207,7 @@
|
|||||||
|
|
||||||
(defn form [{:keys [can-change-amount?] :as params}]
|
(defn form [{:keys [can-change-amount?] :as params}]
|
||||||
[forms/side-bar-form {:form ::form }
|
[forms/side-bar-form {:form ::form }
|
||||||
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::form])
|
(let [{:keys [data active? error id]} @(re-frame/subscribe [::form])
|
||||||
exists? (:id data)
|
exists? (:id data)
|
||||||
current-client @(re-frame/subscribe [::subs/client])
|
current-client @(re-frame/subscribe [::subs/client])
|
||||||
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
||||||
@@ -303,12 +323,12 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(for [[index {:keys [id location] :as expense-account {account-id :id account-numeric-code :numeric-code account-name :name} :account}] (map vector (range) (:expense-accounts data))]
|
(for [[index {:keys [title account id location] :as expense-account {account-id :id account-numeric-code :numeric-code account-name :name} :account}] (map vector (range) (:expense-accounts data))]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[:div.box
|
[:div.box
|
||||||
[:div.columns
|
[:div.columns
|
||||||
[:div.column
|
[:div.column
|
||||||
[:h1.subtitle.is-5 "Ex"]]
|
[:h1.subtitle.is-6 title]]
|
||||||
[:div.column.is-narrow
|
[:div.column.is-narrow
|
||||||
[:a.button {:on-click (dispatch-event [::remove-expense-account id])} [:span.icon [:i.fa.fa-times]]]]]
|
[:a.button {:on-click (dispatch-event [::remove-expense-account id])} [:span.icon [:i.fa.fa-times]]]]]
|
||||||
[:div.field
|
[:div.field
|
||||||
@@ -328,11 +348,11 @@
|
|||||||
[:div.control
|
[:div.control
|
||||||
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (get-in data [:expense-accounts index :account :id])]))]
|
(if-let [forced-location (:location @(re-frame/subscribe [::subs/account (get-in data [:expense-accounts index :account :id])]))]
|
||||||
[:div.select
|
[:div.select
|
||||||
[:select {:disabled "disabled" :style {:width "4em"} :value forced-location} [:option {:value forced-location} forced-location]]]
|
[:select {:disabled "disabled" :style {:width "5em"} :value forced-location} [:option {:value forced-location} forced-location]]]
|
||||||
[:div.select
|
[:div.select
|
||||||
[bind-field
|
[bind-field
|
||||||
[:select {:type "select"
|
[:select {:type "select"
|
||||||
:style {:width "4em"}
|
:style {:width "5em"}
|
||||||
:field [:expense-accounts index :location]
|
:field [:expense-accounts index :location]
|
||||||
:allow-nil? true
|
:allow-nil? true
|
||||||
:spec (set locations)
|
:spec (set locations)
|
||||||
|
|||||||
@@ -110,14 +110,14 @@
|
|||||||
keys (dissoc keys :field :subscription :event :spec)]
|
keys (dissoc keys :field :subscription :event :spec)]
|
||||||
(into [dom keys] (with-keys rest))))
|
(into [dom keys] (with-keys rest))))
|
||||||
|
|
||||||
(defmethod do-bind "typeahead" [dom {:keys [field text-field event subscription class spec] :as keys} & rest]
|
(defmethod do-bind "typeahead" [dom {:keys [field text-field event text-event subscription class spec] :as keys} & rest]
|
||||||
(let [field (if (keyword? field) [field] field)
|
(let [field (if (keyword? field) [field] field)
|
||||||
event (if (keyword? event) [event] event)
|
event (if (keyword? event) [event] event)
|
||||||
keys (assoc keys
|
keys (assoc keys
|
||||||
:on-change (fn [selected text-description text-value]
|
:on-change (fn [selected text-description text-value]
|
||||||
(re-frame/dispatch (conj (conj event field) selected))
|
(re-frame/dispatch (conj (conj event field) selected))
|
||||||
(when text-field
|
(when text-field
|
||||||
(re-frame/dispatch (conj (conj event text-field) text-value))))
|
(re-frame/dispatch (conj (conj (or text-event event) text-field) text-value))))
|
||||||
:value (get-in subscription field)
|
:value (get-in subscription field)
|
||||||
:class (str class
|
:class (str class
|
||||||
(when (and spec (not (s/valid? spec (get-in subscription field))))
|
(when (and spec (not (s/valid? spec (get-in subscription field))))
|
||||||
|
|||||||
Reference in New Issue
Block a user