Makes it so that voiding cash payments is possible
This commit is contained in:
@@ -508,6 +508,41 @@
|
|||||||
(-> (d-checks/get-by-id id)
|
(-> (d-checks/get-by-id id)
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
|
(defn void-payments-internal [all-ids id]
|
||||||
|
(transact-with-ledger (->> all-ids
|
||||||
|
(d/q '[:find [(pull ?p [:db/id
|
||||||
|
{:invoice-payment/_payment [:invoice-payment/amount
|
||||||
|
:db/id
|
||||||
|
{:invoice-payment/invoice [:db/id :invoice/outstanding-balance]}]}]) ...]
|
||||||
|
:in $ [?p ...]
|
||||||
|
:where
|
||||||
|
(not [_ :transaction/payment ?p])
|
||||||
|
(not [?p :payment/status :payment-status/voided])
|
||||||
|
[?p :payment/client ?c]
|
||||||
|
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
||||||
|
[?p :payment/date ?d]
|
||||||
|
[(>= ?d ?lu)]
|
||||||
|
]
|
||||||
|
(d/db conn))
|
||||||
|
(mapcat (fn [{:keys [:db/id]
|
||||||
|
invoices :invoice-payment/_payment}]
|
||||||
|
(into
|
||||||
|
[{:db/id id
|
||||||
|
:payment/amount 0.0
|
||||||
|
:payment/status :payment-status/voided}]
|
||||||
|
(->> invoices
|
||||||
|
(mapcat (fn [{:keys [:invoice-payment/invoice :db/id :invoice-payment/amount]}]
|
||||||
|
(let [new-balance (+ (:invoice/outstanding-balance invoice)
|
||||||
|
amount)]
|
||||||
|
[[:db.fn/retractEntity id]
|
||||||
|
{:db/id (:db/id invoice)
|
||||||
|
:invoice/outstanding-balance new-balance
|
||||||
|
:invoice/status (if (dollars-0? new-balance)
|
||||||
|
(:invoice/status invoice)
|
||||||
|
:invoice-status/unpaid)}]))))))))
|
||||||
|
id))
|
||||||
|
|
||||||
|
|
||||||
(defn void-payments [context args _]
|
(defn void-payments [context args _]
|
||||||
(assert-admin (:id context))
|
(assert-admin (:id context))
|
||||||
(let [args (assoc args :id (:id context))
|
(let [args (assoc args :id (:id context))
|
||||||
@@ -523,38 +558,9 @@
|
|||||||
specific-ids (d-checks/filter-ids (:ids args))
|
specific-ids (d-checks/filter-ids (:ids args))
|
||||||
all-ids (into (set ids) specific-ids)]
|
all-ids (into (set ids) specific-ids)]
|
||||||
(log/info "Voiding " (count all-ids) args)
|
(log/info "Voiding " (count all-ids) args)
|
||||||
(transact-with-ledger (->> all-ids
|
|
||||||
(d/q '[:find [(pull ?p [:db/id
|
(void-payments-internal all-ids (:id context))
|
||||||
{:invoice-payment/_payment [:invoice-payment/amount
|
|
||||||
:db/id
|
|
||||||
{:invoice-payment/invoice [:db/id :invoice/outstanding-balance]}]}]) ...]
|
|
||||||
:in $ [?p ...]
|
|
||||||
:where
|
|
||||||
(not [_ :transaction/payment ?p])
|
|
||||||
(not [?p :payment/status :payment-status/voided])
|
|
||||||
[?p :payment/client ?c]
|
|
||||||
[(get-else $ ?c :client/locked-until #inst "2000-01-01") ?lu]
|
|
||||||
[?p :payment/date ?d]
|
|
||||||
[(>= ?d ?lu)]
|
|
||||||
]
|
|
||||||
(d/db conn))
|
|
||||||
(mapcat (fn [{:keys [:db/id]
|
|
||||||
invoices :invoice-payment/_payment}]
|
|
||||||
(into
|
|
||||||
[{:db/id id
|
|
||||||
:payment/amount 0.0
|
|
||||||
:payment/status :payment-status/voided}]
|
|
||||||
(->> invoices
|
|
||||||
(mapcat (fn [{:keys [:invoice-payment/invoice :db/id :invoice-payment/amount]}]
|
|
||||||
(let [new-balance (+ (:invoice/outstanding-balance invoice)
|
|
||||||
amount)]
|
|
||||||
[[:db.fn/retractEntity id]
|
|
||||||
{:db/id (:db/id invoice)
|
|
||||||
:invoice/outstanding-balance new-balance
|
|
||||||
:invoice/status (if (dollars-0? new-balance)
|
|
||||||
(:invoice/status invoice)
|
|
||||||
:invoice-status/unpaid)}]))))))))
|
|
||||||
(:id context))
|
|
||||||
{:message (str "Succesfully voided " (count all-ids))}))
|
{:message (str "Succesfully voided " (count all-ids))}))
|
||||||
|
|
||||||
(defn get-all-payments [context args _]
|
(defn get-all-payments [context args _]
|
||||||
|
|||||||
@@ -267,12 +267,27 @@
|
|||||||
(defn void-invoices [context args _]
|
(defn void-invoices [context args _]
|
||||||
(let [_ (assert-admin (:id context))
|
(let [_ (assert-admin (:id context))
|
||||||
args (assoc args :id (: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)
|
(log/info "Voiding " (count all-ids) args)
|
||||||
(transact-with-ledger
|
(transact-with-ledger
|
||||||
(->> all-ids
|
(->> 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 ...]
|
:in $ [?i ...]
|
||||||
:where (not [_ :invoice-payment/invoice ?i])
|
:where (not [_ :invoice-payment/invoice ?i])
|
||||||
[?i :invoice/client ?c]
|
[?i :invoice/client ?c]
|
||||||
|
|||||||
@@ -218,8 +218,7 @@
|
|||||||
{:keys [total]} @(re-frame/subscribe [::data-page/data :invoices])
|
{:keys [total]} @(re-frame/subscribe [::data-page/data :invoices])
|
||||||
]
|
]
|
||||||
[:div.buttons
|
[:div.buttons
|
||||||
(when (and (= :unpaid status)
|
(when is-admin?
|
||||||
is-admin?)
|
|
||||||
[void-selected-button])
|
[void-selected-button])
|
||||||
|
|
||||||
[buttons/new-button {:event [::new-invoice-clicked]
|
[buttons/new-button {:event [::new-invoice-clicked]
|
||||||
|
|||||||
Reference in New Issue
Block a user