From 04bc7cae78abe32254281616bf1e3468dc584643 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 9 Apr 2026 14:32:39 -0700 Subject: [PATCH] total column --- src/clj/auto_ap/pdf/ledger.clj | 5 +- src/clj/auto_ap/ssr/ledger/balance_sheet.clj | 8 ++- src/cljc/auto_ap/ledger/reports.cljc | 72 +++++++++++++------ .../views/pages/ledger/balance_sheet.cljs | 3 +- start-solr.sh | 5 +- 5 files changed, 60 insertions(+), 33 deletions(-) diff --git a/src/clj/auto_ap/pdf/ledger.clj b/src/clj/auto_ap/pdf/ledger.clj index 77361e42..567063e6 100644 --- a/src/clj/auto_ap/pdf/ledger.clj +++ b/src/clj/auto_ap/pdf/ledger.clj @@ -177,8 +177,9 @@ (conj [:paragraph {:color [128 0 0] :size 9} (:warning report)]) (conj (table->pdf report - (cond-> (into [30 ] (repeat client-count 13)) - (:include-comparison args) (into (repeat (* 2 client-count) 13)))))) + (cond-> (into [30 ] (repeat client-count 13)) + (:include-comparison args) (into (repeat (* 2 client-count) 13)) + (and (> client-count 1) (not (:include-comparison args))) (conj 13))))) output-stream) (.toByteArray output-stream))) diff --git a/src/clj/auto_ap/ssr/ledger/balance_sheet.clj b/src/clj/auto_ap/ssr/ledger/balance_sheet.clj index adfc67e5..491fbfec 100644 --- a/src/clj/auto_ap/ssr/ledger/balance_sheet.clj +++ b/src/clj/auto_ap/ssr/ledger/balance_sheet.clj @@ -120,7 +120,8 @@ (list [:div.text-2xl.font-bold.text-gray-600 (str "Balance Sheet - " (str/join ", " (map :client/name client))) ] (rtable/table {:widths (cond-> (into [30 ] (repeat 13 client-count)) - (> (count date) 1) (into (repeat 13 (* 2 client-count (dec (count date)))))) + (> (count date) 1) (into (repeat 13 (* 2 client-count (dec (count date))))) + (and (> client-count 1) (= (count date) 1)) (conj 13)) :investigate-url (bidi.bidi/path-for ssr-routes/only-routes ::route/investigate) :table report :warning (not-empty (str/join "\n " (filter not-empty [warning (:warning report)])))} ))))]) @@ -201,8 +202,9 @@ (conj [:paragraph {:color [128 0 0] :size 9} (:warning report)]) (conj (table->pdf report - (cond-> (into [30 ] (repeat client-count 13)) - (> (count date) 1) (into (repeat (* 2 client-count (dec (count date))) 13 )))))) + (cond-> (into [30 ] (repeat client-count 13)) + (> (count date) 1) (into (repeat (* 2 client-count (dec (count date))) 13 )) + (and (> client-count 1) (= (count date) 1)) (conj 13))))) output-stream) (.toByteArray output-stream))) diff --git a/src/cljc/auto_ap/ledger/reports.cljc b/src/cljc/auto_ap/ledger/reports.cljc index 6cf377fa..f884f6f3 100644 --- a/src/cljc/auto_ap/ledger/reports.cljc +++ b/src/cljc/auto_ap/ledger/reports.cljc @@ -798,30 +798,34 @@ (defn balance-sheet-headers [pnl-data] - (let [period-count (count (:periods (:args pnl-data)))] + (let [period-count (count (:periods (:args pnl-data))) + client-ids (set (map :client-id (:data pnl-data))) + client-count (count client-ids) + show-total? (and (> client-count 1) (= 1 period-count))] (cond-> [] - (> (count (set (map :client-id (:data pnl-data)))) 1) - (conj (into [{:value "Client"}] + (> client-count 1) + (conj (cond-> (into [{:value "Client"}] + (mapcat identity + (for [client client-ids] + (cond-> [{:value (str (-> pnl-data :client-codes (get client)))}] + (> period-count 1) + (into (apply concat (repeat (dec period-count) ["" ""]))))))) + show-total? (conj {:value "Total" :bold true :border [:left]}))) - (mapcat identity - (for [client (set (map :client-id (:data pnl-data))) ] - (cond-> [{:value (str (-> pnl-data :client-codes (get client)))}] - - (> period-count 1) - (into (apply concat (repeat (dec period-count) ["" ""])))))))) true - (conj (into [{:value "Period Ending"}] - (for [client (set (map :client-id (:data pnl-data))) + (conj (cond-> (into [{:value "Period Ending"}] + (for [client client-ids [index p] (map vector (range) (:periods (:args pnl-data))) :let [is-first? (= 0 index) period-date (date->str p) period-headers (if (or is-first? (not (:include-deltas (:args pnl-data)))) - [{:value period-date}] - [{:value period-date} - {:value "+/-"}])] + [{:value period-date}] + [{:value period-date} + {:value "+/-"}])] header period-headers] - header)))))) + header)) + show-total? (conj {:value (date->str (first (:periods (:args pnl-data)))) :border [:left]})))))) (defn append-deltas [table] (->> table @@ -890,12 +894,33 @@ :rows table}))) ) +(defn add-total-border [rows] + (map (fn [row] + (let [last-idx (dec (count row))] + (map-indexed + (fn [i cell] + (if (= i last-idx) + (let [borders (or (:border cell) [])] + (assoc cell :border (conj borders :left))) + cell)) + row))) + rows)) + (defn summarize-balance-sheet [pnl-data] - (let [pnl-datas (for [client-id (set (map :client-id (:data pnl-data))) - p (:periods (:args pnl-data))] - (-> pnl-data - (filter-client client-id) - (filter-period p)))] + (let [client-ids (set (map :client-id (:data pnl-data))) + client-count (count client-ids) + period-count (count (:periods (:args pnl-data))) + show-total? (and (> client-count 1) (= 1 period-count)) + pnl-datas (for [client-id client-ids + p (:periods (:args pnl-data))] + (-> pnl-data + (filter-client client-id) + (filter-period p))) + total-data (when show-total? + (-> pnl-data + (filter-period (first (:periods (:args pnl-data)))) + (assoc :cell-args {:bold true}))) + pnl-datas (concat pnl-datas (when total-data [total-data]))] (let [table (-> [] (into (detail-rows pnl-datas :assets @@ -912,10 +937,11 @@ (negate #{:cogs :payroll :controllable :fixed-overhead :ownership-controllable})) pnl-datas) "Retained Earnings"))) - table (if (and (> (count (:periods (:args pnl-data))) 1) + table (if (and (> period-count 1) (:include-deltas (:args pnl-data))) - (append-deltas table) - table)] + (append-deltas table) + table) + table (if show-total? (add-total-border table) table)] {:warning (warning-message pnl-data) :header (balance-sheet-headers pnl-data) :rows table})) diff --git a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs index 5812d9ca..475ce1ae 100644 --- a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs @@ -265,7 +265,8 @@ NOTE: Please review the transactions we may have question for you here: https:// [:div.notification.is-warning.is-light (:warning report)]) [rtable/table {:widths (cond-> (into [30 ] (repeat 13 client-count)) - (:include-comparison args) (into (repeat 13 (* 2 client-count)))) + (:include-comparison args) (into (repeat 13 (* 2 client-count))) + (and (> client-count 1) (not (:include-comparison args))) (conj 13)) :click-event ::investigate-clicked :table report}]])) diff --git a/start-solr.sh b/start-solr.sh index 18633b74..ff54adcb 100755 --- a/start-solr.sh +++ b/start-solr.sh @@ -1,5 +1,2 @@ #!/bin/bash -sudo docker run --rm -ti -v ~/dev/integreat/data/solr:/var/solr --network=bridge -p 8983:8983 bryce-solr -#sudo podman container run --user 1000 --privileged --volume /home/notid/dev/integreat/data/solr:/var/solr -p 8983:8983 bryce-solr - - +sudo docker run --rm -ti -v ~/dev/integreat/data/solr:/var/solr --network=bridge -p 8983:8983 679918342773.dkr.ecr.us-east-1.amazonaws.com/integreat-solr