Adds totals
This commit is contained in:
@@ -635,7 +635,8 @@
|
|||||||
(:per-page args)
|
(:per-page args)
|
||||||
default-pagination-size))
|
default-pagination-size))
|
||||||
(map last))
|
(map last))
|
||||||
:count (count results)})
|
:count (count results)
|
||||||
|
:all-ids (map last results)})
|
||||||
|
|
||||||
(defn audit-transact-batch [txes id]
|
(defn audit-transact-batch [txes id]
|
||||||
(let [batch-id (.toString (java.util.UUID/randomUUID))]
|
(let [batch-id (.toString (java.util.UUID/randomUUID))]
|
||||||
|
|||||||
@@ -83,8 +83,9 @@
|
|||||||
:sort sort)
|
:sort sort)
|
||||||
(let [start (or start 0)
|
(let [start (or start 0)
|
||||||
per-page (or per-page 25)
|
per-page (or per-page 25)
|
||||||
[entities total] ((:fetch-page grid-spec)
|
[entities total :as page-results] ((:fetch-page grid-spec)
|
||||||
request)]
|
request)
|
||||||
|
request (assoc request :page-results page-results)]
|
||||||
|
|
||||||
(com/data-grid-card {:id (:id grid-spec)
|
(com/data-grid-card {:id (:id grid-spec)
|
||||||
:title (if (string? (:title grid-spec))
|
:title (if (string? (:title grid-spec))
|
||||||
|
|||||||
@@ -251,12 +251,42 @@
|
|||||||
(map first))]
|
(map first))]
|
||||||
refunds))
|
refunds))
|
||||||
|
|
||||||
|
(defn sum-outstanding [ids]
|
||||||
|
|
||||||
|
(->>
|
||||||
|
(dc/q {:find ['?id '?o]
|
||||||
|
:in ['$ '[?id ...]]
|
||||||
|
:where ['[?id :invoice/outstanding-balance ?o]]}
|
||||||
|
(dc/db conn)
|
||||||
|
ids)
|
||||||
|
(map last)
|
||||||
|
(reduce
|
||||||
|
+
|
||||||
|
0.0)))
|
||||||
|
|
||||||
|
(defn sum-total-amount [ids]
|
||||||
|
|
||||||
|
(->>
|
||||||
|
(dc/q {:find ['?id '?o]
|
||||||
|
:in ['$ '[?id ...]]
|
||||||
|
:where ['[?id :invoice/total ?o]]
|
||||||
|
}
|
||||||
|
(dc/db conn)
|
||||||
|
ids)
|
||||||
|
(map last)
|
||||||
|
(reduce
|
||||||
|
+
|
||||||
|
0.0)))
|
||||||
|
|
||||||
(defn fetch-page [request]
|
(defn fetch-page [request]
|
||||||
(let [db (dc/db conn)
|
(let [db (dc/db conn)
|
||||||
{ids-to-retrieve :ids matching-count :count} (fetch-ids db request)]
|
{ids-to-retrieve :ids matching-count :count
|
||||||
|
all-ids :all-ids} (fetch-ids db request)]
|
||||||
|
|
||||||
[(->> (hydrate-results ids-to-retrieve db request))
|
[(->> (hydrate-results ids-to-retrieve db request))
|
||||||
matching-count]))
|
matching-count
|
||||||
|
(sum-outstanding all-ids)
|
||||||
|
(sum-total-amount all-ids)]))
|
||||||
|
|
||||||
(def query-schema (mc/schema
|
(def query-schema (mc/schema
|
||||||
[:maybe [:map {:date-range [:date-range :start-date :end-date]}
|
[:maybe [:map {:date-range [:date-range :start-date :end-date]}
|
||||||
@@ -378,7 +408,6 @@
|
|||||||
(:query-params request))})))
|
(:query-params request))})))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;; TODO test as a real user
|
;; TODO test as a real user
|
||||||
(def grid-page
|
(def grid-page
|
||||||
(helper/build {:id "entity-table"
|
(helper/build {:id "entity-table"
|
||||||
@@ -395,18 +424,24 @@
|
|||||||
(alog/peek ::PARSE
|
(alog/peek ::PARSE
|
||||||
(mc/decode query-schema p main-transformer)))
|
(mc/decode query-schema p main-transformer)))
|
||||||
:action-buttons (fn [request]
|
:action-buttons (fn [request]
|
||||||
[(when (can? (:identity request) {:subject :invoice :activity :bulk-delete})
|
(let [[_ _ outstanding total] (:page-results request)]
|
||||||
(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/bulk-delete))
|
[(com/pill {:color :primary} "Outstanding: "
|
||||||
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
|
(format "$%,.2f" outstanding))
|
||||||
"hx-include" "#invoice-filters"
|
(com/pill {:color :secondary} "Total: "
|
||||||
:color :red}
|
(format "$%,.2f" total))
|
||||||
"Void selected"))
|
|
||||||
(when (can? (:identity request) {:subject :invoice :activity :pay})
|
(when (can? (:identity request) {:subject :invoice :activity :bulk-delete})
|
||||||
(pay-button* {:ids (selected->ids request
|
(com/button {:hx-get (str (bidi/path-for ssr-routes/only-routes ::route/bulk-delete))
|
||||||
(:query-params request))}))
|
"x-bind:hx-vals" "JSON.stringify({selected: $data.selected, 'all-selected': $data.all_selected})"
|
||||||
(when (can? (:identity request) {:subject :invoice :activity :create})
|
"hx-include" "#invoice-filters"
|
||||||
(com/button {:hx-get (bidi/path-for ssr-routes/only-routes ::route/new-wizard)}
|
:color :red}
|
||||||
"New invoice"))])
|
"Void selected"))
|
||||||
|
(when (can? (:identity request) {:subject :invoice :activity :pay})
|
||||||
|
(pay-button* {:ids (selected->ids request
|
||||||
|
(:query-params request))}))
|
||||||
|
(when (can? (:identity request) {:subject :invoice :activity :create})
|
||||||
|
(com/button {:hx-get (bidi/path-for ssr-routes/only-routes ::route/new-wizard)}
|
||||||
|
"New invoice"))]))
|
||||||
:row-buttons (fn [request entity]
|
:row-buttons (fn [request entity]
|
||||||
[(when (and (= :invoice-status/unpaid (:invoice/status entity))
|
[(when (and (= :invoice-status/unpaid (:invoice/status entity))
|
||||||
(can? (:identity request) {:subject :invoice :activity :delete}))
|
(can? (:identity request) {:subject :invoice :activity :delete}))
|
||||||
|
|||||||
Reference in New Issue
Block a user