Makes reports exportable

This commit is contained in:
2023-09-23 07:48:06 -07:00
parent 12c676629d
commit be13bbbb4d
7 changed files with 15 additions and 19 deletions

View File

@@ -3,7 +3,6 @@
[auto-ap.datomic [auto-ap.datomic
:refer [audit-transact-batch conn pull-many remove-nils]] :refer [audit-transact-batch conn pull-many remove-nils]]
[auto-ap.datomic.accounts :as a] [auto-ap.datomic.accounts :as a]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.ledger :as l] [auto-ap.datomic.ledger :as l]
[auto-ap.graphql.utils [auto-ap.graphql.utils
:refer [->graphql :refer [->graphql
@@ -11,15 +10,18 @@
assert-admin assert-admin
assert-can-see-client assert-can-see-client
attach-tracing-resolvers attach-tracing-resolvers
extract-client-ids
result->page]] result->page]]
[auto-ap.ledger :refer [build-account-lookup]] [auto-ap.ledger :refer [build-account-lookup]]
[auto-ap.ledger.reports :as l-reports] [auto-ap.ledger.reports :as l-reports]
[auto-ap.logging :as alog]
[auto-ap.parse.util :as parse] [auto-ap.parse.util :as parse]
[auto-ap.pdf.ledger [auto-ap.pdf.ledger
:refer [print-balance-sheet :refer [print-balance-sheet
print-cash-flows print-cash-flows
print-journal-detail-report print-journal-detail-report
print-pnl]] print-pnl]]
[auto-ap.solr :as solr]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[auto-ap.utils :refer [by dollars=]] [auto-ap.utils :refer [by dollars=]]
[clj-time.coerce :as coerce] [clj-time.coerce :as coerce]
@@ -28,9 +30,7 @@
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
[com.brunobonacci.mulog :as mu] [com.brunobonacci.mulog :as mu]
[datomic.api :as dc] [datomic.api :as dc]
[iol-ion.tx :refer [random-tempid]] [iol-ion.tx :refer [random-tempid]])
[auto-ap.solr :as solr]
[auto-ap.logging :as alog])
(:import (:import
(org.apache.commons.codec.binary Base64))) (org.apache.commons.codec.binary Base64)))
@@ -310,7 +310,9 @@
(->graphql result))) (->graphql result)))
(defn balance-sheet-pdf [context args value] (defn balance-sheet-pdf [context args value]
(let [data (get-balance-sheet context args value) (let [valid-clients (extract-client-ids (:clients context)
(:client_ids args))
data (get-balance-sheet context args value)
result (print-balance-sheet (:id context) args data)] result (print-balance-sheet (:id context) args data)]
(->graphql result))) (->graphql result)))

View File

@@ -182,7 +182,7 @@
(sequential? x) (sequential? x)
(map x coerce-client-ids) (mapcat coerce-client-ids x)
:else :else
[])) []))

View File

@@ -153,7 +153,7 @@
args (assoc args args (assoc args
:periods (filter identity (cond-> [(:date args)] :periods (filter identity (cond-> [(:date args)]
(:include-comparison args) (conj (:comparison-date args))))) (:include-comparison args) (conj (:comparison-date args)))))
clients (pull-many (dc/db conn) [:client/code :client/name :db/id] [(:client-id args)]) clients (pull-many (dc/db conn) [:client/code :client/name :db/id] (:client-ids args))
data (concat (->> (:balance-sheet-accounts data) data (concat (->> (:balance-sheet-accounts data)
(map (fn [b] (map (fn [b]
(assoc b (assoc b
@@ -167,7 +167,6 @@
report (l-reports/summarize-balance-sheet pnl-data) report (l-reports/summarize-balance-sheet pnl-data)
output-stream (ByteArrayOutputStream.)] output-stream (ByteArrayOutputStream.)]
(log/info report)
(pdf/pdf (pdf/pdf
(-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15 (-> [{:left-margin 10 :right-margin 10 :top-margin 15 :bottom-margin 15
:size :letter :size :letter

View File

@@ -23,7 +23,6 @@
(let [variables (some-> (query-params "variables") (let [variables (some-> (query-params "variables")
edn/read-string) edn/read-string)
body (some-> r :body slurp)] body (some-> r :body slurp)]
(println "CLIENTS" clients)
{:status 200 {:status 200
:body (pr-str (ql/query (:identity r) (if (= request-method :get) (query-params "query") body) (assoc variables :body (pr-str (ql/query (:identity r) (if (= request-method :get) (query-params "query") body) (assoc variables

View File

@@ -97,7 +97,7 @@ NOTE: Please review the transactions we may have question for you here: https://
:body [:div :body [:div
[:div "Click " [:div "Click "
[:a {:href (-> result :balance-sheet-pdf :url) :target "_new"} "here"] " to view it."] [:a {:href (-> result :balance-sheet-pdf :url) :target "_new"} "here"] " to view it."]
(when (seq (:emails client)) (when (and (seq (:emails client)) @(re-frame/subscribe [::subs/is-admin?]))
[:div "Once you've confirmed you're happy with it, click " [:div "Once you've confirmed you're happy with it, click "
[:a {:href (str "mailto:" (str/join ";" (map :email (:emails client))) "?body=" (email-body (-> result :balance-sheet-pdf :url)) [:a {:href (str "mailto:" (str/join ";" (map :email (:emails client))) "?body=" (email-body (-> result :balance-sheet-pdf :url))
"&subject=" (-> result :balance-sheet-pdf :name) " is ready")} "&subject=" (-> result :balance-sheet-pdf :name) " is ready")}
@@ -235,9 +235,7 @@ NOTE: Please review the transactions we may have question for you here: https://
[date-picker {:output :cljs-date}]])]] [date-picker {:output :cljs-date}]])]]
[:div.level-right [:div.level-right
[:div.buttons [:div.buttons
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"]
(when @(re-frame/subscribe [::subs/is-admin?])
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]]] [:button.button.is-primary "Run"]]]]
[:div.report-control-detail {:ref (fn [el] [:div.report-control-detail {:ref (fn [el]
(when (not= @!box el) (when (not= @!box el)

View File

@@ -112,7 +112,7 @@ NOTE: Please review the transactions we may have question for you here: https://
:body [:div :body [:div
[:div "Click " [:div "Click "
[:a {:href (-> result :profit-and-loss-pdf :url) :target "_new"} "here"] " to view it."] [:a {:href (-> result :profit-and-loss-pdf :url) :target "_new"} "here"] " to view it."]
(when (and single-client? (seq client-emails)) (when (and single-client? (seq client-emails) @(re-frame/subscribe [::subs/is-admin?]))
[:div "Once you've confirmed you're happy with it, click " [:div "Once you've confirmed you're happy with it, click "
[:a {:href (str "mailto:" (str/join ";" (map :email client-emails)) "?body=" (email-body (-> result :profit-and-loss-pdf :url)) [:a {:href (str "mailto:" (str/join ";" (map :email client-emails)) "?body=" (email-body (-> result :profit-and-loss-pdf :url))
"&subject=" (-> result :profit-and-loss-pdf :name) " is ready")} "&subject=" (-> result :profit-and-loss-pdf :name) " is ready")}
@@ -402,8 +402,7 @@ NOTE: Please review the transactions we may have question for you here: https://
[:div.level-right [:div.level-right
[:div.buttons [:div.buttons
(when @(re-frame/subscribe [::subs/is-admin?]) [:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"]
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]] [:button.button.is-primary "Run"]]
]] ]]

View File

@@ -94,7 +94,7 @@ NOTE: Please review the transactions we may have question for you here: https://
:body [:div :body [:div
[:div "Click " [:div "Click "
[:a {:href (-> result :journal-detail-report-pdf :url) :target "_new"} "here"] " to view it."] [:a {:href (-> result :journal-detail-report-pdf :url) :target "_new"} "here"] " to view it."]
(when (and single-client? (seq client-emails)) (when (and single-client? (seq client-emails) @(re-frame/subscribe [::subs/is-admin?]))
[:div "Once you've confirmed you're happy with it, click " [:div "Once you've confirmed you're happy with it, click "
[:a {:href (str "mailto:" (str/join ";" (map :email client-emails)) "?body=" (email-body (-> result :journal-detail-report-pdf :url)) [:a {:href (str "mailto:" (str/join ";" (map :email client-emails)) "?body=" (email-body (-> result :journal-detail-report-pdf :url))
"&subject=" (-> result :journal-detail-report-pdf :name) " is ready")} "&subject=" (-> result :journal-detail-report-pdf :name) " is ready")}
@@ -181,8 +181,7 @@ NOTE: Please review the transactions we may have question for you here: https://
[date-picker {:output :cljs-date}]]] [date-picker {:output :cljs-date}]]]
[:div.level-right [:div.level-right
[:div.buttons [:div.buttons
(when @(re-frame/subscribe [::subs/is-admin?]) [:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"]
[:button.button.is-secondary {:on-click (dispatch-event [::export-pdf])} "Export"])
[:button.button.is-primary "Run"]]]]] [:button.button.is-primary "Run"]]]]]
[:div.report-control-detail {:ref (fn [el] [:div.report-control-detail {:ref (fn [el]
(when (not= @!box el) (when (not= @!box el)