From 3ecfde69d0504409313aae111871d8856d8fdda4 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Wed, 17 Apr 2019 19:30:01 -0700 Subject: [PATCH] Added bank accounts being credit card accounts --- config/dev.edn | 4 +- resources/public/css/main.css | 7 +++ src/clj/auto_ap/datomic/ledger.clj | 3 +- src/clj/auto_ap/datomic/migrate.clj | 2 + .../datomic/migrate/add_general_ledger.clj | 5 ++ src/clj/auto_ap/graphql.clj | 1 + src/clj/auto_ap/graphql/ledger.clj | 14 +++-- src/clj/auto_ap/ledger.clj | 21 +++++--- src/clj/auto_ap/yodlee/core.clj | 2 +- src/cljc/auto_ap/entities/clients.cljc | 9 +++- .../auto_ap/views/pages/admin/clients.cljs | 51 ++++++++++++++++--- 11 files changed, 96 insertions(+), 23 deletions(-) diff --git a/config/dev.edn b/config/dev.edn index 08c40b31..4ec086ce 100644 --- a/config/dev.edn +++ b/config/dev.edn @@ -11,8 +11,8 @@ :yodlee-cobrand-name "restserver" :yodlee-cobrand-login "sbCobda48aa19712a83c3ca4e935dd5e5d46b1a" :yodlee-cobrand-password "0a07ea32-1b5d-461b-ad0f-2752cdd77602" - :yodlee-user-login "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a1" - :yodlee-user-password "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a1#123" + :yodlee-user-login "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2" + :yodlee-user-password "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2#123" :yodlee-base-url "https://developer.api.yodlee.com/ysl" :yodlee-app "10003600" :yodlee-fastlink "https://node.developer.yodlee.com/authenticate/restserver/?channelAppName=restserver" diff --git a/resources/public/css/main.css b/resources/public/css/main.css index e354a7b5..22deb221 100644 --- a/resources/public/css/main.css +++ b/resources/public/css/main.css @@ -90,6 +90,13 @@ .nav.menu { border-bottom: 1px solid #e1e1e1; } + +.menu .icon.inline { + width: 1.5em; + height: 1.5em; + + font-size: 1.5em; +} .nav.menu .nav-item .icon-btn { border: 3px solid #B7C6C9; border-radius: 90px; diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 45bf48cd..a12719ce 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -56,7 +56,8 @@ (->> (d/pull-many db '[* {:journal-entry/client [:client/name :client/code :db/id] :journal-entry/vendor [:vendor/name :db/id] :journal-entry/line-items [* {:journal-entry-line/account [* - {:account/type [*]}]}] + {:account/type [*]} + {:bank-account/type [*]}]}] }] ids) diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 88a37de4..2be04772 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -118,6 +118,8 @@ :requires [:auto-ap/change-expense-account-to-entity]} :auto-ap/add-location-to-transaction {:txes add-general-ledger/add-location-to-transaction :requires [:auto-ap/add-account-to-vendor]} + :auto-ap/add-credit-bank-account {:txes add-general-ledger/add-credit-bank-account + :requires [:auto-ap/add-location-to-transaction]} :auto-ap/convert-vendors {:txes-fn `add-general-ledger/convert-vendors :requires [:auto-ap/add-location-to-transaction]} :auto-ap/convert-invoices {:txes-fn `add-general-ledger/convert-invoices 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 0fa3f4cf..3738e992 100644 --- a/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj +++ b/src/clj/auto_ap/datomic/migrate/add_general_ledger.clj @@ -269,6 +269,11 @@ :db/cardinality :db.cardinality/one :db/doc "Location of the transaction's target"}]]) +(def add-credit-bank-account + [[{:db/ident :bank-account-type/credit}]]) + + + #_(do (doseq [tran (convert-transactions (d/connect auto-ap.datomic/uri))] @(d/transact (d/connect auto-ap.datomic/uri) tran)) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index 3f0c551c..733558bd 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -437,6 +437,7 @@ {:enum-value :cash} {:enum-value :debit}]} :bank_account_type {:values [{:enum-value :check} + {:enum-value :credit} {:enum-value :cash}]} :account_type {:values [{:enum-value :dividend} {:enum-value :expense} diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index ac231ac4..c61ec750 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -16,17 +16,21 @@ :start (:start args 0) :end (+ (:start args 0) (count journal-entries))})) (defn credit-account? [account] - (#{:account-type/liability - :account-type/equity - :account-type/revenue} - (:db/ident (:account/type account)))) + (or + (#{:account-type/liability + :account-type/equity + :account-type/revenue} + (:db/ident (:account/type account))) + (#{:bank-account-type/credit} + (-> account :bank-account/type :db/ident )))) (defn debit-account? [account] (or (#{:account-type/asset :account-type/dividend :account-type/expense} (:db/ident (:account/type account))) - (:bank-account/name account))) + (#{:bank-account-type/check} + (-> account :bank-account/type :db/ident )))) (defn expense-account? [account] (= :account-type/expense (:db/ident (:account/type account)))) diff --git a/src/clj/auto_ap/ledger.clj b/src/clj/auto_ap/ledger.clj index f116da81..b625cb63 100644 --- a/src/clj/auto_ap/ledger.clj +++ b/src/clj/auto_ap/ledger.clj @@ -59,7 +59,15 @@ (defmethod entity-change->ledger :transaction [db [type id]] - (let [entity (d/pull db ['* {:transaction/vendor '[*] :transaction/client '[*] :transaction/accounts '[* {:transaction-account/account [*]}] }] id)] + (let [entity (d/pull db ['* {:transaction/vendor '[*] + :transaction/client '[*] + :transaction/bank-account '[* {:bank-account/type [:db/ident]}] + :transaction/accounts '[* + {:transaction-account/account [*]}] }] id) + bank-account-type (-> entity :transaction/bank-account :bank-account/type :db/ident) + decreasing? (< (:transaction/amount entity) 0.0) + credit-from-bank? decreasing? + debit-from-bank? (not decreasing?)] (println "processing entity" entity) (when (:transaction/vendor entity) (remove-nils @@ -70,21 +78,20 @@ :journal-entry/vendor (:db/id (:transaction/vendor entity)) :journal-entry/amount (Math/abs (:transaction/amount entity)) - :journal-entry/line-items (into [ - (remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity)) + :journal-entry/line-items (into [(remove-nils {:journal-entry-line/account (:db/id (:transaction/bank-account entity)) :journal-entry-line/location "A" - :journal-entry-line/credit (when (< (:transaction/amount entity) 0.0) + :journal-entry-line/credit (when credit-from-bank? (Math/abs (:transaction/amount entity))) - :journal-entry-line/debit (when (>= (:transaction/amount entity) 0.0) + :journal-entry-line/debit (when debit-from-bank? (Math/abs (:transaction/amount entity)))}) ] (map (fn [a] (remove-nils{:journal-entry-line/account (:db/id (:transaction-account/account a)) :journal-entry-line/location (:transaction-account/location a) - :journal-entry-line/debit (when (< (:transaction/amount entity) 0.0) + :journal-entry-line/debit (when credit-from-bank? (Math/abs (:transaction-account/amount a))) - :journal-entry-line/credit (when (>= (:transaction/amount entity) 0.0) + :journal-entry-line/credit (when debit-from-bank? (Math/abs (:transaction-account/amount a)))})) (:transaction/accounts entity))) diff --git a/src/clj/auto_ap/yodlee/core.clj b/src/clj/auto_ap/yodlee/core.clj index ed289e3d..50ae8816 100644 --- a/src/clj/auto_ap/yodlee/core.clj +++ b/src/clj/auto_ap/yodlee/core.clj @@ -27,7 +27,7 @@ (defn login-user - ([cob-session] (login-user cob-session "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2" "sbMemda48aa19712a83c3ca4e935dd5e5d46b1a2#123")) + ([cob-session] (login-user cob-session (:yodlee-user-login env) (:yodlee-user-password env))) ([cob-session user password] (-> (str (:yodlee-base-url env) "/user/login") (client/post {:headers (merge base-headers {"Authorization" (auth-header cob-session)}) diff --git a/src/cljc/auto_ap/entities/clients.cljc b/src/cljc/auto_ap/entities/clients.cljc index a3fc5367..ac0a5bea 100644 --- a/src/cljc/auto_ap/entities/clients.cljc +++ b/src/cljc/auto_ap/entities/clients.cljc @@ -23,9 +23,16 @@ (s/def ::checking-bank-account (s/and (s/keys :req-un [::code ::name ::bank-name ::number ::type] :opt-un [::bank-code ::routing]) #(= (:type %) :check))) + +(s/def ::credit-account (s/and (s/keys :req-un [::code ::name ::bank-name ::number ::type] + :opt-un []) + #(= (:type %) :credit))) + (s/def ::cash-account (s/and (s/keys :req-un [::type ::code ::name]) #(= (:type %) :cash))) -(s/def ::bank-account (s/or :cash ::cash-account :checking ::checking-bank-account)) +(s/def ::bank-account (s/or :cash ::cash-account + :checking ::checking-bank-account + :credit ::credit-account)) (s/def ::bank-accounts (s/coll-of ::bank-account)) (s/def ::location string?) diff --git a/src/cljs/auto_ap/views/pages/admin/clients.cljs b/src/cljs/auto_ap/views/pages/admin/clients.cljs index f021b68a..1911a79b 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients.cljs @@ -193,10 +193,13 @@ [:div.card {:style {:margin-bottom "1em"}} [:header.card-header [:p.card-header-title {:style {:text-overflow "ellipsis"}} - [:span.icon - (if ({:check ":check"} type) - [:span.icon-check-payment-sign] - [:span.icon-accounting-bill])] + [:span.icon.inline + (cond + (#{:check ":check"} type) [:span.icon-check-payment-sign] + + (#{:credit ":credit"} type) [:span.icon-credit-card-1] + + :else [:span.icon-accounting-bill])] code ": " name] [:p {:style {:padding "0.75em 0.25em"}} [:a.button.is-outlined {:on-click (dispatch-event [::toggle-visible sort-order])} [:span.icon (if visible @@ -297,6 +300,40 @@ :subscription new-client}]]]] [:div.field [:label.label "Yodlee Account"] + [:div.control + [bind-field + [:input.input {:placeholder "Yodlee Account #" + :type "text" + :field [:bank-accounts sort-order :yodlee-account-id] + :event change-event + :subscription new-client}]]]]]) + (when (#{:credit ":credit"} type ) + [:div + + [:label.label "Account"] + [horizontal-field + nil + [:div.control + [:p.help "Bank Name"] + [bind-field + [:input.input {:placeholder "Bank of America" + :type "text" + :field [:bank-accounts sort-order :bank-name] + :event change-event + :subscription new-client}]]]] + + [horizontal-field + nil + [:div.control + [:p.help "Account #"] + [bind-field + [:input.input {:placeholder "123456789" + :type "text" + :field [:bank-accounts sort-order :number] + :event change-event + :subscription new-client}]]]] + [:div.field + [:p.help "Yodlee Account"] [:div.control [bind-field [:input.input {:placeholder "Yodlee Account #" @@ -380,9 +417,11 @@ [bank-account-card new-client bank-account (= 0 (:sort-order bank-account)) (= (:sort-order bank-account) (dec (count (:bank-accounts new-client))))]) [:div.columns - [:div.column.is-half + [:div.column.is-third + [:a.button.is-primary.is-outlined.is-fullwidth {:on-click (dispatch-event [::add-new-bank-account :credit])} "Add Credit Account"]] + [:div.column.is-third [:a.button.is-primary.is-outlined.is-fullwidth {:on-click (dispatch-event [::add-new-bank-account :check])} "Add Checking Account"]] - [:div.column.is-half + [:div.column.is-third [:a.button.is-primary.is-outlined.is-fullwidth {:on-click (dispatch-event [::add-new-bank-account :cash])} "Add Cash Account"]]] #_[:h2.subtitle "Add bank account"]