starting work on cash flow.

This commit is contained in:
Bryce Covert
2020-06-15 08:19:43 -07:00
parent bd17cd3caa
commit ef843ac9a2
11 changed files with 136 additions and 20 deletions

View File

@@ -13,7 +13,7 @@
[auto-ap.views.components.address :refer [address-field]]
[auto-ap.views.components.layouts :refer [side-bar-layout appearing-side-bar side-bar] ]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field]]
[auto-ap.views.utils :refer [login-url dispatch-event dispatch-value-change bind-field horizontal-field nf]]
[auto-ap.views.components.modal :refer [action-modal]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
@@ -58,6 +58,12 @@
:city (:city (:address new-client-data))
:state (:state (:address new-client-data))
:zip (:zip (:address new-client-data))}
:forecasted-transactions (map (fn [{:keys [id day-of-month identifier amount]}]
{:id id
:day-of-month day-of-month
:identifier identifier
:amount amount})
(:forecasted-transactions new-client-data))
:bank-accounts (map (fn [{:keys [number name check-number include-in-reports type id code bank-name routing bank-code new? sort-order visible yodlee-account-id locations]}]
{:number number
:name name
@@ -101,6 +107,7 @@
[:id :name :code :email :locations :matches :weekly-debits :weekly-credits
[:location-matches [:location :match]]
[:address [:street1 :street2 :city :state :zip]]
[:forecasted-transactions [:id :amount :identifier :day-of-month]]
[:bank-accounts [:id :number :check-number :name :code :bank-code :bank-name :routing :type :visible :yodlee-account-id :sort-order :locations]]]]}]}
:on-success [::save-complete]
:on-error [::forms/save-error ::new-client]}}
@@ -157,6 +164,28 @@
(update :location-matches conj (:location-match client))
(dissoc :location-match))))
(re-frame/reg-event-db
::add-forecasted-transaction
[(forms/in-form ::form) (re-frame/path [:data])]
(fn [client _]
(-> client
(update :forecasted-transactions conj (assoc (:new-forecasted-transaction client) :temp-id (random-uuid)))
(dissoc :new-forecasted-transaction))))
(re-frame/reg-event-db
::remove-forecasted-transaction
[(forms/in-form ::form) (re-frame/path [:data])]
(fn [client [_ which]]
(-> client
(update :forecasted-transactions #(transduce
(filter (fn [x] (and (not= (:temp-id x) which)
(not= (:id x) which))))
conj
[]
%)))))
(re-frame/reg-event-db
::remove-location-match
[(forms/in-form ::form) (re-frame/path [:data])]
@@ -506,6 +535,7 @@
[:div.column.is-third
[:a.button.is-primary.is-outlined.is-fullwidth {:on-click (dispatch-event [::add-new-bank-account :cash])} "Add Cash Account"]]]
[:h2.subtitle "Cash flow"]
[field "Weekly credits"
[:input.input {:type "number"
:placeholder "250.00"
@@ -516,8 +546,42 @@
:placeholder "250.00"
:field [:weekly-debits]
:step "0.01"}]]
[:div.field
[:label.label "Forecasted transactions"]
[:div.control
[horizontal-field
nil
[:p.control
[:p.help "Identifier"]
[raw-field
[:input.input {:type "text"
:placeholder "Identifier"
:field [:new-forecasted-transaction :identifier]}]]]
[:p.control
[:p.help "Day of month"]
[raw-field
[:input.input {:type "number"
:placeholder "Day of month"
:step "1"
:field [:new-forecasted-transaction :day-of-month]}]]]
[:p.control
[:p.help "Amount"]
[raw-field
[:input.input {:type "number"
:placeholder "250.00"
:field [:new-forecasted-transaction :amount]
:step "0.01"}]]]
[:a.button {:on-click (dispatch-event [::add-forecasted-transaction])} "Add"]]]
[:ul
(for [forecasted-transaction (:forecasted-transactions new-client)]
^{:key (or (:id forecasted-transaction)
(:temp-id forecasted-transaction))}
[:li (:identifier forecasted-transaction) ": " (nf (:amount forecasted-transaction)) " on day " (:day-of-month forecasted-transaction) " of the month"
[:a {:on-click (dispatch-event [::remove-forecasted-transaction (or (:id forecasted-transaction)
(:temp-id forecasted-transaction))])} [:span.icon [:span.fa.fa-times]]]])]]
[error-notification]
[submit-button "Save"]]]))