From 6b1252390b9f9d2fe4595f51b4157be7fda7e7d0 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 16 Apr 2019 06:30:24 -0700 Subject: [PATCH] adding yodlee vetndors. --- src/clj/auto_ap/datomic/migrate.clj | 5 +++-- .../datomic/migrate/add_general_ledger.clj | 17 +++++++++++++++++ src/clj/auto_ap/datomic/transactions.clj | 6 ++++-- src/clj/auto_ap/graphql.clj | 5 ++++- src/clj/auto_ap/graphql/transactions.clj | 1 + src/clj/auto_ap/yodlee/core.clj | 6 +++--- src/clj/auto_ap/yodlee/import.clj | 6 +++++- .../views/pages/transactions/common.cljs | 1 + .../auto_ap/views/pages/transactions/form.cljs | 16 ++++++++++++++-- .../auto_ap/views/pages/transactions/table.cljs | 10 +++++++--- 10 files changed, 59 insertions(+), 14 deletions(-) diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 8d4a25df..b8f48c4c 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -124,9 +124,10 @@ :requires [:auto-ap/convert-vendors]} :auto-ap/convert-transactions {:txes-fn `add-general-ledger/convert-transactions :requires [:auto-ap/convert-invoices]} + :auto-ap/add-yodlee-merchant {:txes add-general-ledger/add-yodlee-merchant :requires [:auto-ap/convert-transactions]} - :auto-ap/bulk-load-invoice-ledger3 {:txes-fn `add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]} - :auto-ap/bulk-load-transaction-ledger3 {:txes-fn `add-general-ledger/bulk-load-transaction-ledger :requires [:auto-ap/convert-transactions]} + #_#_:auto-ap/bulk-load-invoice-ledger3 {:txes-fn `add-general-ledger/bulk-load-invoice-ledger :requires [:auto-ap/convert-transactions]} + #_#_:auto-ap/bulk-load-transaction-ledger3 {:txes-fn `add-general-ledger/bulk-load-transaction-ledger :requires [:auto-ap/convert-transactions]} }] (println "Conforming database...") diff --git a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj index 4ac9935a..02ab3be4 100644 --- a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj +++ b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj @@ -81,6 +81,23 @@ :db/cardinality :db.cardinality/one :db/doc "The debit/credit for this transaction"}]]) +(def add-yodlee-merchant + [[{:db/ident :yodlee-merchant/name + :db/valueType :db.type/string + :db/cardinality :db.cardinality/one + :db/doc "The yodlee merchant name"} + + {:db/ident :yodlee-merchant/id + :db/valueType :db.type/string + :db/unique :db.unique/identity + :db/cardinality :db.cardinality/one + :db/doc "The yodlee merchant id"} + + {:db/ident :transaction/yodlee-merchant + :db/valueType :db.type/ref + :db/cardinality :db.cardinality/one + :db/doc "The yodlee merchant"}]]) + (def add-accounts [[ {:db/ident :account/code diff --git a/src/clj/auto_ap/datomic/transactions.clj b/src/clj/auto_ap/datomic/transactions.clj index b9ba7b17..47f0eed7 100644 --- a/src/clj/auto_ap/datomic/transactions.clj +++ b/src/clj/auto_ap/datomic/transactions.clj @@ -75,7 +75,8 @@ (->> (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/account [:db/id :account/name :account/numeric-code]}] + :transaction/account [:db/id :account/name :account/numeric-code] + :transaction/yodlee-merchant [:db/id :yodlee-merchant/id :yodlee-merchant/name]}] ids) (map #(update % :transaction/date c/from-date)) (map #(update % :transaction/post-date c/from-date)) @@ -95,7 +96,8 @@ '[* {: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/account [:db/id :account/name :account/numeric-code]}] + :transaction/account [:db/id :account/name :account/numeric-code] + :transaction/yodlee-merchant [:db/id :yodlee-merchant/id :yodlee-merchant/name]}] id) (update :transaction/date c/from-date) (update :transaction/post-date c/from-date) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 10e4380b..1d51bab3 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -151,13 +151,16 @@ :invoices {:type '(list :invoice_payment)} }} + :yodlee_merchant {:fields {:id {:type 'String} + :name {:type 'String}}} + :transaction {:fields {:id {:type :id} :amount {:type 'String} :description_original {:type 'String} :description_simple {:type 'String} :location {:type 'String} :status {:type 'String} - :merchant_name {:type 'String} + :yodlee_merchant {:type :yodlee_merchant} :client {:type :client} :account {:type :account} :payment {:type :payment} diff --git a/src/clj/auto_ap/graphql/transactions.clj b/src/clj/auto_ap/graphql/transactions.clj index aed4da08..bd8ae440 100644 --- a/src/clj/auto_ap/graphql/transactions.clj +++ b/src/clj/auto_ap/graphql/transactions.clj @@ -15,6 +15,7 @@ (let [args (assoc args :id (:id context)) [transactions transactions-count] (d-transactions/get-graphql (<-graphql args)) transactions (map ->graphql transactions)] + (println transactions) [{:transactions transactions :total transactions-count :count (count transactions) diff --git a/src/clj/auto_ap/yodlee/core.clj b/src/clj/auto_ap/yodlee/core.clj index 1881833b..ed289e3d 100644 --- a/src/clj/auto_ap/yodlee/core.clj +++ b/src/clj/auto_ap/yodlee/core.clj @@ -1,5 +1,6 @@ (ns auto-ap.yodlee.core (:require [clj-http.client :as client] + [cemerick.url :as u] [clojure.data.json :as json] [config.core :refer [env]])) @@ -26,7 +27,7 @@ (defn login-user - ([cob-session] (:yodlee-user-login env) (:yodlee-user-password env)) + ([cob-session] (login-user cob-session "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2" "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2#123")) ([cob-session user password] (-> (str (:yodlee-base-url env) "/user/login") (client/post {:headers (merge base-headers {"Authorization" (auth-header cob-session)}) @@ -75,7 +76,7 @@ batch-size 100 get-transaction-batch (fn [skip] (-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip) - (doto println) + (client/get {:headers (doto (merge base-headers {"Authorization" (auth-header cob-session user-session)}) @@ -146,7 +147,6 @@ batch-size 100 get-transaction-batch (fn [skip] (-> (str (:yodlee-base-url env) "/transactions?top=" batch-size "&skip=" skip "&accountId=" account) - (doto println) (client/get {:headers (doto (merge base-headers {"Authorization" (auth-header cob-session user-session)}) diff --git a/src/clj/auto_ap/yodlee/import.clj b/src/clj/auto_ap/yodlee/import.clj index b350e26e..54ff5c34 100644 --- a/src/clj/auto_ap/yodlee/import.clj +++ b/src/clj/auto_ap/yodlee/import.clj @@ -53,7 +53,7 @@ {amount :amount} :amount {description-original :original description-simple :simple} :description - {merchant-id :i + {merchant-id :id merchant-name :name} :merchant base-type :baseType type :type @@ -73,6 +73,10 @@ :id (sha-256 (str id)) :account-id account-id :date (coerce/to-date (time/parse date "YYYY-MM-dd")) + :yodlee-merchant (when (and merchant-id merchant-name) + (println "INCLUDING MERCHANT") + {:yodlee-merchant/id merchant-id + :yodlee-merchant/name merchant-name}) :amount (double amount) :description-original description-original :description-simple description-simple diff --git a/src/cljs/auto_ap/views/pages/transactions/common.cljs b/src/cljs/auto_ap/views/pages/transactions/common.cljs index 4dd591e3..47cd4545 100644 --- a/src/cljs/auto_ap/views/pages/transactions/common.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/common.cljs @@ -7,6 +7,7 @@ [:vendor [:name :id]] [:account [:id :name]] :date + [:yodlee_merchant [:name :id]] :post_date :status :description_original diff --git a/src/cljs/auto_ap/views/pages/transactions/form.cljs b/src/cljs/auto_ap/views/pages/transactions/form.cljs index f68de1a8..d640eb2d 100644 --- a/src/cljs/auto_ap/views/pages/transactions/form.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/form.cljs @@ -9,8 +9,11 @@ (re-frame/reg-event-db ::editing (fn [db [_ which]] + (println which) (-> db (forms/start-form ::edit-transaction {:id (:id which) + :yodlee-merchant (:yodlee-merchant which) + :description-original (:description-original which) :location (:location which) :client-id (:id (:client which)) :account-id (:id (:account which)) @@ -69,7 +72,6 @@ (defn form [{:keys [edit-completed]}] [forms/side-bar-form {:form ::edit-transaction } (let [{:keys [data active? error id]} @(re-frame/subscribe [::forms/form ::edit-transaction]) - data (assoc data :merchant-name "Hello") ;; TODO - just until merchant is added locations @(re-frame/subscribe [::subs/locations-for-client (:client-id data)]) change-event [::forms/change ::edit-transaction]] ^{:key id} @@ -78,6 +80,7 @@ (.stopPropagation e) (.preventDefault e)) (re-frame/dispatch-sync [::saving edit-completed]))} + (println data) [:h1.title.is-2 "Edit Transaction"] (comment @@ -90,7 +93,16 @@ [:div.control [bind-field [:input.input {:type "text" - :field [:merchant-name] + :field [:yodlee-merchant :name] + :disabled "disabled" + :subscription data}]]]] + + [:div.field + [:p.help "Description"] + [:div.control + [bind-field + [:input.input {:type "text" + :field [:description-original] :disabled "disabled" :subscription data}]]]] diff --git a/src/cljs/auto_ap/views/pages/transactions/table.cljs b/src/cljs/auto_ap/views/pages/transactions/table.cljs index 325892af..36b989ef 100644 --- a/src/cljs/auto_ap/views/pages/transactions/table.cljs +++ b/src/cljs/auto_ap/views/pages/transactions/table.cljs @@ -77,14 +77,18 @@ [:tr [:td {:col-span 5} [:i.fa.fa-spin.fa-spinner]]] - (for [{:keys [client account vendor payment status bank-account description-original date amount id ] :as i} (:transactions @transaction-page)] + (for [{:keys [client account vendor payment status bank-account description-original date amount id yodlee-merchant ] :as i} (:transactions @transaction-page)] ^{:key id} [:tr {:class (:class i)} (when-not selected-client [:td (:name client)]) - [:td (if vendor + [:td (cond vendor (:name vendor) - [:i.has-text-grey (str "Merchant '" "Hello" "'")])] + yodlee-merchant + [:i.has-text-grey (str "Merchant '" (:name yodlee-merchant) "'")] + + :else + [:i.has-text-grey (str "Unknown Merchant")])] #_[:td description-original] [:td (date->str date) ] [:td.has-text-right (nf amount )]