Merge branch 'integreat-fix-errors' into staging
This commit is contained in:
@@ -215,11 +215,11 @@
|
||||
(fn [{:keys [wizard multi-form-state] :as request}]
|
||||
(assert-schema (step-schema (get-current-step wizard)) (:step-params multi-form-state))
|
||||
(handler request))
|
||||
(wrap-form-4xx-2 (fn [{:keys [wizard] :as request}] ;; THIS MAY BE BETTER TO JUST MAKE THE LINEAR WIZARD POPULATE FROM THE REQUEST
|
||||
(html-response
|
||||
(render-wizard wizard request)
|
||||
:headers {"x-transition-type" "none"
|
||||
"HX-reswap" "outerHTML"})))))
|
||||
(wrap-form-4xx-2 (fn [{:keys [wizard] :as request}] ;; THIS MAY BE BETTER TO JUST MAKE THE LINEAR WIZARD POPULATE FROM THE REQUEST
|
||||
(html-response
|
||||
(render-wizard wizard request)
|
||||
:headers {"x-transition-type" "none"
|
||||
"HX-reswap" "outerHTML"})))))
|
||||
|
||||
(defn get-transition-type [wizard from-step-key to-step-key]
|
||||
(let [to-step-index (.indexOf (steps wizard) to-step-key)
|
||||
|
||||
@@ -161,7 +161,7 @@
|
||||
[["Shared" "Shared"]]))]
|
||||
(com/select {:options options
|
||||
:name name
|
||||
:value (ffirst options)
|
||||
:value (or value (ffirst options))
|
||||
:class "w-full"})))
|
||||
|
||||
(defn account-typeahead*
|
||||
@@ -313,7 +313,9 @@
|
||||
(filter number?)
|
||||
(reduce + 0.0))
|
||||
balance (-
|
||||
(Math/abs (-> request :multi-form-state :snapshot :transaction/amount))
|
||||
(Math/abs (or (-> request :entity :transaction/amount)
|
||||
(-> request :multi-form-state :snapshot :transaction/amount)
|
||||
0.0))
|
||||
total)]
|
||||
[:span {:class (when-not (dollars= 0.0 balance)
|
||||
"text-red-300")}
|
||||
@@ -355,7 +357,9 @@
|
||||
(defn account-grid-body* [request]
|
||||
(let [snapshot (-> request :multi-form-state :snapshot)
|
||||
amount-mode (or (:amount-mode snapshot) "$")
|
||||
total (Math/abs (or (:transaction/amount snapshot) 0.0))]
|
||||
total (Math/abs (or (-> request :entity :transaction/amount)
|
||||
(:transaction/amount snapshot)
|
||||
0.0))]
|
||||
(com/data-grid {:headers [(com/data-grid-header {} "Account")
|
||||
(com/data-grid-header {:class "w-32"} "Location")
|
||||
(com/data-grid-header {:class "w-16"}
|
||||
@@ -913,7 +917,7 @@
|
||||
[:div {:x-show "activeForm === 'manual'", :x-transition:enter "transition ease-out duration-500", :x-transition:enter-start "opacity-0 transform scale-95", :x-transition:enter-end "opacity-100 transform scale-100"}
|
||||
[:div {}
|
||||
[:div {:hx-trigger "change"
|
||||
:hx-get (bidi/path-for ssr-routes/only-routes ::route/edit-vendor-changed)
|
||||
:hx-post (bidi/path-for ssr-routes/only-routes ::route/edit-vendor-changed)
|
||||
:hx-target "#account-grid-body"
|
||||
:hx-swap "outerHTML"
|
||||
:hx-include "closest form"}
|
||||
@@ -1246,14 +1250,16 @@
|
||||
(when (and (= :transaction-approval-status/approved (keyword (:transaction/approval-status tx-data)))
|
||||
(not (seq (:transaction/accounts tx-data))))
|
||||
(throw (ex-info "Approved transactions must have accounts assigned."
|
||||
{:validation-error "Approved transactions must have accounts assigned."})))
|
||||
{:type :form-validation
|
||||
:form-validation-errors ["Approved transactions must have accounts assigned."]})))
|
||||
|
||||
(when (seq (:transaction/accounts tx-data))
|
||||
(let [account-total (reduce + 0 (map :transaction-account/amount (:transaction/accounts tx-data)))]
|
||||
(when (not (dollars= (Math/abs (:transaction/amount existing-tx)) account-total))
|
||||
(throw (ex-info (str "Account total (" account-total ") does not equal transaction amount ("
|
||||
(Math/abs (:transaction/amount existing-tx)) ")")
|
||||
{:validation-error "Account totals must match transaction amount."})))))
|
||||
(let [account-total (reduce + 0 (map :transaction-account/amount (:transaction/accounts tx-data)))
|
||||
tx-amount (Math/abs (:transaction/amount existing-tx))]
|
||||
(when (not (dollars= tx-amount account-total))
|
||||
(throw (ex-info (format "The total of your expense accounts ($%,.2f) must equal the transaction amount ($%,.2f)." account-total tx-amount)
|
||||
{:type :form-validation
|
||||
:form-validation-errors [(format "The total of your expense accounts ($%,.2f) must equal the transaction amount ($%,.2f)." account-total tx-amount)]})))))
|
||||
|
||||
(let [transaction-result (audit-transact [transaction] (:identity request))]
|
||||
(try
|
||||
@@ -1348,8 +1354,6 @@
|
||||
(mm/get-step this current-step)
|
||||
(mm/get-step this :basic-details)))
|
||||
(render-wizard [this {:keys [multi-form-state] :as request}]
|
||||
(println "HERE XYZ" (:form-errors request))
|
||||
(clojure.pprint/pprint (:snapshot multi-form-state))
|
||||
(mm/default-render-wizard
|
||||
this request
|
||||
:form-params
|
||||
@@ -1394,34 +1398,40 @@
|
||||
[]
|
||||
entity)))
|
||||
|
||||
(defn- render-account-grid-body [request]
|
||||
(fc/start-form (:multi-form-state request) nil
|
||||
(fc/with-field :step-params
|
||||
(fc/with-field :transaction/accounts
|
||||
(account-grid-body* request)))))
|
||||
|
||||
(defn edit-vendor-changed-handler [request]
|
||||
(let [snapshot (:snapshot (:multi-form-state request))
|
||||
(let [multi-form-state (:multi-form-state request)
|
||||
snapshot (:snapshot multi-form-state)
|
||||
step-params (:step-params multi-form-state)
|
||||
client-id (or (:transaction/client snapshot)
|
||||
(-> request :entity :transaction/client :db/id))
|
||||
vendor-id (:transaction/vendor snapshot)
|
||||
total (Math/abs (or (:transaction/amount snapshot) 0.0))
|
||||
amount-mode (or (:amount-mode snapshot) "$")]
|
||||
(if (and (empty? (:transaction/accounts snapshot))
|
||||
vendor-id
|
||||
client-id)
|
||||
(if-let [default-account (vendor-default-account vendor-id client-id)]
|
||||
(let [new-account {:db/id (str (java.util.UUID/randomUUID))
|
||||
:transaction-account/account (:db/id default-account)
|
||||
:transaction-account/location (or (:account/location default-account) "Shared")}
|
||||
new-account (if (= amount-mode "%")
|
||||
(assoc new-account :transaction-account/amount 100.0)
|
||||
(assoc new-account :transaction-account/amount total))
|
||||
updated-snapshot (assoc snapshot :transaction/accounts [new-account])
|
||||
updated-request (assoc-in request [:multi-form-state :snapshot] updated-snapshot)]
|
||||
(html-response
|
||||
[:div#account-grid-body
|
||||
(account-grid-body* updated-request)]))
|
||||
(html-response
|
||||
[:div#account-grid-body
|
||||
(account-grid-body* request)]))
|
||||
(html-response
|
||||
[:div#account-grid-body
|
||||
(account-grid-body* request)]))))
|
||||
vendor-id (or (:transaction/vendor step-params) (:transaction/vendor snapshot))
|
||||
total (Math/abs (or (-> request :entity :transaction/amount)
|
||||
(:transaction/amount snapshot)
|
||||
0.0))
|
||||
amount-mode (or (:amount-mode snapshot) "$")
|
||||
existing-accounts (or (seq (:transaction/accounts step-params))
|
||||
(seq (:transaction/accounts snapshot)))
|
||||
default-account (when (and (empty? existing-accounts) vendor-id client-id)
|
||||
(vendor-default-account vendor-id client-id))
|
||||
render-request
|
||||
(if (and (empty? existing-accounts) vendor-id client-id)
|
||||
(let [new-account (cond-> {:db/id (str (java.util.UUID/randomUUID))
|
||||
:transaction-account/location (or (:account/location default-account) "Shared")
|
||||
:transaction-account/amount (if (= amount-mode "%") 100.0 total)}
|
||||
default-account (assoc :transaction-account/account (:db/id default-account)))]
|
||||
(-> request
|
||||
(assoc-in [:multi-form-state :snapshot :transaction/accounts] [new-account])
|
||||
(assoc-in [:multi-form-state :step-params :transaction/accounts] [new-account])))
|
||||
request)]
|
||||
(html-response
|
||||
[:div#account-grid-body
|
||||
(render-account-grid-body render-request)])))
|
||||
|
||||
(def key->handler
|
||||
(apply-middleware-to-all-handlers
|
||||
@@ -1443,6 +1453,7 @@
|
||||
(mm/wrap-decode-multi-form-state))
|
||||
::route/edit-vendor-changed (-> edit-vendor-changed-handler
|
||||
(mm/wrap-wizard edit-wizard)
|
||||
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||
(mm/wrap-decode-multi-form-state))
|
||||
::route/location-select (-> location-select
|
||||
(wrap-schema-enforce :query-schema [:map
|
||||
@@ -1453,12 +1464,15 @@
|
||||
[:maybe entity-id]]]))
|
||||
::route/account-total (-> account-total
|
||||
(mm/wrap-wizard edit-wizard)
|
||||
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||
(mm/wrap-decode-multi-form-state))
|
||||
::route/account-balance (-> account-balance
|
||||
(mm/wrap-wizard edit-wizard)
|
||||
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||
(mm/wrap-decode-multi-form-state))
|
||||
::route/toggle-amount-mode (-> toggle-amount-mode
|
||||
(mm/wrap-wizard edit-wizard)
|
||||
(wrap-entity [:multi-form-state :snapshot :db/id] d-transactions/default-read)
|
||||
(mm/wrap-decode-multi-form-state))
|
||||
::route/edit-wizard-new-account (->
|
||||
(add-new-entity-handler [:step-params :transaction/accounts]
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
[:script {:src "https://cdn.jsdelivr.net/npm/@ryangjchandler/alpine-tooltip@1.x.x/dist/cdn.min.js" :defer true}]
|
||||
[:link {:rel "stylesheet" :href "/css/tippy/tippy.css"}]
|
||||
[:link {:rel "stylesheet" :href "/css/tippy/light.css"}]
|
||||
[:script {:src "/js/htmx.min.js"
|
||||
[:script {:src "/js/htmx.js"
|
||||
:crossorigin= "anonymous"}]
|
||||
|
||||
[:script {:src "https://cdn.jsdelivr.net/npm/sortablejs@1.15.2/Sortable.min.js"}]
|
||||
|
||||
Reference in New Issue
Block a user