diff --git a/src/clj/auto_ap/pdf/ledger.clj b/src/clj/auto_ap/pdf/ledger.clj index 34908723..a8c091c8 100644 --- a/src/clj/auto_ap/pdf/ledger.clj +++ b/src/clj/auto_ap/pdf/ledger.clj @@ -167,6 +167,7 @@ (map (fn [v s] {:format :percent + :color [128 128 128] :value (if (dollars-0? s) 0.0 (/ (:value v) s))}) @@ -184,7 +185,7 @@ (defn combine-tables [pnl-data table percent-of-sales deltas] (map (fn [[title & row] percent-of-sales deltas ] - (let [deltas (cons "-" deltas)] + (let [deltas (cons 0.0 deltas)] (into [title] (mapcat (fn [v p d] @@ -193,8 +194,7 @@ [v p])) row percent-of-sales - deltas)) - )) + deltas)))) table percent-of-sales deltas)) @@ -216,17 +216,15 @@ sub-header (into [{:value ""}] (mapcat (fn [_] - (cond-> [{:value "" - :align :right - :bold true} - {:value "" - :align :right - :bold true}] - (-> pnl-data :args :include-deltas) (conj {:value "" - :align :right - :bold true}))) + (cond-> [{:value "Amt" + :align :right} + {:value "%" + :align :right}] + (-> pnl-data :args :include-deltas) (conj {:value "+/-" + :align :right}))) (:periods (:args pnl-data))))] - [big-header])) + [big-header + sub-header])) (defn location-summary-table [pnl-data title] (let [table [(subtotal-row (filter-categories pnl-data [:sales]) "Sales") @@ -341,15 +339,21 @@ (:align cell) (assoc :align (:align cell)) (= :dollar (:format cell)) (assoc :align :right) (= :percent (:format cell)) (assoc :align :right) - (:bold cell) (assoc-in [:ttf-name] "fonts/calibri-bold.ttf")) - (cond (= :dollar (:format cell)) - (.format (DecimalFormat. "$###,##0.00") (:value cell)) + (:bold cell) (assoc-in [:ttf-name] "fonts/calibri-bold.ttf") + (:color cell) (assoc :color (:color cell))) + (cond + (and (= :dollar (:format cell)) + (dollars-0? (:value cell))) + "-" - (= :percent (:format cell)) - (.format (DecimalFormat. "0%") (:value cell)) + (= :dollar (:format cell)) + (.format (DecimalFormat. "$###,##0.00") (:value cell)) - :else - (str (:value cell)))]) + (= :percent (:format cell)) + (.format (DecimalFormat. "0%") (:value cell)) + + :else + (str (:value cell)))]) (defn cell-count [table] (let [counts (map count (:rows table))] @@ -468,12 +472,19 @@ (pdf/pdf (into [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15 - :size (if (>= (count (-> pnl-data :args :periods)) 4 ) + :size (cond + (and (>= (count (-> pnl-data :args :periods)) 8 ) + (-> pnl-data :args :include-deltas)) + :a2 + + (>= (count (-> pnl-data :args :periods)) 4 ) :tabloid + + :else :letter) :orientation :landscape :font {:size 6 - :ttf-name "fonts/calibri.ttf"}} + :ttf-name "fonts/calibri-light.ttf"}} [:heading (str "Profit and Loss - " (str/join ", " (map :client/name clients)))]] (for [table (concat (:summaries report) (:details report))] @@ -482,8 +493,8 @@ (mapcat identity (repeat (if (-> pnl-data :args :include-deltas) - [12 6 12] - [12 6])))))))) + [13 6 13] + [13 6])))))))) output-stream) (.toByteArray output-stream)))