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