Adding transaction approval status to transaction page
This commit is contained in:
@@ -88,6 +88,7 @@
|
||||
|
||||
(defn graphql-results [ids db args]
|
||||
(let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code]
|
||||
:transaction/approval-status [:db/ident :db/id]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
||||
:transaction/vendor [:db/id :vendor/name]
|
||||
:transaction/matched-rule [:db/id :transaction-rule/note]
|
||||
@@ -116,6 +117,7 @@
|
||||
(->
|
||||
(d/pull (d/db (d/connect uri))
|
||||
'[* {:transaction/client [:client/name :db/id :client/code :client/locations]
|
||||
:transaction/approval-status [:db/ident :db/id]
|
||||
:transaction/bank-account [:bank-account/name :bank-account/code :bank-account/yodlee-account-id :db/id]
|
||||
:transaction/vendor [:db/id :vendor/name]
|
||||
:transaction/matched-rule [:db/id :transaction-rule/note]
|
||||
|
||||
@@ -190,6 +190,7 @@
|
||||
:bank_account {:type :bank_account}
|
||||
:date {:type 'String}
|
||||
:post_date {:type 'String}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:matched_rule {:type :transaction_rule}}}
|
||||
|
||||
:transaction_rule {:fields {:id {:type :id}
|
||||
@@ -529,6 +530,7 @@
|
||||
{:fields {:id {:type :id}
|
||||
:exclude_from_ledger {:type 'Boolean}
|
||||
:vendor_id {:type :id}
|
||||
:approval_status {:type :transaction_approval_status}
|
||||
:accounts {:type '(list :edit_expense_account)}}}
|
||||
|
||||
:edit_percentage_account
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
[datomic.api :as d]
|
||||
[auto-ap.datomic :refer [remove-nils uri merge-query replace-nils-with-retract]]
|
||||
[auto-ap.utils :refer [dollars=]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab]]
|
||||
[auto-ap.graphql.utils :refer [->graphql <-graphql limited-clients assert-admin result->page snake->kebab ident->enum-f]]
|
||||
[clj-time.coerce :as c]
|
||||
[clojure.set :as set]
|
||||
[clojure.string :as str]
|
||||
@@ -13,9 +13,7 @@
|
||||
[clj-time.coerce :as coerce])
|
||||
(:import [java.time.temporal ChronoField]))
|
||||
|
||||
(defn ident->enum-f [k]
|
||||
#(update % k
|
||||
(fn [value] (some-> value :db/ident name keyword))))
|
||||
|
||||
|
||||
(defn get-transaction-rule-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
@@ -47,7 +45,7 @@
|
||||
:account account_id
|
||||
:location location}))
|
||||
;; TODO ASSERT ADMIN
|
||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status ]} :transaction_rule :as z} value]
|
||||
(defn upsert-transaction-rule [context {{:keys [id description yodlee_merchant_id note client_id bank_account_id amount_lte amount_gte vendor_id accounts transaction_approval_status dom_gte dom_lte]} :transaction_rule :as z} value]
|
||||
#_(assert-admin (:id context))
|
||||
(let [existing-transaction (tr/get-by-id id)
|
||||
deleted (deleted-accounts existing-transaction accounts)
|
||||
@@ -67,6 +65,8 @@
|
||||
:client client_id
|
||||
:bank-account bank_account_id
|
||||
:yodlee-merchant yodlee_merchant_id
|
||||
:dom-lte dom_lte
|
||||
:dom-gte dom_gte
|
||||
:amount-lte amount_lte
|
||||
:amount-gte amount_gte
|
||||
:vendor vendor_id
|
||||
@@ -78,7 +78,6 @@
|
||||
:accounts (map transaction-rule-account->entity accounts)}
|
||||
existing-transaction)
|
||||
|
||||
_ (println transaction)
|
||||
|
||||
transaction (into transaction
|
||||
(map (fn [d]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(ns auto-ap.graphql.transactions
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin]]
|
||||
(:require [auto-ap.graphql.utils :refer [->graphql <-graphql assert-can-see-client assert-admin ident->enum-f snake->kebab]]
|
||||
[auto-ap.datomic.transactions :as d-transactions]
|
||||
[auto-ap.datomic.vendors :as d-vendors]
|
||||
[auto-ap.datomic.checks :as d-checks]
|
||||
@@ -17,11 +17,17 @@
|
||||
[auto-ap.datomic.transaction-rules :as tr]
|
||||
[auto-ap.rule-matching :as rm]
|
||||
[clj-time.coerce :as coerce]))
|
||||
(defn prn-each [xs]
|
||||
(doseq [x xs]
|
||||
(println x))
|
||||
xs)
|
||||
|
||||
(def approval-status->graphql (ident->enum-f :transaction/approval-status))
|
||||
|
||||
(defn get-transaction-page [context args value]
|
||||
(let [args (assoc args :id (:id context))
|
||||
[transactions transactions-count] (d-transactions/get-graphql (<-graphql args))
|
||||
transactions (map ->graphql transactions)]
|
||||
transactions (map ->graphql (map approval-status->graphql transactions))]
|
||||
[{:transactions transactions
|
||||
:total transactions-count
|
||||
:count (count transactions)
|
||||
@@ -45,7 +51,7 @@
|
||||
set)]
|
||||
(set/difference existing-ids specified-ids)))
|
||||
|
||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id] :as transaction} :transaction} value]
|
||||
(defn edit-transaction [context {{:keys [id exclude_from_ledger accounts vendor_id approval_status] :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)
|
||||
@@ -69,13 +75,19 @@
|
||||
@(d/transact (d/connect uri)
|
||||
(concat [(remove-nils {:db/id id
|
||||
:transaction/vendor vendor_id
|
||||
:transaction/approval-status (some->> approval_status
|
||||
name
|
||||
snake->kebab
|
||||
(keyword "transaction-approval-status"))
|
||||
:transaction/exclude-from-ledger exclude_from_ledger
|
||||
:transaction/accounts (map transaction-account->entity accounts)
|
||||
})]
|
||||
(map (fn [d]
|
||||
[:db/retract id :transaction/accounts d])
|
||||
deleted)))
|
||||
(->graphql (d-transactions/get-by-id id))))
|
||||
(-> (d-transactions/get-by-id id)
|
||||
approval-status->graphql
|
||||
->graphql)))
|
||||
|
||||
(defn match-transaction [context {:keys [transaction_id payment_id]} value]
|
||||
(let [transaction (d-transactions/get-by-id transaction_id)
|
||||
@@ -103,7 +115,9 @@
|
||||
: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)))
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
->graphql))
|
||||
|
||||
(defn match-transaction-rule [context {:keys [transaction_id transaction_rule_id]} value]
|
||||
(let [_ (assert-admin (:id context))
|
||||
@@ -122,4 +136,6 @@
|
||||
|
||||
;; TODO use bank account locations as well
|
||||
(-> transaction :transaction/client :client/locations))]))
|
||||
(->graphql (d-transactions/get-by-id transaction_id)))
|
||||
(-> (d-transactions/get-by-id transaction_id)
|
||||
approval-status->graphql
|
||||
->graphql))
|
||||
|
||||
@@ -77,3 +77,7 @@
|
||||
:count (count results)
|
||||
:start (:start args 0)
|
||||
:end (+ (:start args 0) (count results))})
|
||||
|
||||
(defn ident->enum-f [k]
|
||||
#(update % k
|
||||
(fn [value] (some-> value :db/ident name keyword))))
|
||||
|
||||
Reference in New Issue
Block a user