slightly better report

This commit is contained in:
2022-10-17 06:23:39 -07:00
parent fb607b3345
commit 05af4ba603
4 changed files with 90 additions and 11 deletions

View File

@@ -20,7 +20,8 @@
(defn cell->pdf [cell]
(let [cell-contents (cond
(and (= :dollar (:format cell))
(dollars-0? (:value cell)))
(or (nil? (:value cell))
(dollars-0? (:value cell))))
"-"
(= :dollar (:format cell))
@@ -225,6 +226,28 @@
output-stream)
(.toByteArray output-stream)))
(defn make-journal-detail-report [args data]
(println args)
(let [data (<-graphql data)
args (<-graphql args)
clients (d/pull-many (d/db conn) '[:client/code :client/name :db/id] (:client-ids args))
report (l-reports/journal-detail-report args data (by :db/id :client/code clients))
output-stream (ByteArrayOutputStream.)]
(log/info report)
(pdf/pdf
(-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15
:size :letter
:font {:size 6
:ttf-name "fonts/calibri-light.ttf"}}
[:heading (str "Journal Detail Report - " (str/join ", " (map :client/name clients)))]]
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
(conj
(table->pdf report
[20 80 20 20 20])))
output-stream)
(.toByteArray output-stream)))
(defn pnl-args->name [args]
(let [min-date (atime/unparse-local
(->> args :periods (map :start) first)
@@ -235,6 +258,17 @@
names (str/replace (->> args :client_ids (d/pull-many (d/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )]
(format "Profit-and-loss-%s-to-%s-for-%s" min-date max-date names)))
(defn journal-detail-args->name [args]
(println args)
(let [min-date (atime/unparse-local
(->> args :date_range :start)
atime/iso-date)
max-date (atime/unparse-local
(->> args :date_range :end)
atime/iso-date)
names (str/replace (->> args :client_ids (d/pull-many (d/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )]
(format "Profit-and-loss-%s-to-%s-for-%s" min-date max-date names)))
(defn balance-sheet-args->name [args]
(let [date (atime/unparse-local
(:date args)
@@ -283,3 +317,24 @@
:report/created (java.util.Date.)}])
{:report/name name
:report/url url }))
(defn print-journal-detail-report [user args data]
(let [uuid (str (UUID/randomUUID))
pdf-data (make-journal-detail-report args data)
name (journal-detail-args->name args)
key (str "reports/journal-detail/" uuid "/" name ".pdf")
url (str "http://" (:data-bucket env) ".s3-website-us-east-1.amazonaws.com/" key)]
(s3/put-object :bucket-name (:data-bucket env)
:key key
:input-stream (io/make-input-stream pdf-data {})
:metadata {:content-length (count pdf-data)
:content-type "application/pdf"})
@(d/transact conn
[{:report/name name
:report/client (:client_ids args)
:report/key key
:report/url url
:report/creator (:user user)
:report/created (java.util.Date.)}])
{:report/name name
:report/url url }))