From b669984673c55b1d01e3ccaebe21ea86d2e76db1 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 10 Mar 2023 14:15:18 -0800 Subject: [PATCH] Only shows most recent payments for potential payments for transactions, fixes invoice multiple prints. --- src/clj/auto_ap/graphql/checks.clj | 11 ++++++----- src/cljs/auto_ap/views/pages/invoices/form.cljs | 6 +++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/clj/auto_ap/graphql/checks.clj b/src/clj/auto_ap/graphql/checks.clj index 0c00cf91..ee1b631f 100644 --- a/src/clj/auto_ap/graphql/checks.clj +++ b/src/clj/auto_ap/graphql/checks.clj @@ -448,11 +448,12 @@ (defn get-potential-payments [context args _] (let [transaction (d-transactions/get-by-id (:transaction_id args)) _ (assert-can-see-client (:id context) (:transaction/client transaction)) - [payments _] (d-checks/get-graphql {:client-id (:db/id (:transaction/client transaction)) - :bank-account-id (:db/id (:transaction/bank-account transaction)) - :amount (- (:transaction/amount transaction)) - :status :payment-status/pending})] - (map ->graphql payments))) + [payments _] (d-checks/get-graphql {:client-id (:db/id (:transaction/client transaction)) + :bank-account-id (:db/id (:transaction/bank-account transaction)) + :amount (- (:transaction/amount transaction)) + :status :payment-status/pending + :date-range {:start (time/plus (:transaction/date transaction) (time/days 1))}})] + (map ->graphql (reverse (sort-by :payment/date payments))))) (defn add-handwritten-check [context args _] (let [invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args))) diff --git a/src/cljs/auto_ap/views/pages/invoices/form.cljs b/src/cljs/auto_ap/views/pages/invoices/form.cljs index 9db65213..64174d6b 100644 --- a/src/cljs/auto_ap/views/pages/invoices/form.cljs +++ b/src/cljs/auto_ap/views/pages/invoices/form.cljs @@ -234,7 +234,7 @@ :bank-account-id bank-account-id :type type} [:pdf-url [:invoices invoice-read]]]}]} - :on-success [::added-and-printed] + :on-success [::added-and-printed client] :on-error [::forms/save-error ::form]}}) )) @@ -284,9 +284,9 @@ (re-frame/reg-event-fx ::added-and-printed - (fn [_ [_ result]] + (fn [_ [_ client result]] (let [invoice (first (:invoices (:add-and-print-invoice result)))] - {:dispatch-n [[::updated (assoc invoice :class "live-added") :create] + {:dispatch-n [[::updated (assoc invoice :class "live-added") :create client] [::checks-printed [invoice] (:pdf-url (:add-and-print-invoice result))]]}))) (re-frame/reg-event-db