so many bug fixes.

This commit is contained in:
Bryce Covert
2020-07-03 17:50:37 -07:00
parent 3de59d3fdc
commit 86f51f93e4
22 changed files with 1447 additions and 521 deletions

View File

@@ -7,7 +7,7 @@
(re-frame/reg-sub
::form
(fn [db [_ x]]
(-> db ::forms x)))
(get (-> db ::forms) x)))
(re-frame/reg-sub
@@ -47,7 +47,7 @@
:after (fn [context]
(let [db (i/get-coeffect context :db)
result (get-in (i/get-coeffect context :event) [1 data-key])]
(println (get-in db [::forms form :complete-listener]))
(cond-> context
true
(i/assoc-effect :db (update-in db
@@ -95,7 +95,8 @@
(re-frame/reg-event-db
::save-error
(fn [db [_ form result]]
(println form result)
(println result)
(-> db
(assoc-in [::forms form :status] :error)
(assoc-in [::forms form :error] (or (:message (first result))
@@ -114,7 +115,6 @@
(i/->interceptor
:id :settles
:befor (fn [context]
(println "here2")
context)
:after (fn [context]
(i/assoc-effect context :dispatch-debounce {:event event
@@ -143,18 +143,20 @@
(defn vertical-form [{:keys [can-submit id change-event submit-event ]}]
{:form (fn [{:keys [title] :as params} & children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
can-submit @(re-frame/subscribe can-submit)]
(into ^{:key id} [:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(when can-submit
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
[:h1.title.is-2 title]]
children)))
{:form ^{:key "form"}
(fn [{:keys [title] :as params} & children]
(let [{:keys [data active? error]} @(re-frame/subscribe [::form id])
can-submit @(re-frame/subscribe can-submit)]
[:form { :on-submit (fn [e]
(when (.-stopPropagation e)
(.stopPropagation e)
(.preventDefault e))
(when can-submit
(re-frame/dispatch-sync (vec (conj submit-event params)))))}
[:h1.title.is-2 title]
[:<>
children]]))
:raw-field (fn [control]
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
[bind-field (-> control
@@ -164,18 +166,20 @@
[:div.field
(when label [:p.help label])
[:div.control control]])
:field (fn [label control]
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
[:div.field
(when label [:p.help label])
[:div.control [bind-field (-> control
(assoc-in [1 :subscription] data)
(assoc-in [1 :event] change-event))]]]))
:field ^{:key "field"}
(fn [label control]
(let [{:keys [data]} @(re-frame/subscribe [::form id])]
[:div.field
(when label [:p.help label])
[:div.control [bind-field (-> control
(assoc-in [1 :subscription] data)
(assoc-in [1 :event] change-event))]]]))
:error-notification (fn []
(when-let [error (:error @(re-frame/subscribe [::form id]))]
^{:key error}
[:div.notification.is-warning.animated.fadeInUp error]))
:error-notification
(fn []
(when-let [error (:error @(re-frame/subscribe [::form id]))]
^{:key error}
[:div.notification.is-warning.animated.fadeInUp {} error]))
:submit-button (fn [child]
(let [error (:error @(re-frame/subscribe [::form id]))]
[:button.button.is-medium.is-primary.is-fullwidth {:disabled (if @(re-frame/subscribe can-submit)

View File

@@ -32,31 +32,4 @@
:event on-change-event
:step "0.01"
:subscription value}]]]]]]
#_[:div
[:div.field.has-addons
[:div.control
[bind-field
[date-picker {:class-name "input is-fullwidth"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder-text "Start"
:next-month-button-label ""
:next-month-label ""
:event on-change-event
:type "date"
:field [:start]
:subscription value}]]]
[:div.control
[bind-field
[date-picker {:class-name "input is-fullwidth"
:class "input"
:format-week-number (fn [] "")
:previous-month-button-label ""
:placeholder-text "End"
:next-month-button-label ""
:event on-change-event
:next-month-label ""
:type "date"
:field [:end]
:subscription value}]]]]])
)

View File

@@ -147,28 +147,33 @@
[horizontal-field
[:label.label "Default"]
[bind-field
(assoc-in template [1 :field ] default-key)]]
(template default-key nil)
#_(assoc-in template [1 :field ] default-key)]]
(when is-admin?
[horizontal-field
[:label.label "Overrides"]
(for [[i override] (map vector (range) (conj (override-key data) {:key (random-uuid)}))]
^{:key (or
(:id override)
(:key override))}
[:div.columns
[:div.column
[bind-field
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[:div.column
[bind-field
(assoc-in template [1 :field ] [override-key i :override])]]
[:div.column.is-1
[:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]])])]))
(doall
(for [[i override] (map vector (range) (conj (override-key data) {:key (random-uuid)}))]
^{:key (or
(:id override)
(:key override))}
[:div.columns
[:div.column
[bind-field
[typeahead-entity {:matches clients
:match->text :name
:type "typeahead-entity"
:field [override-key i :client]
:event change-event
:subscription data}]]]
[:div.column
[bind-field
(template
[override-key i :override]
(get-in data [override-key i :client])
)]]
[:div.column.is-1
[:a.button {:on-click (dispatch-event [::removed-override override-key i])} [:span.icon [:span.icon-remove]]]]]))])]))
(defn form-content [{:keys [data change-event]}]
(let [accounts @(re-frame/subscribe [::subs/accounts])
@@ -210,23 +215,28 @@
[default-with-overrides {:data data :change-event change-event
:default-key :terms
:override-key :terms-overrides}
[:input.input {:type "number"
:step "1"
:style {:width "4em"}
:size 3
:spec ::entity/terms
:event change-event
:subscription data}]]
(fn [field client]
[:input.input {:type "number"
:step "1"
:style {:width "4em"}
:field field
:size 3
:spec ::entity/terms
:event change-event
:subscription data}])]
[:h2.subtitle "Expense Accounts"]
[default-with-overrides {:data data :change-event change-event
:default-key :default-account
:override-key :account-overrides}
[typeahead-entity {:matches accounts
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:type "typeahead-entity"
:event change-event
:subscription data}]]
(fn [field client]
[typeahead-entity {:matches @(re-frame/subscribe [::subs/accounts client])
:match->text (fn [x ] (str (:numeric-code x) " - " (:name x)))
:field field
:type "typeahead-entity"
:event change-event
:subscription data}])]
[:h2.subtitle "Address"]
[address-field {:field [:address]

View File

@@ -1,15 +1,17 @@
(ns auto-ap.views.pages.admin.yodlee
(:require-macros [cljs.core.async.macros :refer [go]])
(:require [re-frame.core :as re-frame]
[auto-ap.forms :as forms]
[reagent.core :as reagent]
[clojure.string :as str]
[cljs-time.format :as f]
[auto-ap.subs :as subs]
[auto-ap.events.admin.clients :as events]
[auto-ap.entities.clients :as entity]
[auto-ap.views.components.layouts :refer [side-bar-layout]]
[auto-ap.views.components.admin.side-bar :refer [admin-side-bar]]
[auto-ap.views.components.address :refer [address-field]]
[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 str->date date->str with-user]]
[auto-ap.views.components.modal :refer [action-modal]]
[cljs.reader :as edn]
[auto-ap.routes :as routes]
@@ -22,6 +24,11 @@
(fn [db]
(-> db ::yodlee :authentication)))
(re-frame/reg-sub
::can-submit
(fn [db]
true))
(re-frame/reg-sub
::loading?
(fn [db]
@@ -37,6 +44,16 @@
(fn [db]
(-> db ::yodlee :accounts-loading?)))
(re-frame/reg-sub
::provider-accounts-loading?
(fn [db]
(-> db ::provider-accounts-loading?)))
(re-frame/reg-sub
::provider-accounts
(fn [db]
(-> db ::provider-accounts)))
(re-frame/reg-event-fx
::authenticate-with-yodlee
(fn [{:keys [db]} _]
@@ -51,40 +68,34 @@
(re-frame/reg-event-fx
::mounted
(fn [{:keys [db]} _]
{:db (assoc-in db [::yodlee] {:accounts-loading? true})
{:db (-> db
(assoc ::yodlee {:provider-accounts-loading? true})
#_(assoc ::provider-accounts [])
#_(assoc ::provider-accounts-loading? true))
:http {:token (:user db)
:method :get
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/accounts")
:on-success [::got-accounts]
:uri (str "/api/yodlee/provider-accounts")
:on-success [::got-provider-accounts]
:on-error [::save-error]}}))
(re-frame/reg-event-fx
::kicked
(fn [{:keys [db]} [_ id state]]
{:db (update-in db [::yodlee :accounts]
(fn [as]
(map (fn [a]
(if (= (:id a) id)
(assoc a :status state)
a))
as)))}))
{:dispatch [::mounted]}))
(re-frame/reg-event-fx
::kicked
(fn [{:keys [db]} [_ id state]]
{:dispatch [::mounted]}))
(re-frame/reg-event-fx
::kick
(fn [{:keys [db]} [_ id]]
{:db (update-in db [::yodlee :accounts]
(fn [as]
(map (fn [a]
(if (= (:id a) id)
(assoc a :status :kicking)
a))
as)))
:http {:token (:user db)
{:http {:token (:user db)
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/accounts/" id)
:uri (str "/api/yodlee/provider-accounts/" id)
:on-success [::kicked id :kicked]
:on-error [::kicked id :errored]}}))
@@ -95,14 +106,22 @@
(assoc-in [::yodlee :accounts] accounts)
(assoc-in [::yodlee :accounts-loading?] false))}))
(re-frame/reg-event-fx
::got-provider-accounts
(fn [{:keys [db]} [_ accounts]]
{:db (-> db
(assoc-in [::provider-accounts] accounts)
(assoc-in [::provider-accounts-loading?] false))}))
(re-frame/reg-event-fx
::authenticated
(fn [{:keys [db]} [_ authentication]]
{:db (-> db
(assoc-in [::yodlee :authentication] authentication)
(assoc-in [::yodlee :loading?] false))}))
{:dispatch [::mounted]}))
(re-frame/reg-event-fx
::save-error
(fn [{:keys [db]} [_ authentication]]
{:dispatch [::mounted]}))
(defn yodlee-link-button []
[:div
@@ -130,7 +149,16 @@
[:button.button.is-primary {:class (if loading? "is-loading" "") :on-click (dispatch-event [::authenticate-with-yodlee])} "Authenticate with Yodlee"]))])
(defn yodlee-accounts-table []
(defn yodlee-date->str [d]
(try
(or (some-> d
(str->date (:date-time-no-ms f/formatters))
date->str)
"N/A")
(catch js/Error e
"N/A")))
(defn yodlee-accounts-table [accounts]
[:div
[:table.table
@@ -139,41 +167,132 @@
[:th "Account Name"]
[:th "Account Number"]
[:th "Yodlee Account Number"]
[:th "Yodlee Last updated"]
[:th "Yodlee Status"]
[:th]]]
[:th "Balance"]
[:th "Yodlee Status"]]]
[:tbody
(if @(re-frame/subscribe [::accounts-loading?])
[:tr [:td {:col-span "6"} "Loading..."]
]
(for [account @(re-frame/subscribe [::accounts])]
^{:key (:id account)} [:tr
[:td (:accountName account)]
[:td (:accountNumber account)]
[:td (:id account)]
[:td (str/join ", " (map :lastUpdated (:dataset account)))]
[:td (str/join ", " (map :additionalStatus (:dataset account)))]
[:td
(cond (= (:status account) :kicking)
[:button.button.is-success.is-loading {:disabled "disabled"} "Kick."]
(for [account accounts]
^{:key (:id account)} [:tr
[:td (:accountName account)]
[:td (:accountNumber account)]
[:td (:id account)]
[:td.has-text-right (:amount (:balance account))]
[:td (str/join ", " (map :additionalStatus (:dataset account)))]
])]]])
(= (:status account) :kicked)
[:button.button {:disabled "disabled"} "In progress..."]
(re-frame/reg-event-fx
::reauthenticate-mfa
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:db (forms/loading db [::mfa-form provider-account-id])
:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/reauthenticate/" provider-account-id )
:body {"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
(:data (get-in db [::forms/forms [::mfa-form provider-account-id]])))}
:on-success [::authenticated]
:on-error [::forms/save-error [::mfa-form provider-account-id] ]}}))
(= (:status account) :errored)
[:button.button.is-danger {:disabled "disabled"} "Error."]
(re-frame/reg-event-fx
::reauthenticate
[with-user ]
(fn [{:keys [user db]} [_ provider-account-id ]]
{:db (forms/loading db [::login-form provider-account-id])
:http {:token user
:method :post
:headers {"Content-Type" "application/edn"}
:uri (str "/api/yodlee/reauthenticate/" provider-account-id )
:body {"loginForm"
{"row"
[{"field"
(mapv (fn [[k v]]
{"id" k
"value" v})
(:data (get-in db [::forms/forms [::login-form provider-account-id]])))}]}}
:on-success [::authenticated]
:on-error [::forms/save-error [::login-form provider-account-id]]}}))
:else
[:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Kick." ])]]))]])
(defn yodlee-provider-accounts-table []
(if @(re-frame/subscribe [::provider-accounts-loading?])
[:div "Loading..."]
[:div.columns
[:div.column.is-three-quarters
(doall
(for [account @(re-frame/subscribe [::provider-accounts])]
^{:key (:id account)}
[:div.card {:style {:margin-bottom "1em"}}
[:div.card-header
[:div.card-header-title "Provider account " (:id account)
]]
[:div.card-content
[:div.notification.is-info.is-light
[:div.level
[:div.level-left
[:div.level-item
[:p
"This account was last updated on "
(yodlee-date->str (-> account :dataset first :lastUpdated))
", and last attempted "
(yodlee-date->str (-> account :dataset first :lastUpdateAttempt))
"."]]]
[:div.level-right [:button.button.is-success {:on-click (dispatch-event [::kick (:id account)] )} "Force refresh" ]]]
]
[:div.notification.is-info.is-warning
[:div.level
[:div.level-left
[:div.level-item
"This provider account's status is '"
(-> account :dataset first :additionalStatus)
"'. If this is in error, it might help to try reauthenticating by filling out the form below."]]]]
[yodlee-accounts-table (:accounts account)]
[:div
(if (:field account)
(for [f (:field account)]
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form [::mfa-form (:id account)]])
change-event [::forms/change [::mfa-form (:id account)]]
{:keys [form field field-holder raw-field error-notification submit-button]} (forms/vertical-form {:can-submit [::can-submit]
:change-event change-event
:submit-event [::reauthenticate-mfa (:id account)]
:id [::mfa-form (:id account)]} )]
(form {:title "Reauthenticate (login)"}
(error-notification)
(for [f (-> account :field)]
^{:key (:id f)}
(field (:label f)
[:input.input {:type "text" :field [(:id f)] :value (-> f :field first :value)}]))
(submit-button "Reauthenticate"))))
(let [{error :error account-data :data } @(re-frame/subscribe [::forms/form [::login-form (:id account)]])
change-event [::forms/change [::login-form (:id account)]]
{:keys [form field field-holder raw-field error-notification submit-button]} (forms/vertical-form {:can-submit [::can-submit]
:change-event change-event
:submit-event [::reauthenticate (:id account)]
:id [::login-form (:id account)]} )]
(form {:title "Reauthenticate (MFA)"}
(error-notification)
(for [f (-> account :loginForm first :row)]
^{:key (:id f)}
(field (:label f)
[:input.input {:type "text" :field [(:id f)] :value (-> f :field first :value)}]))
(submit-button "Reauthenticate"))))]]]))]]))
(defn admin-yodlee-content []
[(with-meta
(fn []
[:div
[:h1.title "Yodlee"]
[:h1.title "Yodlee provider accounts"]
[yodlee-accounts-table]
[yodlee-provider-accounts-table]
[yodlee-link-button]])
{:component-did-mount (fn []
(re-frame/dispatch [::mounted]))})])

View File

@@ -11,7 +11,7 @@
(def ranges
{:sales [40000 48999]
:cogs [50000 59999]
:payroll [60000 62999]
:payroll [60000 69999]
:controllable [70000 79999]
:fixed-overhead [80000 89999]
:ownership-controllable [90000 99999]})
@@ -98,6 +98,16 @@
(fn [[accounts] _]
(reduce + 0 (map :amount (vals accounts)))))
(re-frame/reg-sub
::percent-of-sales
(fn [[_ type only-location]]
[(re-frame/subscribe [::amount :sales only-location])
(re-frame/subscribe [::amount type only-location])])
(fn [[sales accounts] _]
(if (> (or sales 0) 0 )
(/ accounts sales)
0.0)))
(re-frame/reg-sub
::comparable-percent-of-sales
(fn [[_ type only-location]]
@@ -293,78 +303,76 @@
(defn grouping [{:keys [header accounts comparable-accounts groupings location sales comparable-sales]}]
(for [[grouping-name from to] groupings
:let [matching-accounts (filter
#(<= from (:numeric-code %) to)
accounts)
total (reduce + 0 (map :amount matching-accounts))
comparable-total (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0) matching-accounts))]
:when (seq matching-accounts)
]
(list
^{:key "title"}
[:tr [:th "---" grouping-name "---"]
[:td]
[:td]
[:td]
[:td]
[:td]
]
^{:key "detail"}
(for [account matching-accounts]
^{:key (:name account)}
[:tr [:td (:name account)]
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :current])}
(->$ (:amount account))]]
[:td.has-text-right (->% (if (> sales 0)
(/ (:amount account) sales)
0.0))]
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :comparable])}
(->$ (:amount (get comparable-accounts (:id account)) 0))]]
[:td.has-text-right (->% (if (> comparable-sales 0)
(/ (:amount (get comparable-accounts (:id account)) 0) sales)
0.0))]
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))]])
[:<>
(for [[grouping-name from to] groupings
:let [matching-accounts (filter
#(<= from (:numeric-code %) to)
accounts)
total (reduce + 0 (map :amount matching-accounts))
comparable-total (reduce + 0 (map #(:amount (get comparable-accounts (:id %)) 0) matching-accounts))]
:when (seq matching-accounts)
]
^{:key grouping-name}
[:<>
[:tr [:td "---" grouping-name "---"]
[:td]
[:td]
[:td]
[:td]
[:td]
]
[:<>
(for [account matching-accounts]
^{:key (:name account)}
[:tr [:td (:name account)]
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :current])}
(->$ (:amount account))]]
[:td.has-text-right (->% (if (> sales 0)
(/ (:amount account) sales)
0.0))]
[:td.has-text-right [:a {:on-click (dispatch-event [::investigate-clicked location (:numeric-code account) (:numeric-code account) :comparable])}
(->$ (:amount (get comparable-accounts (:id account)) 0))]]
[:td.has-text-right (->% (if (> comparable-sales 0)
(/ (:amount (get comparable-accounts (:id account)) 0) sales)
0.0))]
[:td.has-text-right (->$ (- (:amount account ) (:amount (get comparable-accounts (:id account)) 0)))]])]
^{:key "total"}
[:tr [:th "---" grouping-name "---"]
[:th.has-text-right.total [:a
{:on-click (dispatch-event [::investigate-clicked location from to :current])}
(->$ total)] ]
[:th.has-text-right.total (->% (if (> sales 0)
(/ total sales)
0.0))]
[:th.has-text-right.total [:a
{:on-click (dispatch-event [::investigate-clicked location from to :comparable])}
(->$ comparable-total)]]
[:th.has-text-right.total (->% (if (> comparable-sales 0)
(/ comparable-total sales)
0.0))]
[:th.has-text-right.total (->$ (- total comparable-total))]
[:td]
])))
[:tr [:th ]
[:th.has-text-right.total [:a
{:on-click (dispatch-event [::investigate-clicked location from to :current])}
(->$ total)] ]
[:th.has-text-right.total (->% (if (> sales 0)
(/ total sales)
0.0))]
[:th.has-text-right.total [:a
{:on-click (dispatch-event [::investigate-clicked location from to :comparable])}
(->$ comparable-total)]]
[:th.has-text-right.total (->% (if (> comparable-sales 0)
(/ comparable-total sales)
0.0))]
[:th.has-text-right.total (->$ (- total comparable-total))]
[:td]
]
[:tr [:td]]])])
(defn overall-grouping [type title location]
(let [accounts @(re-frame/subscribe [::accounts type location])
min-numeric-code (or (first (map :numeric-code accounts)) 0)
max-numeric-code (or (last (map :numeric-code accounts)) 0)]
(list
^{:key "title"}
[:tr [:th.has-text-centered title]
[:<>
[:tr [:th.is-size-5 title]
[:td]
[:td]
[:td]]
^{:key "grouping"}
(grouping {:accounts accounts
[grouping {:accounts accounts
:location location
:groupings (type groupings)
:comparable-accounts @(re-frame/subscribe [::comparable-accounts-by-id type location])
:sales @(re-frame/subscribe [::amount :sales location])
:comparable-sales @(re-frame/subscribe [::comparable-amount :sales location])})
:comparable-sales @(re-frame/subscribe [::comparable-amount :sales location])}]
^{:key "total"}
[:tr [:th.has-text-centered title]
[:tr [:th.is-size-5 title]
[:th.has-text-right [:a
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
(->$ @(re-frame/subscribe [::amount type location]))]]
@@ -374,7 +382,7 @@
(->$ @(re-frame/subscribe [::comparable-amount type location]))]]
[:th.has-text-right (->% @(re-frame/subscribe [::comparable-percent-of-sales type location]))]
[:th.has-text-right (->$ (- @(re-frame/subscribe [::amount type location])
@(re-frame/subscribe [::comparable-amount type location])))]])))
@(re-frame/subscribe [::comparable-amount type location])))]]]))
(defn subtotal [types negs title location]
(let [accounts (transduce (comp
@@ -400,7 +408,7 @@
max-numeric-code (or (last (map :numeric-code accounts)) 0)
sales @(re-frame/subscribe [::amount :sales location])
comparable-sales @(re-frame/subscribe [::comparable-amount :sales location])]
[:tr [:th.has-text-centered title]
[:tr [:th.is-size-5 title]
[:td.has-text-right [:a
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
(->$ (reduce + 0 (map :amount accounts)))]]
@@ -418,6 +426,42 @@
[:td.has-text-right (->$ (- (reduce + 0 (map :amount accounts))
(reduce + 0 (map :amount comparable))))]]))
(defn location-rows [location]
[:<>
[overall-grouping :sales (str location " Sales") location]
[overall-grouping :cogs (str location " COGS") location]
[overall-grouping :payroll (str location " Payroll") location]
[subtotal [:payroll :cogs] #{} (str location " Prime Costs") location]
[subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location]
[overall-grouping :controllable (str location " Controllable Expenses") location]
[overall-grouping :fixed-overhead (str location " Fixed Overhead") location]
[overall-grouping :ownership-controllable (str location " Ownership Controllable") location]
[subtotal [:controllable :fixed-overhead :ownership-controllable] #{} (str location " Overhead") location]
[subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} (str location " Net Income") location]
[subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" nil]])
(defn location-summary [location params]
[:div
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} location " Summary"]
[:table.table.compact.balance-sheet {:style {:margin-bottom "2.5rem"}}
[:tbody
[:tr
[:td.has-text-right "Period ending"]
[:td.has-text-right (date->str (str->date (:to-date params) standard))]
[:td]
[:td.has-text-right (when (:to-date params)
(date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))]
[:td]
[:td]]
[subtotal [:sales ] #{} "Sales" location]
[subtotal [:cogs ] #{} "Cogs" location]
[subtotal [:payroll ]#{} "Payroll" location]
[subtotal [:sales :payroll :cogs] #{:payroll :cogs} "Gross Profits" location]
[subtotal [:controllable :fixed-overhead :ownership-controllable] #{} "Overhead" location]
[subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" location]]]
])
(def profit-and-loss-content
(with-meta
(fn []
@@ -550,41 +594,27 @@
:else
[:div
[:<>
(for [location @(re-frame/subscribe [::locations])]
^{:key (str location "-summary")}
[location-summary location params]
)]
[:h2.title.is-4 {:style {:margin-bottom "1rem"}} "Detail"]
[:table.table.compact.balance-sheet
(list
^{:key "title"}
[:tbody
[:tr
[:td.has-text-right "Period ending"]
[:td.has-text-right "Period Ending"]
[:td.has-text-right (date->str (str->date (:to-date params) standard))]
[:td]
[:td.has-text-right (when (:to-date params)
(date->str (t/minus (str->date (:to-date params) standard) (t/years 1))))]
[:td]]
^{:key "report"}
(for [location @(re-frame/subscribe [::locations])]
^{:key location}
(list
^{:key "sales"}
(overall-grouping :sales (str location " Sales") location)
^{:key "cogs"}
(overall-grouping :cogs (str location " COGS") location)
^{:key "payroll"}
(overall-grouping :payroll (str location " Payroll") location)
^{:key "prime"}
(subtotal [:payroll :cogs] #{} (str location " Prime Costs") location)
^{:key "gross profit"}
(subtotal [:sales :payroll :cogs] #{:payroll :cogs} (str location " Gross Profits") location)
^{:key "controllable"}
(overall-grouping :controllable (str location " Controllable Expenses") location)
^{:key "fixed overhead"}
(overall-grouping :fixed-overhead (str location " Fixed Overhead") location)
^{:key "ownership"}
(overall-grouping :ownership-controllable (str location " Ownership Controllable") location)
^{:key "sub-overhead"}
(subtotal [:controllable :fixed-overhead :ownership-controllable] #{} (str location " Overhead") location)
^{:key "sub-loc-income"}
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} (str location " Net Income") location)
^{:key "sub-net-income"}
(subtotal [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable] #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable} "Net Income" nil))))]])])))
[:td]
[:td.has-text-right "𝝙"]]
[:<>
(for [location @(re-frame/subscribe [::locations])]
^{:key location}
[location-rows location]
)]]]])])))
{:component-will-mount #(re-frame/dispatch-sync [::params-change {:from-date (date->str (t/minus (local-now) (t/period :years 1)) standard)
:to-date (date->str (local-now) standard)}]) }))

View File

@@ -226,8 +226,8 @@
(re-frame/dispatch (-> event
(conj field)
(conj (let [val (.. e -target -value)]
(cond (and val (not (str/blank? val))
(not (str/ends-with? val ".")))
(cond (and val
(re-matches #"[\-]?(\d+)(\.\d{2})?" val))
(js/parseFloat val)
(str/blank? val )