Able to send email version

This commit is contained in:
2022-03-23 08:22:57 -07:00
parent 4c0fcf3718
commit 327a5e3856
3 changed files with 74 additions and 42 deletions

View File

@@ -598,13 +598,15 @@
:profit_and_loss {:type :profit_and_loss_report
:args {:client_id {:type :id}
:client_ids {:type '(list :id)}
:periods {:type '(list :date_range)}}
:periods {:type '(list :date_range)}
:include_deltas {:type 'Boolean}}
:resolve :get-profit-and-loss}
:profit_and_loss_pdf {:type :profit_and_loss_pdf
:args {:client_id {:type :id}
:client_ids {:type '(list :id)}
:periods {:type '(list :date_range)}}
:periods {:type '(list :date_range)}
:include_deltas {:type 'Boolean}}
:resolve :profit-and-loss-pdf}
:ledger_page {:type :ledger_page

View File

@@ -15,10 +15,6 @@
(java.text DecimalFormat)
(java.util UUID)))
(defn distribute [nums]
(let [sum (reduce + 0 nums)]
(map #(* 100 (/ % sum)) nums)))
(defn date->str [d]
(atime/unparse-local d atime/normal-date))
@@ -82,7 +78,7 @@
(->> data
(filter (comp in-range? :numeric-code))
(group-by (juxt :client-id :location))
(filter (fn [[k as]]
(filter (fn [[_ as]]
(not (dollars-0? (reduce + 0 (map :amount as))))))
(mapcat second)
(map (fn [a]
@@ -105,7 +101,7 @@
(defn best-category [a]
(->> ranges
(filter (fn [[category [start end]]]
(filter (fn [[_ [start end]]]
(<= start (:numeric-code a) end)))
first
first))
@@ -192,7 +188,9 @@
(into [title]
(mapcat
(fn [v p d]
[v p d])
(if (:include-deltas (:args pnl-data))
[v p d]
[v p]))
row
percent-of-sales
deltas))
@@ -204,27 +202,29 @@
(defn headers [pnl-data header-title]
(let [big-header (into [{:value header-title
:bold true}]
(map-indexed (fn [i p]
{:value
(str (date->str (:start p))
" - "
(date->str (:end p)))
:colspan 3
:align :center
:bold true})
(:periods (:args pnl-data))))
(map (fn [p]
{:value
(str (date->str (:start p))
" - "
(date->str (:end p)))
:colspan (if (-> pnl-data :args :include-deltas)
3
2)
:align :center
:bold true})
(:periods (:args pnl-data))))
sub-header (into [{:value ""}]
(mapcat
(fn [_]
[{:value "Amount"
:align :right
:bold true}
{:value "% Sales"
:align :right
:bold true}
{:value "Change"
:align :right
:bold true}])
(cond-> [{:value "Amount"
:align :right
:bold true}
{:value "% Sales"
:align :right
:bold true}]
(-> pnl-data :args :include-deltas) (conj {:value "Change"
:align :right
:bold true})))
(:periods (:args pnl-data))))]
[big-header
sub-header]))
@@ -442,9 +442,11 @@
(into [new-table]
(split-table remaining n))))))
(defn break-apart-tables [tables]
(defn break-apart-tables [pnl-data tables]
(for [table tables
table (split-table table 10)]
table (split-table table (if (:include-deltas (:args pnl-data))
10
9))]
table))
(defn make-pnl [args data]
@@ -462,7 +464,8 @@
(:accounts p2))
)
(:periods args)))
report (summarize-pnl (PNLData. (assoc args :deltas true) data (by :db/id clients)))
pnl-data (PNLData. args data (by :db/id clients))
report (summarize-pnl pnl-data)
output-stream (ByteArrayOutputStream.)]
(pdf/pdf
(into
@@ -470,7 +473,8 @@
:orientation :landscape
:font {:size 8}}
[:heading (str "Profit and Loss - " (str/join ", " (map :client/name clients)))]]
(for [table (break-apart-tables (concat (:summaries report)
(for [table (break-apart-tables pnl-data
(concat (:summaries report)
(:details report)))]
(table->pdf table)))
output-stream)