cleaning up invoice pagination.
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.entities.clients :as client]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[auto-ap.entities.invoice :as invoice]
|
||||
[reagent.core :as reagent]
|
||||
[goog.string :as gstring]
|
||||
[clojure.spec.alpha :as s]
|
||||
@@ -18,7 +17,6 @@
|
||||
[auto-ap.views.pages.payments.side-bar :as side-bar]
|
||||
[auto-ap.views.pages.payments.table :as table]
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
|
||||
@@ -91,21 +89,27 @@
|
||||
(update ::payment-page merge (first (:payment-page data)))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(def checks-content
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Checks"]
|
||||
[table/table {:id :payments
|
||||
:payment-page (re-frame/subscribe [::payment-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:void-event [::void-check]
|
||||
}]]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::last-params ::table/table-params ::side-bar/filters ::payment-page)}))
|
||||
|
||||
(defn content []
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
[:div
|
||||
[:h1.title "Payments"]
|
||||
[table/table {:id :payments
|
||||
:payment-page (re-frame/subscribe [::payment-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:void-event [::void-check]}]]))
|
||||
|
||||
|
||||
(defn payments-page []
|
||||
[side-bar-layout {:side-bar [side-bar/side-bar]
|
||||
:main [checks-content]}])
|
||||
(reagent/create-class
|
||||
{:display-name "payments-page"
|
||||
:component-did-mount #(re-frame/dispatch [::params-change {}])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
[side-bar-layout {:side-bar [side-bar/side-bar]
|
||||
:main [content]}])}))
|
||||
|
||||
@@ -7,22 +7,14 @@
|
||||
[auto-ap.views.pages.invoices.form :as form]
|
||||
[auto-ap.views.components.dropdown :refer [drop-down]]
|
||||
[auto-ap.views.components.expense-accounts-dialog :as expense-accounts-dialog :refer [change-expense-accounts-modal]]
|
||||
[auto-ap.views.components.invoice-table :as invoice-table :refer [invoice-table]]
|
||||
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar]]
|
||||
[auto-ap.views.components.invoice-table :as table :refer [invoice-table]]
|
||||
[auto-ap.views.components.invoices.side-bar :refer [invoices-side-bar] :as side-bar]
|
||||
[auto-ap.views.components.layouts :refer [appearing-side-bar side-bar-layout]]
|
||||
[auto-ap.views.components.modal :refer [action-modal modal]]
|
||||
[auto-ap.views.components.typeahead :refer [typeahead]]
|
||||
[auto-ap.views.components.vendor-filter :refer [vendor-filter]]
|
||||
[auto-ap.views.components.date-range-filter :refer [date-range-filter]]
|
||||
[auto-ap.views.pages.invoices.common :refer [invoice-read]]
|
||||
[auto-ap.views.utils
|
||||
:refer
|
||||
[bind-field
|
||||
date->str
|
||||
date-picker
|
||||
dispatch-event
|
||||
horizontal-field
|
||||
standard]]
|
||||
[auto-ap.views.utils :refer [bind-field date->str date-picker dispatch-event horizontal-field standard with-user]]
|
||||
[cljs-time.core :as c]
|
||||
[clojure.spec.alpha :as s]
|
||||
[clojure.string :as str :refer [blank?]]
|
||||
@@ -74,8 +66,14 @@
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db (::params {}))))
|
||||
:<- [::subs/client]
|
||||
:<- [::side-bar/filter-params]
|
||||
:<- [::table/table-params]
|
||||
(fn [[client filter-params table-params]]
|
||||
(cond-> {:import-status "imported"}
|
||||
client (assoc :client-id (:id client))
|
||||
(seq filter-params) (merge filter-params)
|
||||
(seq table-params) (merge @(re-frame/subscribe [::table/table-params])))))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::invoice-updated
|
||||
@@ -86,22 +84,24 @@
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-change
|
||||
(fn [cofx [_ params]]
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::params] params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj (invoice-table/query (-> params (assoc :import-status "imported") (dissoc :invoice-number-like-current)) )
|
||||
:on-success [::received]
|
||||
:on-error [::events/page-failed]}}))
|
||||
[with-user]
|
||||
(fn [cofx _]
|
||||
(let [new-params @(re-frame/subscribe [::params])]
|
||||
(when (not= new-params (::last-params (:db cofx)))
|
||||
{:db (-> (:db cofx)
|
||||
(assoc-in [:status :loading] true)
|
||||
(assoc-in [::last-params] new-params))
|
||||
:graphql {:token (-> cofx :db :user)
|
||||
:query-obj (table/query new-params )
|
||||
:on-success [::received]
|
||||
:on-error [::events/page-failed]}}))))
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::unmount-invoices
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(dissoc ::invoice-page ))))
|
||||
(re-frame/reg-event-fx
|
||||
::unmounted
|
||||
(fn [{:keys [db]} _]
|
||||
{:db (dissoc db ::invoice-page ::table/table-params ::side-bar/filters ::last-params)}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
@@ -272,11 +272,6 @@
|
||||
(assoc-in [::check-results :shown?] true)
|
||||
(assoc-in [::check-results :pdf-url] pdf-url))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::new-invoice-clicked
|
||||
(fn [{:keys [db]} _]
|
||||
@@ -356,16 +351,6 @@
|
||||
(dissoc ::handwrite-checks))})))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-unvoided
|
||||
(fn [{:keys [db]} [_ {:keys [unvoid-invoice]}]]
|
||||
@@ -551,48 +536,6 @@
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::change-selected-vendor
|
||||
(fn [db [_ key value]]
|
||||
(let [[key] key
|
||||
updated (assoc-in db [::invoice-page :vendor-filter key] value)]
|
||||
(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 :start 0)])
|
||||
(assoc-in updated [::params :vendor-id] value))
|
||||
updated))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::change-selected-date-range
|
||||
(fn [{:keys [db]} [_ key value]]
|
||||
(let [[key] key
|
||||
updated (-> db
|
||||
(assoc-in [::invoice-page :date-range-filter key] value)
|
||||
(assoc-in [::params :date-range key] value))]
|
||||
{:dispatch [::params-change (::params updated)]
|
||||
:db updated})))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-number-like-current-changed
|
||||
(fn [{:keys [db]} [_ params invoice-like]]
|
||||
{:db (assoc-in db [::params :invoice-number-like-current] invoice-like )
|
||||
:dispatch-debounce {:event [::invoice-number-like-settled invoice-like]
|
||||
:time 500
|
||||
:key ::invoice-number-like}}))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invoice-number-like-settled
|
||||
(fn [{:keys [db]} [_ invoice-like]]
|
||||
{:dispatch [::params-change (assoc (::params db) :invoice-number-like invoice-like :start 0) ]}))
|
||||
|
||||
(defn invoice-number-filter []
|
||||
(let [{:keys [invoice-number-like-current] :as params} @(re-frame/subscribe [::params])]
|
||||
[:div.field
|
||||
[:div.control [:input.input {:placeholder "AP-123"
|
||||
:value invoice-number-like-current
|
||||
:on-change (fn [x]
|
||||
(re-frame/dispatch [::invoice-number-like-current-changed params (.. x -target -value) ]))} ]]]))
|
||||
|
||||
(defn pay-button [{:keys [print-checks-shown? checked-invoices print-checks-loading?]}]
|
||||
(let [current-client @(re-frame/subscribe [::subs/client])]
|
||||
@@ -603,14 +546,7 @@
|
||||
(when current-client
|
||||
[drop-down {:header [:button.button.is-success {:aria-haspopup true
|
||||
:on-click (dispatch-event [::events/toggle-menu ::print-checks ])
|
||||
:disabled (if (and (seq checked-invoices)
|
||||
#_(->> checked-invoices
|
||||
vals
|
||||
(group-by #(get-in % [:vendor :id]))
|
||||
(reduce-kv (fn [negative? _ invoices]
|
||||
(or negative? (< (reduce + 0 (map (fn [x] (-> x :outstanding-balance js/parseFloat)) invoices) ) 0)))
|
||||
false)
|
||||
not))
|
||||
:disabled (if (and (seq checked-invoices))
|
||||
""
|
||||
"disabled")
|
||||
|
||||
@@ -666,63 +602,42 @@
|
||||
]))))
|
||||
|
||||
(defn unpaid-invoices-content [{:keys [status] :as params}]
|
||||
(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])]
|
||||
[:div
|
||||
[:h1.title (str (str/capitalize (or status "all")) " invoices")]
|
||||
|
||||
(when (= status "unpaid")
|
||||
[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])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::form/editing which]))
|
||||
:on-unvoid-invoice (fn [which]
|
||||
(re-frame/dispatch [::unvoid-invoice which]))
|
||||
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))
|
||||
:check-boxes (= status "unpaid")
|
||||
:checked checked
|
||||
:on-check-changed (fn [which invoice]
|
||||
(re-frame/dispatch [::toggle-check which invoice]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
]))
|
||||
:component-will-mount #(re-frame/dispatch-sync [::params-change params]) }))
|
||||
(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])]
|
||||
[:div
|
||||
[:h1.title (str (str/capitalize (or status "all")) " invoices")]
|
||||
(when (= status "unpaid")
|
||||
[pay-button {:print-checks-shown? print-checks-shown? :checked-invoices checked :print-checks-loading? print-checks-loading?}])
|
||||
[table/invoice-table {:id :unpaid
|
||||
:invoice-page (re-frame/subscribe [::invoice-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-edit-invoice (fn [which]
|
||||
(re-frame/dispatch [::form/editing which]))
|
||||
:on-unvoid-invoice (fn [which]
|
||||
(re-frame/dispatch [::unvoid-invoice which]))
|
||||
:on-void-invoice (fn [which]
|
||||
(re-frame/dispatch [::void-invoice which]))
|
||||
:check-boxes (= status "unpaid")
|
||||
:checked checked
|
||||
:on-check-changed (fn [which invoice]
|
||||
(re-frame/dispatch [::toggle-check which invoice]))
|
||||
:expense-event [::expense-accounts-dialog/change-expense-accounts]}]
|
||||
]))
|
||||
|
||||
(defn unpaid-invoices-page [params]
|
||||
(let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])]
|
||||
[side-bar-layout {:side-bar [invoices-side-bar {}
|
||||
^{:key "extra-filter"}
|
||||
[:div
|
||||
[:p.menu-label "Vendor"]
|
||||
[:div [vendor-filter {:on-change-event [::change-selected-vendor]
|
||||
:value (:vendor-filter @(re-frame/subscribe [::invoice-page]))
|
||||
:vendors @(re-frame/subscribe [::subs/vendors])}]]
|
||||
[:p.menu-label "Date Range"]
|
||||
[:div
|
||||
[date-range-filter
|
||||
{:on-change-event [::change-selected-date-range]
|
||||
:value (:date-range-filter @(re-frame/subscribe [::invoice-page]))}]]
|
||||
[:p.menu-label "Invoice #"]
|
||||
[:div
|
||||
[invoice-number-filter]]]]
|
||||
:main [unpaid-invoices-content params]
|
||||
:bottom [:div
|
||||
[check-results-dialog]
|
||||
[print-checks-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]]
|
||||
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [form/form {:invoice-created [::invoice-updated]
|
||||
:invoice-printed [::checks-printed]}]]}]))
|
||||
(r/create-class
|
||||
{:display-name "invoices-page"
|
||||
:component-did-mount #(re-frame/dispatch [::params-change])
|
||||
:component-will-unmount #(re-frame/dispatch [::unmounted])
|
||||
:reagent-render
|
||||
(fn []
|
||||
(let [{invoice-bar-active? :active?} @(re-frame/subscribe [::forms/form ::form/form])]
|
||||
[side-bar-layout {:side-bar [invoices-side-bar {}]
|
||||
:main [unpaid-invoices-content params]
|
||||
:bottom [:div
|
||||
[check-results-dialog]
|
||||
[print-checks-modal]
|
||||
[handwrite-checks-modal]
|
||||
[change-expense-accounts-modal {:updated-event [::expense-accounts-updated]}]]
|
||||
:right-side-bar [appearing-side-bar {:visible? invoice-bar-active?} [form/form {:invoice-created [::invoice-updated]
|
||||
:invoice-printed [::checks-printed]}]]}]))}))
|
||||
|
||||
Reference in New Issue
Block a user