updates the location of the expense account when one is selected.
This commit is contained in:
@@ -44,31 +44,35 @@
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
(fn [db [_ which potential-payment-matches]]
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:yodlee-merchant (:yodlee-merchant which)
|
||||
:amount (:amount which)
|
||||
:potential-payment-matches potential-payment-matches
|
||||
:description-original (:description-original which)
|
||||
:location (:location which)
|
||||
:exclude-from-ledger (:exclude-from-ledger which)
|
||||
:payment (:payment which)
|
||||
:client-id (:id (:client which))
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))
|
||||
:accounts (if (seq (:accounts which))
|
||||
(vec (map
|
||||
(fn [a]
|
||||
(-> a
|
||||
(update :amount js/parseFloat)
|
||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||
(Math/abs (js/parseFloat (:amount which))))))
|
||||
(assoc :amount-mode "$")))
|
||||
(:accounts which)))
|
||||
[{:id (str "new-" (random-uuid))
|
||||
:amount-mode "$"
|
||||
:amount (Math/abs (:amount which))
|
||||
:amount-percentage 100}])}))))
|
||||
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:yodlee-merchant (:yodlee-merchant which)
|
||||
:amount (:amount which)
|
||||
:potential-payment-matches potential-payment-matches
|
||||
:description-original (:description-original which)
|
||||
:location (:location which)
|
||||
:exclude-from-ledger (:exclude-from-ledger which)
|
||||
:payment (:payment which)
|
||||
:client-id (:id (:client which))
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))
|
||||
:accounts (if (seq (:accounts which))
|
||||
(vec (map
|
||||
(fn [a]
|
||||
(-> a
|
||||
(update :amount js/parseFloat)
|
||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||
(Math/abs (js/parseFloat (:amount which))))))
|
||||
(assoc :amount-mode "$")))
|
||||
(:accounts which)))
|
||||
[{:id (str "new-" (random-uuid))
|
||||
:amount-mode "$"
|
||||
:amount (Math/abs (:amount which))
|
||||
:amount-percentage 100
|
||||
:location (if (= 1 (count locations))
|
||||
(first locations)
|
||||
nil)}])})))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -118,6 +122,9 @@
|
||||
:amount (Math/abs (:amount data))
|
||||
:amount-percentage 100
|
||||
:amount-mode "%"
|
||||
:location (or
|
||||
(:location @(re-frame/subscribe [::subs/vendor-default-account value]))
|
||||
(get-in data [:accounts 0 :account :location]))
|
||||
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
|
||||
{:dispatch [::forms/change ::edit-transaction field value]}))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user