attempt to look more like printed pdf.

This commit is contained in:
2022-03-23 10:30:29 -07:00
parent 327a5e3856
commit 60cd35b3fb

View File

@@ -216,18 +216,17 @@
sub-header (into [{:value ""}] sub-header (into [{:value ""}]
(mapcat (mapcat
(fn [_] (fn [_]
(cond-> [{:value "Amount" (cond-> [{:value ""
:align :right :align :right
:bold true} :bold true}
{:value "% Sales" {:value ""
:align :right :align :right
:bold true}] :bold true}]
(-> pnl-data :args :include-deltas) (conj {:value "Change" (-> pnl-data :args :include-deltas) (conj {:value ""
:align :right :align :right
:bold true}))) :bold true})))
(:periods (:args pnl-data))))] (:periods (:args pnl-data))))]
[big-header [big-header]))
sub-header]))
(defn location-summary-table [pnl-data title] (defn location-summary-table [pnl-data title]
(let [table [(subtotal-row (filter-categories pnl-data [:sales]) "Sales") (let [table [(subtotal-row (filter-categories pnl-data [:sales]) "Sales")
@@ -260,11 +259,9 @@
:let [pnl-data (filter-numeric-code pnl-data from to) :let [pnl-data (filter-numeric-code pnl-data from to)
account-codes (used-accounts pnl-data)] account-codes (used-accounts pnl-data)]
:when (seq account-codes) :when (seq account-codes)
row (-> [[{:value (str "---" grouping-name "---") row (-> [[{:value (str "---" grouping-name "---")}]]
:bold true}]]
(into (for [{:keys [numeric-code name]} account-codes] (into (for [{:keys [numeric-code name]} account-codes]
(into [{:value name (into [{:value name}]
:bold true}]
(map (map
(fn [p] (fn [p]
{:format :dollar {:format :dollar
@@ -339,12 +336,12 @@
(defn cell->pdf [cell] (defn cell->pdf [cell]
[:pdf-cell [:pdf-cell
(cond-> {} (cond-> {}
(:colspan cell) (assoc :colspan (:colspan cell))
(:align cell) (assoc :align (:align cell))
(= :dollar (:format cell)) (assoc :align :right) (= :dollar (:format cell)) (assoc :align :right)
(= :percent (:format cell)) (assoc :align :right) (= :percent (:format cell)) (assoc :align :right)
(:bold cell) (assoc :style :bold) (:bold cell) (assoc-in [:ttf-name] "fonts/calibri-bold.ttf"))
(:align cell) (assoc :align (:align cell))
(:colspan cell) (assoc :colspan (:colspan cell)))
(cond (= :dollar (:format cell)) (cond (= :dollar (:format cell))
(.format (DecimalFormat. "$###,##0.00") (:value cell)) (.format (DecimalFormat. "$###,##0.00") (:value cell))
@@ -360,7 +357,7 @@
(apply max counts) (apply max counts)
0))) 0)))
(defn table->pdf [table] (defn table->pdf [table widths]
(let [cell-count (cell-count table)] (let [cell-count (cell-count table)]
(-> [:pdf-table {:header (mapv (-> [:pdf-table {:header (mapv
(fn [header] (fn [header]
@@ -381,7 +378,8 @@
:else :else
100)} 100)}
(into [20] (take (dec cell-count) (repeat 10)))] widths
]
(into (into
(for [row (:rows table)] (for [row (:rows table)]
@@ -469,14 +467,23 @@
output-stream (ByteArrayOutputStream.)] output-stream (ByteArrayOutputStream.)]
(pdf/pdf (pdf/pdf
(into (into
[{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15 :size :letter [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15
:size (if (>= (count (-> pnl-data :args :periods)) 4 )
:tabloid
:letter)
:orientation :landscape :orientation :landscape
:font {:size 8}} :font {:size 6
:ttf-name "fonts/calibri.ttf"}}
[:heading (str "Profit and Loss - " (str/join ", " (map :client/name clients)))]] [:heading (str "Profit and Loss - " (str/join ", " (map :client/name clients)))]]
(for [table (break-apart-tables pnl-data (for [table (concat (:summaries report)
(concat (:summaries report) (:details report))]
(:details report)))] (table->pdf table
(table->pdf table))) (into [20] (take (dec (cell-count table))
(mapcat identity
(repeat
(if (-> pnl-data :args :include-deltas)
[12 6 12]
[12 6]))))))))
output-stream) output-stream)
(.toByteArray output-stream))) (.toByteArray output-stream)))