supports changing expense accounts
This commit is contained in:
@@ -50,7 +50,6 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::change
|
::change
|
||||||
(fn [db [_ form & path-pairs]]
|
(fn [db [_ form & path-pairs]]
|
||||||
(println "CHANGED" path-pairs)
|
|
||||||
(reduce
|
(reduce
|
||||||
(fn [db [path value]]
|
(fn [db [path value]]
|
||||||
(assoc-in db (into [::forms form :data] path) value))
|
(assoc-in db (into [::forms form :data] path) value))
|
||||||
|
|||||||
@@ -17,23 +17,7 @@
|
|||||||
[goog.string :as gstring]))
|
[goog.string :as gstring]))
|
||||||
|
|
||||||
;; SUBS
|
;; SUBS
|
||||||
(re-frame/reg-sub
|
|
||||||
::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
|
(re-frame/reg-sub
|
||||||
::can-submit-edit-invoice
|
::can-submit-edit-invoice
|
||||||
@@ -52,7 +36,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 [::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::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
|
||||||
@@ -72,7 +56,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 [::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::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
|
||||||
@@ -90,7 +74,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 [::form])]
|
(let [{:keys [data] {:keys [id invoice-number date location total expense-accounts vendor-id client-id]} :data} @(re-frame/subscribe [::forms/form ::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
|
||||||
@@ -150,6 +134,16 @@
|
|||||||
[:client-id] value
|
[:client-id] value
|
||||||
[:location] first-location]})))
|
[:location] first-location]})))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::change-expense-account-account
|
||||||
|
(fn [{:keys [db]} [_ [_ which _] value]]
|
||||||
|
|
||||||
|
(let [account @(re-frame/subscribe [::subs/account value])
|
||||||
|
changes (cond-> [[:expense-accounts which :account :id] value]
|
||||||
|
(:location account) (into [[:expense-accounts which :location] (:location account)]))]
|
||||||
|
|
||||||
|
{:dispatch (into [::forms/change ::form] changes)})))
|
||||||
|
|
||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::add-expense-account
|
::add-expense-account
|
||||||
[(forms/in-form ::form) (re-frame/path [:data])]
|
[(forms/in-form ::form) (re-frame/path [:data])]
|
||||||
@@ -172,7 +166,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 [::form])]
|
(let [{:keys [data]} @(re-frame/subscribe [::forms/form ::form])]
|
||||||
{:db (forms/loading db ::form)
|
{:db (forms/loading db ::form)
|
||||||
:graphql
|
:graphql
|
||||||
{:token (-> db :user)
|
{:token (-> db :user)
|
||||||
@@ -207,7 +201,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 [::form])
|
(let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::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))
|
||||||
@@ -220,7 +214,8 @@
|
|||||||
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
||||||
should-select-location? (and locations
|
should-select-location? (and locations
|
||||||
(> (count locations) 1))
|
(> (count locations) 1))
|
||||||
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])]
|
chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||||
|
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[:form { :on-submit (fn [e]
|
[:form { :on-submit (fn [e]
|
||||||
(when (.-stopPropagation e)
|
(when (.-stopPropagation e)
|
||||||
@@ -323,12 +318,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(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))]
|
(for [[index {:keys [account id location amount] :as expense-account}] (map vector (range) (:expense-accounts data))
|
||||||
|
:let [account (accounts-by-id (:id account))]]
|
||||||
^{:key id}
|
^{:key id}
|
||||||
[:div.box
|
[:div.box
|
||||||
[:div.columns
|
[:div.columns
|
||||||
[:div.column
|
[:div.column
|
||||||
[:h1.subtitle.is-6 title]]
|
[:h1.subtitle.is-6 (if account
|
||||||
|
(str (:name account) " - "
|
||||||
|
location ": "
|
||||||
|
(gstring/format "$%.2f" (or amount 0) ))
|
||||||
|
[:i "New expense account"])]]
|
||||||
[: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
|
||||||
@@ -340,8 +340,7 @@
|
|||||||
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) @(re-frame/subscribe [::subs/chooseable-expense-accounts]))
|
[typeahead {:matches (map (fn [x] [(:id x) (str (:numeric-code x) " - " (:name x))]) @(re-frame/subscribe [::subs/chooseable-expense-accounts]))
|
||||||
:type "typeahead"
|
:type "typeahead"
|
||||||
:field [:expense-accounts index :account :id]
|
:field [:expense-accounts index :account :id]
|
||||||
:text-field [:expense-accounts index :account :name]
|
:event [::change-expense-account-account]
|
||||||
:event [::forms/change ::form ]
|
|
||||||
:subscription data}]]]]
|
:subscription data}]]]]
|
||||||
[:div.column.is-narrow
|
[:div.column.is-narrow
|
||||||
[:p.help "Location"]
|
[:p.help "Location"]
|
||||||
|
|||||||
Reference in New Issue
Block a user