invoices can be payed again

This commit is contained in:
Bryce Covert
2020-08-12 10:04:53 -07:00
parent 255a73dc30
commit 27a66f11f1
3 changed files with 61 additions and 42 deletions

View File

@@ -135,13 +135,22 @@
(re-frame/reg-event-db
::toggle-check
(fn [db [_ id invoice]]
(-> db
(update-in [::invoice-page :checked] (fn [x]
(let [x (or x {})]
(if (x id)
(dissoc x id)
(assoc x id invoice))))))))
[(re-frame/path [::invoice-page :checked])]
(fn [db [_ new]]
new))
(re-frame/reg-event-db
::remove-check
[(re-frame/path [::invoice-page :checked])]
(fn [db [_ to-remove]]
(let [db (or db #{})]
(disj db to-remove))))
(re-frame/reg-sub
::checked-invoices
:<- [::invoice-page]
(fn [page]
(filter (comp #(get (:checked page) %) :id) (:invoices page))))
@@ -238,10 +247,10 @@
:graphql
{:token (-> db :user)
:query-obj (print-checks-query (map (fn [[id invoice]]
:query-obj (print-checks-query (map (fn [{:keys [id outstanding-balance] }]
{:invoice-id id
:amount (:outstanding-balance invoice)})
(get-in db [::invoice-page :checked]))
:amount outstanding-balance})
@(re-frame/subscribe [::checked-invoices]))
bank-account-id
type
(:client db))
@@ -542,8 +551,9 @@
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
(let [current-client @(re-frame/subscribe [::subs/client])]
(defn pay-button [{:keys [print-checks-shown? print-checks-loading?]}]
(let [current-client @(re-frame/subscribe [::subs/client])
checked-invoices @(re-frame/subscribe [::checked-invoices])]
[:div
[:div.is-pulled-right
[:div.buttons
@@ -564,7 +574,6 @@
(count checked-invoices)
" invoices "
"(" (->> checked-invoices
vals
(map (comp js/parseFloat :outstanding-balance))
(reduce + 0)
(gstring/format "$%.2f" ))
@@ -583,11 +592,14 @@
^{: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 (set (map (comp :id :vendor) (vals checked-invoices)))))
(when (= 1 (count (set (map (comp :id :vendor) checked-invoices))))
^{:key "handwritten"} [:a.dropdown-item {:on-click (dispatch-event [::handwrite-checks])} "Handwritten Check..."])
^{:key "advanced"} [:a.dropdown-item {:on-click (dispatch-event [::advanced-print-checks])} "Advanced..."])]])]]
[:div.is-pulled-right {:style {:margin-right "0.5rem"}}
(into [:div.tags ] (map (fn [[id invoice]] [:span.tag.is-medium (:invoice-number invoice) [:button.delete.is-small {:on-click (dispatch-event [::toggle-check id invoice])}]]) checked-invoices))]]
(into [:div.tags ] (map (fn [{:keys [id invoice-number]}]
[:span.tag.is-medium invoice-number
[:button.delete.is-small {:on-click
(dispatch-event [::remove-check id])}]]) checked-invoices))]]
))
(defn check-results-dialog []
@@ -615,15 +627,15 @@
[:div.notification
action-notification])
(when (= status :unpaid)
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
[pay-button {:print-checks-shown? print-checks-shown? :print-checks-loading? print-checks-loading?}])
[table/invoice-table {:id :unpaid
:invoice-page @(re-frame/subscribe [::invoice-page])
:status @(re-frame/subscribe [::status/single ::page])
:check-boxes (= status :unpaid)
:checked checked
:on-check-changed (fn [which invoice]
(re-frame/dispatch [::toggle-check which invoice]))
:on-check-changed (fn [new]
(re-frame/dispatch [::toggle-check new ]))
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]]))
(defn unpaid-invoices-page [params]