Add vendor pre-population for bulk code and individual edit forms

- Add vendor-changed HTMX handlers for both bulk code and individual edit
- Pre-populate default account at 100% when vendor is selected and no accounts exist
- Fix render-accounts-section to render from step-params correctly
- Change bulk code vendor-changed from hx-get to hx-post to include form data
- Add routes for vendor-changed endpoints
- Update e2e tests to cover vendor pre-population
- Run lein cljfmt fix across codebase
This commit is contained in:
2026-05-21 14:45:19 -07:00
parent 8bd0cee1b1
commit ba87805d4c
210 changed files with 8694 additions and 9627 deletions

View File

@@ -33,7 +33,6 @@
[:processor {:optional true} [:maybe (ref->enum-schema "ccp-processor")]]]
default-grid-fields-schema)]))
(defn filters [request]
[:form {"hx-trigger" "change delay:500ms, keyup changed from:.hot-filter delay:1000ms"
"hx-get" (bidi/path-for ssr-routes/only-routes
@@ -42,7 +41,7 @@
"hx-indicator" "#expected-deposit-table"
#_#_:hx-disabled-elt "find fieldset"}
[:fieldset.space-y-6
[:fieldset.space-y-6
(date-range-field* request)
(exact-match-id-field* request)]])
@@ -70,26 +69,25 @@
(some-> (:start-date query-params) c/to-date)
(some-> (:end-date query-params) c/to-date)]]}
(:sort query-params) (add-sorter-fields {"client" ['[?e :expected-deposit/client ?c]
'[?c :client/name ?sort-client]]
"location" ['[?e :expected-deposit/location ?sort-location]]
"date" ['[?e :expected-deposit/date ?sort-date]]
"total" ['[?e :expected-deposit/total ?sort-total]]
"fee" ['[?e :expected-deposit/fee ?sort-fee]]}
query-params)
'[?c :client/name ?sort-client]]
"location" ['[?e :expected-deposit/location ?sort-location]]
"date" ['[?e :expected-deposit/date ?sort-date]]
"total" ['[?e :expected-deposit/total ?sort-total]]
"fee" ['[?e :expected-deposit/fee ?sort-fee]]}
query-params)
(:exact-match-id query-params)
(merge-query {:query {:in ['?e]
:where []}
:args [(:exact-match-id query-params)]})
(:total-gte query-params)
(:total-gte query-params)
(merge-query {:query {:in ['?total-gte]
:where ['[?e :expected-deposit/total ?a]
'[(>= ?a ?total-gte)]]}
:args [(:total-gte query-params)]})
(:total-lte query-params)
(:total-lte query-params)
(merge-query {:query {:in ['?total-lte]
:where ['[?e :expected-deposit/total ?a]
'[(<= ?a ?total-lte)]]}
@@ -104,7 +102,7 @@
true
(merge-query {:query {:find ['?sort-default '?e]
:where ['[?e :expected-deposit/date ?sort-default]]}}))]
(cond->> (query2 query)
true (apply-sort-3 query-params)
true (apply-pagination query-params))))
@@ -113,25 +111,25 @@
(let [results (->> (pull-many db default-read ids)
(group-by :db/id))
payments (->> ids
(map results)
(map first)
(map (fn get-totals [ed]
(assoc ed :totals
(->> (dc/q '[:find ?d4 (count ?c) (sum ?a)
:in $ ?ed
:where [?ed :expected-deposit/charges ?c]
[?c :charge/total ?a]
[?o :sales-order/charges ?c]
[?o :sales-order/date ?d]
[(clj-time.coerce/from-date ?d) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(clj-time.coerce/to-local-date ?d3) ?d4]]
(dc/db conn)
(:db/id ed))
(map (fn [[date count amount]]
{:date (c/to-date-time date)
:count count
:amount amount})))))))]
(map results)
(map first)
(map (fn get-totals [ed]
(assoc ed :totals
(->> (dc/q '[:find ?d4 (count ?c) (sum ?a)
:in $ ?ed
:where [?ed :expected-deposit/charges ?c]
[?c :charge/total ?a]
[?o :sales-order/charges ?c]
[?o :sales-order/date ?d]
[(clj-time.coerce/from-date ?d) ?d2]
[(auto-ap.time/localize ?d2) ?d3]
[(clj-time.coerce/to-local-date ?d3) ?d4]]
(dc/db conn)
(:db/id ed))
(map (fn [[date count amount]]
{:date (c/to-date-time date)
:count count
:amount amount})))))))]
payments))
(defn fetch-page [args]
@@ -142,66 +140,64 @@
matching-count]))
(def grid-page
(helper/build
{:id "expected-deposit-table"
:nav com/main-aside-nav
:page-specific-nav filters
:fetch-page fetch-page
:oob-render
(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"]
(helper/build
{:id "expected-deposit-table"
:nav com/main-aside-nav
:page-specific-nav filters
:fetch-page fetch-page
:oob-render
(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"]
[:a {:href (bidi/path-for ssr-routes/only-routes
:pos-expected-deposits)}
"Expected deposits"]]
:title "Expected deposits"
:entity-name "Expected deposit"
:query-schema query-schema
:route :pos-expected-deposit-table
:row-buttons (fn [_ e]
[
(when (:expected-deposit/reference-link e)
(com/a-icon-button {:href (:expected-deposit/reference-link e)}
svg/external-link))
(when-let [transaction-id (-> e (:transaction/_expected-deposit) first :db/id)]
(com/a-button {:href (str (bidi/path-for ssr-routes/only-routes
::transaction-routes/all-page)
"?exact-match-id="
transaction-id)} "Transaction"))])
:headers [{:key "client"
:name "Client"
:sort-key "client"
:hide? (fn [args]
(= (count (:clients args)) 1))
:render #(-> % :expected-deposit/client :client/code)}
{:key "date"
:name "Date"
:sort-key "date"
:render #(atime/unparse-local (:expected-deposit/date %) atime/standard-time)}
{:key "sales-date"
:name "Sales Date"
:sort-key "sales-date"
:render #(atime/unparse-local (:expected-deposit/sales-date %) atime/standard-time)}
{:key "total"
:name "Total"
:sort-key "total"
:render #(some->> % :expected-deposit/total (format "$%.2f"))}
{:key "fee"
:name "Fee"
:sort-key "fee"
:render #(some->> % :expected-deposit/fee (format "$%.2f"))}]}))
[:a {:href (bidi/path-for ssr-routes/only-routes
:pos-expected-deposits)}
"Expected deposits"]]
:title "Expected deposits"
:entity-name "Expected deposit"
:query-schema query-schema
:route :pos-expected-deposit-table
:row-buttons (fn [_ e]
[(when (:expected-deposit/reference-link e)
(com/a-icon-button {:href (:expected-deposit/reference-link e)}
svg/external-link))
(when-let [transaction-id (-> e (:transaction/_expected-deposit) first :db/id)]
(com/a-button {:href (str (bidi/path-for ssr-routes/only-routes
::transaction-routes/all-page)
"?exact-match-id="
transaction-id)} "Transaction"))])
:headers [{:key "client"
:name "Client"
:sort-key "client"
:hide? (fn [args]
(= (count (:clients args)) 1))
:render #(-> % :expected-deposit/client :client/code)}
{:key "date"
:name "Date"
:sort-key "date"
:render #(atime/unparse-local (:expected-deposit/date %) atime/standard-time)}
{:key "sales-date"
:name "Sales Date"
:sort-key "sales-date"
:render #(atime/unparse-local (:expected-deposit/sales-date %) atime/standard-time)}
{:key "total"
:name "Total"
:sort-key "total"
:render #(some->> % :expected-deposit/total (format "$%.2f"))}
{:key "fee"
:name "Fee"
:sort-key "fee"
:render #(some->> % :expected-deposit/fee (format "$%.2f"))}]}))
(def row* (partial helper/row* grid-page))
(def table* (partial helper/table* grid-page))
(def key->handler
(apply-middleware-to-all-handlers
{:pos-expected-deposits (helper/page-route grid-page)
:pos-expected-deposit-table (helper/table-route grid-page)}
:pos-expected-deposit-table (helper/table-route grid-page)}
(fn [h]
(-> h
(wrap-copy-qp-pqp)