adding ability to preserve checks across pages
This commit is contained in:
@@ -140,7 +140,8 @@
|
||||
)]
|
||||
[invoice payment])))
|
||||
(filter identity)
|
||||
(map remove-nils)))
|
||||
(map remove-nils)
|
||||
))
|
||||
|
||||
(defroutes routes
|
||||
(wrap-routes
|
||||
|
||||
@@ -133,10 +133,12 @@
|
||||
}
|
||||
""]]]
|
||||
[:tbody
|
||||
(println checked)
|
||||
(if (:loading @status)
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
|
||||
(for [{:keys [client payments expense-accounts invoice-number date total outstanding-balance id vendor] :as i} (:invoices @invoice-page)]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
@@ -146,7 +148,8 @@
|
||||
"checked"
|
||||
"")
|
||||
:on-change (fn [x e] (when on-check-changed
|
||||
(on-check-changed id)))} ]])
|
||||
(println id i)
|
||||
(on-check-changed id i)))} ]])
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td (:name vendor)]
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]]
|
||||
[auto-ap.expense-accounts :as expense-accounts]
|
||||
[auto-ap.entities.invoices-expense-accounts :as invoices-expense-accounts]
|
||||
[auto-ap.views.utils :refer [active-when dispatch-event bind-field horizontal-field date->str str->date pretty standard]]
|
||||
[auto-ap.views.utils :refer [active-when dispatch-event bind-field horizontal-field date->str date-time->str str->date pretty standard]]
|
||||
[auto-ap.utils :refer [by replace-if]]
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
@@ -81,22 +81,28 @@
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj (invoice-table/query (doto (assoc params :imported true) println))
|
||||
:on-success [::received]}}))
|
||||
(re-frame/reg-event-db
|
||||
::unmount-invoices
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(dissoc ::invoice-page ))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(assoc ::invoice-page (first (:invoice-page data)))
|
||||
(update ::invoice-page merge (first (:invoice-page data)))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::toggle-check
|
||||
(fn [db [_ data]]
|
||||
(update-in db [::invoice-page :checked] (fn [x]
|
||||
(let [x (or x #{})]
|
||||
(if (x data)
|
||||
(disj x data)
|
||||
(conj x data)))))))
|
||||
(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/reg-event-db
|
||||
::print-checks-clicked
|
||||
@@ -111,8 +117,8 @@
|
||||
(update-in [::invoice-page :print-checks-shown?] #(not %) )
|
||||
(assoc-in [::advanced-print-checks] {:shown? true
|
||||
:bank-account-id (:id (first (:bank-accounts @(re-frame/subscribe [::subs/clients]))))
|
||||
:invoices (->> invoices
|
||||
(filter (comp checked :id))
|
||||
:invoices (->> checked
|
||||
vals
|
||||
(map #(assoc % :amount (:outstanding-balance %))))} )))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
@@ -171,22 +177,20 @@
|
||||
(re-frame/reg-event-fx
|
||||
::print-checks
|
||||
(fn [{:keys [db]} [_ bank-account-id type]]
|
||||
(let [invoice-amounts (by :id :outstanding-balance (get-in db [::invoice-page :invoices]))]
|
||||
|
||||
{:db (-> db
|
||||
(assoc-in [::invoice-page :print-checks-shown?] false )
|
||||
(assoc-in [::invoice-page :print-checks-loading?] true ))
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
|
||||
:query-obj (print-checks-query (map (fn [id]
|
||||
{:invoice-id id
|
||||
:amount (invoice-amounts id)})
|
||||
(get-in db [::invoice-page :checked]))
|
||||
bank-account-id
|
||||
type
|
||||
(:client db))
|
||||
:on-success [::checks-created]}})))
|
||||
{:db (-> db
|
||||
(assoc-in [::invoice-page :print-checks-shown?] false )
|
||||
(assoc-in [::invoice-page :print-checks-loading?] true ))
|
||||
:graphql
|
||||
{:token (-> db :user)
|
||||
|
||||
:query-obj (print-checks-query (map (fn [[id invoice]]
|
||||
{:invoice-id id
|
||||
:amount (:outstanding-balance invoice)})
|
||||
(get-in db [::invoice-page :checked]))
|
||||
bank-account-id
|
||||
type
|
||||
(:client db))
|
||||
:on-success [::checks-created]}}))
|
||||
|
||||
|
||||
|
||||
@@ -675,7 +679,7 @@
|
||||
(if (and (= key :vendor-id)
|
||||
(not= value (get-in db [::params :vendor-id])))
|
||||
(do
|
||||
(re-frame/dispatch [::params-change (assoc (::params updated) :vendor-id value)])
|
||||
(re-frame/dispatch [::params-change (assoc (::params updated) :vendor-id value :start 0)])
|
||||
(assoc-in updated [::params :vendor-id] value))
|
||||
updated))))
|
||||
|
||||
@@ -685,47 +689,74 @@
|
||||
[:div.control [:input.input {:placeholder "AP-123"
|
||||
:value invoice-number-like
|
||||
:on-change (fn [x]
|
||||
(re-frame/dispatch [::params-change (assoc params :invoice-number-like (.. x -target -value)) ])
|
||||
(re-frame/dispatch [::params-change (assoc params :invoice-number-like (.. x -target -value) :start 0) ])
|
||||
)} ]]]))
|
||||
|
||||
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div.is-pulled-right
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
|
||||
(when current-client
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown-trigger
|
||||
[:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::print-checks-clicked ])
|
||||
:disabled (if (seq checked-invoices)
|
||||
""
|
||||
"disabled")
|
||||
[:div
|
||||
|
||||
|
||||
|
||||
[:div.is-pulled-right
|
||||
|
||||
|
||||
[:button.button.is-danger {:on-click (dispatch-event [::new-invoice])} "New Invoice"]
|
||||
|
||||
|
||||
(when current-client
|
||||
[:div.dropdown.is-right {:class (if print-checks-shown?
|
||||
"is-active"
|
||||
"")}
|
||||
[:div.dropdown-trigger
|
||||
[:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::print-checks-clicked ])
|
||||
:disabled (if (seq checked-invoices)
|
||||
""
|
||||
"disabled")
|
||||
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")}
|
||||
"Pay "
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-client)]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
|
||||
(list
|
||||
^{: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]
|
||||
:class (if print-checks-loading?
|
||||
"is-loading"
|
||||
"")}
|
||||
"Pay "
|
||||
(when (> (count checked-invoices ))
|
||||
(str
|
||||
(count checked-invoices)
|
||||
" invoices "
|
||||
"(" (->> checked-invoices
|
||||
vals
|
||||
(map (comp js/parseFloat :outstanding-balance))
|
||||
(reduce + 0)
|
||||
(gstring/format "$%.2f" ))
|
||||
")"))
|
||||
|
||||
|
||||
[:span " "]
|
||||
[:span.icon.is-small [:i.fa.fa-angle-down {:aria-hidden "true"}]]]]
|
||||
[:div.dropdown-menu {:role "menu"}
|
||||
[:div.dropdown-content
|
||||
(list
|
||||
(for [{:keys [id number name type]} (:bank-accounts current-client)]
|
||||
(if (= :cash type)
|
||||
^{:key id} [:a.dropdown-item {:on-click (dispatch-event [::print-checks id :cash])} "With cash"]
|
||||
(list
|
||||
^{: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]
|
||||
|
||||
(when (= 1 (count 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..."])]]])]))
|
||||
(when (= 1 (count 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
|
||||
(into [:div.tags {:style {:margin-right ".5 rem;"}}] (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))]]
|
||||
))
|
||||
|
||||
(defn unpaid-invoices-content [{:keys [status]}]
|
||||
(r/create-class {:display-name "unpaid-invoices-content"
|
||||
:component-will-unmount (fn [this]
|
||||
(re-frame/dispatch [::unmount-invoices])
|
||||
|
||||
)
|
||||
:reagent-render (fn [{:keys [status]}]
|
||||
(let [{:keys [checked print-checks-shown? print-checks-loading? advanced-print-shown? vendor-filter]} @(re-frame/subscribe [::invoice-page])
|
||||
current-client @(re-frame/subscribe [::subs/client])
|
||||
@@ -736,6 +767,7 @@
|
||||
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
|
||||
|
||||
|
||||
|
||||
[invoice-table {:id :unpaid
|
||||
:params (re-frame/subscribe [::params])
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
@@ -749,8 +781,8 @@
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes (= status "unpaid")
|
||||
:checked checked
|
||||
:on-check-changed (fn [which]
|
||||
(re-frame/dispatch [::toggle-check which]))
|
||||
:on-check-changed (fn [which invoice]
|
||||
(re-frame/dispatch [::toggle-check which invoice]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
|
||||
[print-checks-modal]
|
||||
|
||||
Reference in New Issue
Block a user