Enables Cash flows
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
[auto-ap.graphql.utils
|
||||
:refer [->graphql <-graphql assert-admin assert-can-see-client result->page]]
|
||||
[auto-ap.parse.util :as parse]
|
||||
[auto-ap.pdf.ledger :refer [print-balance-sheet print-pnl print-journal-detail-report]]
|
||||
[auto-ap.pdf.ledger :refer [print-balance-sheet print-pnl print-journal-detail-report print-cash-flows]]
|
||||
[auto-ap.utils :refer [by dollars= heartbeat]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clj-time.core :as t]
|
||||
@@ -240,6 +240,11 @@
|
||||
|
||||
(->graphql result)))
|
||||
|
||||
(defn cash-flows-pdf [context args value]
|
||||
(let [data (get-profit-and-loss context args value)
|
||||
result (print-cash-flows (:id context) args data)]
|
||||
(->graphql result)))
|
||||
|
||||
(defn balance-sheet-pdf [context args value]
|
||||
(let [data (get-balance-sheet context args value)
|
||||
result (print-balance-sheet (:id context) args data)]
|
||||
@@ -804,6 +809,14 @@
|
||||
:column_per_location {:type 'Boolean}}
|
||||
:resolve :profit-and-loss-pdf}
|
||||
|
||||
:cash_flows_pdf {:type :report_pdf
|
||||
:args {:client_id {:type :id}
|
||||
:client_ids {:type '(list :id)}
|
||||
:periods {:type '(list :date_range)}
|
||||
:include_deltas {:type 'Boolean}
|
||||
:column_per_location {:type 'Boolean}}
|
||||
:resolve :cash-flows-pdf}
|
||||
|
||||
:balance_sheet_pdf {:type :report_pdf
|
||||
:args {:client_id {:type :id}
|
||||
:include_comparison {:type 'Boolean}
|
||||
@@ -884,6 +897,7 @@
|
||||
:get-balance-sheet get-balance-sheet
|
||||
:get-profit-and-loss get-profit-and-loss
|
||||
:profit-and-loss-pdf profit-and-loss-pdf
|
||||
:cash-flows-pdf cash-flows-pdf
|
||||
:journal-detail-report-pdf journal-detail-report-pdf
|
||||
:balance-sheet-pdf balance-sheet-pdf
|
||||
:get-ledger-csv get-ledger-csv
|
||||
|
||||
@@ -180,7 +180,6 @@
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn make-pnl [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))
|
||||
@@ -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 (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 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