supports adding conclusions.
This commit is contained in:
@@ -350,6 +350,32 @@
|
||||
:db/valueType :db.type/long
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "Day of month has to be greater than or equal to this"}
|
||||
|
||||
{:db/ident :transaction-rule/vendor
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The vendor to assign"}
|
||||
|
||||
{:db/ident :transaction-rule-account/percentage
|
||||
:db/valueType :db.type/double
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "How much should go to this account"}
|
||||
|
||||
{:db/ident :transaction-rule-account/location
|
||||
:db/valueType :db.type/string
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The location this split is for"}
|
||||
|
||||
{:db/ident :transaction-rule-account/account
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/one
|
||||
:db/doc "The account of this split"}
|
||||
|
||||
{:db/ident :transaction-rule/accounts
|
||||
:db/valueType :db.type/ref
|
||||
:db/cardinality :db.cardinality/many
|
||||
:db/isComponent true
|
||||
:db/doc "The outcome split"}
|
||||
]])
|
||||
|
||||
(def add-credit-bank-account
|
||||
|
||||
@@ -11,7 +11,12 @@
|
||||
(def default-read '[*
|
||||
{:transaction-rule/client [:client/name :db/id :client/code]}
|
||||
{:transaction-rule/bank-account [*]}
|
||||
{:transaction-rule/yodlee-merchant [*]}])
|
||||
{:transaction-rule/yodlee-merchant [*]}
|
||||
{:transaction-rule/vendor [:vendor/name :db/id :vendor/default-account]}
|
||||
{:transaction-rule/accounts [:transaction-rule-account/percentage
|
||||
:transaction-rule-account/location
|
||||
{:transaction-rule-account/account [*]}
|
||||
:db/id]}])
|
||||
|
||||
(defn raw-graphql-ids [db args]
|
||||
(let [query (cond-> {:query {:find []
|
||||
|
||||
@@ -47,7 +47,14 @@
|
||||
:serialize (schema/as-conformer #(if (double? %)
|
||||
(str %)
|
||||
%))
|
||||
}}
|
||||
}
|
||||
:percentage {:parse (schema/as-conformer #(if (and (string? %)
|
||||
(not (str/blank? %)))
|
||||
(Double/parseDouble %)
|
||||
%))
|
||||
:serialize (schema/as-conformer #(if (double? %)
|
||||
(str %)
|
||||
%))}}
|
||||
:objects
|
||||
{
|
||||
:client
|
||||
@@ -193,7 +200,8 @@
|
||||
:amount_gte {:type 'String}
|
||||
:dom_lte {:type 'Int}
|
||||
:dom_gte {:type 'Int}
|
||||
:vendor {:type :vendor}}}
|
||||
:vendor {:type :vendor}
|
||||
:accounts {:type '(list :percentage_account)}}}
|
||||
|
||||
:invoice_payment
|
||||
{:fields {:id {:type :id}
|
||||
@@ -226,6 +234,11 @@
|
||||
|
||||
:amount {:type 'String}}}
|
||||
|
||||
:percentage_account
|
||||
{:fields {:id {:type :id}
|
||||
:account {:type :account}
|
||||
:location {:type 'String}
|
||||
:percentage {:type :percentage}}}
|
||||
:invoice
|
||||
{:fields {:id {:type :id}
|
||||
:original_id {:type 'Int}
|
||||
@@ -507,6 +520,12 @@
|
||||
:vendor_id {:type :id}
|
||||
:accounts {:type '(list :edit_expense_account)}}}
|
||||
|
||||
:edit_percentage_account
|
||||
{:fields {:id {:type :id}
|
||||
:account_id {:type :id}
|
||||
:location {:type 'String}
|
||||
:percentage {:type :percentage}}}
|
||||
|
||||
:edit_transaction_rule
|
||||
{:fields {:id {:type :id}
|
||||
:description {:type 'String}
|
||||
@@ -516,7 +535,9 @@
|
||||
:amount_lte {:type :money}
|
||||
:amount_gte {:type :money}
|
||||
:dom_lte {:type 'Int}
|
||||
:dom_gte {:type 'Int}}}
|
||||
:dom_gte {:type 'Int}
|
||||
:vendor_id {:type :id}
|
||||
:accounts {:type '(list :edit_percentage_account)}}}
|
||||
|
||||
:edit_account
|
||||
{:fields {:id {:type :id}
|
||||
|
||||
@@ -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