Check matching
This commit is contained in:
@@ -527,6 +527,11 @@
|
||||
:edit_transaction {:type :transaction
|
||||
:args {:transaction {:type :edit_transaction}}
|
||||
:resolve :mutation/edit-transaction}
|
||||
|
||||
:match_transaction {:type :transaction
|
||||
:args {:transaction_id {:type :id}
|
||||
:payment_id {:type :id}}
|
||||
:resolve :mutation/match-transaction}
|
||||
:void_invoice {:type :invoice
|
||||
:args {:invoice_id {:type :id}}
|
||||
:resolve :mutation/void-invoice}
|
||||
@@ -580,18 +585,11 @@
|
||||
m))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
(defn get-all-payments [context args value]
|
||||
(assert-admin (:id context))
|
||||
(map
|
||||
->graphql
|
||||
(d-checks/get-graphql (assoc (<-graphql args)
|
||||
:count Integer/MAX_VALUE))))
|
||||
|
||||
|
||||
(d-checks/get-graphql (assoc (<-graphql args) :count Integer/MAX_VALUE))))
|
||||
|
||||
|
||||
(defn get-user [context args value]
|
||||
@@ -699,6 +697,7 @@
|
||||
:mutation/add-and-print-invoice gq-invoices/add-and-print-invoice
|
||||
:mutation/edit-invoice gq-invoices/edit-invoice
|
||||
:mutation/edit-transaction gq-transactions/edit-transaction
|
||||
:mutation/match-transaction gq-transactions/match-transaction
|
||||
:mutation/edit-client gq-clients/edit-client
|
||||
:mutation/upsert-vendor gq-vendors/upsert-vendor
|
||||
:mutation/upsert-account gq-accounts/upsert-account
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [uri remove-nils]]
|
||||
[com.walmartlabs.lacinia :refer [execute]]
|
||||
@@ -11,7 +12,8 @@
|
||||
[auto-ap.time :refer [parse normal-date]]
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]))
|
||||
[clojure.string :as str]
|
||||
[auto-ap.datomic.accounts :as a]))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -42,6 +44,7 @@
|
||||
|
||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id] :as transaction} :transaction} value]
|
||||
(let [existing-transaction (d-transactions/get-by-id id)
|
||||
_ (assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
account-total (reduce + 0 (map (fn [x] (Double/parseDouble (:amount x))) accounts))
|
||||
missing-locations (seq (set/difference
|
||||
@@ -53,7 +56,7 @@
|
||||
set
|
||||
(conj "A")
|
||||
(conj "HQ"))))]
|
||||
(assert-can-see-client (:id context) (:transaction/client existing-transaction) )
|
||||
|
||||
(when-not (dollars= (Math/abs (:transaction/amount existing-transaction)) account-total)
|
||||
(let [error (str "Expense account total (" account-total ") does not equal transaction total (" (Math/abs (:transaction/amount existing-transaction)) ")")]
|
||||
(throw (ex-info error {:validation-error error}))))
|
||||
@@ -70,3 +73,31 @@
|
||||
[:db/retract id :transaction/accounts d])
|
||||
deleted)))
|
||||
(->graphql (d-transactions/get-by-id id))))
|
||||
|
||||
(defn match-transaction [context {:keys [transaction_id payment_id]} value]
|
||||
(let [transaction (d-transactions/get-by-id transaction_id)
|
||||
payment (d-checks/get-by-id payment_id)
|
||||
_ (assert-can-see-client (:id context) (:transaction/client transaction) )
|
||||
_ (assert-can-see-client (:id context) (:payment/client payment) )]
|
||||
(when (not= (:db/id (:transaction/client transaction))
|
||||
(:db/id (:payment/client payment)))
|
||||
(throw (ex-info "Clients don't match" {:validation-error "Payment and client do not match."})))
|
||||
|
||||
(when-not (dollars= (- (:transaction/amount transaction))
|
||||
(:payment/amount payment))
|
||||
(throw (ex-info "Amounts don't match" {:validation-error "Amounts don't match"})))
|
||||
(d/transact (d/connect uri)
|
||||
(into
|
||||
[{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/cleared}
|
||||
|
||||
{:db/id (:db/id transaction)
|
||||
:transaction/payment (:db/id payment)
|
||||
:transaction/vendor (:db/id (:payment/vendor payment))
|
||||
:transaction/location "A"
|
||||
:transaction/accounts [{:transaction-account/account (:db/id (a/get-account-by-numeric-code-and-sets 2110 ["default"]))
|
||||
:transaction-account/location "A"
|
||||
:transaction-account/amount (Math/abs (:transaction/amount transaction))}]}]
|
||||
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||
(:transaction/accounts transaction)))))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
|
||||
Reference in New Issue
Block a user