From 36f6eabcbab552fe5bde0d0c728992863ad9c260 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 25 Jan 2019 13:31:07 -0800 Subject: [PATCH] improvements for expense account dialog --- .../components/expense_accounts_dialog.cljs | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs b/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs index fc79fa5f..e10d97bc 100644 --- a/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs +++ b/src/cljs/auto_ap/views/components/expense_accounts_dialog.cljs @@ -81,7 +81,10 @@ expense-accounts-total (->> expense-accounts (map :amount) (map js/parseFloat) - (map #(or % 0)) + (map #(or % 0.0)) + (map #(if (js/Number.isNaN %) + 0.0 + %)) (reduce + 0)) does-add-up? (< (Math/abs (- expense-accounts-total (js/parseFloat total))) 0.01)] [action-modal {:id ::change-expense-accounts @@ -111,7 +114,7 @@ :type "typeahead" :field [:invoice :expense-accounts index :expense-account-id] :event change-event - :spec ::invoice/vendor-id + :spec ::invoices-expense-accounts/expense-account-id :subscription data}]]]] (when multi-location? @@ -136,14 +139,22 @@ [bind-field [:input.input {:type "number" :field [:invoice :expense-accounts index :amount] + :style {:text-align "right"} :event change-event :subscription data :value (get-in data [:invoice :expense-accounts index :amount]) :max (:total data) :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 ) ")" )]]]]])) + [:td { :col-span (when multi-location? "2") :style { :text-align "right"} } "Subtotal: "] + [:td { :style { :text-align "right"} } (str (gstring/format "$%.2f" expense-accounts-total ) )]] + [:tr + [:td { :col-span (when multi-location? "2") :style { :text-align "right"} } "Remaining: "] + [:td { :style { :text-align "right"} } (str (gstring/format "$%.2f" (- total expense-accounts-total) ) )]] + + [:tr + [:td { :col-span (when multi-location? "2") :style { :text-align "right"} } "Invoice total: "] + [:td { :style { :text-align "right"} } (str (gstring/format "$%.2f" total ) )]] + ]]]))