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