From 8845ec96884bf8177b6ce8112edbe598cc2b707e Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Thu, 16 May 2019 08:34:12 -0700 Subject: [PATCH] showing matched rule. --- src/clj/auto_ap/datomic/transactions.clj | 2 ++ src/clj/auto_ap/graphql.clj | 3 ++- src/cljs/auto_ap/subs.cljs | 6 ++++++ .../views/pages/transactions/common.cljs | 1 + .../views/pages/transactions/form.cljs | 20 +++++++++++++------ test/clj/auto_ap/graphql.clj | 11 +++++----- test/clj/auto_ap/yodlee/import.clj | 11 +++++----- 7 files changed, 37 insertions(+), 17 deletions(-) diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index b2a03e33..555ed4a2 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -90,6 +90,7 @@ (let [results (->> (d/pull-many db '[* {:transaction/client [:client/name :db/id :client/code] :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] :transaction/accounts [:transaction-account/amount :db/id :transaction-account/location @@ -117,6 +118,7 @@ '[* {:transaction/client [:client/name :db/id :client/code :client/locations] :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] :transaction/accounts [:transaction-account/amount :db/id :transaction-account/location diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index b712d474..80f7460a 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -188,7 +188,8 @@ :vendor {:type :vendor} :bank_account {:type :bank_account} :date {:type 'String} - :post_date {:type 'String}}} + :post_date {:type 'String} + :matched_rule {:type :transaction_rule}}} :transaction_rule {:fields {:id {:type :id} :note {:type 'String} diff --git a/src/cljs/auto_ap/subs.cljs b/src/cljs/auto_ap/subs.cljs index 802bb9fa..c9536eb9 100644 --- a/src/cljs/auto_ap/subs.cljs +++ b/src/cljs/auto_ap/subs.cljs @@ -151,6 +151,12 @@ false %)))) +(re-frame/reg-sub + ::is-admin? + :<- [::user] + (fn [user] + (= "admin" (:user/role user)))) + (re-frame/reg-sub ::user (fn [db] diff --git a/src/cljs/auto_ap/views/pages/transactions/common.cljs b/src/cljs/auto_ap/views/pages/transactions/common.cljs index c59428c1..989d5425 100644 --- a/src/cljs/auto_ap/views/pages/transactions/common.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/common.cljs @@ -5,6 +5,7 @@ :amount :location :exclude-from-ledger + [:matched-rule [:note :id]] [:vendor [:name :id]] [:accounts [:id :amount :location [:account [:name :id :location :numeric-code]]]] :date diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index 31265f53..fa0663ab 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -49,7 +49,8 @@ (-> which (select-keys [:vendor :amount :payment :client :description-original :yodlee-merchant :id :potential-payment-matches - :exclude-from-ledger :location :accounts :transaction-approval-status]) + :exclude-from-ledger :location :accounts :transaction-approval-status + :matched-rule]) (assoc :potential-payment-matches potential-payment-matches) (update :accounts expense-accounts-field/from-graphql (:amount which) locations)))))) @@ -114,7 +115,6 @@ (defn potential-payment-matches-box [{:keys [potential-payment-matches] :as params}] - (println potential-payment-matches) [:div.box [:div.columns [:div.column @@ -140,10 +140,18 @@ locations @(re-frame/subscribe [::subs/locations-for-client (:id (:client data))]) {:keys [form field raw-field error-notification submit-button ]} transaction-form] [form {:title "Hello" :edit-completed edit-completed} - [field "Merchant" - [:input.input {:type "text" - :field [:yodlee-merchant :name] - :disabled "disabled"}]] + + (when @(re-frame/subscribe [::subs/is-admin?]) + [field "Merchant" + [:input.input {:type "text" + :field [:yodlee-merchant :name] + :disabled "disabled"}]]) + + (when @(re-frame/subscribe [::subs/is-admin?]) + [field "Matched Rule" + [:input.input {:type "text" + :field [:matched-rule :note] + :disabled "disabled"}]]) [field "Amount" [:input.input {:type "text" :field [:amount] diff --git a/test/clj/auto_ap/graphql.clj b/test/clj/auto_ap/graphql.clj index caabb9b0..449894b4 100644 --- a/test/clj/auto_ap/graphql.clj +++ b/test/clj/auto_ap/graphql.clj @@ -7,11 +7,12 @@ [auto-ap.datomic :refer [uri]])) (defn wrap-setup [f] - (d/create-database uri) - (m/-main false) - (f) - (d/release (d/connect uri)) - (d/delete-database uri)) + (with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"] + (d/create-database uri) + (m/-main false) + (f) + (d/release (d/connect uri)) + (d/delete-database uri))) (use-fixtures :each wrap-setup) (deftest ledger-page diff --git a/test/clj/auto_ap/yodlee/import.clj b/test/clj/auto_ap/yodlee/import.clj index 455e6b1d..4ff6b0f5 100644 --- a/test/clj/auto_ap/yodlee/import.clj +++ b/test/clj/auto_ap/yodlee/import.clj @@ -8,11 +8,12 @@ (defn wrap-setup [f] - (d/create-database uri) - (m/-main false) - (f) - (d/release (d/connect uri)) - (d/delete-database uri)) + (with-redefs [auto-ap.datomic/uri "datomic:mem://datomic-transactor:4334/invoice"] + (d/create-database uri) + (m/-main false) + (f) + (d/release (d/connect uri)) + (d/delete-database uri))) (t/use-fixtures :each wrap-setup)