check filter refactor.
This commit is contained in:
124
src/cljs/auto_ap/views/pages/payments/table.cljs
Normal file
124
src/cljs/auto_ap/views/pages/payments/table.cljs
Normal file
@@ -0,0 +1,124 @@
|
||||
(ns auto-ap.views.pages.payments.table
|
||||
(:require [auto-ap.subs :as subs]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.components.sort-by-list :refer [sort-by-list]]
|
||||
[auto-ap.views.utils :refer [date->str dispatch-event nf]]
|
||||
[goog.string :as gstring]
|
||||
[re-frame.core :as re-frame]))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::table-params
|
||||
(fn [db]
|
||||
(::table-params db)))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::params-changed
|
||||
[(re-frame/path [::table-params])]
|
||||
(fn [{table-params :db} [_ params :as z]]
|
||||
{:db (merge table-params params)
|
||||
:dispatch [:auto-ap.views.pages.payments/params-change]}))
|
||||
|
||||
(defn row [{check :check
|
||||
selected-client :selected-client
|
||||
void-event :void-event
|
||||
}]
|
||||
(let [{:keys [client s3-url bank-account payments type check-number date amount id vendor status] :as check} check]
|
||||
[:tr {:class (:class check)}
|
||||
(when-not selected-client
|
||||
[:td (:name client)])
|
||||
[:td (:name vendor)]
|
||||
[:td (:name bank-account)]
|
||||
[:td (cond
|
||||
(= :cash type) "Cash"
|
||||
(= :debit type) "Debit"
|
||||
:else (if s3-url
|
||||
[:a {:href s3-url :target "_new"} [:a.button [:span.icon [:i.fa.fa-share-square-o]]
|
||||
[:span (str " " check-number )]]]
|
||||
check-number))]
|
||||
[:td (date->str date) ]
|
||||
[:td.has-text-right (nf amount )]
|
||||
[:td status]
|
||||
[:td
|
||||
(when (or (= :pending status)
|
||||
(and (#{":cash" :cash} type)
|
||||
(not= :voided status)))
|
||||
[:button.button.is-warning.is-outlined {:on-click (dispatch-event (conj void-event check))} [:span [:span.icon [:i.fa.fa-minus-circle]]]])]]))
|
||||
|
||||
(defn table [{:keys [id payment-page status void-event]}]
|
||||
(let [{:keys [sort]} @(re-frame/subscribe [::table-params])
|
||||
{:keys [payments start end count total]} @payment-page
|
||||
selected-client @(re-frame/subscribe [::subs/client])
|
||||
percentage-size (if selected-client "50%" "33%")
|
||||
opc (fn [e]
|
||||
(re-frame/dispatch [::params-changed e]))]
|
||||
[:div
|
||||
[:div.level
|
||||
[:div.level-left
|
||||
[:div.level-item
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change opc}]]
|
||||
[:div.level-item
|
||||
[sort-by-list {:sort sort
|
||||
:on-change opc}]]]]
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
(when-not selected-client
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "client"
|
||||
:sort-name "Client"
|
||||
:sort sort}
|
||||
"Client"])
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-name "Vendor"
|
||||
:sort sort}
|
||||
"Vendor"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "bank-account"
|
||||
:sort-name "Bank Account"
|
||||
:sort sort}
|
||||
"Bank Account"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width percentage-size :cursor "pointer"}
|
||||
:sort-key "check-number"
|
||||
:sort-name "Check #"
|
||||
:sort sort}
|
||||
"Check #"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-name "Date"
|
||||
:sort sort}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:class "has-text-right"
|
||||
:sort-key "amount"
|
||||
:sort-name "Amount"
|
||||
:sort sort}
|
||||
"Amount"]
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "status"
|
||||
:sort-name "Status"
|
||||
:sort sort}
|
||||
"Status"]
|
||||
[:th {:style {:width "8em"}} "" ]]]
|
||||
[:tbody
|
||||
(if (:loading @status)
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
(for [check (:payments @payment-page)]
|
||||
^{:key (:id check)}
|
||||
[row {:check check
|
||||
:selected-client selected-client
|
||||
:void-event void-event}]))]]]))
|
||||
Reference in New Issue
Block a user