Makes it so that voiding cash payments is possible
This commit is contained in:
@@ -508,21 +508,7 @@
|
|||||||
(-> (d-checks/get-by-id id)
|
(-> (d-checks/get-by-id id)
|
||||||
(->graphql))))
|
(->graphql))))
|
||||||
|
|
||||||
(defn void-payments [context args _]
|
(defn void-payments-internal [all-ids id]
|
||||||
(assert-admin (:id context))
|
|
||||||
(let [args (assoc args :id (:id context))
|
|
||||||
ids (some-> args
|
|
||||||
:filters
|
|
||||||
(assoc :id (:id context))
|
|
||||||
(<-graphql)
|
|
||||||
(update :payment-type enum->keyword "payment-type")
|
|
||||||
(update :status enum->keyword "payment-status")
|
|
||||||
(assoc :per-page Integer/MAX_VALUE)
|
|
||||||
d-checks/raw-graphql-ids
|
|
||||||
:ids)
|
|
||||||
specific-ids (d-checks/filter-ids (:ids args))
|
|
||||||
all-ids (into (set ids) specific-ids)]
|
|
||||||
(log/info "Voiding " (count all-ids) args)
|
|
||||||
(transact-with-ledger (->> all-ids
|
(transact-with-ledger (->> all-ids
|
||||||
(d/q '[:find [(pull ?p [:db/id
|
(d/q '[:find [(pull ?p [:db/id
|
||||||
{:invoice-payment/_payment [:invoice-payment/amount
|
{:invoice-payment/_payment [:invoice-payment/amount
|
||||||
@@ -554,7 +540,27 @@
|
|||||||
:invoice/status (if (dollars-0? new-balance)
|
:invoice/status (if (dollars-0? new-balance)
|
||||||
(:invoice/status invoice)
|
(:invoice/status invoice)
|
||||||
:invoice-status/unpaid)}]))))))))
|
:invoice-status/unpaid)}]))))))))
|
||||||
(:id context))
|
id))
|
||||||
|
|
||||||
|
|
||||||
|
(defn void-payments [context args _]
|
||||||
|
(assert-admin (:id context))
|
||||||
|
(let [args (assoc args :id (:id context))
|
||||||
|
ids (some-> args
|
||||||
|
:filters
|
||||||
|
(assoc :id (:id context))
|
||||||
|
(<-graphql)
|
||||||
|
(update :payment-type enum->keyword "payment-type")
|
||||||
|
(update :status enum->keyword "payment-status")
|
||||||
|
(assoc :per-page Integer/MAX_VALUE)
|
||||||
|
d-checks/raw-graphql-ids
|
||||||
|
:ids)
|
||||||
|
specific-ids (d-checks/filter-ids (:ids args))
|
||||||
|
all-ids (into (set ids) specific-ids)]
|
||||||
|
(log/info "Voiding " (count all-ids) args)
|
||||||
|
|
||||||
|
(void-payments-internal all-ids (: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