merged
This commit is contained in:
@@ -180,7 +180,6 @@
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn make-pnl [args data]
|
||||
|
||||
(let [data (<-graphql data)
|
||||
args (<-graphql args)
|
||||
clients (pull-many (dc/db conn) [:client/code :client/name :db/id] (:client-ids args))
|
||||
@@ -226,6 +225,52 @@
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn make-cash-flows [args data]
|
||||
(let [data (<-graphql data)
|
||||
args (<-graphql args)
|
||||
clients (d/pull-many (d/db conn) '[:client/code :client/name :db/id] (:client-ids args))
|
||||
data (->> data
|
||||
:periods
|
||||
(mapcat (fn [p1 p2]
|
||||
(map
|
||||
(fn [a]
|
||||
(assoc a :period p1)
|
||||
)
|
||||
(:accounts p2))
|
||||
)
|
||||
(:periods args)))
|
||||
pnl-data (l-reports/->PNLData args data (by :db/id :client/code clients))
|
||||
report (l-reports/summarize-cash-flows pnl-data)
|
||||
output-stream (ByteArrayOutputStream.)]
|
||||
(pdf/pdf
|
||||
(-> [{:left-margin 10 :right-margin 10 :top-margin 5 :bottom-margin 15
|
||||
: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-light.ttf"}}
|
||||
[:heading (str "Statement of Cash Flows - " (str/join ", " (map :client/name clients)))]]
|
||||
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
|
||||
(into
|
||||
(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)
|
||||
[13 6 13]
|
||||
[13 6])))))))))
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn make-journal-detail-report [args data]
|
||||
|
||||
(println args)
|
||||
@@ -258,6 +303,16 @@
|
||||
names (str/replace (->> args :client_ids (pull-many (dc/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )]
|
||||
(format "Profit-and-loss-%s-to-%s-for-%s" min-date max-date names)))
|
||||
|
||||
(defn cash-flows-args->name [args]
|
||||
(let [min-date (atime/unparse-local
|
||||
(->> args :periods (map :start) first)
|
||||
atime/iso-date)
|
||||
max-date (atime/unparse-local
|
||||
(->> args :periods (map :end) last)
|
||||
atime/iso-date)
|
||||
names (str/replace (->> args :client_ids (d/pull-many (d/db conn) [:client/name]) (map :client/name) (str/join "-")) #" " "_" )]
|
||||
(format "Cash-flows-%s-to-%s-for-%s" min-date max-date names)))
|
||||
|
||||
(defn journal-detail-args->name [args]
|
||||
(println args)
|
||||
(let [min-date (atime/unparse-local
|
||||
@@ -297,6 +352,27 @@
|
||||
{:report/name name
|
||||
:report/url url }))
|
||||
|
||||
(defn print-cash-flows [user args data]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
pdf-data (make-cash-flows args data)
|
||||
name (cash-flows-args->name args)
|
||||
key (str "reports/cash-flows/" 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 }))
|
||||
|
||||
(defn print-balance-sheet [user args data]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
pdf-data (make-balance-sheet args data)
|
||||
|
||||
Reference in New Issue
Block a user