allows manually matching rules.
This commit is contained in:
@@ -7,7 +7,10 @@
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str])
|
||||
[clojure.string :as str]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[clj-time.coerce :as coerce])
|
||||
(:import [java.time.temporal ChronoField]))
|
||||
|
||||
(defn ident->enum-f [k]
|
||||
@@ -21,6 +24,13 @@
|
||||
(map (ident->enum-f :transaction-rule/transaction-approval-status)))
|
||||
journal-entries-count :transaction_rules args)))
|
||||
|
||||
(defn get-transaction-rule-matches [context args value]
|
||||
(if (= "admin" (:user/role (:id context)))
|
||||
(let [all-rules (tr/get-all)
|
||||
transaction (update (d-transactions/get-by-id (:transaction_id args)) :transaction/date coerce/to-date)]
|
||||
(map ->graphql (rm/get-matching-rules transaction all-rules)))
|
||||
nil))
|
||||
|
||||
(defn deleted-accounts [transaction accounts]
|
||||
(let [current-accounts (:transaction-rule/accounts transaction)
|
||||
specified-ids (->> accounts
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
@@ -13,7 +13,10 @@
|
||||
[auto-ap.datomic.clients :as d-clients]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
[auto-ap.datomic.accounts :as a]))
|
||||
[auto-ap.datomic.accounts :as a]
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[clj-time.coerce :as coerce]))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -86,7 +89,7 @@
|
||||
(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)
|
||||
@(d/transact (d/connect uri)
|
||||
(into
|
||||
[{:db/id (:db/id payment)
|
||||
:payment/status :payment-status/cleared}
|
||||
@@ -101,3 +104,22 @@
|
||||
(map (fn [x] [:db/retractEntity (:db/id x)] )
|
||||
(:transaction/accounts transaction)))))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
|
||||
(defn match-transaction-rule [context {:keys [transaction_id transaction_rule_id]} value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
transaction (update (d-transactions/get-by-id transaction_id) :transaction/date coerce/to-date)
|
||||
transaction-rule (update (tr/get-by-id transaction_rule_id) :transaction-rule/description #(some-> % re-pattern))]
|
||||
(when (not (rm/rule-applies? transaction transaction-rule))
|
||||
(throw (ex-info "Transaction rule does not apply" {:validation-error "Transaction rule does not apply"})))
|
||||
|
||||
(when (:transaction/payment transaction)
|
||||
(throw (ex-info "Transaction already associated with a payment" {:validation-error "Transaction already associated with a payment"})))
|
||||
|
||||
@(d/transact (d/connect uri)
|
||||
[(rm/apply-rule {:db/id (:db/id transaction)
|
||||
:transaction/amount (:transaction/amount transaction)}
|
||||
transaction-rule
|
||||
|
||||
;; TODO use bank account locations as well
|
||||
(-> transaction :transaction/client :client/locations))]))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
|
||||
Reference in New Issue
Block a user