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

@@ -9,5 +9,6 @@
(s/def ::dom-lte (s/nilable int?))
(s/def ::note (s/nilable string?))
(s/def ::bank-account (s/nilable map?))
(s/def ::vendor (s/nilable map?))
(s/def ::transaction-rule (s/keys :req-un [::client ::description ::amount-gte ::amount-lte ::dom-gte ::dom-lte ::note ::bank-account]))
(s/def ::transaction-rule (s/keys :req-un [::client ::description ::amount-gte ::amount-lte ::dom-gte ::dom-lte ::note ::bank-account ::vendor]))

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]

View File

@@ -7,6 +7,7 @@
:amount-lte
:dom-gte
:dom-lte
[:vendor [:name :id]]
[:client [:name :id]]
[:bank-account [:name :id]]
])

View File

@@ -87,22 +87,24 @@
:amount-gte nil
:dom-lte nil
:dom-gte nil
)))))
:vendor nil
:expense-accounts [])))))
(re-frame/reg-event-db
::editing
(fn [db [_ which]]
(-> db (forms/start-form ::form (select-keys which
[:description
:id
:client
:bank-account
:note
:amount-lte
:amount-gte
:dom-lte
:dom-gte
])))))
(-> db (forms/start-form ::form (assoc (select-keys which
[:description
:id
:client
:bank-account
:note
:amount-lte
:amount-gte
:dom-lte
:dom-gte
:vendor])
:expense-accounts [])))))
(re-frame/reg-event-db
@@ -165,6 +167,11 @@
accounts-by-id @(re-frame/subscribe [::subs/accounts-for-client-by-id])]
^{:key id}
[form (assoc params :title "New Transaction Rule")
[field "Note"
[:input.input {:type "text"
:field [:note]
:spec ::entity/note}]]
[field "Client"
[typeahead-entity {:matches @(re-frame/subscribe [::subs/clients])
:match->text :name
@@ -226,11 +233,25 @@
:precision 0
:step "1"}]]]]]]
[field "Note"
[:input.input {:type "text"
:field [:note]
:spec ::entity/note}]]
[:h2.title.is-4 "Outcomes"]
[field "Assign Vendor"
[typeahead-entity {:matches @(re-frame/subscribe [::subs/vendors])
:match->text :name
:type "typeahead-entity"
:auto-focus (if @(re-frame/subscribe [::subs/vendors]) false true)
:field [:vendor]
:spec ::entity/vendor}]]
[field nil
[expense-accounts-field {:type "expense-accounts"
:descriptor "account asssignment"
:percentage-only? true
:locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))])
:max 100
:field [:expense-accounts]}]]
[error-notification]

View File

@@ -189,7 +189,6 @@
(when (and spec (not (s/valid? spec (get-in subscription field))))
" is-danger")))
keys (dissoc keys :field :subscription :spec)]
(into [dom keys] (with-keys rest))))
(defmethod do-bind "number" [dom {:keys [field precision event subscription class spec] :as keys :or {precision 2}} & rest]