tweak for cash flow
This commit is contained in:
@@ -71,6 +71,8 @@
|
||||
(conj acc (merge {:id (str account-id "-" location)
|
||||
:location (or location "")
|
||||
:count count
|
||||
:debits debit
|
||||
:credits credit
|
||||
:amount (if account-type (if (#{:account-type/asset
|
||||
:account-type/dividend
|
||||
:account-type/expense} account-type)
|
||||
@@ -609,6 +611,8 @@
|
||||
{:balance_sheet_account
|
||||
{:fields {:id {:type 'String}
|
||||
:amount {:type 'String}
|
||||
:debits {:type :money}
|
||||
:credits {:type :money}
|
||||
:location {:type 'String}
|
||||
:client_id {:type :id}
|
||||
:count {:type 'Int}
|
||||
|
||||
@@ -136,6 +136,12 @@
|
||||
(defn aggregate-accounts [pnl-data]
|
||||
(reduce (fnil + 0.0) 0.0 (map :amount (:data pnl-data))))
|
||||
|
||||
(defn aggregate-credits [pnl-data]
|
||||
(reduce (fnil + 0.0) 0.0 (map :credits (:data pnl-data))))
|
||||
|
||||
(defn aggregate-debits [pnl-data]
|
||||
(reduce (fnil + 0.0) 0.0 (map :debits (:data pnl-data))))
|
||||
|
||||
(defn best-category [a]
|
||||
(->> flat-categories
|
||||
(filter (fn [[category start end]]
|
||||
@@ -228,7 +234,6 @@
|
||||
:bold true}]
|
||||
(map
|
||||
(fn [p]
|
||||
(println "FILTERS" (:filters p))
|
||||
(merge
|
||||
{:format :dollar
|
||||
:value (aggregate-accounts p)
|
||||
@@ -238,6 +243,35 @@
|
||||
cell-args))
|
||||
pnl-datas)))
|
||||
|
||||
(defn cashflow-subtotal-by-column-row [pnl-datas title & [cell-args]]
|
||||
(into [{:value title
|
||||
:bold true}]
|
||||
(mapcat
|
||||
(fn [p]
|
||||
[
|
||||
(merge
|
||||
{:format :dollar
|
||||
:value (aggregate-credits p)
|
||||
: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)
|
||||
(merge
|
||||
{:format :dollar
|
||||
:value (aggregate-debits p)
|
||||
: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)
|
||||
(merge
|
||||
{:format :dollar
|
||||
:value (aggregate-accounts p)
|
||||
: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)])
|
||||
pnl-datas)))
|
||||
|
||||
(defn calc-percent-of-sales [table pnl-datas]
|
||||
(let [sales (map
|
||||
(fn [p]
|
||||
@@ -383,7 +417,8 @@
|
||||
:rows (combine-tables pnl-datas table percent-of-sales deltas)}))
|
||||
|
||||
|
||||
(defn detail-rows [pnl-datas grouping title]
|
||||
(defn detail-rows
|
||||
[pnl-datas grouping title]
|
||||
(let [pnl-datas (map #(filter-categories % [grouping])
|
||||
pnl-datas)
|
||||
individual-accounts
|
||||
@@ -472,25 +507,75 @@
|
||||
{:header (headers pnl-datas title)
|
||||
:rows (combine-tables pnl-datas table percent-of-sales deltas)}))
|
||||
|
||||
(defn cash-flows-location-detail-table [pnl-datas #_client-datas title prefix]
|
||||
|
||||
(defn cash-flow-detail-rows
|
||||
[pnl-datas grouping title]
|
||||
(let [pnl-datas (map #(filter-categories % [grouping])
|
||||
pnl-datas)
|
||||
individual-accounts
|
||||
(for [[grouping-name from to] (groupings grouping)
|
||||
:let [pnl-datas (map #(filter-numeric-code % from to)
|
||||
pnl-datas)
|
||||
account-codes (used-accounts pnl-datas)]
|
||||
:when (seq account-codes)
|
||||
row (-> [(into [{:value (str "---" grouping-name "---")}]
|
||||
(map
|
||||
(fn [p]
|
||||
(assoc (:cell-args p) :value "" :format ""))
|
||||
pnl-datas)
|
||||
)]
|
||||
(into (for [{:keys [numeric-code name]} account-codes]
|
||||
(into [{:value name}]
|
||||
(mapcat
|
||||
(fn [p]
|
||||
(let [pnl-data (-> p (filter-numeric-code numeric-code numeric-code))]
|
||||
[(merge
|
||||
{:format :dollar
|
||||
:filters (:filters pnl-data)
|
||||
:value (aggregate-credits pnl-data)}
|
||||
(:cell-args p))
|
||||
(merge
|
||||
{:format :dollar
|
||||
:filters (:filters pnl-data)
|
||||
:value (aggregate-debits pnl-data)}
|
||||
(:cell-args p))
|
||||
(merge
|
||||
{:format :dollar
|
||||
:filters (:filters pnl-data)
|
||||
:value (aggregate-accounts pnl-data)}
|
||||
(:cell-args p))]))
|
||||
|
||||
pnl-datas))))
|
||||
(conj (cashflow-subtotal-by-column-row pnl-datas "" {:border [:top]})))]
|
||||
row)]
|
||||
(-> [(into [{:value title
|
||||
:bold true}]
|
||||
(map
|
||||
(fn [p]
|
||||
(assoc (:cell-args p) :value "" :format ""))
|
||||
pnl-datas))]
|
||||
(into individual-accounts)
|
||||
(conj (cashflow-subtotal-by-column-row pnl-datas title)))))
|
||||
|
||||
(defn cash-flows-table [pnl-datas #_client-datas title prefix]
|
||||
(let [table (-> []
|
||||
(into (detail-rows pnl-datas
|
||||
(into (cash-flow-detail-rows pnl-datas
|
||||
:operating-activities
|
||||
(str prefix " Operating Activities")))
|
||||
(into (detail-rows pnl-datas
|
||||
(into (cash-flow-detail-rows pnl-datas
|
||||
:investment-activities
|
||||
(str prefix " Investment Activities")))
|
||||
(into (detail-rows pnl-datas
|
||||
(into (cash-flow-detail-rows pnl-datas
|
||||
:financing-activities
|
||||
(str prefix " Financing Activities")))
|
||||
|
||||
(into (detail-rows pnl-datas
|
||||
(into (cash-flow-detail-rows pnl-datas
|
||||
:bottom-line
|
||||
(str prefix " Bottom Line"))))
|
||||
|
||||
percent-of-sales (calc-percent-of-sales table pnl-datas)
|
||||
deltas (into [] (calc-deltas table))]
|
||||
{:header (headers pnl-datas title)
|
||||
(str prefix " Bottom Line"))))]
|
||||
{:header [[{:value "Account"}
|
||||
{:value "Increases"}
|
||||
{:value "Decreases"}
|
||||
{:value "Total"}]]
|
||||
:rows table}))
|
||||
|
||||
(defn warning-message [pnl-data]
|
||||
@@ -566,27 +651,14 @@
|
||||
set)]
|
||||
{:warning (warning-message pnl-data)
|
||||
:details
|
||||
(doall (if (-> pnl-data :args :column-per-location)
|
||||
[(cash-flows-location-detail-table (mapcat identity (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
|
||||
(concat
|
||||
(for [[client-id location] (client-locations pnl-data)]
|
||||
(-> pnl-data
|
||||
(filter-client client-id)
|
||||
(filter-period period)
|
||||
(zebra i)))
|
||||
[(-> pnl-data
|
||||
(filter-period period)
|
||||
(zebra i))])))
|
||||
"All location Detail"
|
||||
"")]
|
||||
(for [client-id client-ids]
|
||||
(cash-flows-location-detail-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
|
||||
(-> pnl-data
|
||||
(filter-client client-id)
|
||||
(filter-period period)
|
||||
(zebra i)))
|
||||
(str (-> pnl-data :clients-by-id (get client-id)) " Detail")
|
||||
""))))}))
|
||||
(doall (for [client-id client-ids]
|
||||
(cash-flows-table (for [[period i] (map vector (-> pnl-data :args :periods ) (range))]
|
||||
(-> pnl-data
|
||||
(filter-client client-id)
|
||||
(filter-period period)
|
||||
(zebra i)))
|
||||
(str (-> pnl-data :clients-by-id (get client-id)) " Detail")
|
||||
"")))}))
|
||||
|
||||
|
||||
(defn balance-sheet-headers [pnl-data]
|
||||
|
||||
@@ -76,7 +76,7 @@
|
||||
:periods (mapv #(select-keys % #{:start :end} ) (:periods (:data db)))
|
||||
:include-deltas (:include-deltas (:data db))
|
||||
:column-per-location (:column-per-location (:data db))}
|
||||
[[:periods [[:accounts [:name :amount :client_id :account-type :id :count :numeric-code :location]]]]]]]}
|
||||
[[:periods [[:accounts [:name :amount :debits :credits :client_id :account-type :id :count :numeric-code :location]]]]]]]}
|
||||
:on-success [::received]}
|
||||
:set-uri-params {:periods (mapv
|
||||
encode-period
|
||||
@@ -379,24 +379,8 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
[form-builder/raw-field-v2 {:field :end}
|
||||
[date-picker {:output :cljs-date}]]]}]])]]]
|
||||
|
||||
[:div.level-item
|
||||
[:div
|
||||
[switch-field {:id "include-deltas"
|
||||
:checked (boolean include-deltas)
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::change
|
||||
[:include-deltas] (.-checked (.-target e))]))
|
||||
:label "Include deltas"
|
||||
:type "checkbox"}]]]
|
||||
[:div.level-item
|
||||
[:div
|
||||
[switch-field {:id "column-per-location"
|
||||
:checked (boolean column-per-location)
|
||||
:on-change (fn [e]
|
||||
(re-frame/dispatch [::change
|
||||
[:column-per-location] (.-checked (.-target e))]))
|
||||
:label "Column per location"
|
||||
:type "checkbox"}]]]]
|
||||
|
||||
]
|
||||
[:div.level-right
|
||||
[:div.buttons
|
||||
|
||||
@@ -418,7 +402,9 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
(map
|
||||
(fn [a]
|
||||
(assoc a :period p1
|
||||
:amount (js/parseFloat (:amount a)))
|
||||
:amount (js/parseFloat (:amount a))
|
||||
:debits (js/parseFloat (:debits a))
|
||||
:credits (js/parseFloat (:credits a)))
|
||||
)
|
||||
(:accounts p2)))
|
||||
(:periods args)))
|
||||
@@ -437,9 +423,7 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
[rtable/table {:widths (into [20] (take (dec (rtable/cell-count table))
|
||||
(mapcat identity
|
||||
(repeat
|
||||
(if (-> pnl-data :args :include-deltas)
|
||||
[13 6 13]
|
||||
[13 6])))))
|
||||
[13 6]))))
|
||||
:click-event ::investigate-clicked
|
||||
:table table}]]))
|
||||
|
||||
@@ -474,7 +458,6 @@ NOTE: Please review the transactions we may have question for you here: https://
|
||||
:clients (mapv (fn [c] {:client c :id (random-uuid)})
|
||||
(or (:clients qp)
|
||||
[(some-> @(re-frame/subscribe [::subs/client]) (select-keys [:name :id]) )]))
|
||||
:include-deltas false
|
||||
:show-advanced? false})
|
||||
::track/register {:id ::ledger-params
|
||||
:subscription [::data-page/params ::ledger]
|
||||
|
||||
Reference in New Issue
Block a user