Switching to radio.

This commit is contained in:
2025-03-10 09:26:29 -07:00
parent 0a797fea3a
commit 8429d8516c
2 changed files with 258 additions and 256 deletions

View File

@@ -2,11 +2,12 @@
(:require [auto-ap.ssr.hiccup-helper :as hh]
[auto-ap.ssr.hx :as hx]))
(defn radio-card- [{:keys [options name title size orientation] :or {size :medium} selected-value :value}]
(defn radio-card- [{:keys [options name title size orientation width] :or {size :medium width "w-48"} selected-value :value}]
[:h3 {:class "mb-4 font-semibold text-gray-900 dark:text-white"} title]
[:ul {:class (cond-> "w-48 text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white"
[:ul {:class (cond-> " text-sm font-medium text-gray-900 bg-white border border-gray-200 rounded-lg dark:bg-gray-700 dark:border-gray-600 dark:text-white"
(= orientation :horizontal) (-> (hh/add-class "flex gap-2 flex-wrap")
(hh/remove-wildcard ["w-" "rounded-lg" "border" "bg-"])))}
(hh/remove-wildcard ["w-" "rounded-lg" "border" "bg-"]))
true (str " " width " "))}
(for [{:keys [value content]} options]
[:li {:class (cond-> "w-full border-b border-gray-200 rounded-t-lg dark:border-gray-600"
(= orientation :horizontal) (-> (hh/remove-wildcard ["w-full" "rounded-"])

View File

@@ -79,8 +79,8 @@
:error/path [:transaction-account/location]}
(fn [iea]
(check-location-belongs (:transaction-account/location iea)
(:transaction-account/account iea)))]]]]
])
(:transaction-account/account iea)))]]]]])
(defn clientize-vendor [{:vendor/keys [terms-overrides automatically-paid-when-due default-account account-overrides] :as vendor} client-id]
(if (nil? vendor)
@@ -270,41 +270,41 @@
[:div.grid.grid-cols-2.gap-4
[:div
[:div.text-sm.font-medium.text-gray-500 "Amount"]
[:div.text-base (format "$%,.2f" (Math/abs (:transaction/amount tx)))]
]
[:div.text-base (format "$%,.2f" (Math/abs (:transaction/amount tx)))]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Date"]
[:div.text-base (some-> tx :transaction/date coerce/to-date-time (atime/unparse-local atime/normal-date))]
]
[:div.text-base (some-> tx :transaction/date coerce/to-date-time (atime/unparse-local atime/normal-date))]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Bank Account"]
[:div.text-base (or (-> tx :transaction/bank-account :bank-account/name) "-")]
]
[:div.text-base (or (-> tx :transaction/bank-account :bank-account/name) "-")]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Post Date"]
[:div.text-base (some-> tx :transaction/post-date coerce/to-date-time (atime/unparse-local atime/normal-date))]
]
[:div.text-base (some-> tx :transaction/post-date coerce/to-date-time (atime/unparse-local atime/normal-date))]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Original Description"]
[:div.text-base (or (:transaction/description-original tx) "-")]
]
[:div.text-base (or (:transaction/description-original tx) "-")]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Simplified Description"]
[:div.text-base (or (:transaction/description-simple tx) "-")]
]
[:div.text-base (or (:transaction/description-simple tx) "-")]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Check Number"]
[:div.text-base (or (:transaction/check-number tx) "-")]
]
[:div.text-base (or (:transaction/check-number tx) "-")]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Status"]
[:div.text-base (or (some-> tx :transaction/status) "-")]
]
[:div.text-base (or (some-> tx :transaction/status) "-")]]
[:div
[:div.text-sm.font-medium.text-gray-500 "Transaction Type"]
[:div.text-base (or (some-> tx :transaction/type) "-")]
]
]]
[:div.text-base (or (some-> tx :transaction/type) "-")]]]]
;; Transaction Links Section
#_[:div.mb-6.border.rounded-lg.p-4.bg-gray-50
@@ -348,10 +348,10 @@
(if op [:span.text-green-600 "✓ "] "")
(str "Payment #" (:payment/invoice-number payment) " - "
(-> payment :payment/vendor :vendor/name))])]
[:p.text-sm.text-gray-500.italic "No payments linked to this transaction"])]
[:p.text-sm.text-gray-500.italic "No payments linked to this transaction"])]])]]
;; Invoices section
])]]
;; Hidden ID field
(fc/with-field :db/id
@@ -547,32 +547,29 @@
(if (seq payments)
[:div
[:h3.text-lg.font-bold.mb-4 "Available Payments"]
[:div.space-y-2
(for [payment payments]
[:div.py-2.border-b.border-gray-200 {:hx-post (bidi/path-for ssr-routes/only-routes
::route/match-payment)
:hx-include "this"
[:div {:hx-post (bidi/path-for ssr-routes/only-routes ::route/match-payment)
:hx-trigger "matchPayment"
:hx-params "transaction-id, match-payment-id"
:hx-target "#modal-holder"
:hx-include "this"
:hx-swap "outerHTML"}
(com/hidden {:name "transaction-id"
:form ""
:value (-> request :multi-form-state :snapshot :db/id)})
(com/hidden {:name "match-payment-id"
:value (:db/id payment)
(com/hidden {:name "action"
:value "link-payment"
:form ""})
[:div.flex.justify-between.items-center
[:div.space-y-1
[:div.font-medium
(str (:payment/invoice-number payment) " - " (-> payment :payment/vendor :vendor/name))]
[:div.text-sm.text-gray-600
(str "Amount: $" (format "%.2f" (:payment/amount payment)))
" • "
(str "Date: " (some-> payment :payment/date coerce/to-date-time (atime/unparse-local atime/normal-date)))]]
(com/a-button {:color :primary :size :small "@click" "$dispatch('matchPayment')"} "Match")]])]]
(com/hidden {:name "transaction-id"
:value (-> request :multi-form-state :snapshot :db/id)
:form ""})
[:div.space-y-2
[:label.block.text-sm.font-medium.mb-1 "Select a payment to match:"]
(when payments
(com/radio-card {:options (for [payment payments]
{:value (:db/id payment)
:content (str (:payment/invoice-number payment) " - "
(-> payment :payment/vendor :vendor/name)
" - Amount: $" (format "%.2f" (:payment/amount payment))
" • Date: " (some-> payment :payment/date coerce/to-date-time (atime/unparse-local atime/normal-date)))})
:name "payment-id"
:width "w-full"}))
(com/a-button {"@click" "$dispatch('matchPayment')"} "Match" #_[:button.mt-4.w-full.py-2.bg-blue-500.text-white.rounded.hover:bg-blue-600 "Match"])]] ]
[:div.text-center.py-4.text-gray-500 "No matching payments available for this transaction."]) ]))
(defn get-available-autopay-invoices [request]
@@ -596,30 +593,24 @@
(if (seq invoice-matches)
[:div
[:h3.text-lg.font-bold.mb-4 "Available Autopay Invoices"]
[:div.space-y-4
(for [match-group invoice-matches]
[:div.border.border-gray-200.rounded.p-4 {:hx-post (bidi/path-for ssr-routes/only-routes
::route/match-autopay-invoices)
:hx-trigger "matchAutopay"
:hx-include "this"
:hx-params "transaction-id, autopay-invoice-ids"
[:form {:hx-post (bidi/path-for ssr-routes/only-routes ::route/match-autopay)
:hx-trigger "submit"
:hx-target "#modal-holder"
:hx-swap "outerHTML"}
[:div.space-y-3
[:div.text-sm.font-medium "Match with these invoices:"]
(com/hidden {:name "transaction-id"
:form ""
:value (-> request :multi-form-state :snapshot :db/id)})
:value (get-in request [:multi-form-state :snapshot :db/id])
:form ""})
[:div.space-y-2
[:label.block.text-sm.font-medium.mb-1 "Select an autopay invoice to apply:"]
(for [match-group invoice-matches]
(for [invoice match-group]
[:div.flex.justify-between.items-center.py-2.border-b.border-gray-100
[:div
[:div.font-medium (:invoice/invoice-number invoice)]
[:div.text-sm.text-gray-600 (-> invoice :invoice/vendor :vendor/name)]]
[:div.text-right
[:div.font-medium (format "$%.2f" (:invoice/total invoice))]
(com/hidden {:name "autopay-invoice-ids" :value (:db/id invoice) :form ""})]])
[:div.flex.justify-end.mt-4
(com/a-button {:color :primary :size :small "@click" "$dispatch('matchAutopay')"} "Match")]]])]]
[:div.flex.items-center
[:input {:type :radio :value (:db/id invoice) :name "autopay-invoice-id"}]
[:div.ml-3
[:span.block.text-sm.font-medium (:invoice/invoice-number invoice)]
[:span.block.text-sm.text-gray-500 (-> invoice :invoice/vendor :vendor/name)]
[:span.block.text-sm.font-medium (format "$%.2f" (:invoice/total invoice))]]]))]
[:button.mt-4.w-full.py-2.bg-blue-500.text-white.rounded.hover:bg-blue-600 "Match"]]]
[:div.text-center.py-4.text-gray-500 "No matching autopay invoices available for this transaction."])]))
(defn get-available-unpaid-invoices [request]
@@ -643,32 +634,24 @@
(if (seq invoice-matches)
[:div
[:h3.text-lg.font-bold.mb-4 "Available Unpaid Invoices"]
[:div.space-y-4
(for [match-group invoice-matches]
[:div.border.border-gray-200.rounded.p-4 {:hx-post (bidi/path-for ssr-routes/only-routes
::route/match-unpaid-invoices)
:hx-trigger "matchUnpaidInvoices"
:hx-include "this"
:hx-params "transaction-id, unpaid-invoice-ids"
[:form {:hx-post (bidi/path-for ssr-routes/only-routes ::route/match-unpaid-invoices)
:hx-trigger "submit"
:hx-target "#modal-holder"
:hx-swap "outerHTML"}
[:div.space-y-3
[:div.text-sm.font-medium "Match with these invoices:"]
(com/hidden {:name "transaction-id"
:form ""
:value (-> request :multi-form-state :snapshot :db/id)})
:value (get-in request [:multi-form-state :snapshot :db/id])
:form ""})
[:div.space-y-2
[:label.block.text-sm.font-medium.mb-1 "Select an unpaid invoice to apply:"]
(for [match-group invoice-matches]
(for [invoice match-group]
[:div.flex.justify-between.items-center.py-2.border-b.border-gray-100
[:div
[:div.font-medium (:invoice/invoice-number invoice)]
[:div.text-sm.text-gray-600 (-> invoice :invoice/vendor :vendor/name)]]
[:div.text-right
[:div.font-medium (format "$%.2f" (:invoice/outstanding-balance invoice))]
(com/hidden {:name "unpaid-invoice-ids" :value (:db/id invoice) :form ""})]])
[:div.flex.justify-end.mt-4
(com/a-button {:color :primary :size :small "@click" "$dispatch('matchUnpaidInvoices')"} "Match")]]])]]
[:div.flex.items-center
[:input {:type :radio :value (:db/id invoice) :name "unpaid-invoice-id"}]
[:div.ml-3
[:span.block.text-sm.font-medium (:invoice/invoice-number invoice)]
[:span.block.text-sm.text-gray-500 (-> invoice :invoice/vendor :vendor/name)]
[:span.block.text-sm.font-medium (format "$%.2f" (:invoice/outstanding-balance invoice))]]]))]
[:button.mt-4.w-full.py-2.bg-blue-500.text-white.rounded.hover:bg-blue-600 "Match"]]]
[:div.text-center.py-4.text-gray-500 "No matching unpaid invoices available for this transaction."])]))
(defn get-available-rules [request]
@@ -685,18 +668,18 @@
:transaction-rule/client :transaction-rule/bank-account
:transaction-rule/yodlee-merchant])
:where
[?r :transaction-rule/description]
]
[?r :transaction-rule/description]]
(dc/db conn))]
(when tx
(->> patterns
(map first)
(filter (fn [rule]
(rm/rule-applies? (-> tx
(update :transaction/date coerce/to-date)
) (-> rule
(update :transaction-rule/description #(some-> % iol-ion.query/->pattern))))))
))))
(update :transaction/date coerce/to-date))
(-> rule
(update :transaction-rule/description #(some-> % iol-ion.query/->pattern))))))))))
(defn transaction-rules-view [request]
(let [matching-rules (get-available-rules request)]
@@ -704,27 +687,22 @@
(if (seq matching-rules)
[:div
[:h3.text-lg.font-bold.mb-4 "Matching Transaction Rules"]
[:div.space-y-2
(for [{:keys [:db/id :transaction-rule/note :transaction-rule/description]} matching-rules]
[:div.py-2.border-b.border-gray-200 {:hx-post (bidi/path-for ssr-routes/only-routes
::route/apply-rule)
:hx-params "transaction-id, rule-id"
:hx-include "this"
:hx-trigger "applyRule"
[:form {:hx-post (bidi/path-for ssr-routes/only-routes ::route/apply-rule)
:hx-trigger "submit"
:hx-target "#modal-holder"
:hx-swap "outerHTML"}
(com/hidden {:name "transaction-id"
:value (get-in request [:multi-form-state :snapshot :db/id])
:form ""})
(com/hidden {:name "rule-id"
:value id
:form ""})
[:div.flex.justify-between.items-center
[:div.space-y-1
[:div.font-medium note]
[:div.text-sm.text-gray-600
(str "Pattern: " description)]]
(com/a-button {:color :primary :size :small "@click" "$dispatch('applyRule')"} "Apply")]])]]
[:div.space-y-2
[:label.block.text-sm.font-medium.mb-1 "Select a rule to apply:"]
(for [{:keys [:db/id :transaction-rule/note :transaction-rule/description]} matching-rules]
[:div.flex.items-center
[:input {:type :radio :value id :name "rule-id"}]
[:div.ml-3
[:span.block.text-sm.font-medium note]
[:span.block.text-sm.text-gray-500 description]]])]
[:button.mt-4.w-full.py-2.bg-blue-500.text-white.rounded.hover:bg-blue-600 "Apply"]]]
[:div.text-center.py-4.text-gray-500 "No matching rules found for this transaction."])]))
(defn payment-info-view [request]
@@ -737,8 +715,8 @@
[:payment/date :xform clj-time.coerce/from-date]
{ [ :payment/status :xform iol-ion.query/ident] [:db/ident]
:payment/vendor [:vendor/name]}
]
:payment/vendor [:vendor/name]}]
(-> tx :transaction/payment :db/id))]
(when payment
[:div.my-4.p-4.bg-blue-50.rounded
@@ -892,6 +870,8 @@
(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"} "Done"))
:validation-route ::route/edit-wizard-navigate)) )
(defrecord EditWizard [_ current-step]
mm/LinearModalWizard
(hydrate-from-request
@@ -1152,12 +1132,12 @@
(solr/touch-with-ledger transaction-id)
(modal-response
(com/success-modal {:title "Rule applied successfully"
}
(com/success-modal {:title "Rule applied successfully"}
[:p.text-gray-600.mt-2 "The selected rule has been applied to this transaction."])
:headers {"hx-trigger" "invalidated"})))
(defn unlink-payment [{{:keys [transaction-id]} :form-params :as request}]
(defn unlink-payment [{{:keys [transaction-id] :as fp} :form-params :as request}]
(let [transaction (dc/pull (dc/db conn)
'[:transaction/approval-status
@@ -1241,6 +1221,25 @@
(mm/wrap-wizard edit-wizard)
(mm/wrap-init-multi-form-state initial-edit-wizard-state))))
(def save-schema
(mc/schema
[:and [:map [:action [:enum :apply-rule :unlink-payment :link-unpaid-invoices :link-autopay-invoices :link-payment]]]
[:multi {:dispatch :action}
[:apply-rule [:map
[:transaction-id entity-id]
[:rule-id entity-id]]]
[:unlink-payment [:map
[:transaction-id entity-id]]]
[:link-unpaid-invoices [:map
[:transaction-id entity-id]
[:unpaid-invoice-ids [:vector {:coerce? true} entity-id]]]]
[:link-autopay-invoices [:map
[:transaction-id entity-id]
[:autopay-invoice-ids [:vector {:coerce? true} entity-id]]]]
[:link-payment [:map
[:transaction-id entity-id]
[:payment-id entity-id]]]]]))
(def key->handler
(apply-middleware-to-all-handlers
{::route/edit-wizard (-> mm/open-wizard-handler
@@ -1279,8 +1278,7 @@
[:maybe entity-id]]]))
::route/match-payment (-> match-payment
(wrap-schema-enforce :form-schema
[:map [:transaction-id entity-id]
[:match-payment-id entity-id]]))
save-schema))
::route/match-autopay-invoices (-> match-autopay-invoices
(wrap-schema-enforce :form-schema
[:map [:transaction-id entity-id]
@@ -1295,7 +1293,10 @@
[:rule-id entity-id]]))
::route/unlink-payment (-> unlink-payment
(wrap-schema-enforce :form-schema
[:map [:transaction-id entity-id]]))}
save-schema))}
(fn [h]
(-> h
(wrap-client-redirect-unauthenticated)))))