From d8030e98a16a92612f621b9f2c395293aeb6da8c Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Sat, 22 Oct 2022 20:45:22 -0700 Subject: [PATCH] long shot attempt to get report looking better --- src/clj/auto_ap/graphql/ledger.clj | 54 +++++++++++++------ src/cljc/auto_ap/ledger/reports.cljc | 10 ++-- .../pages/ledger/profit_and_loss_detail.cljs | 18 ++----- 3 files changed, 47 insertions(+), 35 deletions(-) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 2d245a3a..8636544e 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -520,25 +520,39 @@ :per_page Integer/MAX_VALUE}} nil) :journal_entries - (map (fn [je] - (update je :line_items - (fn [jels] - (into [] - (filter (fn [jel] - (when-let [account (account-lookup (:id (:account jel)))] - (and - (<= (get-in l-reports/ranges [category 0]) - (:numeric_code account) - (get-in l-reports/ranges [category 1])) - (= location (:location jel))))) - jels )))))) - (group-by #(account-lookup (get-in % [:line_items 0 :account :id]))))] + (mapcat (fn [je] + (->> (je :line_items) + (filter (fn [jel] + (when-let [account (account-lookup (:id (:account jel)))] + (and + (<= (get-in l-reports/ranges [category 0]) + (:numeric_code account) + (get-in l-reports/ranges [category 1])) + (= location (:location jel))))) + ) + (map (fn [jel ] + {:date (:date je) + :debit (:debit jel) + :credit (:credit jel) + :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] {:category category :client_id client-id :location location :account account - :journal_entries journal-entries})}) + :journal_entries (reduce + (fn [[acc last-je] je] + (let [next-je (assoc je :running_balance + (- (+ (:running_balance last-je 0.0) + (Double/parseDouble (:debit je 0.0))) + (Double/parseDouble (:credit je 0.0))))] + [(conj acc next-je) next-je])) + [] + journal-entries)})}) @@ -596,6 +610,16 @@ :date {:type 'String} :line_items {:type '(list :journal_entry_line)}}} + :journal_detail_report_row + {:fields {:client {:type :client} + :description {:type 'String} + :date {:type 'String} + :account {:type :account} + :location {:type 'String} + :debit {:type 'String} + :credit {:type 'String} + :running_balance {:type :money}}} + :ledger_page {:fields {:journal_entries {:type '(list :journal_entry)} :count {:type 'Int} @@ -619,7 +643,7 @@ :account {:type :account} :client_id {:type :id} :location {:type 'String} - :journal_entries {:type '(list :journal_entry)}}} + :journal_entries {:type '(list :journal_detail_report_row)}}} :journal_detail_report {:fields {:categories {:type '(list :journal_detail_report_category)}}}}) diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 979e7126..1b13779b 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -575,14 +575,12 @@ (map (fn [je] [{:value (user-friendly-date (:date je))} - {:value (or (:description je) - (:name (:vendor je)) - "")} - {:value (get-in je [:line-items 0 :debit]) + {:value (:description je "")} + {:value (get je :debit) :format :dollar} - {:value (get-in je [:line-items 0 :credit]) + {:value (get je :credit) :format :dollar} - {:value (get-in je [:line-items 0 :running-balance]) + {:value (get je :running-balance) :format :dollar}]) (:journal-entries category)))) diff --git a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss_detail.cljs b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss_detail.cljs index aa52675b..473cd951 100644 --- a/src/cljs/auto_ap/views/pages/ledger/profit_and_loss_detail.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/profit_and_loss_detail.cljs @@ -49,20 +49,10 @@ :categories [:sales :cogs :payroll]} - [[:categories [[:journal-entries [:id - :source - :original-entity - :note - :amount - :alternate-description - [:vendor - [:name :id]] - [:client - [:name :id]] - [:line-items - [:id :debit :credit :location :running-balance - [:account [:id :name]]]] - :date]] + [[:categories [[:journal-entries [:description + :date + :debit :credit :location :running-balance + [:account [:id :name]]]] :category :client-id :location