Trying one fix

This commit is contained in:
Bryce Covert
2022-12-10 13:37:25 -08:00
parent a9f71ef3f3
commit 5e260f2f9d
6 changed files with 60 additions and 110 deletions

View File

@@ -21,20 +21,6 @@
:cljs (au/date->str d au/pretty)))
(def ranges
{:assets [11000 19999]
:liabilities [20100 28999]
:equities [30000 39999]
:sales [40000 49999]
:cogs [50000 59999]
:payroll [60000 69999]
:controllable [70000 79999]
:fixed-overhead [80000 89999]
:ownership-controllable [90000 99999]
:operating-activities [10000 99999]
:investment-activities [10000 99999]
:financing-activities [10000 99999]
:bottom-line [10000 99999]})
(def groupings
{:assets [["1100 Cash and Bank Accounts" 11000 11999]
@@ -93,18 +79,24 @@
:investment-activities [["14000-18000 Investments" 14000 17999]]
:financing-activities [["28000-35000 Financing Activities" 28000 34999]
["35001-40000 Other" 35001 39999]]
["35000-40000 Other" 35000 39999]]
:bottom-line [["11000-12000 Bottom Line" 11000 11999]]})
(def flat-categories
(for [[category groups] groupings
[_ start end] groups]
[category start end]))
(defn in-range? [code]
(if code
(reduce
(fn [acc [start end]]
(fn [acc [_ start end]]
(if (<= start code end)
(reduced true)
acc))
false
(vals ranges))
flat-categories)
false))
(defn client-locations [pnl-data]
@@ -135,8 +127,8 @@
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))
(defn best-category [a]
(->> ranges
(filter (fn [[_ [start end]]]
(->> flat-categories
(filter (fn [[category start end]]
(and (:numeric-code a)
(<= start (:numeric-code a) end))))
first
@@ -164,19 +156,29 @@
data)))
(update :filters (fn [f]
(assoc f
:from-numeric-code from
:to-numeric-code to)))))
:numeric-code [{:from from
:to to}])))))
(defn account-belongs-in-category? [numeric-code category]
(->> (groupings category)
(some (fn [[_ from to]]
(<= from (or numeric-code 0) to)))))
;; TODO make click-through work for multiple ranges :fliters
(defn filter-categories [pnl-data categories]
(if (= 1 (count categories))
(let [[from to] (ranges (first categories))]
(-> pnl-data
(filter-numeric-code from to)))
(-> pnl-data
(update :data (fn [data]
(mapcat identity
((apply juxt categories)
(group-by best-category data))))))))
(-> pnl-data
(update :data
(fn [data]
(for [account data
:when (some #(account-belongs-in-category? (:numeric-code account) %) categories)]
account)))
(update :filters
(fn [f]
(assoc f :numeric-code
(for [category categories
[_ from to] (groupings category)]
{:from from
:to to}))))))
(defn filter-period [pnl-data period]
(-> pnl-data
@@ -216,10 +218,11 @@
:bold true}]
(map
(fn [p]
(println "FILTERS" (:filters p))
(merge
{:format :dollar
:value (aggregate-accounts p)
:filters (when (:from-numeric-code (:filters p)) ;; don't allow filtering when you don't at least filter numeric codes
:filters (when (:numeric-code (:filters p)) ;; don't allow filtering when you don't at least filter numeric codes
(:filters p))}
(:cell-args p)
cell-args))
@@ -473,52 +476,12 @@
(into (detail-rows pnl-datas
:bottom-line
(str prefix " Bottom Line")))
#_(into (detail-rows pnl-datas
:cogs
(str prefix " COGS")))
#_(into (detail-rows
pnl-datas
:payroll
(str prefix " Payroll")))
#_(conj (subtotal-by-column-row (map #(filter-categories % [:payroll :cogs])
pnl-datas)
(str prefix " Prime Costs")))
#_(conj (subtotal-by-column-row (map #(-> %
(filter-categories [:sales :payroll :cogs])
(negate #{:payroll :cogs}))
pnl-datas)
(str prefix " Gross Profits")))
#_(into (detail-rows
pnl-datas
:controllable
(str prefix " Controllable Expenses")))
#_(into (detail-rows
pnl-datas
:fixed-overhead
(str prefix " Fixed Overhead")))
#_(into (detail-rows
pnl-datas
:ownership-controllable
(str prefix " Ownership Controllable")))
#_(conj (subtotal-by-column-row (map #(filter-categories % [:controllable :fixed-overhead :ownership-controllable]) pnl-datas)
(str prefix " Overhead")))
#_(conj (subtotal-by-column-row (map #(-> %
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
pnl-datas)
(str prefix " Net Income"))))
#_table #_(if (seq client-datas)
(conj table (subtotal-by-column-row (map #(-> %
(filter-categories [:sales :cogs :payroll :controllable :fixed-overhead :ownership-controllable])
(negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable}))
client-datas)
"All Location Net Income"))
table)
(str prefix " Bottom Line"))))
percent-of-sales (calc-percent-of-sales table pnl-datas)
deltas (into [] (calc-deltas table))]
{:header (headers pnl-datas title)
:rows (combine-tables pnl-datas table percent-of-sales deltas)}))
:rows table}))
(defn warning-message [pnl-data]
(let [errors (->> pnl-data
@@ -599,7 +562,6 @@
(for [[client-id location] (client-locations pnl-data)]
(-> pnl-data
(filter-client client-id)
(filter-location location)
(filter-period period)
(zebra i)))
[(-> pnl-data
@@ -611,7 +573,6 @@
(cash-flows-location-detail-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
(-> pnl-data
(filter-client client-id)
(filter-location "A")
(filter-period period)
(zebra i)))
(str (-> pnl-data :clients-by-id (get client-id)) " Detail")