applied feedback

This commit is contained in:
2024-04-04 21:18:47 -07:00
parent 543c09118a
commit 7c4e3d52f1
4 changed files with 60 additions and 6 deletions

View File

@@ -397,7 +397,7 @@
{:errors (fc/field-errors) {:errors (fc/field-errors)
:x-hx-val:account-id "accountId" :x-hx-val:account-id "accountId"
:hx-vals (hx/json {:name (fc/field-name) :hx-vals (hx/json {:name (fc/field-name)
:clientId client-id}) :client-id client-id})
:x-dispatch:changed "accountId" :x-dispatch:changed "accountId"
:hx-trigger "changed" :hx-trigger "changed"
:hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select) :hx-get (bidi/path-for ssr-routes/only-routes ::route/location-select)

View File

@@ -374,6 +374,8 @@
(pay-button* {:ids (selected->ids request (pay-button* {:ids (selected->ids request
(:query-params request))}))) (:query-params request))})))
;; TODO test as a real user ;; TODO test as a real user
(def grid-page (def grid-page
(helper/build {:id "entity-table" (helper/build {:id "entity-table"
@@ -409,11 +411,19 @@
:db/id (:db/id entity)) :db/id (:db/id entity))
:hx-confirm "Are you sure you want to void this invoice?"} :hx-confirm "Are you sure you want to void this invoice?"}
svg/trash)) 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 (com/icon-button {:hx-put (bidi/path-for ssr-routes/only-routes
::route/edit-wizard ::route/edit-wizard
:db/id (:db/id entity))} :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)} :breadcrumbs [[:a {:href (bidi/path-for ssr-routes/only-routes ::route/page)}
"Invoices"]] "Invoices"]]
:title (fn [r] :title (fn [r]
@@ -514,6 +524,39 @@
(def row* (partial helper/row* grid-page)) (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}] (defn delete [{invoice :entity :as request identity :identity}]
(exception->notification (exception->notification
@@ -1141,6 +1184,9 @@
(wrap-implied-route-param :status :invoice-status/unpaid)) (wrap-implied-route-param :status :invoice-status/unpaid))
::route/voided-page (-> (helper/page-route grid-page) ::route/voided-page (-> (helper/page-route grid-page)
(wrap-implied-route-param :status :invoice-status/voided)) (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 ::route/pay-button (-> pay-button
(wrap-schema-enforce :query-schema query-schema)) (wrap-schema-enforce :query-schema query-schema))
::route/delete (-> delete ::route/delete (-> delete

View File

@@ -513,3 +513,10 @@
:stroke-linecap "round", :stroke-linecap "round",
:stroke-linejoin "round", :stroke-linejoin "round",
:stroke-width "1"}]]) :stroke-width "1"}]])
(def undo
[:svg {:xmlns "http://www.w3.org/2000/svg", :viewbox "0 0 24 24", :id "Undo--Streamline-Streamline--3.0"}
[:defs]
[:title "undo"]
[:path {:d "m1.5 0.498 0 7 7 0", :fill "none", :stroke "currentcolor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]
[:path {:d "M1.5 7.5a11.656 11.656 0 0 1 16.179 -2.647 11.508 11.508 0 0 1 0.11 18.645", :fill "none", :stroke "currentcolor", :stroke-linecap "round", :stroke-linejoin "round", :stroke-width "1"}]])

View File

@@ -21,6 +21,7 @@
"/bulk-delete" {:get ::bulk-delete "/bulk-delete" {:get ::bulk-delete
:delete ::bulk-delete-confirm} :delete ::bulk-delete-confirm}
["/" [#"\d+" :db/id]] {:delete ::delete ["/" [#"\d+" :db/id]] {:delete ::delete
"/unvoid" ::unvoid
"/edit" ::edit-wizard} "/edit" ::edit-wizard}
"/table" ::table "/table" ::table