allowing users to self service delete links to payments.
This commit is contained in:
@@ -911,6 +911,10 @@
|
|||||||
:all {:type 'Boolean}
|
:all {:type 'Boolean}
|
||||||
:transaction_rule_id {:type :id}}
|
:transaction_rule_id {:type :id}}
|
||||||
:resolve :mutation/match-transaction-rules}
|
:resolve :mutation/match-transaction-rules}
|
||||||
|
|
||||||
|
:unlink_transaction {:type :transaction
|
||||||
|
:args {:transaction_id {:type :id}}
|
||||||
|
:resolve :mutation/unlink-transaction}
|
||||||
:void_invoice {:type :invoice
|
:void_invoice {:type :invoice
|
||||||
:args {:invoice_id {:type :id}}
|
:args {:invoice_id {:type :id}}
|
||||||
:resolve :mutation/void-invoice}
|
:resolve :mutation/void-invoice}
|
||||||
@@ -1183,6 +1187,7 @@
|
|||||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||||
|
:mutation/unlink-transaction gq-transactions/unlink-transaction
|
||||||
:mutation/unapprove-transactions gq-transactions/unapprove-transactions
|
:mutation/unapprove-transactions gq-transactions/unapprove-transactions
|
||||||
:mutation/delete-external-ledger gq-ledger/delete-external-ledger
|
:mutation/delete-external-ledger gq-ledger/delete-external-ledger
|
||||||
:mutation/delete-transactions gq-transactions/delete-transactions
|
:mutation/delete-transactions gq-transactions/delete-transactions
|
||||||
|
|||||||
@@ -80,6 +80,43 @@
|
|||||||
(:id context))
|
(:id context))
|
||||||
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
|
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
|
||||||
|
|
||||||
|
(defn unlink-transaction [context args value]
|
||||||
|
(let [_ (assert-admin (:id context))
|
||||||
|
args (assoc args :id (:id context))
|
||||||
|
transaction-id (:transaction_id args)
|
||||||
|
transaction (d/pull (d/db conn)
|
||||||
|
[:transaction/approval-status
|
||||||
|
:transaction/status
|
||||||
|
:transaction/location
|
||||||
|
:transaction/vendor
|
||||||
|
:transaction/accounts
|
||||||
|
|
||||||
|
{:transaction/payment [{:payment/status [:db/ident]} :db/id]} ]
|
||||||
|
transaction-id)
|
||||||
|
payment (-> transaction :transaction/payment )
|
||||||
|
]
|
||||||
|
|
||||||
|
(log/info "Unlinking " transaction-id " from payment " payment)
|
||||||
|
(when (not= :payment-status/cleared (-> payment :payment/status :db/ident))
|
||||||
|
(throw (ex-info "Payment can't be undone because it isn't cleared." {:validation-error "Payment can't be undone because it isn't cleared."})))
|
||||||
|
(audit-transact
|
||||||
|
(into [{:db/id (:db/id payment)
|
||||||
|
:payment/status :payment-status/pending}
|
||||||
|
{:db/id transaction-id
|
||||||
|
:transaction/approval-status :transaction-approval-status/unapproved}
|
||||||
|
[:db/retract transaction-id :transaction/payment (:db/id payment)]
|
||||||
|
[:db/retract transaction-id :transaction/vendor (:db/id (:transaction/vendor transaction))]
|
||||||
|
[:db/retract transaction-id :transaction/location (:transaction/location transaction)]]
|
||||||
|
|
||||||
|
(map (fn [a]
|
||||||
|
[:db/retract transaction-id :transaction/accounts (:db/id a)])
|
||||||
|
(:transaction/accounts transaction)))
|
||||||
|
(:id context))
|
||||||
|
(-> (d-transactions/get-by-id transaction-id)
|
||||||
|
approval-status->graphql
|
||||||
|
->graphql)))
|
||||||
|
|
||||||
|
|
||||||
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
(defn transaction-account->entity [{:keys [id account_id amount location]}]
|
||||||
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
(remove-nils #:transaction-account {:amount (Double/parseDouble amount)
|
||||||
:db/id id
|
:db/id id
|
||||||
|
|||||||
@@ -122,6 +122,21 @@
|
|||||||
[::edited (first (:match-transaction-rules result))])
|
[::edited (first (:match-transaction-rules result))])
|
||||||
:on-error [::forms/save-error ::form]}}))
|
:on-error [::forms/save-error ::form]}}))
|
||||||
|
|
||||||
|
(re-frame/reg-event-fx
|
||||||
|
::unlink
|
||||||
|
[with-user (forms/triggers-loading ::form) (forms/in-form ::form)]
|
||||||
|
(fn [{{{:keys [id]} :data} :db user :user} [_]]
|
||||||
|
{:graphql
|
||||||
|
{:token user
|
||||||
|
:query-obj {:venia/operation {:operation/type :mutation
|
||||||
|
:operation/name "UnlinkTransaction"}
|
||||||
|
:venia/queries [{:query/data [:unlink-transaction
|
||||||
|
{:transaction-id id}
|
||||||
|
transaction-read]}]}
|
||||||
|
:on-success (fn [result]
|
||||||
|
[::edited (:unlink-transaction result)])
|
||||||
|
:on-error [::forms/save-error ::form]}}))
|
||||||
|
|
||||||
(re-frame/reg-event-fx
|
(re-frame/reg-event-fx
|
||||||
::edited
|
::edited
|
||||||
[(forms/triggers-stop ::form)]
|
[(forms/triggers-stop ::form)]
|
||||||
@@ -274,6 +289,12 @@
|
|||||||
:type "typeahead-entity"
|
:type "typeahead-entity"
|
||||||
:field [:forecast-match]}])
|
:field [:forecast-match]}])
|
||||||
|
|
||||||
|
(when (and (:payment data)
|
||||||
|
is-admin?)
|
||||||
|
[:p.notification.is-info.is-light>div.level>div.level-left
|
||||||
|
[:div.level-item "This transaction is linked to a payment "]
|
||||||
|
[:div.level-item [:button.button.is-warning {:on-click (dispatch-event [::unlink])} "Unlink"]]])
|
||||||
|
|
||||||
|
|
||||||
(error-notification)
|
(error-notification)
|
||||||
(when-not should-disable-for-client?
|
(when-not should-disable-for-client?
|
||||||
|
|||||||
Reference in New Issue
Block a user