applied feedback
This commit is contained in:
@@ -374,6 +374,8 @@
|
||||
(pay-button* {:ids (selected->ids request
|
||||
(:query-params request))})))
|
||||
|
||||
|
||||
|
||||
;; TODO test as a real user
|
||||
(def grid-page
|
||||
(helper/build {:id "entity-table"
|
||||
@@ -409,11 +411,19 @@
|
||||
:db/id (:db/id entity))
|
||||
:hx-confirm "Are you sure you want to void this invoice?"}
|
||||
svg/trash))
|
||||
(when (can? (:identity request) {:subject :invoice :activity :edit})
|
||||
(when (and (can? (:identity request) {:subject :invoice :activity :edit})
|
||||
(#{:invoice-status/unpaid :invoice-status/paid} (:invoice/status entity)))
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
::route/edit-wizard
|
||||
:db/id (:db/id entity))}
|
||||
svg/pencil))])
|
||||
svg/pencil))
|
||||
(when (and (can? (:identity request) {:subject :invoice :activity :edit})
|
||||
(#{:invoice-status/voided} (:invoice/status entity)))
|
||||
(com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
|
||||
::route/unvoid
|
||||
:db/id (:db/id entity))}
|
||||
svg/undo))])
|
||||
|
||||
:breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
|
||||
"Invoices"]]
|
||||
:title (fn [r]
|
||||
@@ -514,6 +524,39 @@
|
||||
|
||||
(def row* (partial helper/row* grid-page))
|
||||
|
||||
(defn unvoid-invoice [{: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))
|
||||
history (dc/history (dc/db conn))
|
||||
txs (dc/q {:find ['?tx '?e '?original-status '?original-outstanding '?total '?ea '?ea-amount]
|
||||
:where ['[?e :invoice/status :invoice-status/voided ?tx true]
|
||||
'[?e :invoice/status ?original-status ?tx false]
|
||||
'[?e :invoice/outstanding-balance ?original-outstanding ?tx false]
|
||||
'[?e :invoice/total ?total ?tx false]
|
||||
'[?ea :invoice-expense-account/amount ?ea-amount ?tx false]]
|
||||
:in ['$ '?e]}
|
||||
history id)
|
||||
[last-transaction] (->> txs (sort-by first) (last))
|
||||
tx [[:upsert-invoice
|
||||
(->> txs
|
||||
(filter (fn [[tx]] (= tx last-transaction)))
|
||||
(reduce (fn [new-transaction [_ entity original-status original-outstanding total expense-account expense-account-amount]]
|
||||
(-> new-transaction
|
||||
(assoc :db/id entity
|
||||
:invoice/total total
|
||||
:invoice/status original-status
|
||||
:invoice/outstanding-balance original-outstanding)
|
||||
(update :invoice/expense-accounts (fnil conj []) {:db/id expense-account :invoice-expense-account/amount expense-account-amount})))
|
||||
{}))]]
|
||||
_ (audit-transact tx identity)]
|
||||
(alog/info ::unvoiding-invoice :transaction :tx)
|
||||
(html-response
|
||||
(row* identity (dc/pull (dc/db conn) default-read id) {: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
|
||||
@@ -885,7 +928,7 @@
|
||||
(format "Pay in full ($%,.2f)" total)))}
|
||||
{:value "advanced"
|
||||
:content "Customize payments"}]})
|
||||
[:div.space-y-4
|
||||
[:div.space-y-4
|
||||
(fc/with-field :invoices
|
||||
(com/validated-field
|
||||
{:errors (fc/field-errors)}
|
||||
@@ -1141,6 +1184,9 @@
|
||||
(wrap-implied-route-param :status :invoice-status/unpaid))
|
||||
::route/voided-page (-> (helper/page-route grid-page)
|
||||
(wrap-implied-route-param :status :invoice-status/voided))
|
||||
::route/unvoid (-> unvoid-invoice
|
||||
(wrap-entity [:route-params :db/id] default-read)
|
||||
(wrap-schema-enforce :route-params [:map [:db/id entity-id]]))
|
||||
::route/pay-button (-> pay-button
|
||||
(wrap-schema-enforce :query-schema query-schema))
|
||||
::route/delete (-> delete
|
||||
|
||||
Reference in New Issue
Block a user