allowing paying using debit.
This commit is contained in:
@@ -273,6 +273,7 @@
|
||||
{:print_checks {:type :check_result
|
||||
:args {:invoice_payments {:type '(list :invoice_payment)}
|
||||
:bank_account_id {:type 'Int}
|
||||
:type {:type 'String}
|
||||
:company_id {:type 'Int}}
|
||||
:resolve :mutation/print-checks}
|
||||
|
||||
@@ -482,7 +483,8 @@
|
||||
:amount (:amount i)})
|
||||
(:invoice_payments args))
|
||||
(:company_id args)
|
||||
(:bank_account_id args))))
|
||||
(:bank_account_id args)
|
||||
(:type args))))
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -177,10 +177,10 @@
|
||||
|
||||
|
||||
|
||||
(defmulti check-for-invoices (fn [invoices vendor-id vendors company bank-account index invoice-amounts]
|
||||
(or (:type bank-account) "check")))
|
||||
(defmulti check-for-invoices (fn [invoices vendor-id vendors company bank-account type index invoice-amounts]
|
||||
type))
|
||||
|
||||
(defmethod check-for-invoices "check" [invoices vendor-id vendors company bank-account index invoice-amounts]
|
||||
(defmethod check-for-invoices "check" [invoices vendor-id vendors company bank-account type index invoice-amounts]
|
||||
(let [uuid (str (UUID/randomUUID))
|
||||
vendor (vendors vendor-id)
|
||||
|
||||
@@ -217,7 +217,19 @@
|
||||
|
||||
:invoices (map :id invoices)}))
|
||||
|
||||
(defmethod check-for-invoices "cash" [invoices vendor-id vendors company bank-account index invoice-amounts]
|
||||
(defmethod check-for-invoices "debit" [invoices vendor-id vendors company bank-account type index invoice-amounts]
|
||||
(let [vendor (vendors vendor-id)]
|
||||
{:type "debit"
|
||||
:bank-account-id (:id bank-account)
|
||||
:amount (reduce + 0 (map (comp invoice-amounts :id) invoices))
|
||||
:status "cleared"
|
||||
:memo "Debit"
|
||||
:vendor-id (:id vendor)
|
||||
:company-id (:id company)
|
||||
:date (time/now)
|
||||
:invoices (map :id invoices)}))
|
||||
|
||||
(defmethod check-for-invoices "cash" [invoices vendor-id vendors company bank-account type index invoice-amounts]
|
||||
(let [vendor (vendors vendor-id)]
|
||||
{:type "cash"
|
||||
:bank-account-id (:id bank-account)
|
||||
@@ -229,7 +241,7 @@
|
||||
:date (time/now)
|
||||
:invoices (map :id invoices)}))
|
||||
|
||||
(defn print-checks [invoice-payments company-id bank-account-id]
|
||||
(defn print-checks [invoice-payments company-id bank-account-id type]
|
||||
(let [invoices (invoices/get-multi (map :invoice-id invoice-payments))
|
||||
company (companies/get-by-id company-id)
|
||||
vendors (by :id (vendors/get-all))
|
||||
@@ -237,7 +249,7 @@
|
||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
|
||||
checks (-> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account index invoice-amounts))])
|
||||
[invoices (checks/insert! (check-for-invoices invoices vendor-id vendors company bank-account type index invoice-amounts))])
|
||||
doall)
|
||||
invoice-checks (invoices-checks/insert-multi!
|
||||
(mapcat
|
||||
@@ -249,25 +261,25 @@
|
||||
:amount (invoice-amounts (:id i))})
|
||||
invoices))
|
||||
checks))
|
||||
updated-company (if (= (:type bank-account) "cash" )
|
||||
company
|
||||
updated-company (if (= type "check" )
|
||||
(update company :bank-accounts
|
||||
(fn [bas]
|
||||
(map (fn [ba]
|
||||
(if (= bank-account-id (:id ba))
|
||||
(update ba :check-number + (count checks))
|
||||
ba))
|
||||
bas))))]
|
||||
bas)))
|
||||
company)]
|
||||
|
||||
(when (not= (:type bank-account) "cash")
|
||||
(when (= type "check")
|
||||
(make-pdfs (map second checks))
|
||||
(companies/upsert company-id updated-company))
|
||||
(doseq [{:keys [invoice-id amount]} invoice-payments]
|
||||
(invoices/apply-payment invoice-id amount))
|
||||
{:invoices (invoices/get-multi (map :id (mapcat first checks)))
|
||||
:pdf-url (if (= (:type bank-account) "cash")
|
||||
nil
|
||||
(merge-pdfs (map (comp :s3-key second) checks)))}))
|
||||
:pdf-url (if (= type "check")
|
||||
(merge-pdfs (map (comp :s3-key second) checks))
|
||||
nil)}))
|
||||
|
||||
|
||||
(defroutes routes
|
||||
|
||||
Reference in New Issue
Block a user