Tons of small fixes

This commit is contained in:
Bryce Covert
2020-07-27 21:28:02 -07:00
parent 3737cfa628
commit fdc1d3e9e4
26 changed files with 428 additions and 178 deletions

View File

@@ -293,6 +293,19 @@
(conj payment)
(into (invoice-payments invoices invoice-amounts)))))
(defn validate-belonging [client-id invoices bank-account]
(when-not (apply = client-id (map (comp :db/id :invoice/client) invoices ))
(throw (ex-info "You can't pay for that invoice from this bank account."
{:validation-error "You can't pay for that invoice from this bank account."
:client-id client-id
:invoices (map :invoice/invoice-number invoices)}))
)
(when-not (= client-id (:db/id (:client/_bank-accounts bank-account)))
(throw (ex-info "The selected bank doesn't belong to this client"
{:validation-error "The selected bank doesn't belong to this client"
:client-id client-id
:invoices (map :invoice/invoice-number invoices)}))))
(defn print-checks [invoice-payments client-id bank-account-id type]
(let [type (keyword "payment-type" (name type))
invoices (d-invoices/get-multi (map :invoice-id invoice-payments))
@@ -303,6 +316,8 @@
invoices-grouped-by-vendor (group-by (comp :db/id :invoice/vendor) invoices)
bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (validate-belonging client-id invoices bank-account)
checks (->> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
(invoices->entities invoices (vendors vendor-id) client bank-account type index invoice-amounts))
(reduce into [])
@@ -347,6 +362,7 @@
bank-account (d-bank-accounts/get-by-id bank-account-id)
_ (doseq [invoice invoices]
(assert-can-see-client (:id context) (:invoice/client invoice)))
_ (validate-belonging (:db/id (:client/_bank-accounts bank-account)) invoices bank-account)
invoice-payment-lookup (by :invoice_id :amount (:invoice_payments args))
base-payment (base-payment invoices
(:invoice/vendor (first invoices))