attempt for the crazy

This commit is contained in:
Bryce Covert
2022-10-24 22:43:38 -07:00
parent fa8b9b0ab2
commit c8012555ff

View File

@@ -511,7 +511,7 @@
c (d/pull (d/db conn) '[:client/locations] client-id) ] c (d/pull (d/db conn) '[:client/locations] client-id) ]
location (:client/locations c) location (:client/locations c)
category (:categories input) category (:categories input)
:let [journal-entries (->> (get-ledger-page context :let [all-journal-entries (->> (get-ledger-page context
{:filters {:client_id client-id {:filters {:client_id client-id
:location location :location location
:date_range (:date_range input) :date_range (:date_range input)
@@ -537,15 +537,15 @@
:description (or (:name (:vendor je)) :description (or (:name (:vendor je))
(:alternate_description je)) (:alternate_description je))
:account (:account jel) :account (:account jel)
:location (:location jel)}))))) :location (:location jel)}))))))
(group-by #(account-lookup (get-in % [:account :id]))))] journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])))]
[account journal-entries] journal-entries [account journal-entries] (conj journal-entries-by-account [nil all-journal-entries])
:let [journal-entries (first (reduce :let [journal-entries (first (reduce
(fn [[acc last-je] je] (fn [[acc last-je] je]
(let [next-je (assoc je :running_balance (let [next-je (assoc je :running_balance
(- (+ (or (:running_balance last-je 0.0) 0.0) (- (+ (or (:running_balance last-je 0.0) 0.0)
(or (:debit je 0.0) 0.0)) (or (:credit je 0.0) 0.0))
(or (:credit je 0.0) 0.0)))] (or (:debit je 0.0) 0.0)))]
[(conj acc next-je) next-je])) [(conj acc next-je) next-je]))
[] []
(sort-by :date journal-entries)))]] (sort-by :date journal-entries)))]]
@@ -553,9 +553,9 @@
:client_id client-id :client_id client-id
:location location :location location
:account account :account account
:journal_entries (sort-by :date journal-entries) :journal_entries (when account (sort-by :date journal-entries))
:total (- (or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0) :total (- (or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0)
(or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0))})}) (or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0))})})