Transactions get unlinked when voided
This commit is contained in:
@@ -232,3 +232,4 @@
|
|||||||
|
|
||||||
(def page (helper/page-route grid-page))
|
(def page (helper/page-route grid-page))
|
||||||
(def table (helper/table-route grid-page))
|
(def table (helper/table-route grid-page))
|
||||||
|
|
||||||
|
|||||||
@@ -462,7 +462,7 @@
|
|||||||
#(assert-can-see-client identity (:db/id (:payment/client check))))
|
#(assert-can-see-client identity (:db/id (:payment/client check))))
|
||||||
(notify-if-locked (:db/id (:payment/client check))
|
(notify-if-locked (:db/id (:payment/client check))
|
||||||
(:payment/date check))
|
(:payment/date check))
|
||||||
(let [removing-payments (mapcat (fn [x]
|
(let [ removing-payments (mapcat (fn [x]
|
||||||
(let [invoice (:invoice-payment/invoice x)
|
(let [invoice (:invoice-payment/invoice x)
|
||||||
new-balance (+ (:invoice/outstanding-balance invoice)
|
new-balance (+ (:invoice/outstanding-balance invoice)
|
||||||
(:invoice-payment/amount x))]
|
(:invoice-payment/amount x))]
|
||||||
@@ -476,7 +476,11 @@
|
|||||||
updated-payment {:db/id (:db/id check)
|
updated-payment {:db/id (:db/id check)
|
||||||
:payment/amount 0.0
|
:payment/amount 0.0
|
||||||
:payment/status :payment-status/voided}]
|
:payment/status :payment-status/voided}]
|
||||||
(audit-transact (conj removing-payments updated-payment)
|
(audit-transact (cond-> removing-payments
|
||||||
|
true (conj updated-payment)
|
||||||
|
(:transaction/_payment check) (conj [:db/retract (:db/id (first (:transaction/_payment check)))
|
||||||
|
:transaction/payment
|
||||||
|
(:db/id check)]))
|
||||||
identity)
|
identity)
|
||||||
|
|
||||||
(html-response (row* (:identity request) updated-payment {:delete-after-settle? true :class "live-removed"
|
(html-response (row* (:identity request) updated-payment {:delete-after-settle? true :class "live-removed"
|
||||||
@@ -536,24 +540,33 @@
|
|||||||
[?p :payment/date ?d]
|
[?p :payment/date ?d]
|
||||||
[(>= ?d ?lu)]]
|
[(>= ?d ?lu)]]
|
||||||
(dc/db conn))
|
(dc/db conn))
|
||||||
(map first))]
|
(map first))
|
||||||
|
transactions-to-unlink (->> payments-to-update
|
||||||
|
(dc/q '[:find ?p ?t
|
||||||
|
:in $ [?p ...]
|
||||||
|
:where [?t :transaction/payment ?p]]
|
||||||
|
(dc/db conn)))]
|
||||||
(audit-transact (->> payments-to-update
|
(audit-transact (->> payments-to-update
|
||||||
(mapcat (fn [{:keys [:db/id]
|
(mapcat (fn [{:keys [:db/id]
|
||||||
invoices :invoice-payment/_payment}]
|
invoices :invoice-payment/_payment}]
|
||||||
(into
|
(-> [{:db/id id
|
||||||
[{:db/id id
|
:payment/amount 0.0
|
||||||
:payment/amount 0.0
|
:payment/status :payment-status/voided}]
|
||||||
:payment/status :payment-status/voided}]
|
;; TODO this doesn't do anything because payments with invoices are filtered out
|
||||||
(->> invoices
|
(into (->> transactions-to-unlink
|
||||||
(mapcat (fn [{:keys [:invoice-payment/invoice :db/id :invoice-payment/amount]}]
|
(map (fn [[p t]]
|
||||||
(let [new-balance (+ (:invoice/outstanding-balance invoice)
|
[:db/retract t :transaction/payment p]))))
|
||||||
amount)]
|
(into
|
||||||
[[:db.fn/retractEntity id]
|
(->> invoices
|
||||||
[:upsert-invoice {:db/id (:db/id invoice)
|
(mapcat (fn [{:keys [:invoice-payment/invoice :db/id :invoice-payment/amount]}]
|
||||||
:invoice/outstanding-balance new-balance
|
(let [new-balance (+ (:invoice/outstanding-balance invoice)
|
||||||
:invoice/status (if (dollars-0? new-balance)
|
amount)]
|
||||||
(:invoice/status invoice)
|
[[:db.fn/retractEntity id]
|
||||||
:invoice-status/unpaid)}]]))))))))
|
[:upsert-invoice {:db/id (:db/id invoice)
|
||||||
|
:invoice/outstanding-balance new-balance
|
||||||
|
:invoice/status (if (dollars-0? new-balance)
|
||||||
|
(:invoice/status invoice)
|
||||||
|
:invoice-status/unpaid)}]])))))))))
|
||||||
id)
|
id)
|
||||||
(count payments-to-update)))
|
(count payments-to-update)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user