further cleans up POS
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
pull-many
|
||||
query2]]
|
||||
[auto-ap.graphql.utils :refer [extract-client-ids]]
|
||||
[auto-ap.query-params :as query-params]
|
||||
[auto-ap.routes.utils
|
||||
:refer [wrap-client-redirect-unauthenticated wrap-secure]]
|
||||
[auto-ap.ssr-routes :as ssr-routes]
|
||||
@@ -21,7 +22,6 @@
|
||||
[datomic.api :as dc]))
|
||||
|
||||
;; always should be fast
|
||||
;; make params parsing composable
|
||||
|
||||
(defn filters [params]
|
||||
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
|
||||
@@ -35,36 +35,26 @@
|
||||
(date-range-field* params)
|
||||
(total-field* params)]])
|
||||
|
||||
(defn <-datomic [result]
|
||||
(cond-> result
|
||||
true (update :cash-drawer-shift/date c/from-date)))
|
||||
|
||||
(def default-read '[*
|
||||
(def default-read '[:db/id
|
||||
:cash-drawer-shift/paid-in :cash-drawer-shift/paid-out :cash-drawer-shift/expected-cash :cash-drawer-shift/opened-cash
|
||||
[:cash-drawer-shift/date :xform clj-time.coerce/from-date]
|
||||
{:cash-drawer-shift/client [:client/name :db/id :client/code]}])
|
||||
|
||||
(defn fetch-ids [db args]
|
||||
(let [query-params (:parsed-query-params args)
|
||||
valid-clients (extract-client-ids (:clients args)
|
||||
(defn fetch-ids [db request]
|
||||
(let [query-params (:parsed-query-params request)
|
||||
valid-clients (extract-client-ids (:clients request)
|
||||
(:client-id query-params)
|
||||
(when (:client-code query-params)
|
||||
[:client/code (:client-code query-params)]))
|
||||
valid-clients (->> valid-clients
|
||||
(take 10)
|
||||
set)
|
||||
start-date (some-> args
|
||||
:parsed-query-params
|
||||
:start-date
|
||||
(atime/parse atime/normal-date))
|
||||
end-date (some-> args
|
||||
:parsed-query-params
|
||||
:end-date
|
||||
(atime/parse atime/normal-date))
|
||||
query (cond-> {:query {:find []
|
||||
:in ['$ '[?clients ?start-date ?end-date]]
|
||||
:where '[[(iol-ion.query/scan-cash-drawer-shifts $ ?clients ?start-date ?end-date) [[?e _ ?sort-default] ...]]]}
|
||||
:args [db [valid-clients
|
||||
(some-> start-date c/to-date)
|
||||
(some-> end-date c/to-date )]]}
|
||||
(some-> (:start-date query-params) c/to-date)
|
||||
(some-> (:end-date query-params) c/to-date )]]}
|
||||
(:sort query-params) (add-sorter-fields {"client" ['[?e :cash-drawer-shift/client ?c]
|
||||
'[?c :client/name ?sort-client]]
|
||||
"date" ['[?e :cash-drawer-shift/date ?sort-date]]
|
||||
@@ -80,18 +70,6 @@
|
||||
:where []}
|
||||
:args [(:exact-match-id query-params)]})
|
||||
|
||||
start-date
|
||||
(merge-query {:query {:in '[?start-date]
|
||||
:where ['[?e :cash-drawer-shift/date ?date]
|
||||
'[(>= ?date ?start-date)]]}
|
||||
:args [(c/to-date start-date)]})
|
||||
|
||||
end-date
|
||||
(merge-query {:query {:in '[?end-date]
|
||||
:where ['[?e :cash-drawer-shift/date ?date]
|
||||
'[(<= ?date ?end-date)]]}
|
||||
:args [(c/to-date end-date)]})
|
||||
|
||||
true
|
||||
(merge-query {:query {:find ['?sort-default '?e]
|
||||
:where ['[?e :cash-drawer-shift/date ?sort-default]]}}))]
|
||||
@@ -105,16 +83,14 @@
|
||||
(group-by :db/id))
|
||||
cash-drawer-shifts (->> ids
|
||||
(map results)
|
||||
(map first)
|
||||
(mapv <-datomic)
|
||||
)]
|
||||
(map first))]
|
||||
cash-drawer-shifts))
|
||||
|
||||
(defn fetch-page [_ args]
|
||||
(defn fetch-page [request]
|
||||
(let [db (dc/db conn)
|
||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db args)]
|
||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db request)]
|
||||
|
||||
[(->> (hydrate-results ids-to-retrieve db args))
|
||||
[(->> (hydrate-results ids-to-retrieve db request))
|
||||
matching-count]))
|
||||
|
||||
(def grid-page {:id "cash-drawer-shift-table"
|
||||
@@ -123,8 +99,8 @@
|
||||
:id-fn :db/id
|
||||
:fetch-page fetch-page
|
||||
:oob-render
|
||||
(fn [_ params]
|
||||
[(assoc-in (date-range-field* params) [1 :hx-swap-oob] true)])
|
||||
(fn [request]
|
||||
[(assoc-in (date-range-field* request) [1 :hx-swap-oob] true)])
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes
|
||||
:company)}
|
||||
"POS"]
|
||||
@@ -135,7 +111,7 @@
|
||||
:title "Cash drawer shifts"
|
||||
:entity-name "Cash drawer shift"
|
||||
:route :pos-cash-drawer-shift-table
|
||||
:action-buttons (fn [_ args])
|
||||
:action-buttons (fn [request])
|
||||
:row-buttons (fn [_ e])
|
||||
:headers [{:key "client"
|
||||
:name "Client"
|
||||
@@ -167,8 +143,13 @@
|
||||
|
||||
(def row* (partial helper/row* grid-page))
|
||||
(def table* (partial helper/table* grid-page))
|
||||
(def table (partial helper/table grid-page))
|
||||
(def page (partial helper/page grid-page))
|
||||
(def table
|
||||
(query-params/wrap-parse-query-params (partial helper/table grid-page)
|
||||
(helper/default-parse-query-params grid-page))
|
||||
|
||||
)
|
||||
(def page (query-params/wrap-parse-query-params (partial helper/page grid-page)
|
||||
(helper/default-parse-query-params grid-page)))
|
||||
|
||||
(def key->handler
|
||||
{:pos-cash-drawer-shifts (wrap-client-redirect-unauthenticated (wrap-secure page))
|
||||
|
||||
Reference in New Issue
Block a user