Prevents errors from multiple dialogs open

This commit is contained in:
Bryce
2024-03-29 11:14:30 -07:00
parent d34e125b6f
commit a8e1a15393
3 changed files with 22 additions and 28 deletions

View File

@@ -41,8 +41,9 @@
[:input (merge {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes :name (:name params) :value (:value params)} params)] [:input (merge {:id "checkbox-all", :type "checkbox", :class inputs/default-checkbox-classes :name (:name params) :value (:value params)} params)]
[:label {:for "checkbox-all", :class "sr-only"} "checkbox"]]]) [:label {:for "checkbox-all", :class "sr-only"} "checkbox"]]])
(defn data-grid- [{:keys [headers thead-params id]} & rest] (defn data-grid- [{:keys [headers thead-params id] :as params} & rest]
[:table {:class "w-full text-sm text-left text-gray-500 dark:text-gray-400" :id id} [:table (merge {:class "w-full text-sm text-left text-gray-500 dark:text-gray-400"}
(dissoc params :headers :thead-params))
[:thead (assoc thead-params :class "text-xs text-gray-800 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400") [:thead (assoc thead-params :class "text-xs text-gray-800 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400")
(into (into
[:tr] [:tr]

View File

@@ -596,8 +596,6 @@
}) })
[:headers "hx-trigger"] "invalidated"))))) [:headers "hx-trigger"] "invalidated")))))
(def new-wizard (->NewWizard2 nil nil)) (def new-wizard (->NewWizard2 nil nil))

View File

@@ -39,7 +39,7 @@
dissoc-nil-transformer entity-id html-response dissoc-nil-transformer entity-id html-response
main-transformer modal-response money ref->enum-schema main-transformer modal-response money ref->enum-schema
round-money strip wrap-entity wrap-implied-route-param round-money strip wrap-entity wrap-implied-route-param
wrap-merge-prior-hx wrap-schema-enforce]] wrap-merge-prior-hx wrap-schema-enforce form-validation-error assert-schema]]
[auto-ap.time :as atime] [auto-ap.time :as atime]
[auto-ap.utils :refer [by dollars=]] [auto-ap.utils :refer [by dollars=]]
[bidi.bidi :as bidi] [bidi.bidi :as bidi]
@@ -642,8 +642,9 @@
(and (< outstanding-balance 0) (and (< outstanding-balance 0)
(< amount outstanding-balance)) (< amount outstanding-balance))
(and (< outstanding-balance 0) (and (< outstanding-balance 0)
(>= amount 0))))) (>= amount 0))
(and (= outstanding-balance 0.0)
(not= amount 0.0)))))
(def payment-form-schema (def payment-form-schema
(mc/schema (mc/schema
@@ -663,6 +664,7 @@
(map :invoice-id invoices)) (map :invoice-id invoices))
(into {}))] (into {}))]
(every? (fn [%] (every? (fn [%]
(println "TEST" (:amount %) (outstanding-balances (:invoice-id %)))
(not (does-amount-exceed-outstanding? (:amount %) (outstanding-balances (:invoice-id %))))) (not (does-amount-exceed-outstanding? (:amount %) (outstanding-balances (:invoice-id %)))))
invoices)))]]] invoices)))]]]
[:has-warning? :boolean] [:has-warning? :boolean]
@@ -838,7 +840,7 @@
[]) [])
(step-schema [_] (step-schema [_]
(mut/select-keys (mm/form-schema linear-wizard) #{:invoices :check-number :handwritten-date})) (mut/select-keys (mm/form-schema linear-wizard) #{:invoices :check-number :handwritten-date :mode}))
(render-step [this request] (render-step [this request]
(mm/default-render-step (mm/default-render-step
@@ -877,15 +879,16 @@
(format "Pay in full ($%,.2f)" total)))} (format "Pay in full ($%,.2f)" total)))}
{:value "advanced" {:value "advanced"
:content "Customize payments"}]}) :content "Customize payments"}]})
[:div.space-y-4 (hx/alpine-appear {:x-show "mode==\"advanced\""}) [:div.space-y-4
(fc/with-field :invoices (fc/with-field :invoices
(com/validated-field (com/validated-field
{:errors (fc/field-errors)} {:errors (fc/field-errors)}
(com/data-grid (com/data-grid
{:headers [(com/data-grid-header {} "Vendor") (hx/alpine-appear {:headers [(com/data-grid-header {} "Vendor")
(com/data-grid-header {} "Invoice Number") (com/data-grid-header {} "Invoice Number")
(com/data-grid-header {:class "text-right"} "Total") (com/data-grid-header {:class "text-right"} "Total")
(com/data-grid-header {:class "text-right"} "Pay")]} (com/data-grid-header {:class "text-right"} "Pay")]
:x-show "mode==\"advanced\""})
(fc/cursor-map (fc/cursor-map
(fn [i] (fn [i]
(com/data-grid-row (com/data-grid-row
@@ -945,16 +948,6 @@
(doseq [[_ i] (:tempids result)] (doseq [[_ i] (:tempids result)]
(solr/touch-with-ledger i))))) (solr/touch-with-ledger i)))))
;; TODO Payment validations
;; 1. ensure that filtering for selected ids happens again
;; at the end of the modal to prevent race conditions
;; add validation to prevent overpaying
;; Paying a completed invoice is allowed presently
;; Thought is to put it into the pay function itself
;; balance should only go to negative if total was negative
;; balance should stay positive if total was positive
;; NOTE: payable-ids function could be used.
;; TODO support crediting from balance ;; TODO support crediting from balance
(defrecord PayWizard [form-params current-step invoice-by-id] (defrecord PayWizard [form-params current-step invoice-by-id]
mm/LinearModalWizard mm/LinearModalWizard
@@ -1029,14 +1022,16 @@
payment-form-schema payment-form-schema
(:snapshot multi-form-state) (:snapshot multi-form-state)
mt/strip-extra-keys-transformer) mt/strip-extra-keys-transformer)
_ (assert-schema payment-form-schema snapshot)
_ (exception->4xx _ (exception->4xx
#(if (= :handwrite-check (:method snapshot)) #(if (= :handwrite-check (:method snapshot))
(when (or (not (some? (:check-number snapshot))) (when (or (not (some? (:check-number snapshot)))
(= "" (:check-number snapshot))) (= "" (:check-number snapshot)))
(throw (Exception. "Check number is required"))) (throw (Exception. "Check number is required")))
true)) true))
;; TODO just confirm that the outstanding balances haven't been surpassed
;; and that the invoices are still pending
result (exception->4xx result (exception->4xx
#(if (= :handwrite-check (:method snapshot)) #(if (= :handwrite-check (:method snapshot))
(add-handwritten-check request this snapshot) (add-handwritten-check request this snapshot)