supports adding conclusions.
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils uri merge-query]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page]]
|
||||
[clj-time.coerce :as c])
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :as set])
|
||||
(:import [java.time.temporal ChronoField]))
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
@@ -12,9 +13,27 @@
|
||||
[journal-entries journal-entries-count] (tr/get-graphql (<-graphql args))]
|
||||
(result->page journal-entries journal-entries-count :transaction_rules args)))
|
||||
|
||||
(defn deleted-accounts [transaction accounts]
|
||||
(let [current-accounts (:transaction-rule/accounts transaction)
|
||||
specified-ids (->> accounts
|
||||
(map :id)
|
||||
set)
|
||||
existing-ids (->> current-accounts
|
||||
(map :db/id)
|
||||
set)]
|
||||
(set/difference existing-ids specified-ids)))
|
||||
|
||||
(defn transaction-rule-account->entity [{:keys [id account_id percentage location]}]
|
||||
(remove-nils #:transaction-rule-account {:percentage percentage
|
||||
:db/id id
|
||||
:account account_id
|
||||
:location location}))
|
||||
;; TODO ASSERT ADMIN
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte ]} :transaction_rule :as z} value]
|
||||
(let [transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||
(defn upsert-transaction-rule [context {{:keys [id description note client_id bank_account_id amount_lte amount_gte vendor_id accounts ]} :transaction_rule :as z} value]
|
||||
#_(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
transaction [(remove-nils #:transaction-rule {:db/id (if id
|
||||
id
|
||||
"transaction-rule")
|
||||
:description description
|
||||
@@ -22,8 +41,14 @@
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte})]
|
||||
_ (println transaction)
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
:accounts (map transaction-rule-account->entity accounts)})]
|
||||
|
||||
transaction (into transaction
|
||||
(map (fn [d]
|
||||
[:db/retract id :transaction-rule/accounts d])
|
||||
deleted))
|
||||
transaction-result @(d/transact (d/connect uri) transaction)]
|
||||
(-> (tr/get-by-id (or (-> transaction-result :tempids (get "transaction-rule"))
|
||||
id))
|
||||
@@ -33,7 +58,6 @@
|
||||
(re-find (re-pattern z) x))
|
||||
|
||||
(defn test-transaction-rule [{:keys [id]} {{:keys [description note client_id bank_account_id amount_lte amount_gte dom_lte dom_gte]} :transaction_rule :as z} value]
|
||||
(prn z)
|
||||
(->>
|
||||
(d/query
|
||||
(cond-> {:query {:find ['(pull ?e [* {:transaction/client [:client/name]
|
||||
@@ -95,6 +119,7 @@
|
||||
:args [client_id]})
|
||||
true
|
||||
(merge-query {:query {:where ['[?e :transaction/id]]}})))
|
||||
|
||||
(transduce (comp
|
||||
(take 15)
|
||||
(map first)
|
||||
|
||||
Reference in New Issue
Block a user