voiding moves an invoices state back
This commit is contained in:
@@ -34,6 +34,13 @@
|
||||
(first (query (-> base-query
|
||||
(helpers/merge-where [:= :id id])))))
|
||||
|
||||
(defn get-by-check-id [check-id]
|
||||
(query (-> base-query
|
||||
(helpers/merge-where [:= :check-id check-id]))))
|
||||
|
||||
(defn delete! [id]
|
||||
(j/delete! (get-conn) :invoices_checks ["id = ?" id]))
|
||||
|
||||
(defn insert-multi! [rows]
|
||||
(->> (j/insert-multi! (get-conn)
|
||||
:invoices_checks
|
||||
|
||||
@@ -66,9 +66,24 @@
|
||||
|
||||
|
||||
(defn void-check [context {id :check_id} value]
|
||||
(let [check (checks/get-by-id id)]
|
||||
(let [check (checks/get-by-id id)
|
||||
invoices-checks (invoices-checks/get-by-check-id id)]
|
||||
(assert (or (= "pending" (:status check))
|
||||
(#{"cash" "debit"} (:type check))))
|
||||
|
||||
(assert-can-see-company (:id context) (:company-id check))
|
||||
(assert (= "pending" (:status check)))
|
||||
(doseq [ci invoices-checks
|
||||
:let [{:keys [outstanding-balance status] :as invoice invoice-id :id} (invoices/get-by-id (:invoice-id ci))
|
||||
new-balance (+ outstanding-balance (:amount ci))
|
||||
updated-invoice {:id invoice-id
|
||||
:outstanding-balance new-balance
|
||||
:status (if (> new-balance 0)
|
||||
"unpaid"
|
||||
status)}] ]
|
||||
(println updated-invoice)
|
||||
(invoices-checks/delete! (:id ci))
|
||||
(invoices/update updated-invoice))
|
||||
|
||||
(checks/update! {:id id
|
||||
:amount 0
|
||||
:status "voided"})
|
||||
|
||||
@@ -161,7 +161,8 @@
|
||||
[:td (gstring/format "$%.2f" amount )]
|
||||
[:td status]
|
||||
[:td
|
||||
(when (= "pending" status)
|
||||
(when (or (= "pending" status)
|
||||
(#{"cash" "debit"} type))
|
||||
[:button.button.is-warning.is-outlined {:on-click (dispatch-event [::void-check i])} [:span [:span.icon [:i.fa.fa-minus-circle]]]])
|
||||
(if s3-url
|
||||
[:a.tag {:href s3-url :target "_new"} [:i.fa.fa-money-check] [:span.icon [:i.fa.fa-money]] (str " " check-number " (" (gstring/format "$%.2f" amount ) ")")]
|
||||
|
||||
Reference in New Issue
Block a user