making it possible to see a list of checks
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
(def routes ["/" {"" :index
|
||||
"login/" :login
|
||||
"needs-activation/" :needs-activation
|
||||
"check/" :check
|
||||
"checks/" :checks
|
||||
"admin/" {"" :admin
|
||||
"companies" :admin-companies
|
||||
"users" :admin-users
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
(defn page->layout [page]
|
||||
({:login :blank
|
||||
:check :blank
|
||||
:checks :left-panel
|
||||
:needs-activation :blank
|
||||
:index :left-panel
|
||||
:invoices :left-panel
|
||||
@@ -188,6 +188,12 @@
|
||||
[:i {:class "fa fa-envelope-o"}]]
|
||||
[:span {:class "name"} "Paid Invoices"]]
|
||||
]
|
||||
[:li.menu-item
|
||||
[:a {:href (bidi/path-for routes/routes :checks), :class (str "item" (active-when= ap :checks))}
|
||||
[:span {:class "icon"}
|
||||
[:i {:class "fa fa-envelope-o"}]]
|
||||
[:span {:class "name"} "Payments"]]]
|
||||
|
||||
[:ul ]]]
|
||||
|
||||
]
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
[auto-ap.views.pages.admin.vendors :refer [admin-vendors-page]]
|
||||
[auto-ap.views.pages.admin.reminders :refer [admin-reminders-page]]
|
||||
[auto-ap.views.pages.unpaid-invoices :refer [unpaid-invoices-page]]
|
||||
[auto-ap.views.pages.checks :refer [checks-page]]
|
||||
[auto-ap.views.pages.new-invoice :refer [new-invoice-page]]
|
||||
[auto-ap.views.pages.import-invoices :refer [import-invoices-page]]
|
||||
[auto-ap.views.pages.admin.excel-import :refer [admin-excel-import-page]]
|
||||
@@ -64,6 +65,9 @@
|
||||
(defmethod active-page :paid-invoices []
|
||||
[paid-invoices-page])
|
||||
|
||||
(defmethod active-page :checks []
|
||||
[checks-page])
|
||||
|
||||
(defmethod active-page :invoices []
|
||||
[(with-meta
|
||||
(fn []
|
||||
|
||||
142
src/cljs/auto_ap/views/pages/checks.cljs
Normal file
142
src/cljs/auto_ap/views/pages/checks.cljs
Normal file
@@ -0,0 +1,142 @@
|
||||
(ns auto-ap.views.pages.checks
|
||||
(:require [re-frame.core :as re-frame]
|
||||
[auto-ap.entities.companies :as company]
|
||||
[auto-ap.entities.vendors :as vendor]
|
||||
[reagent.core :as reagent]
|
||||
[goog.string :as gstring]
|
||||
[auto-ap.views.components.sorter :refer [sorted-column]]
|
||||
[auto-ap.views.components.paginator :refer [paginator]]
|
||||
[auto-ap.events :as events]
|
||||
[auto-ap.views.utils :refer [dispatch-event date->str ]]
|
||||
[auto-ap.utils :refer [by]]
|
||||
[auto-ap.views.pages.check :as check]
|
||||
[auto-ap.views.components.invoice-table :refer [invoice-table] :as invoice-table]
|
||||
[auto-ap.subs :as subs]))
|
||||
|
||||
|
||||
|
||||
|
||||
(re-frame/reg-sub
|
||||
::check-page
|
||||
(fn [db]
|
||||
(-> db ::check-page)))
|
||||
|
||||
(re-frame/reg-sub
|
||||
::params
|
||||
(fn [db]
|
||||
(-> db (::params {}))))
|
||||
|
||||
(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 {:venia/queries [[:check_page
|
||||
(assoc params :company-id (:id @(re-frame/subscribe [::subs/company])))
|
||||
[[:checks [:id :amount :check_number :s3_url :date [:vendor [:name :id]] [:company [:name :id]]]]
|
||||
:total
|
||||
:start
|
||||
:end]]]}
|
||||
:on-success [::received]}}))
|
||||
|
||||
(re-frame/reg-event-db
|
||||
::received
|
||||
(fn [db [_ data]]
|
||||
(-> db
|
||||
(assoc ::check-page (first (:check-page data)))
|
||||
(assoc-in [:status :loading] false))))
|
||||
|
||||
(re-frame/reg-event-fx
|
||||
::invalidated
|
||||
(fn [cofx [_ params]]
|
||||
{:dispatch [::params-change @(re-frame/subscribe [::params])]}))
|
||||
|
||||
(defn check-table [{:keys [id check-page status on-params-change vendors params check-boxes checked on-check-changed expense-event]}]
|
||||
(let [state (reagent/atom (or @params {}))
|
||||
opc (fn [p]
|
||||
(swap! state merge p)
|
||||
(on-params-change p))]
|
||||
(fn [{:keys [id check-page status on-params-change vendors checked]}]
|
||||
(println @check-page)
|
||||
(let [{:keys [sort-by asc]} @state
|
||||
{:keys [checks start end count total]} @check-page]
|
||||
[:div
|
||||
[paginator {:start start :end end :count count :total total
|
||||
:on-change (fn [p ]
|
||||
(on-params-change (swap! state merge p)))}]
|
||||
"Showing " (inc start) "-" end "/" total
|
||||
|
||||
[:table.table.is-fullwidth
|
||||
[:thead
|
||||
[:tr
|
||||
|
||||
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "33%" :cursor "pointer"}
|
||||
:sort-key "company"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Company"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "33%" :cursor "pointer"}
|
||||
:sort-key "vendor"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Vendor"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "33%" :cursor "pointer"}
|
||||
:sort-key "invoice-number"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Check #"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "date"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Date"]
|
||||
[sorted-column {:on-sort opc
|
||||
:style {:width "8em" :cursor "pointer"}
|
||||
:sort-key "total"
|
||||
:sort-by sort-by
|
||||
:asc asc}
|
||||
"Amount"]
|
||||
|
||||
|
||||
[:th {:style {:width "10em"}} "" ]]]
|
||||
[:tbody
|
||||
(if (:loading @status)
|
||||
[:tr
|
||||
[:td {:col-span 5}
|
||||
[:i.fa.fa-spin.fa-spinner]]]
|
||||
(for [{:keys [company s3-url checks check-number date amount id vendor] :as i} (:checks @check-page)]
|
||||
^{:key id}
|
||||
[:tr {:class (:class i)}
|
||||
|
||||
[:td (:name company)]
|
||||
[:td (:name vendor)]
|
||||
[:td check-number]
|
||||
[:td (date->str date) ]
|
||||
[:td (gstring/format "$%.2f" amount )]
|
||||
[:td [:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]]
|
||||
]))]]]))))
|
||||
|
||||
|
||||
(def checks-page
|
||||
|
||||
(with-meta
|
||||
(fn []
|
||||
(let [current-company @(re-frame/subscribe [::subs/company])]
|
||||
[:div
|
||||
[:h1.title "Payments"]
|
||||
[check-table {:id :checks
|
||||
:params (re-frame/subscribe [::params])
|
||||
:check-page (re-frame/subscribe [::check-page])
|
||||
:status (re-frame/subscribe [::subs/status])
|
||||
:on-params-change (fn [params]
|
||||
(re-frame/dispatch [::params-change params]))}]]))
|
||||
{:component-will-mount #(re-frame/dispatch-sync [::params-change {}]) }))
|
||||
|
||||
Reference in New Issue
Block a user