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
|
||||
|
||||
@@ -154,9 +154,10 @@
|
||||
(when-not selected-company
|
||||
[:td (:name company)])
|
||||
[:td (:name vendor)]
|
||||
[:td (if (= "cash" type)
|
||||
"Cash"
|
||||
check-number)]
|
||||
[:td (cond
|
||||
(= "cash" type) "Cash"
|
||||
(= "debit" type) "Debit"
|
||||
:else check-number)]
|
||||
[:td (date->str date) ]
|
||||
[:td (gstring/format "$%.2f" amount )]
|
||||
[:td status]
|
||||
|
||||
@@ -149,12 +149,13 @@
|
||||
(assoc-in i f v)
|
||||
i))))))
|
||||
|
||||
(defn print-checks-query [invoice-payments bank-account-id company-id]
|
||||
(defn print-checks-query [invoice-payments bank-account-id type company-id]
|
||||
{:venia/operation {:operation/type :mutation
|
||||
:operation/name "PrintChecks"}
|
||||
|
||||
:venia/queries [[:print-checks
|
||||
{:invoice_payments invoice-payments
|
||||
:type type
|
||||
:bank_account_id bank-account-id
|
||||
:company_id company-id}
|
||||
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
||||
@@ -162,7 +163,7 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::print-checks
|
||||
(fn [{:keys [db]} [_ bank-account-id]]
|
||||
(fn [{:keys [db]} [_ bank-account-id type]]
|
||||
(let [invoice-amounts (by :id :outstanding-balance (get-in db [::invoice-page :invoices]))]
|
||||
|
||||
{:db (-> db
|
||||
@@ -176,6 +177,7 @@
|
||||
:amount (invoice-amounts id)})
|
||||
(get-in db [::invoice-page :checked]))
|
||||
bank-account-id
|
||||
type
|
||||
(:company db))
|
||||
:on-success [::checks-created]}})))
|
||||
|
||||
@@ -185,7 +187,12 @@
|
||||
::advanced-print-checks-submitted
|
||||
(fn [{:keys [db]} [_ bank-account-id]]
|
||||
(let [invoice-amounts (by :id (comp js/parseFloat :amount) (get-in db [::advanced-print-checks :invoices]))
|
||||
bank-account-id (get-in db [::advanced-print-checks :bank-account-id])]
|
||||
bank-account-id (get-in db [::advanced-print-checks :bank-account-id])
|
||||
type (->> @(re-frame/subscribe [::subs/company])
|
||||
:bank-accounts
|
||||
(filter #(= bank-account-id (:id %)))
|
||||
first
|
||||
:type)]
|
||||
{:db (-> db
|
||||
(assoc-in [::advanced-print-checks :printing?] true ))
|
||||
:graphql
|
||||
@@ -196,6 +203,7 @@
|
||||
:amount (invoice-amounts (:id x))})
|
||||
(get-in db [::advanced-print-checks :invoices]))
|
||||
bank-account-id
|
||||
(or type "check")
|
||||
(:company db))
|
||||
|
||||
:on-success [::checks-created]}})))
|
||||
@@ -793,10 +801,11 @@
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-company)]
|
||||
(do (println type)
|
||||
(if (= "cash" type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} "With cash"]
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} "Print checks from " name])))
|
||||
(if (= "cash" type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id "cash"])} "With cash"]
|
||||
(list
|
||||
^{:key (str id "-check")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id "check"])} "Print checks from " name]
|
||||
^{:key (str id "-debit")} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id "debit"])} "Debit from " name])))
|
||||
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||
|
||||
(when (= 1 (count checked))
|
||||
|
||||
Reference in New Issue
Block a user