From c417c4ac14d6ab664e6c26792ecb658585e9adcd Mon Sep 17 00:00:00 2001 From: Bryce Date: Wed, 6 Sep 2023 07:35:47 -0700 Subject: [PATCH] balance sheet fixes --- scratch-sessions/fix-page-performance.repl | 15 +++++++++++++++ src/clj/auto_ap/handler.clj | 6 ++++-- src/clj/auto_ap/pdf/ledger.clj | 12 +++++++----- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/scratch-sessions/fix-page-performance.repl b/scratch-sessions/fix-page-performance.repl index 6a626bef..4bfe274c 100644 --- a/scratch-sessions/fix-page-performance.repl +++ b/scratch-sessions/fix-page-performance.repl @@ -133,6 +133,7 @@ (do + (println "INVOICES") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :invoice/client ?c]] @@ -143,6 +144,7 @@ :invoice/client c}))) {:user/name "hydrate-tuples"}) + (println "TRANSACTIONS") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :transaction/client ?c]] @@ -154,6 +156,7 @@ {:user/name "hydrate-tuples"}) + (println "JOURNALS") (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c :in $ :where [?e :journal-entry/client ?c]] @@ -165,4 +168,16 @@ {:user/name "hydrate-tuples"}) + (println "PAYMENTS") + (auto-ap.datomic/audit-transact-batch (->> (dc/q '[:find ?e ?c + :in $ + :where [?e :payment/client ?c]] + (dc/db conn) + ) + (map (fn [[i c]] + {:db/id i + :payment/client c}))) + + {:user/name "hydrate-tuples"}) + ) diff --git a/src/clj/auto_ap/handler.clj b/src/clj/auto_ap/handler.clj index 9bd28ef5..f7e15d62 100644 --- a/src/clj/auto_ap/handler.clj +++ b/src/clj/auto_ap/handler.clj @@ -127,13 +127,15 @@ :request-method (:request-method request) :user (:identity request) :user-role (:user/role (:identity request)) - :user-name (:user/name (:identity request))} + :user-name (:user/name (:identity request)) + :query-params (:query-params request)} (mu/trace ::http-request-trace [] (lc/with-context {:uri (:uri request) :source "request" :user-role (:user/role (:identity request)) - :user-name (:user/name (:identity request))} + :user-name (:user/name (:identity request)) + :query-params (:query-params request)} (when-not (str/includes? (:uri request) "health-check") diff --git a/src/clj/auto_ap/pdf/ledger.clj b/src/clj/auto_ap/pdf/ledger.clj index 2aaab4ac..b651d75f 100644 --- a/src/clj/auto_ap/pdf/ledger.clj +++ b/src/clj/auto_ap/pdf/ledger.clj @@ -56,6 +56,7 @@ (defn table->pdf [table widths] (let [cell-count (cell-count table)] + (-> [:pdf-table {:header (mapv (fn [header] (map cell->pdf header)) @@ -162,6 +163,8 @@ (assoc b :period (:comparison-date args)))))) pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients)) + client-count (count (set (map :client-id (:data pnl-data)))) + report (l-reports/summarize-balance-sheet pnl-data) output-stream (ByteArrayOutputStream.)] (log/info report) @@ -174,8 +177,8 @@ (conj [:paragraph {:color [128 0 0] :size 9} (:warning report)]) (conj (table->pdf report - (cond-> [30 13] - (:include-comparison args) (into [13 13]))))) + (cond-> (into [30 ] (repeat client-count 13)) + (:include-comparison args) (into (repeat (* 2 client-count) 13)))))) output-stream) (.toByteArray output-stream))) @@ -312,7 +315,6 @@ (format "Cash-flows-%s-to-%s-for-%s" min-date max-date names))) (defn journal-detail-args->name [args] - (println args) (let [min-date (atime/unparse-local (->> args :date_range :start) atime/iso-date) @@ -326,7 +328,7 @@ (let [date (atime/unparse-local (:date args) atime/iso-date) - name (str/replace (->> args :client_id (pull-attr (dc/db conn) :client/name)) #" " "_" )] + name (str/replace (->> args :client_ids (pull-many (dc/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )] (format "Balance-sheet-%s-for-%s" date name))) (defn print-pnl [user args data] @@ -384,7 +386,7 @@ :content-type "application/pdf"}) @(dc/transact conn [{:report/name name - :report/client [(:client_id args)] + :report/client (:client_ids args) :report/key key :report/url url :report/creator (:user user)