diff --git a/src/clj/auto_ap/ssr/transaction/edit.clj b/src/clj/auto_ap/ssr/transaction/edit.clj index 2967c299..2d494ef2 100644 --- a/src/clj/auto_ap/ssr/transaction/edit.clj +++ b/src/clj/auto_ap/ssr/transaction/edit.clj @@ -241,6 +241,16 @@ :hx-swap "outerHTML"} "Switch to advanced mode"]]])) +(defn- manual-mode-initial + "Returns :simple or :advanced based on existing account row count." + [snapshot] + (let [rows (seq (:transaction/accounts snapshot))] + (if (and rows (> (count rows) 1)) + :advanced + :simple))) + +(declare manual-coding-section*) + (defn transaction-account-row* [{:keys [value client-id amount-mode total]}] (com/data-grid-row (-> {:class "account-row" @@ -482,6 +492,52 @@ (format "$%,.2f" total)) (com/data-grid-cell {}))))) +(defn manual-coding-section* + "Renders the vendor field + account/location section for the manual tab. + mode is :simple or :advanced. + In simple mode, establishes Alpine x-data with simpleAccountId in scope. + Must be called within a fc/start-form + fc/with-field :step-params context." + [mode request] + (let [snapshot (-> request :multi-form-state :snapshot) + row-count (count (:transaction/accounts snapshot))] + [:div#manual-coding-section + (com/hidden {:name "mode" :value (name mode)}) + [:div {:hx-trigger "change" + :hx-post (bidi/path-for ssr-routes/only-routes ::route/edit-vendor-changed) + :hx-target "#manual-coding-section" + :hx-swap "outerHTML" + :hx-include "closest form"} + (fc/with-field :transaction/vendor + (com/validated-field + {:label "Vendor" :errors (fc/field-errors)} + [:div.w-96 + (com/typeahead {:name (fc/field-name) + :error? (fc/error?) + :class "w-96" + :placeholder "Search..." + :url (bidi/path-for ssr-routes/only-routes :vendor-search) + :value (fc/field-value) + :content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})]))] + (if (= mode :simple) + [:div {:x-data (hx/json {:simpleAccountId + (-> snapshot :transaction/accounts first + :transaction-account/account)})} + (simple-mode-fields* request)] + [:div + (when (<= row-count 1) + [:div.mb-2 + [: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 simple mode"]]) + (fc/with-field :transaction/accounts + (com/validated-field + {:errors (fc/field-errors)} + [:div#account-grid-body + (account-grid-body* request)]))])])) + (defn toggle-amount-mode [request] (let [snapshot (-> request :multi-form-state :snapshot) old-mode (or (:amount-mode snapshot) "$") @@ -877,7 +933,6 @@ ":disabled" "!canChange"} "Manual"))] [:div {:x-show "activeForm === 'link-payment'", :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"} - (payment-matches-view request)] [:div {:x-show "activeForm === 'link-unpaid-invoices'", :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"} (unpaid-invoices-view request)] @@ -887,27 +942,7 @@ (transaction-rules-view request)] [: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-post (bidi/path-for ssr-routes/only-routes ::route/edit-vendor-changed) - :hx-target "#account-grid-body" - :hx-swap "outerHTML" - :hx-include "closest form"} - (fc/with-field :transaction/vendor - (com/validated-field - {:label "Vendor" - :errors (fc/field-errors)} - [:div.w-96 - (com/typeahead {:name (fc/field-name) - :error? (fc/error?) - :class "w-96" - :placeholder "Search..." - :url (bidi/path-for ssr-routes/only-routes :vendor-search) - :value (fc/field-value) - :content-fn (fn [c] (pull-attr (dc/db conn) :vendor/name c))})]))] - - ;; Memo field - - ;; Approval status field + (manual-coding-section* (manual-mode-initial snapshot) request) (fc/with-field :transaction/approval-status (com/validated-field {:label "Status" @@ -929,12 +964,7 @@ (com/button-group-button {"@click" "approvalStatus = 'suppressed'" ":class" "{ '!bg-primary-200 text-primary-800': approvalStatus === 'suppressed' }" :class "rounded-r-lg"} - "Client Review")]]))) - (fc/with-field :transaction/accounts - (com/validated-field - {:errors (fc/field-errors)} - [:div#account-grid-body - (account-grid-body* request)]))]]]]) + "Client Review")]])))]]]]) :footer (mm/default-step-footer linear-wizard this :validation-route ::route/edit-wizard-navigate :next-button (com/button {:color :primary :x-ref "next" :class "w-32 wizard-save-action"} "Done"))