enforce locked until for payments
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
:as u
|
||||
:refer [<-graphql
|
||||
assert-admin
|
||||
assert-not-locked
|
||||
assert-can-see-client
|
||||
assert-power-user
|
||||
assert-failure
|
||||
@@ -149,11 +150,8 @@
|
||||
(when-not (dollars= total expense-account-total)
|
||||
(let [error (str "Expense account total (" expense-account-total ") does not equal invoice total (" total ")")]
|
||||
(throw (ex-info error {:validation-error error}))))))
|
||||
(defn assert-not-locked [client-id date]
|
||||
(let [{:client/keys [locked-until]} (d/pull (d/db conn) [:client/locked-until] client-id)]
|
||||
(when (and locked-until
|
||||
(>= (compare locked-until (coerce/to-date date)) 0))
|
||||
(assert-failure (str "Integreat has locked finances prior to " (-> locked-until coerce/to-date-time (atime/unparse-local atime/normal-date)) ".")))))
|
||||
|
||||
|
||||
|
||||
(defn add-invoice [context {{:keys [expense_accounts client_id] :as in} :invoice} _]
|
||||
(assert-no-conflicting in)
|
||||
@@ -252,11 +250,14 @@
|
||||
(log/info "Voiding " (count all-ids) args)
|
||||
(audit-transact
|
||||
(->> all-ids
|
||||
(d/q '[:find [(pull ?i [:db/id {: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])]
|
||||
(d/db conn)
|
||||
)
|
||||
:where (not [_ :invoice-payment/invoice ?i])
|
||||
[?i :invoice/client ?c]
|
||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||
[?i :invoice/date ?d]
|
||||
[(>= ?d ?lu)]]
|
||||
(d/db conn))
|
||||
(mapcat
|
||||
(fn [i]
|
||||
(into
|
||||
|
||||
Reference in New Issue
Block a user