Performance improvements for printing checks
This commit is contained in:
@@ -31,6 +31,7 @@
|
|||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.string :as str]
|
[clojure.string :as str]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
|
[com.brunobonacci.mulog :as mu]
|
||||||
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
|
||||||
[config.core :refer [env]]
|
[config.core :refer [env]]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
@@ -390,14 +391,11 @@
|
|||||||
(let [type (keyword "payment-type" (name type))
|
(let [type (keyword "payment-type" (name type))
|
||||||
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
||||||
client (d-clients/get-by-id client-id)
|
client (d-clients/get-by-id client-id)
|
||||||
vendors (->> (d/q '[:find [?e ...]
|
|
||||||
:in $
|
|
||||||
:where [?e :vendor/name]]
|
|
||||||
(d/db conn))
|
|
||||||
(d/pull-many (d/db conn) d-vendors/default-read)
|
|
||||||
(by :db/id))
|
|
||||||
invoice-amounts (by :invoice-id :amount invoice-payments)
|
invoice-amounts (by :invoice-id :amount invoice-payments)
|
||||||
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
|
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
|
||||||
|
vendors (->> (d/pull-many (d/db conn) d-vendors/default-read (keys invoices-grouped-by-vendor))
|
||||||
|
(by :db/id))
|
||||||
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
bank-account (d-bank-accounts/get-by-id bank-account-id)
|
||||||
_ (validate-belonging client-id invoices bank-account)
|
_ (validate-belonging client-id invoices bank-account)
|
||||||
_ (when (and (nil? (:bank-account/check-number bank-account))
|
_ (when (and (nil? (:bank-account/check-number bank-account))
|
||||||
@@ -405,23 +403,27 @@
|
|||||||
(let [message (str "The bank account " (:bank-account/name bank-account) " does not have a starting check number. Please ask the integreat staff to initialize it.")]
|
(let [message (str "The bank account " (:bank-account/name bank-account) " does not have a starting check number. Please ask the integreat staff to initialize it.")]
|
||||||
(throw (ex-info message
|
(throw (ex-info message
|
||||||
{:validation-error message}))))
|
{:validation-error message}))))
|
||||||
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
checks (mu/trace ::build-checks []
|
||||||
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
|
(->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||||
(reduce into [])
|
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
|
||||||
doall)
|
(reduce into [])
|
||||||
|
doall))
|
||||||
checks (if (= type :payment-type/check)
|
checks (if (= type :payment-type/check)
|
||||||
(conj checks [:inc (:db/id bank-account) :bank-account/check-number (count invoices-grouped-by-vendor)])
|
(conj checks [:inc (:db/id bank-account) :bank-account/check-number (count invoices-grouped-by-vendor)])
|
||||||
checks)]
|
checks)]
|
||||||
(when (= type :payment-type/check)
|
(when (= type :payment-type/check)
|
||||||
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
(mu/trace ::making-pdfs [:checks checks]
|
||||||
(> (:payment/amount %) 0.0))
|
(make-pdfs (filter #(and (= :payment-type/check (:payment/type %))
|
||||||
checks)))
|
(> (:payment/amount %) 0.0))
|
||||||
|
checks))))
|
||||||
(transact-with-ledger checks id)
|
(transact-with-ledger checks id)
|
||||||
|
|
||||||
|
|
||||||
{:invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
{:invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
|
||||||
:pdf-url (if (= type :payment-type/check)
|
:pdf-url (if (= type :payment-type/check)
|
||||||
(merge-pdfs (filter identity (map :payment/s3-key checks)))
|
(mu/trace ::merge-pdfs
|
||||||
|
[]
|
||||||
|
(merge-pdfs (filter identity (map :payment/s3-key checks))))
|
||||||
nil)}))
|
nil)}))
|
||||||
|
|
||||||
(defn get-payment-page [context args _]
|
(defn get-payment-page [context args _]
|
||||||
|
|||||||
@@ -24,7 +24,8 @@
|
|||||||
[clojure.set :as set]
|
[clojure.set :as set]
|
||||||
[clojure.tools.logging :as log]
|
[clojure.tools.logging :as log]
|
||||||
[datomic.api :as d]
|
[datomic.api :as d]
|
||||||
[manifold.deferred :as de]))
|
[manifold.deferred :as de]
|
||||||
|
[com.brunobonacci.mulog :as mu]))
|
||||||
|
|
||||||
(defn ->graphql [invoice user ]
|
(defn ->graphql [invoice user ]
|
||||||
(if (= "admin" (:user/role user))
|
(if (= "admin" (:user/role user))
|
||||||
@@ -188,20 +189,24 @@
|
|||||||
|
|
||||||
|
|
||||||
(defn add-and-print-invoice [context {{:keys [total client_id vendor_id] :as in} :invoice bank-account-id :bank_account_id type :type} _]
|
(defn add-and-print-invoice [context {{:keys [total client_id vendor_id] :as in} :invoice bank-account-id :bank_account_id type :type} _]
|
||||||
(assert-no-conflicting in)
|
(mu/trace ::validating-invoice [:invoice in]
|
||||||
(assert-can-see-client (:id context) client_id)
|
(do
|
||||||
(assert-bank-account-belongs client_id bank-account-id)
|
(assert-no-conflicting in)
|
||||||
(assert-not-locked client_id (:date in))
|
(assert-can-see-client (:id context) client_id)
|
||||||
(assert-valid-expense-accounts (:expense_accounts in) vendor_id)
|
(assert-bank-account-belongs client_id bank-account-id)
|
||||||
(assert-invoice-amounts-add-up in)
|
(assert-not-locked client_id (:date in))
|
||||||
|
(assert-valid-expense-accounts (:expense_accounts in) vendor_id)
|
||||||
|
(assert-invoice-amounts-add-up in)))
|
||||||
(let [transaction-result (transact-with-ledger [(add-invoice-transaction in)] (:id context))]
|
(let [transaction-result (transact-with-ledger [(add-invoice-transaction in)] (:id context))]
|
||||||
(-> (gq-checks/print-checks-internal [{:invoice-id (get-in transaction-result [:tempids "invoice"])
|
(mu/trace ::printing-checks
|
||||||
:amount total}]
|
[]
|
||||||
client_id
|
(-> (gq-checks/print-checks-internal [{:invoice-id (get-in transaction-result [:tempids "invoice"])
|
||||||
bank-account-id
|
:amount total}]
|
||||||
type
|
client_id
|
||||||
(:id context))
|
bank-account-id
|
||||||
u/->graphql)))
|
type
|
||||||
|
(:id context))
|
||||||
|
u/->graphql))))
|
||||||
|
|
||||||
(defn edit-invoice [context {{:keys [id due invoice_number vendor_id total date expense_accounts scheduled_payment] :as in} :invoice} _]
|
(defn edit-invoice [context {{:keys [id due invoice_number vendor_id total date expense_accounts scheduled_payment] :as in} :invoice} _]
|
||||||
(let [invoice (d-invoices/get-by-id id)
|
(let [invoice (d-invoices/get-by-id id)
|
||||||
|
|||||||
Reference in New Issue
Block a user