adds subtotals
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
:cogs [5100 5999]
|
||||
:payroll [6010 6299]
|
||||
:controllable [7100 7999]
|
||||
:direct [8100 9999]})
|
||||
:noncontrollable [8100 9999]})
|
||||
|
||||
;; SUBS
|
||||
(re-frame/reg-sub
|
||||
@@ -77,7 +77,8 @@
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||
|
||||
(and (= only-location location)
|
||||
(and (or (nil? only-location)
|
||||
(= only-location location))
|
||||
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
||||
(sort-by :numeric-code))))
|
||||
|
||||
@@ -92,7 +93,8 @@
|
||||
:balance-sheet-accounts
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||
(and (= only-location location)
|
||||
(and (or (nil? only-location)
|
||||
(= only-location location))
|
||||
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
||||
(by :id))))
|
||||
|
||||
@@ -104,7 +106,8 @@
|
||||
:comparable-balance-sheet-accounts
|
||||
(map #(update % :amount js/parseFloat))
|
||||
(filter (fn [{:keys [account-type location numeric-code]}]
|
||||
(and (= only-location location)
|
||||
(and (or (nil? only-location)
|
||||
(= only-location location))
|
||||
(< (get-in ranges [type 0]) numeric-code (get-in ranges [type 1])))))
|
||||
(by :id))))
|
||||
|
||||
@@ -244,20 +247,20 @@
|
||||
["7400 Building and Equipment Related DirGMC Exp" 7400 7499]
|
||||
["7500 Office/ Management Related DirGMC Exp" 7500 7999]]
|
||||
|
||||
:direct [["8100 Operational" 8100 8199]
|
||||
["8200 Occupancy Costs" 8200 8299]
|
||||
["8300 Utilities" 8300 8399]
|
||||
["8400 Equipment Rental" 8400 8499]
|
||||
["8500-8700 Taxes and Insurance" 8500 8699]
|
||||
["8800 Depreciation" 8800 8899]
|
||||
["9100 Promotion and Outreach" 9100 9199]
|
||||
["9200 Employee Morale and Training" 9200 9299]
|
||||
["9300 Operational" 9300 9499]
|
||||
["9500 Interest and Bank Expenses" 9500 9599]
|
||||
["9600 Depreciation" 9600 9699]
|
||||
["9700 Taxes" 9700 9799]
|
||||
["9800 Other Expenses" 9800 9899]
|
||||
["9900 Tax Only Expenses" 9900 9999]]
|
||||
:noncontrollable [["8100 Operational" 8100 8199]
|
||||
["8200 Occupancy Costs" 8200 8299]
|
||||
["8300 Utilities" 8300 8399]
|
||||
["8400 Equipment Rental" 8400 8499]
|
||||
["8500-8700 Taxes and Insurance" 8500 8699]
|
||||
["8800 Depreciation" 8800 8899]
|
||||
["9100 Promotion and Outreach" 9100 9199]
|
||||
["9200 Employee Morale and Training" 9200 9299]
|
||||
["9300 Operational" 9300 9499]
|
||||
["9500 Interest and Bank Expenses" 9500 9599]
|
||||
["9600 Depreciation" 9600 9699]
|
||||
["9700 Taxes" 9700 9799]
|
||||
["9800 Other Expenses" 9800 9899]
|
||||
["9900 Tax Only Expenses" 9900 9999]]
|
||||
})
|
||||
|
||||
|
||||
@@ -321,6 +324,39 @@
|
||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount @(re-frame/subscribe [::accounts type location])))
|
||||
(reduce + 0 (map :amount (vals @(re-frame/subscribe [::comparable-accounts-by-id type location]))))))]])))
|
||||
|
||||
(defn subtotal [types negs title location]
|
||||
(let [accounts (transduce (comp
|
||||
(map #(map (fn [a]
|
||||
(if (negs %)
|
||||
(update a :amount -)
|
||||
a))
|
||||
(deref (re-frame/subscribe [::accounts % location])))))
|
||||
into
|
||||
[]
|
||||
types)
|
||||
comparable (transduce
|
||||
(comp
|
||||
(map #(map (fn [a]
|
||||
(if (negs %)
|
||||
(update a :amount -)
|
||||
a))
|
||||
(vals (deref (re-frame/subscribe [::comparable-accounts-by-id % location]))))))
|
||||
into
|
||||
[]
|
||||
types)
|
||||
min-numeric-code (or (first (map :numeric-code accounts)) 0)
|
||||
max-numeric-code (or (last (map :numeric-code accounts)) 0)]
|
||||
(list
|
||||
[:tr [:th.has-text-centered title]
|
||||
[:th.has-text-right [:a
|
||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :current])}
|
||||
(->$ (reduce + 0 (map :amount accounts)))]]
|
||||
[:th.has-text-right [:a
|
||||
{:on-click (dispatch-event [::investigate-clicked location min-numeric-code max-numeric-code :comparable])}
|
||||
(->$ (reduce + 0 (map :amount comparable)))]]
|
||||
[:th.has-text-right (->$ (- (reduce + 0 (map :amount accounts))
|
||||
(reduce + 0 (map :amount comparable))))]])))
|
||||
|
||||
(def profit-and-loss-content
|
||||
(with-meta
|
||||
(fn []
|
||||
@@ -439,8 +475,13 @@
|
||||
(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 :direct (str location " Direct Expenses") location))))]])]))
|
||||
(overall-grouping :noncontrollable (str location " Noncontrallable Expenses") location)
|
||||
(subtotal [:controllable :noncontrollable] #{} (str location " Overhead") location)
|
||||
(subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} (str location " Net Income") location)
|
||||
(subtotal [:sales :cogs :payroll :controllable :noncontrollable] #{:cogs :payroll :controllable :noncontrollable} "Net Income" nil))))]])]))
|
||||
{: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