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

@@ -11,15 +11,15 @@
(defn try-cleanse-date [d]
(try
(or
(some-> (atime/parse-utc d atime/normal-date) (atime/unparse atime/solr-date))
(some-> (atime/parse-utc d atime/iso-date) (atime/unparse atime/solr-date))
d)
(or
(some-> (atime/parse-utc d atime/normal-date) (atime/unparse atime/solr-date))
(some-> (atime/parse-utc d atime/iso-date) (atime/unparse atime/solr-date))
d)
(catch Exception _
d)))
(defn try-parse-number [n]
(if (re-find #"^[\-]?\d+\.\d+$" n )
(if (re-find #"^[\-]?\d+\.\d+$" n)
(str (with-precision 2
(some-> n
(Double/parseDouble)
@@ -28,7 +28,6 @@
(double))))
n))
(defn q->solr-q [q]
(let [matches (re-seq #"(?:\".*?\"|\S)+" q)]
(str/join " AND "
@@ -46,10 +45,8 @@
(= "journal-entry" m)
"type:journal-entry"
:else
(str "_text_:\"" (try-parse-number (try-cleanse-date m)) ""\"))))))))
(str "_text_:\"" (try-parse-number (try-cleanse-date m)) "" \"))))))))
(defn search-results [q id]
(into []
@@ -58,96 +55,89 @@
(solr/query solr/impl "invoices" {"query" (q->solr-q q)
"fields" "id, date, amount, type, description, number, client_code, client_id, vendor_name"})))
(defn search-results* [q id]
(let [results (search-results q id)]
[:div
(let [results (search-results q id)]
[:div
(if (seq results)
[:div.flex.gap-8.flex-col
(for [doc results]
(com/card {}
[:div.flex.flex-col.gap-4
[:div.flex.items-center.p-2.gap-4.bg-gray-50.dark:bg-gray-800
[:div.h-8.w-8.p-2
(cond (= "transaction" (:type doc))
svg/bank
[:div.flex.flex-col.gap-4
[:div.flex.items-center.p-2.gap-4.bg-gray-50.dark:bg-gray-800
[:div.h-8.w-8.p-2
(cond (= "transaction" (:type doc))
svg/bank
(= "invoice" (:type doc))
svg/accounting-invoice-mail
(= "invoice" (:type doc))
svg/accounting-invoice-mail
(= "payment" (:type doc))
svg/payments
(= "payment" (:type doc))
svg/payments
(= "journal-entry" (:type doc))
svg/receipt
(= "journal-entry" (:type doc))
svg/receipt
:else
nil)]
(clojure.string/capitalize (:type doc))
(com/pill {:color :primary}
"client: " (:client_code doc))
(com/pill {:color :secondary}
"amount: $" (first (:amount doc)))
(when-let [vendor-name (first (:vendor_name doc))]
(com/pill {:color :yellow}
"vendor: " vendor-name))
[:div
(com/link {:href (str "/" (cond (= "invoice"
(:type doc))
"invoices"
:else
nil)]
(clojure.string/capitalize (:type doc))
(com/pill {:color :primary}
"client: " (:client_code doc))
(com/pill {:color :secondary}
"amount: $" (first (:amount doc)))
(when-let [vendor-name (first (:vendor_name doc))]
(com/pill {:color :yellow}
"vendor: " vendor-name))
[:div
(com/link {:href (str "/" (cond (= "invoice"
(:type doc))
"invoices"
(= "transaction"
(:type doc))
"transactions"
(= "transaction"
(:type doc))
"transactions"
(= "journal-entry"
(:type doc))
"ledger"
(= "journal-entry"
(:type doc))
"ledger"
:else
"payments") "/?exact-match-id=" (:id doc))
:target "_blank"}
[:div.h-8.w-8.p-2
svg/external-link])]
]
[:div.px-4.pb-2
[:span
[:strong (atime/unparse (atime/parse (:date doc) atime/solr-date) atime/normal-date)]
": "
(str (or (first (:description doc))
(first (:number doc))))]]])
)]
:else
"payments") "/?exact-match-id=" (:id doc))
:target "_blank"}
[:div.h-8.w-8.p-2
svg/external-link])]]
[:div.px-4.pb-2
[:span
[:strong (atime/unparse (atime/parse (:date doc) atime/solr-date) atime/normal-date)]
": "
(str (or (first (:description doc))
(first (:number doc))))]]]))]
[:div.block "No results found."])]))
(defn dialog-contents [request]
(if-let [q (get (:form-params request) "q")]
(html-response (search-results* q (:identity request)))
(modal-response
(com/modal {}
(com/modal-card {:class "w-full h-full"}
[:div.p-2 "Search"]
[:div#search.overflow-auto.space-y-6.p-2.w-full
(com/text-input {:id "search-input"
:type "search"
:placeholder "5/5/2034 Magheritas"
:name "q"
:hx-post "/search"
:hx-trigger "keyup changed delay:300ms, search"
:hx-target "#search-results"
:hx-indicator "#search"
:value (:q (:params request))
:autofocus true})
[:i.text-sm.text-gray-600.dark:text-gray-50 "Try dates, numbers, vendors. To filter to specific type, use 'invoice', 'transaction', 'journal-entry', 'payment'."]
#_[:style
".htmx-request #search-results {display: none} .htmx-request .htmx-indicator { display: block !important; }"]
[:div#search-results
]
[:div.loader.is-loading.big.htmx-indicator ]]
nil)))))
(com/modal {}
(com/modal-card {:class "w-full h-full"}
[:div.p-2 "Search"]
[:div#search.overflow-auto.space-y-6.p-2.w-full
(com/text-input {:id "search-input"
:type "search"
:placeholder "5/5/2034 Magheritas"
:name "q"
:hx-post "/search"
:hx-trigger "keyup changed delay:300ms, search"
:hx-target "#search-results"
:hx-indicator "#search"
:value (:q (:params request))
:autofocus true})
[:i.text-sm.text-gray-600.dark:text-gray-50 "Try dates, numbers, vendors. To filter to specific type, use 'invoice', 'transaction', 'journal-entry', 'payment'."]
#_[:style
".htmx-request #search-results {display: none} .htmx-request .htmx-indicator { display: block !important; }"]
[:div#search-results]
[:div.loader.is-loading.big.htmx-indicator]]
nil)))))