ledger export

This commit is contained in:
Bryce Covert
2022-12-14 08:29:16 -08:00
parent 5fad948c12
commit 02696110b8
4 changed files with 92 additions and 10 deletions

View File

@@ -236,6 +236,9 @@
:role {:type :role}
:clients {:type '(list :client)}}}
:csv
{:fields {:csv_content_b64 {:type 'String}}}
:account_client_override
{:fields {:id {:type :id}
:client {:type :client}

View File

@@ -4,6 +4,7 @@
[auto-ap.datomic.accounts :as a]
[auto-ap.datomic.clients :as d-clients]
[auto-ap.datomic.ledger :as l]
[auto-ap.time :as atime]
[auto-ap.ledger.reports :as l-reports]
[auto-ap.datomic.vendors :as d-vendors]
[auto-ap.graphql.utils
@@ -14,11 +15,13 @@
[clj-time.coerce :as coerce]
[clj-time.core :as t]
[clojure.tools.logging :as log]
[clojure.data.csv :as csv]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[datomic.api :as d]
[mount.core :as mount]
[unilog.context :as lc]
[yang.scheduler :as scheduler]))
[yang.scheduler :as scheduler])
(:import [org.apache.commons.codec.binary Base64]))
(mount/defstate running-balance-cache
:start (atom {}))
@@ -43,6 +46,38 @@
journal-entries)]
(result->page journal-entries journal-entries-count :journal_entries (:filters args))))
(defn get-ledger-csv [context args _]
(let [args (assoc args :id (:id context))
[journal-entries journal-entries-count] (l/get-graphql (assoc (<-graphql (:filters args))
:per-page Integer/MAX_VALUE
:id (:id context)))
]
{:csv_content_b64 (Base64/encodeBase64String
(.getBytes
(with-open [w (java.io.StringWriter.)]
(csv/write-csv w
(into [["Client" "Vendor" "Date" "Journal Entry" "Journal Entry Line" "Account" "Debit" "Credit"]]
(->> journal-entries
(mapcat (fn [j]
(map
(fn [li]
[(-> j :journal-entry/client :client/code)
(-> j :journal-entry/vendor :vendor/name)
(atime/unparse (coerce/to-date-time (-> j :journal-entry/date))
atime/normal-date)
(-> j :db/id)
(-> li :db/id)
(-> li :journal-entry-line/account :account/name)
(-> li :journal-entry-line/debit)
(-> li :journal-entry-line/credit)
])
(:journal-entry/line-items j))
))))
:quote? (constantly true))
(.toString w))))}))
(defn roll-up-until
([lookup-account all-ledger-entries end-date]
@@ -741,7 +776,11 @@
:ledger_page {:type :ledger_page
:args {:filters {:type :ledger_filters}}
:resolve :get-ledger-page}})
:resolve :get-ledger-page}
:ledger_csv {:type :csv
:args {:filters {:type :ledger_filters}}
:resolve :get-ledger-csv}})
(def mutations
{:import_ledger
@@ -809,6 +848,7 @@
:profit-and-loss-pdf profit-and-loss-pdf
:journal-detail-report-pdf journal-detail-report-pdf
:balance-sheet-pdf balance-sheet-pdf
:get-ledger-csv get-ledger-csv
:get-journal-detail-report get-journal-detail-report
:mutation/delete-external-ledger delete-external-ledger
:mutation/import-ledger import-ledger})