Makes it so that voiding cash payments is possible

This commit is contained in:
Bryce Covert
2022-12-21 10:59:47 -08:00
parent d36667d0a8
commit 7d0f723ef6
3 changed files with 56 additions and 36 deletions

View File

@@ -267,12 +267,27 @@
(defn void-invoices [context args _]
(let [_ (assert-admin (:id context))
args (assoc args :id (:id context))
all-ids (all-ids-not-locked (get-ids-matching-filters args))]
all-ids (all-ids-not-locked (get-ids-matching-filters args))
voidable-cash-payments (d/q '[:find [?p ...]
:in $ [?i ...]
:where [?ip :invoice-payment/invoice ?i]
[?ip :invoice-payment/payment ?p]
[?p :payment/type :payment-type/cash]
[?i :invoice/client ?c]
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
[?i :invoice/date ?d]
[(>= ?d ?lu)]]
(d/db conn)
all-ids)
]
(log/info "Voiding " (count voidable-cash-payments) "cash payments first")
(gq-checks/void-payments-internal voidable-cash-payments (:id context))
(log/info "Voiding " (count all-ids) args)
(transact-with-ledger
(->> all-ids
(d/q '[:find [(pull ?i [:db/id :invoice/date {:invoice/expense-accounts [:db/id]}]) ...]
(d/q '[:find [(pull ?i [:db/id :invoice/date {:invoice/expense-accounts [:db/id]}
]) ...]
:in $ [?i ...]
:where (not [_ :invoice-payment/invoice ?i])
[?i :invoice/client ?c]