Unpay autopays
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -484,7 +484,13 @@
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
::route/unvoid
|
||||
:db/id (:db/id entity))}
|
||||
svg/undo))])
|
||||
svg/undo))
|
||||
(when (and (can? (:identity request) {:subject :invoice :activity :edit})
|
||||
(#{:invoice-status/paid} (:invoice/status entity)))
|
||||
(com/button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
::route/undo-autopay
|
||||
:db/id (:db/id entity))}
|
||||
"Undo payment"))])
|
||||
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
|
||||
"Invoices"]]
|
||||
@@ -650,6 +656,23 @@
|
||||
:headers (cond-> {"hx-retarget" (format "#entity-table tr[data-id=\"%d\"]" id)
|
||||
"hx-reswap" "outerHTML"}))))
|
||||
|
||||
(defn undo-autopay [{:as request :keys [identity entity]}]
|
||||
(let [invoice entity
|
||||
id (:db/id entity)
|
||||
_ (assert-can-see-client identity (:db/id (:invoice/client invoice)))
|
||||
_ (assert-not-locked (:db/id (:invoice/client invoice)) (:invoice/date invoice)) ]
|
||||
(alog/info ::undoing-autopay :transaction :tx)
|
||||
@(dc/transact conn [[:upsert-invoice {:db/id id
|
||||
:invoice/outstanding-balance (:invoice/total entity)
|
||||
:invoice/status :invoice-status/unpaid
|
||||
:invoice/scheduled-payment nil}]])
|
||||
(html-response
|
||||
(row* identity (assoc (dc/pull (dc/db conn) default-read id)
|
||||
:invoice/status :invoice-status/unpaid) {:flash? true
|
||||
:request request})
|
||||
:headers (cond-> {"hx-retarget" (format "#entity-table tr[data-id=\"%d\"]" id)
|
||||
"hx-reswap" "outerHTML"}))))
|
||||
|
||||
(defn delete [{invoice :entity :as request identity :identity}]
|
||||
(exception->notification
|
||||
#(when-not (= :invoice-status/unpaid (:invoice/status invoice))
|
||||
@@ -1289,6 +1312,9 @@
|
||||
::route/legacy-paid-invoices (redirect-handler ::route/paid-page)
|
||||
::route/legacy-voided-invoices (redirect-handler ::route/voided-page)
|
||||
::route/legacy-new-invoice (redirect-handler ::route/new-wizard)
|
||||
::route/undo-autopay (-> undo-autopay
|
||||
(wrap-entity [:route-params :db/id] default-read)
|
||||
(wrap-schema-enforce :route-params [:map [:db/id entity-id]]))
|
||||
::route/unvoid (-> unvoid-invoice
|
||||
(wrap-entity [:route-params :db/id] default-read)
|
||||
(wrap-schema-enforce :route-params [:map [:db/id entity-id]]))
|
||||
|
||||
@@ -23,12 +23,15 @@
|
||||
"/balance" ::expense-account-balance}
|
||||
|
||||
"/pay-button" ::pay-button
|
||||
|
||||
"/pay" {:get ::pay-wizard
|
||||
|
||||
"/navigate" ::pay-wizard-navigate
|
||||
:post ::pay-submit}
|
||||
"/bulk-delete" {:get ::bulk-delete
|
||||
:delete ::bulk-delete-confirm}
|
||||
["/" [#"\d+" :db/id]] {:delete ::delete
|
||||
"/undo-autopay" ::undo-autopay
|
||||
"/unvoid" ::unvoid
|
||||
"/edit" ::edit-wizard}
|
||||
"/table" ::table })
|
||||
|
||||
Reference in New Issue
Block a user