You can now pay invoices with credits from the same vendor.

This commit is contained in:
2022-05-31 13:21:49 -07:00
parent abd79c4b41
commit 49a0684d63
4 changed files with 131 additions and 14 deletions

View File

@@ -29,7 +29,8 @@
[goog.string :as gstring]
[re-frame.core :as re-frame]
[reagent.core :as r]
[vimsical.re-frame.fx.track :as track]))
[vimsical.re-frame.fx.track :as track]
[vimsical.re-frame.cofx.inject :as inject]))
(re-frame/reg-event-fx
::params-change
@@ -105,6 +106,30 @@
(:invoices (:print-checks result))
(:pdf-url (:print-checks result))])}}))
(re-frame/reg-event-fx
::pay-invoices-from-balance
[with-user (re-frame/inject-cofx ::inject/sub [::data-page/checked :invoices])]
(fn [{:keys [db user] ::data-page/keys [checked] :as cofx} _]
{:graphql
{:token user
:owns-state {:single ::print-checks}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "PayInvoicesFromBalance"}
:venia/queries [[:pay-invoices-from-balance
{:invoices (->> checked
(vals )
(filter (fn [{:keys [id outstanding-balance] }]
(and id outstanding-balance)))
(map :id))
:client_id (:client db)}
[[:invoices invoice-read]
:pdf_url]]]}
:on-success (fn [result]
[::checks-printed
(:invoices (:pay-invoices-from-balance result))
nil])}}))
(re-frame/reg-event-fx
::checks-printed
@@ -229,9 +254,16 @@
:disabled (status/disabled-for print-checks-status)} "Debit from " name])
(list
^{:key (str id "-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::print-checks id :credit])
:disabled (status/disabled-for print-checks-status)} "Credit from " name]))))
(when (> balance 0.001)
^{:key "advanced-divider"} [:hr.dropdown-divider])
:disabled (status/disabled-for print-checks-status)} "Credit from " name]
))))
^{:key "advanced-divider"} [:hr.dropdown-divider]
(when (and (> (count checked-invoices) 1)
(= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
(< balance 0.001))
^{:key (str "balance-credit")} [:a.dropdown-item {:on-click (dispatch-event-with-propagation [::pay-invoices-from-balance])
:disabled (status/disabled-for print-checks-status)} "Pay invoices using balance "])
(when (and (= 1 (count (set (map (comp :id :vendor) (vals checked-invoices)))))
(> balance 0.001))