You can change categories
This commit is contained in:
@@ -3,9 +3,11 @@
|
|||||||
[reagent.core :as r]
|
[reagent.core :as r]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.spec.alpha :as s]
|
[clojure.spec.alpha :as s]
|
||||||
|
[goog.string :as gstring]
|
||||||
[auto-ap.entities.companies :as company]
|
[auto-ap.entities.companies :as company]
|
||||||
[auto-ap.entities.invoice :as invoice]
|
[auto-ap.entities.invoice :as invoice]
|
||||||
[auto-ap.entities.vendors :as vendor]
|
[auto-ap.entities.vendors :as vendor]
|
||||||
|
[auto-ap.entities.invoices-expense-accounts :as invoices-expense-accounts]
|
||||||
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field]]
|
[auto-ap.views.utils :refer [dispatch-event bind-field horizontal-field]]
|
||||||
[auto-ap.utils :refer [by replace-if]]
|
[auto-ap.utils :refer [by replace-if]]
|
||||||
[auto-ap.views.pages.check :as check]
|
[auto-ap.views.pages.check :as check]
|
||||||
@@ -288,13 +290,20 @@
|
|||||||
(drop (inc index) expense-accounts))))))
|
(drop (inc index) expense-accounts))))))
|
||||||
|
|
||||||
(defn change-expense-accounts-modal []
|
(defn change-expense-accounts-modal []
|
||||||
(let [{{:keys [expense-accounts]} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
|
(let [{{:keys [expense-accounts total] :or {expense-accounts [] total 0}} :invoice :as data} @(re-frame/subscribe [::change-expense-accounts])
|
||||||
change-event [::events/change-form [::change-expense-accounts]]]
|
change-event [::events/change-form [::change-expense-accounts]]
|
||||||
|
expense-accounts-total (->> expense-accounts
|
||||||
|
(map :amount)
|
||||||
|
(map js/parseFloat)
|
||||||
|
(map #(or % 0))
|
||||||
|
(reduce + 0))
|
||||||
|
does-add-up? (= expense-accounts-total (js/parseFloat total))]
|
||||||
[action-modal {:id ::change-expense-accounts
|
[action-modal {:id ::change-expense-accounts
|
||||||
:title "Change expense accounts"
|
:title "Change expense accounts"
|
||||||
:action-text "Save"
|
:action-text "Save"
|
||||||
:save-event [::change-expense-accounts-saving]
|
:save-event [::change-expense-accounts-saving]
|
||||||
#_#_:can-submit? (s/valid? ::invoice/invoice data)}
|
:can-submit? (and does-add-up?
|
||||||
|
(s/valid? (s/* ::invoices-expense-accounts/invoices-expense-account) expense-accounts))}
|
||||||
|
|
||||||
[:div
|
[:div
|
||||||
[:a.button.is-primary {:on-click (dispatch-event [::add-expense-account-split])} "Add split"]]
|
[:a.button.is-primary {:on-click (dispatch-event [::add-expense-account-split])} "Add split"]]
|
||||||
@@ -332,7 +341,10 @@
|
|||||||
:max (:total data)
|
:max (:total data)
|
||||||
:step "0.01"}]]]]]]
|
:step "0.01"}]]]]]]
|
||||||
[:td [:a.button {:on-click (dispatch-event [::remove-expense-account-split index])} [:i.fa.fa-times]]]]
|
[:td [:a.button {:on-click (dispatch-event [::remove-expense-account-split index])} [:i.fa.fa-times]]]]
|
||||||
)]]]))
|
)
|
||||||
|
[:tr
|
||||||
|
[:th "TOTAL"]
|
||||||
|
[:th (str (gstring/format "$%.2f" expense-accounts-total ) " (" (gstring/format "$%.2f" total ) ")" )]]]]]))
|
||||||
|
|
||||||
|
|
||||||
(defn print-checks-modal []
|
(defn print-checks-modal []
|
||||||
|
|||||||
Reference in New Issue
Block a user