percentage-based splitting.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
[auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field]]
|
||||
[auto-ap.views.components.expense-accounts-field :refer [expense-accounts-field recalculate-amounts]]
|
||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||
[auto-ap.views.utils
|
||||
:refer
|
||||
@@ -104,7 +104,10 @@
|
||||
(re-frame/reg-event-db
|
||||
::adding
|
||||
(fn [db [_ new]]
|
||||
(-> db (forms/start-form ::form (assoc new :expense-accounts [{:amount 0 :id (str "new-" (random-uuid))}])))))
|
||||
(-> db (forms/start-form ::form (assoc new :expense-accounts [{:amount 0
|
||||
:id (str "new-" (random-uuid))
|
||||
:amount-percentage 100
|
||||
:amount-mode "%"}])))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
@@ -113,16 +116,28 @@
|
||||
edit-invoice (assoc edit-invoice :original edit-invoice)]
|
||||
(-> db
|
||||
(forms/start-form ::form {:id (:id edit-invoice)
|
||||
:status (:status edit-invoice)
|
||||
:date (:date edit-invoice)
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (:total edit-invoice)
|
||||
:original edit-invoice
|
||||
:vendor-id (:id (:vendor edit-invoice))
|
||||
:vendor-name (:name (:vendor edit-invoice))
|
||||
:client-id (:id (:client edit-invoice))
|
||||
:expense-accounts (:expense-accounts edit-invoice)
|
||||
:client-name (:name (:client edit-invoice))})))))
|
||||
:status (:status edit-invoice)
|
||||
:date (:date edit-invoice)
|
||||
:invoice-number (:invoice-number edit-invoice)
|
||||
:total (:total edit-invoice)
|
||||
:original edit-invoice
|
||||
:vendor-id (:id (:vendor edit-invoice))
|
||||
:vendor-name (:name (:vendor edit-invoice))
|
||||
:client-id (:id (:client edit-invoice))
|
||||
:expense-accounts (if (seq (:expense-accounts which))
|
||||
(vec (map
|
||||
(fn [a]
|
||||
(-> a
|
||||
(update :amount #(js/parseFloat %))
|
||||
(assoc :amount-percentage (* 100 (/ (js/parseFloat (:amount a))
|
||||
(Math/abs (js/parseFloat (:total which))))))
|
||||
(assoc :amount-mode "%")))
|
||||
(:expense-accounts edit-invoice)))
|
||||
[{:id (str "new-" (random-uuid))
|
||||
:amount-mode "$"
|
||||
:amount (Math/abs (:total edit-invoice))
|
||||
:amount-percentage 100}])
|
||||
:client-name (:name (:client edit-invoice))})))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -135,6 +150,15 @@
|
||||
[:client-id] value
|
||||
[:location] first-location]})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-amount
|
||||
[(forms/in-form ::form)]
|
||||
(fn [{{:keys [data]} :db} [_ field value]]
|
||||
(print field value (:expense-accounts data))
|
||||
{:dispatch [::forms/change ::form
|
||||
field value
|
||||
[:expense-accounts] (recalculate-amounts (:expense-accounts data) value)]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-vendor
|
||||
[(forms/in-form ::form)]
|
||||
@@ -148,6 +172,8 @@
|
||||
field value
|
||||
[:expense-accounts] [{:id (str "new-" (random-uuid))
|
||||
:amount (:total data)
|
||||
:amount-percentage 100
|
||||
:amount-mode "%"
|
||||
:account @(re-frame/subscribe [::subs/vendor-default-account value])}]]}
|
||||
{:dispatch [::forms/change ::form
|
||||
field value]}))))
|
||||
@@ -284,7 +310,7 @@
|
||||
[:input.input {:type "number"
|
||||
:field [:total]
|
||||
:disabled (if can-change-amount? "" "disabled")
|
||||
:event change-event
|
||||
:event [::change-amount]
|
||||
:min min-total
|
||||
:subscription data
|
||||
:spec ::invoice/total
|
||||
@@ -297,7 +323,7 @@
|
||||
:descriptor "expense account"
|
||||
:event change-event
|
||||
:locations locations
|
||||
:max-value (:total data)
|
||||
:max (:total data)
|
||||
:field [:expense-accounts]}]]]
|
||||
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
(forms/stop-form ::edit-transaction))
|
||||
|
||||
:dispatch (conj edit-completed edit-transaction)}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::editing
|
||||
(fn [db [_ which]]
|
||||
@@ -46,14 +47,25 @@
|
||||
(-> db
|
||||
(forms/start-form ::edit-transaction {:id (:id which)
|
||||
:yodlee-merchant (:yodlee-merchant which)
|
||||
:amount (:amount which)
|
||||
:description-original (:description-original which)
|
||||
:location (:location which)
|
||||
:client-id (:id (:client which))
|
||||
:vendor-id (:id (:vendor which))
|
||||
:vendor-name (:name (:vendor which))
|
||||
:accounts (or (vec (:accounts which))
|
||||
[{:id (str "new-" (random-uuid))
|
||||
:amount (Math/abs (:amount 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}])}))))
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -111,6 +123,15 @@
|
||||
:disabled "disabled"
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Amount"]
|
||||
[:div.control
|
||||
[bind-field
|
||||
[:input.input {:type "text"
|
||||
:field [:amount]
|
||||
:disabled "disabled"
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field
|
||||
[:p.help "Description"]
|
||||
[:div.control
|
||||
@@ -133,15 +154,16 @@
|
||||
:event change-event
|
||||
:subscription data}]]]]
|
||||
|
||||
[:div.field]
|
||||
[bind-field
|
||||
[expense-accounts-field
|
||||
{:type "expense-accounts"
|
||||
:field [:accounts]
|
||||
:descriptor "credit account"
|
||||
:locations locations
|
||||
:event change-event
|
||||
:subscription data}]]
|
||||
[:div.field
|
||||
[bind-field
|
||||
[expense-accounts-field
|
||||
{:type "expense-accounts"
|
||||
:field [:accounts]
|
||||
:max (Math/abs (js/parseFloat (:amount data)))
|
||||
:descriptor "credit account"
|
||||
:locations locations
|
||||
:event change-event
|
||||
:subscription data}]]]
|
||||
|
||||
(comment
|
||||
[:div.field
|
||||
@@ -151,18 +173,11 @@
|
||||
:field [:always-map]
|
||||
:subscription data}]
|
||||
" Always match Merchant '" (:merchant-name data) "' to '" (:vendor-name data) "'" ]]])
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(when error
|
||||
^{:key error} [:div.notification.is-warning.animated.fadeInUp
|
||||
error])
|
||||
|
||||
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe [::can-submit])
|
||||
""
|
||||
"disabled")
|
||||
:class (str @(re-frame/subscribe [::forms/loading-class ::edit-transaction])
|
||||
(when error " animated shake"))} "Save"]
|
||||
])])
|
||||
(when error " animated shake"))} "Save"]])])
|
||||
|
||||
Reference in New Issue
Block a user