From c8012555ff5b384129e68f85fcb0853b36bfefc7 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 24 Oct 2022 22:43:38 -0700 Subject: [PATCH] attempt for the crazy --- src/clj/auto_ap/graphql/ledger.clj | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 07327709..63e0265a 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -511,7 +511,7 @@ c (d/pull (d/db conn) '[:client/locations] client-id) ] location (:client/locations c) category (:categories input) - :let [journal-entries (->> (get-ledger-page context + :let [all-journal-entries (->> (get-ledger-page context {:filters {:client_id client-id :location location :date_range (:date_range input) @@ -537,15 +537,15 @@ :description (or (:name (:vendor je)) (:alternate_description je)) :account (:account jel) - :location (:location jel)}))))) - (group-by #(account-lookup (get-in % [:account :id]))))] - [account journal-entries] journal-entries + :location (:location jel)})))))) + journal-entries-by-account (group-by #(account-lookup (get-in % [:account :id])))] + [account journal-entries] (conj journal-entries-by-account [nil all-journal-entries]) :let [journal-entries (first (reduce (fn [[acc last-je] je] (let [next-je (assoc je :running_balance (- (+ (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])) [] (sort-by :date journal-entries)))]] @@ -553,9 +553,9 @@ :client_id client-id :location location :account account - :journal_entries (sort-by :date journal-entries) - :total (- (or (reduce + 0.0 (map #(or (:debit %) 0.0) journal-entries)) 0.0) - (or (reduce + 0.0 (map #(or (:credit %) 0.0) journal-entries)) 0.0))})}) + :journal_entries (when account (sort-by :date journal-entries)) + :total (- (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))})})