you can pay off more than one invoice for the same vendor.

This commit is contained in:
Bryce Covert
2019-03-21 11:20:37 -07:00
parent 461686aee6
commit d270ca89f9
3 changed files with 104 additions and 55 deletions

View File

@@ -387,8 +387,7 @@
:resolve :mutation/print-checks}
:add_handwritten_check {:type :check_result
:args {:invoice_id {:type :id}
:amount {:type 'Float}
:args {:invoice_payments {:type '(list :invoice_payment_amount)}
:date {:type 'String}
:check_number {:type 'Int}
:bank_account_id {:type :id}}

View File

@@ -330,24 +330,30 @@
:end (+ (:start args 0) (count payments))}]))
(defn add-handwritten-check [context args value]
(let [invoice (d-invoices/get-by-id (:invoice_id args))
(let [invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))
bank-account-id (:bank_account_id args)
bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (assert-can-see-client (:id context) (:invoice/client invoice))
base-payment (base-payment [invoice] (:invoice/vendor invoice)
(:invoice/client invoice)
bank-account :payment-type/check 0 {(:invoice_id args) (:amount args)})]
_ (doseq [invoice invoices]
(assert-can-see-client (:id context) (:invoice/client invoice)))
invoice-payment-lookup (by :invoice_id :amount (:invoice_payments args))
base-payment (base-payment invoices
(:invoice/vendor (first invoices))
(:invoice/client (first invoices))
bank-account
:payment-type/check
0
invoice-payment-lookup)]
@(d/transact (d/connect uri)
(into [(assoc base-payment
:payment/type :payment-type/check
:payment/status :payment-status/pending
:payment/check-number (:check_number args)
:payment/date (c/to-date (parse (:date args) iso-date))
:payment/amount (:amount args))]
(invoice-payments [invoice] {(:invoice_id args) (:amount args)})))
:payment/type :payment-type/check
:payment/status :payment-status/pending
:payment/check-number (:check_number args)
:payment/date (c/to-date (parse (:date args) iso-date)))]
(invoice-payments invoices invoice-payment-lookup)))
(->graphql
{:s3-url nil
:invoices [(d-invoices/get-by-id (:invoice_id args))]})))
:invoices (d-invoices/get-multi (map :invoice_id (:invoice_payments args)))})))
(defn void-check [context {id :payment_id} value]