a lot of ledger progress.

This commit is contained in:
Bryce Covert
2019-05-10 10:41:10 -07:00
parent ea4367a910
commit 1f8a1324a4
5 changed files with 57 additions and 27 deletions

View File

@@ -108,31 +108,39 @@
;; VIEWS
(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor disabled :disabled}]
(defn expense-accounts-field [{expense-accounts :value max-value :max locations :locations event :event descriptor :descriptor disabled :disabled percentage-only? :percentage-only? :or {percentage-only? false}}]
(let [chooseable-expense-accounts @(re-frame/subscribe [::subs/chooseable-expense-accounts])
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
[:div
[:div.columns
[:div.column
[:h1.subtitle.is-4.is-inline (str/capitalize descriptor) "s"]
[:p.help "Remaining " (->$ (- max-value (reduce + 0 (map (comp js/parseFloat :amount) expense-accounts))))]]
(when-not percentage-only?
[:p.help "Remaining " (->$ (- max-value (reduce + 0 (map (comp js/parseFloat :amount) expense-accounts))))])]
[:div.column.is-narrow
(when-not disabled
[: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 locations])} "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-percentage amount-mode] :as expense-account}] (map vector (range) expense-accounts)
:let [account (accounts-by-id (:id account))]]
^{:key id}
[:div.box
[:div.columns
[:div.column
[:h1.subtitle.is-6 (if account
(str (:name account) " - "
location ": "
(gstring/format "$%.2f" (or amount 0) ))
[:i "New " descriptor])]]
[:h1.subtitle.is-6 (cond (and account (not percentage-only?))
(str (:name account) " - "
location ": "
(gstring/format "$%.2f" (or amount 0) ))
account
(str (:name account) " - "
location ": %"
amount-percentage)
:else
[:i "New " descriptor])]]
[:div.column.is-narrow
(when-not disabled
[:a.delete {:on-click (dispatch-event [::remove-expense-account event expense-accounts id])}])]]
@@ -176,7 +184,7 @@
[:p.control [:span.select
[bind-field
[:select {:type "select"
:disabled disabled
:disabled (or disabled percentage-only?)
:field [index :amount-mode]
:allow-nil? false
:event [::expense-account-changed event expense-accounts max-value]