so many bug fixes.
This commit is contained in:
@@ -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)}]) }))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user