supports changing expense accounts
This commit is contained in:
@@ -50,7 +50,6 @@
|
||||
(re-frame/reg-event-db
|
||||
::change
|
||||
(fn [db [_ form & path-pairs]]
|
||||
(println "CHANGED" path-pairs)
|
||||
(reduce
|
||||
(fn [db [path value]]
|
||||
(assoc-in db (into [::forms form :data] path) value))
|
||||
|
||||
@@ -17,23 +17,7 @@
|
||||
[goog.string :as gstring]))
|
||||
|
||||
;; 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
|
||||
::can-submit-edit-invoice
|
||||
@@ -52,7 +36,7 @@
|
||||
command))
|
||||
|
||||
(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
|
||||
:operation/name "AddInvoice"}
|
||||
:venia/queries [{:query/data [:add-invoice
|
||||
@@ -72,7 +56,7 @@
|
||||
invoice-read]}]}))
|
||||
|
||||
(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
|
||||
:operation/name "EditInvoice"}
|
||||
:venia/queries [{:query/data [:edit-invoice
|
||||
@@ -90,7 +74,7 @@
|
||||
invoice-read]}]}))
|
||||
|
||||
(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
|
||||
:operation/name "AddAndPrintInvoice"}
|
||||
:venia/queries [{:query/data [:add-and-print-invoice
|
||||
@@ -150,6 +134,16 @@
|
||||
[:client-id] value
|
||||
[: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
|
||||
::add-expense-account
|
||||
[(forms/in-form ::form) (re-frame/path [:data])]
|
||||
@@ -172,7 +166,7 @@
|
||||
::submitted
|
||||
(fn [{:keys [db]} [_ params command bank-account-id type]]
|
||||
(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)
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
@@ -207,7 +201,7 @@
|
||||
|
||||
(defn form [{:keys [can-change-amount?] :as params}]
|
||||
[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)
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
can-change-amount? (#{:unpaid ":unpaid"} (:status data))
|
||||
@@ -220,7 +214,8 @@
|
||||
(- (:total (:original data)) (:outstanding-balance (:original data))))
|
||||
should-select-location? (and locations
|
||||
(> (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}
|
||||
[:form { :on-submit (fn [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}
|
||||
[:div.box
|
||||
[:div.columns
|
||||
[: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
|
||||
[:a.button {:on-click (dispatch-event [::remove-expense-account id])} [:span.icon [:i.fa.fa-times]]]]]
|
||||
[: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]))
|
||||
:type "typeahead"
|
||||
:field [:expense-accounts index :account :id]
|
||||
:text-field [:expense-accounts index :account :name]
|
||||
:event [::forms/change ::form ]
|
||||
:event [::change-expense-account-account]
|
||||
:subscription data}]]]]
|
||||
[:div.column.is-narrow
|
||||
[:p.help "Location"]
|
||||
|
||||
Reference in New Issue
Block a user