Files
integreat/iol_ion/src/iol_ion/tx/propose_invoice.clj
Bryce ba87805d4c 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
2026-05-21 14:45:19 -07:00

29 lines
1.4 KiB
Clojure

(ns iol-ion.tx.propose-invoice
(:require [datomic.api :as dc]))
(defn propose-invoice [db invoice]
(let [existing? (boolean (seq (dc/q '[:find ?i
:in $ ?invoice-number ?client ?vendor
:where
[?i :invoice/invoice-number ?invoice-number]
[?i :invoice/client ?client]
[?i :invoice/vendor ?vendor]
(not [?i :invoice/status :invoice-status/voided])]
db
(:invoice/invoice-number invoice)
(:invoice/client invoice)
(:invoice/vendor invoice))))
[locked-until] (first (dc/q '[:find ?locked-until
:in $ ?c
:where [?c :client/locked-until ?locked-until]]
db
(:invoice/client invoice)))
is-locked? (cond
(not locked-until) false
(not (:invoice/date invoice)) true
(< (compare (:invoice/date invoice) locked-until) 0) true
:else false)]
(if (or existing? is-locked?)
[]
[[:upsert-invoice invoice]])))