updates the location of the expense account when one is selected.
This commit is contained in:
@@ -12,11 +12,14 @@
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::add-expense-account
|
::add-expense-account
|
||||||
(fn [_ [_ event expense-accounts]]
|
(fn [_ [_ event expense-accounts locations]]
|
||||||
{:dispatch (conj event (conj expense-accounts
|
{:dispatch (conj event (conj expense-accounts
|
||||||
{:amount 0 :id (str "new-" (random-uuid))
|
{:amount 0 :id (str "new-" (random-uuid))
|
||||||
:amount-mode "%"
|
:amount-mode "%"
|
||||||
:amount-percentage 0}))}))
|
:amount-percentage 0
|
||||||
|
:location (if (= 1 (count locations))
|
||||||
|
(first locations)
|
||||||
|
nil)}))}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::remove-expense-account
|
::remove-expense-account
|
||||||
@@ -79,7 +82,7 @@
|
|||||||
(when-not disabled
|
(when-not disabled
|
||||||
[:p.buttons
|
[:p.buttons
|
||||||
[:a.button {:on-click (dispatch-event [::spread-evenly event expense-accounts max-value])} "Spread evenly"]
|
[:a.button {:on-click (dispatch-event [::spread-evenly event expense-accounts max-value])} "Spread evenly"]
|
||||||
[:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts])} "Add"]])]]
|
[:a.button {:on-click (dispatch-event [::add-expense-account event expense-accounts locations])} "Add"]])]]
|
||||||
|
|
||||||
(for [[index {:keys [account id location amount amount-mode] :as expense-account}] (map vector (range) expense-accounts)
|
(for [[index {:keys [account id location amount amount-mode] :as expense-account}] (map vector (range) expense-accounts)
|
||||||
:let [account (accounts-by-id (:id account))]]
|
:let [account (accounts-by-id (:id account))]]
|
||||||
@@ -128,7 +131,6 @@
|
|||||||
:subscription expense-accounts}
|
:subscription expense-accounts}
|
||||||
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]]]]
|
(map (fn [l] ^{:key l} [:option {:value l} l]) locations)]]])]]]]
|
||||||
|
|
||||||
|
|
||||||
[:div.field
|
[:div.field
|
||||||
[:p.help "Amount"]
|
[:p.help "Amount"]
|
||||||
[:div.control
|
[:div.control
|
||||||
|
|||||||
@@ -44,31 +44,35 @@
|
|||||||
(re-frame/reg-event-db
|
(re-frame/reg-event-db
|
||||||
::editing
|
::editing
|
||||||
(fn [db [_ which potential-payment-matches]]
|
(fn [db [_ which potential-payment-matches]]
|
||||||
(-> db
|
(let [locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client which))])]
|
||||||
(forms/start-form ::edit-transaction {:id (:id which)
|
(-> db
|
||||||
:yodlee-merchant (:yodlee-merchant which)
|
(forms/start-form ::edit-transaction {:id (:id which)
|
||||||
:amount (:amount which)
|
:yodlee-merchant (:yodlee-merchant which)
|
||||||
:potential-payment-matches potential-payment-matches
|
:amount (:amount which)
|
||||||
:description-original (:description-original which)
|
:potential-payment-matches potential-payment-matches
|
||||||
:location (:location which)
|
:description-original (:description-original which)
|
||||||
:exclude-from-ledger (:exclude-from-ledger which)
|
:location (:location which)
|
||||||
:payment (:payment which)
|
:exclude-from-ledger (:exclude-from-ledger which)
|
||||||
:client-id (:id (:client which))
|
:payment (:payment which)
|
||||||
:vendor-id (:id (:vendor which))
|
:client-id (:id (:client which))
|
||||||
:vendor-name (:name (:vendor which))
|
:vendor-id (:id (:vendor which))
|
||||||
:accounts (if (seq (:accounts which))
|
:vendor-name (:name (:vendor which))
|
||||||
(vec (map
|
:accounts (if (seq (:accounts which))
|
||||||
(fn [a]
|
(vec (map
|
||||||
(-> a
|
(fn [a]
|
||||||
(update :amount js/parseFloat)
|
(-> a
|
||||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
(update :amount js/parseFloat)
|
||||||
(Math/abs (js/parseFloat (:amount which))))))
|
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||||
(assoc :amount-mode "$")))
|
(Math/abs (js/parseFloat (:amount which))))))
|
||||||
(:accounts which)))
|
(assoc :amount-mode "$")))
|
||||||
[{:id (str "new-" (random-uuid))
|
(:accounts which)))
|
||||||
:amount-mode "$"
|
[{:id (str "new-" (random-uuid))
|
||||||
:amount (Math/abs (:amount which))
|
:amount-mode "$"
|
||||||
:amount-percentage 100}])}))))
|
:amount (Math/abs (:amount which))
|
||||||
|
:amount-percentage 100
|
||||||
|
:location (if (= 1 (count locations))
|
||||||
|
(first locations)
|
||||||
|
nil)}])})))))
|
||||||
|
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
@@ -118,6 +122,9 @@
|
|||||||
:amount (Math/abs (:amount data))
|
:amount (Math/abs (:amount data))
|
||||||
:amount-percentage 100
|
:amount-percentage 100
|
||||||
:amount-mode "%"
|
: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])}]]}
|
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
|
||||||
{:dispatch [::forms/change ::edit-transaction field value]}))))
|
{:dispatch [::forms/change ::edit-transaction field value]}))))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user