diff --git a/src/clj/auto_ap/ssr/transaction/edit.clj b/src/clj/auto_ap/ssr/transaction/edit.clj index 615b3437..605b8bf3 100644 --- a/src/clj/auto_ap/ssr/transaction/edit.clj +++ b/src/clj/auto_ap/ssr/transaction/edit.clj @@ -179,6 +179,71 @@ (:account/name (d-accounts/clientize (dc/pull (dc/db conn) d-accounts/default-read value) client-id)))})]) +(defn simple-mode-fields* + "Renders the simple-mode account + location row and the toggle-to-advanced link. + Must be called within a fc/start-form + fc/with-field :step-params context." + [request] + (let [snapshot (-> request :multi-form-state :snapshot) + client-id (or (-> request :entity :transaction/client :db/id) + (:transaction/client snapshot)) + existing-row (first (:transaction/accounts snapshot)) + account-val (or (:transaction-account/account existing-row) + (fc/with-field :transaction/accounts + (fc/with-cursor (nth fc/*current* 0) + (fc/with-field :transaction-account/account + (fc/field-value))))) + location-val (or (:transaction-account/location existing-row) "Shared") + account-id (when (nat-int? account-val) + (dc/pull (dc/db conn) '[:account/location] account-val)) + row-id (or (:db/id existing-row) (str (java.util.UUID/randomUUID))) + total (Math/abs (or (-> request :entity :transaction/amount) + (:transaction/amount snapshot) + 0.0))] + [:div + (fc/with-field :transaction/accounts + (fc/with-cursor (nth fc/*current* 0) + [:span + (fc/with-field :db/id + (com/hidden {:name (fc/field-name) + :value row-id})) + [:div.flex.gap-2.mt-2 + (fc/with-field :transaction-account/account + (com/validated-field + {:label "Account" + :errors (fc/field-errors)} + [:div.w-72 + (account-typeahead* {:value account-val + :client-id client-id + :name (fc/field-name) + :x-model "simpleAccountId"})])) + (fc/with-field :transaction-account/location + (com/validated-field + {:label "Location" + :errors (fc/field-errors) + :x-hx-val:account-id "simpleAccountId" + :hx-vals (hx/json (cond-> {:name (fc/field-name)} + client-id (assoc :client-id client-id))) + :x-dispatch:changed "simpleAccountId" + :hx-trigger "changed" + :hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select) + :hx-target "find *" + :hx-swap "outerHTML"} + (location-select* + {:name (fc/field-name) + :account-location (:account/location account-id) + :client-locations (pull-attr (dc/db conn) :client/locations client-id) + :value location-val}))) + (fc/with-field :transaction-account/amount + (com/hidden {:name (fc/field-name) + :value total}))]])) + [:div.mt-1 + [:a.text-sm.text-blue-600.hover:underline.cursor-pointer + {:hx-get (bidi/path-for ssr-routes/only-routes ::route/edit-wizard-toggle-mode) + :hx-include "closest form" + :hx-target "#manual-coding-section" + :hx-swap "outerHTML"} + "Switch to advanced mode"]]])) + (defn transaction-account-row* [{:keys [value client-id amount-mode total]}] (com/data-grid-row (-> {:class "account-row"