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

@@ -136,9 +136,26 @@
:class class}] :class class}]
(r/children (r/current-component)))) (r/children (r/current-component))))
(defn row [{:keys [class]}] (defn row [{:keys [class id checkable?]}]
(apply r/create-element "tr" #js {:className class} (let [children (r/children (r/current-component))]
(map r/as-element (r/children (r/current-component))))) [:> Consumer {}
(fn [consume]
(let [{:strs [on-params-change params check-boxes? on-check-changed checked] :as consume} (js->clj consume)]
(apply r/create-element "tr" #js {:className class}
(when check-boxes?
(r/as-element [:th {:style {:width "22px"}}
[:input.checkbox (cond-> {:type "checkbox"
:checked (if (get checked id)
"checked"
"")
:on-change (fn [x e]
(let [checked (or checked #{})]
(if (get checked id)
(on-check-changed (disj checked id))
(on-check-changed (conj checked id)))))}
(boolean? checkable?) (assoc :disabled (not checkable?))) ]]))
(map r/as-element children))))]))
(defn button-cell [params] (defn button-cell [params]
(apply r/create-element "td" #js {"style" #js {"overflow" "visible"}} (apply r/create-element "td" #js {"style" #js {"overflow" "visible"}}
@@ -196,9 +213,12 @@
children) children)
(sort-icon sort-key (:sort params))))))])) (sort-icon sort-key (:sort params))))))]))
(defn grid [{:keys [on-params-change params status column-count]}] (defn grid [{:keys [on-params-change on-check-changed checked params status column-count check-boxes?]}]
(r/create-element Provider (r/create-element Provider
#js {:value #js {:on-params-change on-params-change #js {:value #js {:on-params-change on-params-change
:on-check-changed on-check-changed
:check-boxes? check-boxes?
:checked checked
:params params :params params
:status status :status status
:column-count column-count}} :column-count column-count}}

View File

@@ -92,20 +92,11 @@
(fn [{:keys [db]} [_ invoice]] (fn [{:keys [db]} [_ invoice]]
{:db db})) {:db db}))
(defn row [{:keys [invoice check-boxes checked on-check-changed selected-client overrides expense-event ]}] (defn row [{:keys [invoice check-boxes checked selected-client overrides expense-event ]}]
(let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor checkable?] :as i} invoice (let [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor checkable?] :as i} invoice
accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client]) accounts-by-id @(re-frame/subscribe [::subs/accounts-by-id client])
account->name #(:name (accounts-by-id (:id %)))] account->name #(:name (accounts-by-id (:id %)))]
[grid/row {:class (:class i)} [grid/row {:class (:class i) :id id :checkable? checkable?}
(when check-boxes
[grid/cell {}
[:input.checkbox (cond-> {:type "checkbox"
:checked (if (get checked id)
"checked"
"")
:on-change (fn [x e] (when on-check-changed
(on-check-changed id i)))}
(boolean? checkable?) (assoc :disabled (not checkable?))) ]])
(when-not selected-client (when-not selected-client
[grid/cell {} [grid/cell {}
(if-let [client-override (:client overrides)] (if-let [client-override (:client overrides)]
@@ -184,7 +175,7 @@
[buttons/fa-icon {:icon "fa-undo" [buttons/fa-icon {:icon "fa-undo"
:event [::unvoid-invoice i]}])]]])) :event [::unvoid-invoice i]}])]]]))
(defn invoice-table [{:keys [id invoice-page status vendors check-boxes checked on-check-changed expense-event overrides]}] (defn invoice-table [{:keys [id invoice-page status vendors check-boxes on-check-changed expense-event overrides]}]
(let [selected-client @(re-frame/subscribe [::subs/client]) (let [selected-client @(re-frame/subscribe [::subs/client])
{:keys [sort]} @(re-frame/subscribe [::table-params]) {:keys [sort]} @(re-frame/subscribe [::table-params])
{:keys [invoices outstanding]} invoice-page {:keys [invoices outstanding]} invoice-page
@@ -207,14 +198,14 @@
[[] nil] [[] nil]
(:invoices invoice-page)) (:invoices invoice-page))
[[(:invoices invoice-page)]])] [[(:invoices invoice-page)]])]
^{:key (str @(re-frame/subscribe [::table-params]))}
[grid/grid {:on-params-change (fn [p] [grid/grid {:on-params-change (fn [p]
(re-frame/dispatch [::params-changed p])) (re-frame/dispatch [::params-changed p]))
:on-check-changed on-check-changed
:params @(re-frame/subscribe [::table-params]) :params @(re-frame/subscribe [::table-params])
:checked (:checked invoice-page)
:status status :status status
;; TODO checkboxes :check-boxes? check-boxes
:column-count (if selected-client 8 9)} :column-count (if selected-client 7 8)}
[grid/controls invoice-page [grid/controls invoice-page
[:div.level-item [:div.level-item
"Outstanding " (nf outstanding)]] "Outstanding " (nf outstanding)]]
@@ -223,8 +214,6 @@
[grid/table {:fullwidth true} [grid/table {:fullwidth true}
[grid/header {} [grid/header {}
[grid/row {} [grid/row {}
(when check-boxes
[grid/header-cell {:style {:width "22px"}}])
(when-not selected-client (when-not selected-client
[grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"]) [grid/sortable-header-cell {:sort-key "client" :sort-name "Client"} "Client"])
[grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"} [grid/sortable-header-cell {:sort-key "vendor" :sort-name "Vendor"}
@@ -246,8 +235,6 @@
(for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoices] (for [{:keys [client payments expense-accounts invoice-number date due total outstanding-balance id vendor] :as i} invoices]
^{:key id} ^{:key id}
[row {:invoice i [row {:invoice i
:check-boxes check-boxes
:checked checked
:selected-client selected-client :selected-client selected-client
:overrides overrides :overrides overrides
:expense-event expense-event}])]])])) :expense-event expense-event}])]])]))

View File

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