undoing commit.
This commit is contained in:
@@ -9,7 +9,7 @@
|
||||
:refer [->graphql <-graphql assert-admin assert-can-see-client result->page]]
|
||||
[auto-ap.parse.util :as parse]
|
||||
[auto-ap.utils :refer [by dollars=]]
|
||||
[auto-ap.pdf.ledger :refer [print-pnl print-balance-sheet]]
|
||||
[auto-ap.pdf.ledger :refer [print-pnl]]
|
||||
[clj-time.coerce :as coerce]
|
||||
[clojure.tools.logging :as log]
|
||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||
@@ -214,12 +214,6 @@
|
||||
|
||||
(->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)]
|
||||
|
||||
(->graphql result)))
|
||||
|
||||
|
||||
(defn assoc-error [f]
|
||||
(fn [entry]
|
||||
@@ -518,7 +512,7 @@
|
||||
:account_type {:type :account_type}
|
||||
:name {:type 'String}}}
|
||||
|
||||
:report_pdf
|
||||
:profit_and_loss_pdf
|
||||
{:fields {:url {:type 'String}
|
||||
:name {:type 'String}}}
|
||||
|
||||
@@ -587,20 +581,13 @@
|
||||
:include_deltas {:type 'Boolean}}
|
||||
:resolve :get-profit-and-loss}
|
||||
|
||||
:profit_and_loss_pdf {:type :report_pdf
|
||||
:profit_and_loss_pdf {:type :profit_and_loss_pdf
|
||||
:args {:client_id {:type :id}
|
||||
:client_ids {:type '(list :id)}
|
||||
:periods {:type '(list :date_range)}
|
||||
:include_deltas {:type 'Boolean}}
|
||||
:resolve :profit-and-loss-pdf}
|
||||
|
||||
:balance_sheet_pdf {:type :report_pdf
|
||||
:args {:client_id {:type :id}
|
||||
:include_comparison {:type 'Boolean}
|
||||
:date {:type :iso_date}
|
||||
:comparison_date {:type :iso_date}}
|
||||
:resolve :balance-sheet-pdf}
|
||||
|
||||
:ledger_page {:type :ledger_page
|
||||
:args {:filters {:type :ledger_filters}}
|
||||
:resolve :get-ledger-page}})
|
||||
@@ -669,7 +656,6 @@
|
||||
:get-balance-sheet get-balance-sheet
|
||||
:get-profit-and-loss get-profit-and-loss
|
||||
:profit-and-loss-pdf profit-and-loss-pdf
|
||||
:balance-sheet-pdf balance-sheet-pdf
|
||||
:mutation/delete-external-ledger delete-external-ledger
|
||||
:mutation/import-ledger import-ledger})
|
||||
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
[clojure.java.io :as io]
|
||||
[clojure.string :as str]
|
||||
[config.core :refer [env]]
|
||||
[datomic.api :as d]
|
||||
[clojure.tools.logging :as log])
|
||||
[datomic.api :as d])
|
||||
(:import
|
||||
(java.io ByteArrayOutputStream)
|
||||
(java.text DecimalFormat)
|
||||
@@ -142,40 +141,6 @@
|
||||
9))]
|
||||
table))
|
||||
|
||||
(defn make-balance-sheet [args data]
|
||||
|
||||
(let [data (<-graphql data)
|
||||
args (<-graphql args)
|
||||
args (assoc args
|
||||
:periods (filter identity (cond-> [(:date args)]
|
||||
(:include-comparison args) (conj (:comparison-date args)))))
|
||||
clients (d/pull-many (d/db conn) '[:client/name :db/id] [(:client-id args)])
|
||||
data (concat (->> (:balance-sheet-accounts data)
|
||||
(map (fn [b]
|
||||
(assoc b
|
||||
:period (:date args)))))
|
||||
(->> (:comparable-balance-sheet-accounts data)
|
||||
(map (fn [b]
|
||||
(assoc b
|
||||
:period (:comparison-date args))))))
|
||||
pnl-data (l-reports/->PNLData args data (by :db/id clients))
|
||||
report (l-reports/summarize-balance-sheet pnl-data)
|
||||
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 "Balance Sheet - " (str/join ", " (map :client/name clients)))]]
|
||||
(conj [:paragraph {:color [128 0 0] :size 9} (:warning report)])
|
||||
(conj
|
||||
(table->pdf report
|
||||
(cond-> [30 13]
|
||||
(:include-comparison args) (into [13 13])))))
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn make-pnl [args data]
|
||||
|
||||
(let [data (<-graphql data)
|
||||
@@ -223,7 +188,7 @@
|
||||
output-stream)
|
||||
(.toByteArray output-stream)))
|
||||
|
||||
(defn pnl-args->name [args]
|
||||
(defn args->name [args]
|
||||
(let [min-date (atime/unparse-local
|
||||
(->> args :periods (map :start) first)
|
||||
atime/iso-date)
|
||||
@@ -233,17 +198,10 @@
|
||||
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)
|
||||
atime/iso-date)
|
||||
name (str/replace (->> args :client_id (d/pull (d/db conn) [:client/name]) :client/name ) #" " "_" )]
|
||||
(format "Balance-sheet-%s-for-%s" date name)))
|
||||
|
||||
(defn print-pnl [user args data]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
pdf-data (make-pnl args data)
|
||||
name (pnl-args->name args)
|
||||
name (args->name args)
|
||||
key (str "reports/pnl/" 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)
|
||||
@@ -260,24 +218,3 @@
|
||||
: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)
|
||||
name (balance-sheet-args->name args)
|
||||
key (str "reports/balance-sheet/" 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_id args)]
|
||||
:report/key key
|
||||
:report/url url
|
||||
:report/creator (:user user)
|
||||
:report/created (java.util.Date.)}])
|
||||
{:report/name name
|
||||
:report/url url }))
|
||||
|
||||
Reference in New Issue
Block a user