From 2fb49d3331e799e8013c1a958320768334e5dea0 Mon Sep 17 00:00:00 2001 From: Bryce Date: Thu, 11 Apr 2024 11:42:44 -0700 Subject: [PATCH] QOL items --- .../auto_ap/ssr/components/link_dropdown.clj | 2 +- src/clj/auto_ap/ssr/components/tags.clj | 7 ++- .../ssr/invoice/new_invoice_wizard.clj | 53 +++++++++++++++---- src/cljc/auto_ap/routes/invoice.cljc | 3 +- 4 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/clj/auto_ap/ssr/components/link_dropdown.clj b/src/clj/auto_ap/ssr/components/link_dropdown.clj index a4ad3d96..43a63f1c 100644 --- a/src/clj/auto_ap/ssr/components/link_dropdown.clj +++ b/src/clj/auto_ap/ssr/components/link_dropdown.clj @@ -14,7 +14,7 @@ (com/a-icon-button {:x-ref "link" "@click.prevent" "show=!show; $nextTick(() => popper.update());" :class "relative"} svg/paperclip - (com/badge {} (count links))) + (com/badge {:color "blue"} (count links))) [:div.divide-y.divide-gray-200.bg-white.rounded-lg.shadow.z-50 (hx/alpine-appear {:x-ref "tooltip" :x-show "show" :data-key "show"}) [:div {:class "p-3 overflow-y-auto text-sm text-gray-700 dark:text-gray-200"} [:div.flex.flex-col.gap-y-2 diff --git a/src/clj/auto_ap/ssr/components/tags.clj b/src/clj/auto_ap/ssr/components/tags.clj index da9ceba5..76bc4e7c 100644 --- a/src/clj/auto_ap/ssr/components/tags.clj +++ b/src/clj/auto_ap/ssr/components/tags.clj @@ -21,4 +21,9 @@ children)) (defn badge- [params & children] - [:div {:class (hh/add-class "absolute inline-flex items-center justify-center w-6 h-6 text-xs font-black text-white bg-red-300 border-3 border-white rounded-full -top-2 -right-2 dark:border-gray-900" (:class params))} children]) + [:div {:class (-> (hh/add-class "absolute inline-flex items-center justify-center w-6 h-6 text-xs font-black text-white + border-3 border-white rounded-full -top-2 -right-2 dark:border-gray-900" + (:class params) + ) + (hh/add-class (or (some-> (:color params) (#(str "bg-" % "-300"))) + "bg-red-300")))} children]) diff --git a/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj b/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj index 1cf681b6..e07a4994 100644 --- a/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj +++ b/src/clj/auto_ap/ssr/invoice/new_invoice_wizard.clj @@ -430,17 +430,36 @@ (com/a-icon-button {"@click.prevent.stop" "show=false; setTimeout(() => $refs.p.remove(), 500)"} svg/x)))) (defn invoice-expense-account-total* [request] - (format "$%,.2f" (->> (-> request - :multi-form-state - :step-params - :invoice/expense-accounts) - (map (fnil :invoice-expense-account/amount 0.0)) - (filter number?) - (reduce + 0.0)))) + (let [total (->> (-> request + :multi-form-state + :step-params + :invoice/expense-accounts) + (map (fnil :invoice-expense-account/amount 0.0)) + (filter number?) + (reduce + 0.0))] + (format "$%,.2f" total))) + +(defn invoice-expense-account-balance* [request] + (let [total (->> (-> request + :multi-form-state + :step-params + :invoice/expense-accounts) + (map (fnil :invoice-expense-account/amount 0.0)) + (filter number?) + (reduce + 0.0)) + balance (- + (-> request :multi-form-state :snapshot :invoice/total) + total)] + [:span {:class (when-not (dollars= 0.0 balance) + "text-red-300")} + (format "$%,.2f" balance)])) (defn invoice-expense-account-total [request] (html-response (invoice-expense-account-total* request))) +(defn invoice-expense-account-balance [request] + (html-response (invoice-expense-account-balance* request))) + (defrecord AccountsStep [linear-wizard] mm/ModalWizardStep (step-name [_] @@ -490,6 +509,19 @@ :hx-swap "innerHTML"} (invoice-expense-account-total* request)) (com/data-grid-cell {})) + + (com/data-grid-row {} + (com/data-grid-cell {}) + (com/data-grid-cell {:class "text-right"} [:span.font-bold.text-right "BALANCE"]) + (com/data-grid-cell {:id "total" + :class "text-right" + :hx-trigger "change from:closest form target:.amount-field" + :hx-put (bidi.bidi/path-for ssr-routes/only-routes ::route/expense-account-balance) + :hx-target "this" + :hx-swap "innerHTML"} + (invoice-expense-account-balance* request)) + (com/data-grid-cell {})) + (com/data-grid-row {} (com/data-grid-cell {}) @@ -601,12 +633,12 @@ (when (seq eas) (let [leftover (- invoice-total (reduce + 0 (map :invoice-expense-account/amount eas))) leftover-beyond-a-single-cent? (or (< leftover -1) - (> leftover 1)) + (> leftover 1)) leftover (if leftover-beyond-a-single-cent? 0 leftover) [first-eas & rest] eas] - (cons + (cons (update first-eas :invoice-expense-account/amount #(+ % leftover)) rest)))) @@ -822,6 +854,9 @@ ::route/expense-account-total (-> invoice-expense-account-total (mm/wrap-wizard new-wizard) (mm/wrap-decode-multi-form-state)) + ::route/expense-account-balance (-> invoice-expense-account-balance + (mm/wrap-wizard new-wizard) + (mm/wrap-decode-multi-form-state)) ::route/location-select (-> location-select (wrap-schema-enforce :query-schema [:map [:name :string] diff --git a/src/cljc/auto_ap/routes/invoice.cljc b/src/cljc/auto_ap/routes/invoice.cljc index b6b19552..b1b0d6d2 100644 --- a/src/cljc/auto_ap/routes/invoice.cljc +++ b/src/cljc/auto_ap/routes/invoice.cljc @@ -12,7 +12,8 @@ "/account/new" ::new-wizard-new-account "/account/location-select" ::location-select "/account/prediction" ::account-prediction - "/total" ::expense-account-total} + "/total" ::expense-account-total + "/balance" ::expense-account-balance} "/pay-button" ::pay-button "/pay" {:get ::pay-wizard