allowing paying using debit.
This commit is contained in:
@@ -273,6 +273,7 @@
|
|||||||
{:print_checks {:type :check_result
|
{:print_checks {:type :check_result
|
||||||
:args {:invoice_payments {:type '(list :invoice_payment)}
|
:args {:invoice_payments {:type '(list :invoice_payment)}
|
||||||
:bank_account_id {:type 'Int}
|
:bank_account_id {:type 'Int}
|
||||||
|
:type {:type 'String}
|
||||||
:company_id {:type 'Int}}
|
:company_id {:type 'Int}}
|
||||||
:resolve :mutation/print-checks}
|
:resolve :mutation/print-checks}
|
||||||
|
|
||||||
@@ -482,7 +483,8 @@
|
|||||||
:amount (:amount i)})
|
:amount (:amount i)})
|
||||||
(:invoice_payments args))
|
(:invoice_payments args))
|
||||||
(:company_id 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]
|
(defmulti check-for-invoices (fn [invoices vendor-id vendors company bank-account type index invoice-amounts]
|
||||||
(or (:type bank-account) "check")))
|
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))
|
(let [uuid (str (UUID/randomUUID))
|
||||||
vendor (vendors vendor-id)
|
vendor (vendors vendor-id)
|
||||||
|
|
||||||
@@ -217,7 +217,19 @@
|
|||||||
|
|
||||||
:invoices (map :id invoices)}))
|
: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)]
|
(let [vendor (vendors vendor-id)]
|
||||||
{:type "cash"
|
{:type "cash"
|
||||||
:bank-account-id (:id bank-account)
|
:bank-account-id (:id bank-account)
|
||||||
@@ -229,7 +241,7 @@
|
|||||||
:date (time/now)
|
:date (time/now)
|
||||||
:invoices (map :id invoices)}))
|
: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))
|
(let [invoices (invoices/get-multi (map :invoice-id invoice-payments))
|
||||||
company (companies/get-by-id company-id)
|
company (companies/get-by-id company-id)
|
||||||
vendors (by :id (vendors/get-all))
|
vendors (by :id (vendors/get-all))
|
||||||
@@ -237,7 +249,7 @@
|
|||||||
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
invoices-grouped-by-vendor (group-by :vendor-id invoices)
|
||||||
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
|
bank-account (first (filter #(= (:id %) bank-account-id) (:bank-accounts company)))
|
||||||
checks (-> (for [[[vendor-id invoices] index] (map vector invoices-grouped-by-vendor (range))]
|
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)
|
doall)
|
||||||
invoice-checks (invoices-checks/insert-multi!
|
invoice-checks (invoices-checks/insert-multi!
|
||||||
(mapcat
|
(mapcat
|
||||||
@@ -249,25 +261,25 @@
|
|||||||
:amount (invoice-amounts (:id i))})
|
:amount (invoice-amounts (:id i))})
|
||||||
invoices))
|
invoices))
|
||||||
checks))
|
checks))
|
||||||
updated-company (if (= (:type bank-account) "cash" )
|
updated-company (if (= type "check" )
|
||||||
company
|
|
||||||
(update company :bank-accounts
|
(update company :bank-accounts
|
||||||
(fn [bas]
|
(fn [bas]
|
||||||
(map (fn [ba]
|
(map (fn [ba]
|
||||||
(if (= bank-account-id (:id ba))
|
(if (= bank-account-id (:id ba))
|
||||||
(update ba :check-number + (count checks))
|
(update ba :check-number + (count checks))
|
||||||
ba))
|
ba))
|
||||||
bas))))]
|
bas)))
|
||||||
|
company)]
|
||||||
|
|
||||||
(when (not= (:type bank-account) "cash")
|
(when (= type "check")
|
||||||
(make-pdfs (map second checks))
|
(make-pdfs (map second checks))
|
||||||
(companies/upsert company-id updated-company))
|
(companies/upsert company-id updated-company))
|
||||||
(doseq [{:keys [invoice-id amount]} invoice-payments]
|
(doseq [{:keys [invoice-id amount]} invoice-payments]
|
||||||
(invoices/apply-payment invoice-id amount))
|
(invoices/apply-payment invoice-id amount))
|
||||||
{:invoices (invoices/get-multi (map :id (mapcat first checks)))
|
{:invoices (invoices/get-multi (map :id (mapcat first checks)))
|
||||||
:pdf-url (if (= (:type bank-account) "cash")
|
:pdf-url (if (= type "check")
|
||||||
nil
|
(merge-pdfs (map (comp :s3-key second) checks))
|
||||||
(merge-pdfs (map (comp :s3-key second) checks)))}))
|
nil)}))
|
||||||
|
|
||||||
|
|
||||||
(defroutes routes
|
(defroutes routes
|
||||||
|
|||||||
@@ -154,9 +154,10 @@
|
|||||||
(when-not selected-company
|
(when-not selected-company
|
||||||
[:td (:name company)])
|
[:td (:name company)])
|
||||||
[:td (:name vendor)]
|
[:td (:name vendor)]
|
||||||
[:td (if (= "cash" type)
|
[:td (cond
|
||||||
"Cash"
|
(= "cash" type) "Cash"
|
||||||
check-number)]
|
(= "debit" type) "Debit"
|
||||||
|
:else check-number)]
|
||||||
[:td (date->str date) ]
|
[:td (date->str date) ]
|
||||||
[:td (gstring/format "$%.2f" amount )]
|
[:td (gstring/format "$%.2f" amount )]
|
||||||
[:td status]
|
[:td status]
|
||||||
|
|||||||
@@ -149,12 +149,13 @@
|
|||||||
(assoc-in i f v)
|
(assoc-in i f v)
|
||||||
i))))))
|
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
|
{:venia/operation {:operation/type :mutation
|
||||||
:operation/name "PrintChecks"}
|
:operation/name "PrintChecks"}
|
||||||
|
|
||||||
:venia/queries [[:print-checks
|
:venia/queries [[:print-checks
|
||||||
{:invoice_payments invoice-payments
|
{:invoice_payments invoice-payments
|
||||||
|
:type type
|
||||||
:bank_account_id bank-account-id
|
:bank_account_id bank-account-id
|
||||||
:company_id company-id}
|
:company_id company-id}
|
||||||
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
[[:invoices [:id :outstanding-balance [:checks [:amount [:check [:amount :s3_url :check_number ]]]]]]
|
||||||
@@ -162,7 +163,7 @@
|
|||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::print-checks
|
::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]))]
|
(let [invoice-amounts (by :id :outstanding-balance (get-in db [::invoice-page :invoices]))]
|
||||||
|
|
||||||
{:db (-> db
|
{:db (-> db
|
||||||
@@ -176,6 +177,7 @@
|
|||||||
:amount (invoice-amounts id)})
|
:amount (invoice-amounts id)})
|
||||||
(get-in db [::invoice-page :checked]))
|
(get-in db [::invoice-page :checked]))
|
||||||
bank-account-id
|
bank-account-id
|
||||||
|
type
|
||||||
(:company db))
|
(:company db))
|
||||||
:on-success [::checks-created]}})))
|
:on-success [::checks-created]}})))
|
||||||
|
|
||||||
@@ -185,7 +187,12 @@
|
|||||||
::advanced-print-checks-submitted
|
::advanced-print-checks-submitted
|
||||||
(fn [{:keys [db]} [_ bank-account-id]]
|
(fn [{:keys [db]} [_ bank-account-id]]
|
||||||
(let [invoice-amounts (by :id (comp js/parseFloat :amount) (get-in db [::advanced-print-checks :invoices]))
|
(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
|
{:db (-> db
|
||||||
(assoc-in [::advanced-print-checks :printing?] true ))
|
(assoc-in [::advanced-print-checks :printing?] true ))
|
||||||
:graphql
|
:graphql
|
||||||
@@ -196,6 +203,7 @@
|
|||||||
:amount (invoice-amounts (:id x))})
|
:amount (invoice-amounts (:id x))})
|
||||||
(get-in db [::advanced-print-checks :invoices]))
|
(get-in db [::advanced-print-checks :invoices]))
|
||||||
bank-account-id
|
bank-account-id
|
||||||
|
(or type "check")
|
||||||
(:company db))
|
(:company db))
|
||||||
|
|
||||||
:on-success [::checks-created]}})))
|
:on-success [::checks-created]}})))
|
||||||
@@ -793,10 +801,11 @@
|
|||||||
[:div.dropdown-content
|
[:div.dropdown-content
|
||||||
(list
|
(list
|
||||||
(for [{:keys [id number name type]} (:bank-accounts current-company)]
|
(for [{:keys [id number name type]} (:bank-accounts current-company)]
|
||||||
(do (println type)
|
(if (= "cash" type)
|
||||||
(if (= "cash" type)
|
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id "cash"])} "With cash"]
|
||||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} "With cash"]
|
(list
|
||||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id])} "Print checks from " name])))
|
^{: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]
|
^{:key "advanced-divider"} [:hr.dropdown-divider]
|
||||||
|
|
||||||
(when (= 1 (count checked))
|
(when (= 1 (count checked))
|
||||||
|
|||||||
Reference in New Issue
Block a user