Add the ability to unautopay

This commit is contained in:
2021-07-09 08:40:38 -07:00
parent 8f9d1de32e
commit 12d8aa8ad3
4 changed files with 50 additions and 6 deletions

View File

@@ -2,6 +2,7 @@
(:require [auto-ap.events :as events]
[auto-ap.routes :as routes]
[auto-ap.subs :as subs]
[auto-ap.status :as status]
[auto-ap.views.components.buttons :as buttons]
[auto-ap.views.components.dropdown
:refer
@@ -90,6 +91,21 @@
invoice-read]}]}
:on-success (fn [result]
[::invoice-updated (:unvoid-invoice result)])}}))
(re-frame/reg-event-fx
::unautopay
(fn [{:keys [db]} [_ {id :id}]]
{:graphql
{:token (-> db :user)
:owns-state {:multi ::unautopay
:which id}
:query-obj {:venia/operation {:operation/type :mutation
:operation/name "UnautopayInvoice"}
:venia/queries [{:query/data [:unautopay-invoice
{:invoice-id id}
invoice-read]}]}
:on-success (fn [result]
[::invoice-updated (:unautopay-invoice result)])}}))
(re-frame/reg-event-fx
::invoice-updated
@@ -99,6 +115,7 @@
(defn row [{:keys [invoice check-boxes selected-client overrides checkable? expense-event actions]}]
(let [{:keys [client status payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoice
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])
unautopay-states @(re-frame/subscribe [::status/multi ::unautopay])
account->name #(:name (accounts-by-id (:id %)))]
[grid/row {:class (:class i) :id id :checkable? checkable? :entity invoice}
(when-not selected-client
@@ -121,7 +138,11 @@
[grid/cell {} (str/join ", " (set (map :location expense-accounts)))]
[grid/cell {:class "has-text-right"} (nf total )]
[grid/cell {:class "has-text-right"} (nf outstanding-balance )]
[grid/cell {:class "has-text-right"}
(if (:scheduled-payment i)
[:<> [:div.tag.is-info.is-light "Autopay"] " "]
)
(nf outstanding-balance )]
[grid/button-cell {}
[:div.buttons
(when (seq expense-accounts)
@@ -185,7 +206,13 @@
(when (and (get actions :void)
(= ":voided" (:status i)))
[buttons/fa-icon {:icon "fa-undo"
:event [::unvoid-invoice i]}])]]]))
:event [::unvoid-invoice i]}])
(when (and (get actions :void)
(= ":paid" (:status i))
(:scheduled-payment i))
[buttons/fa-icon {:icon "fa-undo"
:class (status/class-for (get unautopay-states (:id i)))
:event [::unautopay i]}])]]]))
(defn invoice-table [{:keys [id check-boxes overrides actions data-page checkable-fn]}]
(let [selected-client @(re-frame/subscribe [::subs/client])