split evenly
This commit is contained in:
@@ -37,6 +37,16 @@
|
||||
(* (/ (js/parseFloat (:amount-percentage ea)) 100.0) (js/parseFloat total))))))
|
||||
expense-accounts))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::spread-evenly
|
||||
(fn [_ [_ event expense-accounts max-value]]
|
||||
{:dispatch (into event [(recalculate-amounts (mapv
|
||||
(fn [ea]
|
||||
(assoc ea :amount-percentage (js/parseFloat
|
||||
(goog.string/format "%.2f"
|
||||
(* 100 (/ 1 (count expense-accounts)))))))
|
||||
expense-accounts)
|
||||
max-value)])}))
|
||||
(re-frame/reg-event-fx
|
||||
::expense-account-changed
|
||||
(fn [_ [_ event expense-accounts max-value field value]]
|
||||
@@ -46,12 +56,10 @@
|
||||
(= (list :amount-percentage) (drop 1 field)) (assoc-in [(first field) :amount]
|
||||
(js/parseFloat
|
||||
(goog.string/format "%.2f"
|
||||
(do
|
||||
(println value max-value)
|
||||
(* (/ (cond-> value
|
||||
(not (float? value)) (js/parseFloat )) 100.0)
|
||||
(cond-> max-value
|
||||
(not (float? max-value)) (js/parseFloat))))))))
|
||||
(* (/ (cond-> value
|
||||
(not (float? value)) (js/parseFloat )) 100.0)
|
||||
(cond-> max-value
|
||||
(not (float? max-value)) (js/parseFloat)))))))
|
||||
updated-accounts (if-let [location (get-in updated-accounts [(first field) :account :location])]
|
||||
(assoc-in updated-accounts [(first field) :location] location)
|
||||
updated-accounts)]
|
||||
@@ -62,8 +70,6 @@
|
||||
(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor}]
|
||||
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
|
||||
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
|
||||
(println expense-accounts)
|
||||
|
||||
[:div
|
||||
[:div.columns
|
||||
[:div.column
|
||||
@@ -71,6 +77,7 @@
|
||||
[:p.help "Remaining " (->$ (- max-value (reduce + 0 (map (comp js/parseFloat :amount) expense-accounts))))]]
|
||||
[:div.column.is-narrow
|
||||
[:p.buttons
|
||||
[: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"]]]]
|
||||
|
||||
(for [[index {:keys [account id location amount amount-mode] :as expense-account}] (map vector (range) expense-accounts)
|
||||
|
||||
Reference in New Issue
Block a user