From e9c22d2279e5c402a074482a2f1cb9f847cbb7cb Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Fri, 3 Sep 2021 07:12:23 -0700 Subject: [PATCH] Adds ability for bank accounts to have numeric accounts --- src/clj/auto_ap/datomic/ledger.clj | 7 +-- src/clj/auto_ap/datomic/migrate.clj | 3 ++ src/clj/auto_ap/datomic/migrate/clients.clj | 46 ++++++++++++++++++- src/clj/auto_ap/graphql.clj | 2 + src/clj/auto_ap/graphql/clients.clj | 1 + src/clj/auto_ap/graphql/ledger.clj | 7 +-- src/cljs/auto_ap/events.cljs | 2 +- .../views/pages/admin/clients/form.cljs | 14 +++++- .../views/pages/ledger/balance_sheet.cljs | 2 +- 9 files changed, 68 insertions(+), 16 deletions(-) diff --git a/src/clj/auto_ap/datomic/ledger.clj b/src/clj/auto_ap/datomic/ledger.clj index 1a1b1633..abf6a89d 100644 --- a/src/clj/auto_ap/datomic/ledger.clj +++ b/src/clj/auto_ap/datomic/ledger.clj @@ -71,12 +71,7 @@ :where ['[?li :journal-entry-line/account ?a] '(or-join [?a ?c] [?a :account/numeric-code ?c] - (and [?a :bank-account/type :bank-account-type/check] - [(ground 11100) ?c]) - (and [?a :bank-account/type :bank-account-type/cash] - [(ground 11100) ?c]) - (and [?a :bank-account/type :bank-account-type/credit] - [(ground 28000) ?c]))]} + [?a :bank-account/numeric-code ?c])]} :args []}) (:from-numeric-code args) diff --git a/src/clj/auto_ap/datomic/migrate.clj b/src/clj/auto_ap/datomic/migrate.clj index 7a732e9d..cd7edea8 100644 --- a/src/clj/auto_ap/datomic/migrate.clj +++ b/src/clj/auto_ap/datomic/migrate.clj @@ -334,6 +334,9 @@ :db/valueType :db.type/long :db/cardinality :db.cardinality/one}]]} :auto-ap/add-power-user-schema {:txes [[{:db/ident :user-role/power-user}]]}} + :auto-ap/add-transaction-date-index {:txes [[{:db/ident :transaction/date + :db/index true}]] + :requires [:auto-ap/add-accounts]} sales/norms-map diff --git a/src/clj/auto_ap/datomic/migrate/clients.clj b/src/clj/auto_ap/datomic/migrate/clients.clj index 00544623..9137ef2b 100644 --- a/src/clj/auto_ap/datomic/migrate/clients.clj +++ b/src/clj/auto_ap/datomic/migrate/clients.clj @@ -1,4 +1,35 @@ -(ns auto-ap.datomic.migrate.clients) +(ns auto-ap.datomic.migrate.clients + (:require [datomic.api :as d])) + +(defn migrate-bank-account-numeric-codes [conn] + (let [existing-accounts (->> (d/query {:query {:find ['?c '?t2 '?e] + :in ['$] + :where ['[?c :client/bank-accounts ?e] + '[?e :bank-account/type ?t] + '[?t :db/ident ?t2] + '(not [?e :bank-account/numeric-code])]} + :args [(d/db conn)]}) + (group-by (fn [[client type]] + [client type])) + (map second) + (mapcat (fn [account-set] + (map (fn [[_ type bank-account] idx] + [bank-account (+ (condp = type + :bank-account-type/check 11300 + :bank-account-type/cash 11100 + :bank-account-type/credit 20100) + 1 + idx)]) + account-set (range)) + )) + (mapv (fn [[bank-account numeric-code]] + {:db/id bank-account + :bank-account/numeric-code numeric-code})) + + )] + [existing-accounts]) + ) + (def norms-map {::add-bank-account-start-date {:txes [[{:db/ident :bank-account/start-date :db/doc "Setting this date prevents older transactions from being imported" @@ -10,4 +41,15 @@ :db/doc "A precomputed balance for the account" :db/valueType :db.type/double :db/cardinality :db.cardinality/one - :db/noHistory true}]]}}) + :db/noHistory true}]]} + + ::add-bank-account-numeric-codes + {:txes [[{:db/ident :bank-account/numeric-code + :db/doc "The numeric code for the balance sheet" + :db/valueType :db.type/long + :db/cardinality :db.cardinality/one}]]} + + ::migrate-bank-account-numeric-codes + {:txes-fn `migrate-bank-account-numeric-codes + :requires [::add-bank-account-current-balance + ::add-bank-account-numeric-codes]}}) diff --git a/src/clj/auto_ap/graphql.clj b/src/clj/auto_ap/graphql.clj index e8e25129..9db774da 100644 --- a/src/clj/auto_ap/graphql.clj +++ b/src/clj/auto_ap/graphql.clj @@ -130,6 +130,7 @@ :type {:type :ident} :start_date {:type :iso_date} :number {:type 'String} + :numeric_code {:type 'Int} :sort_order {:type 'Int} :visible {:type 'Boolean} :include_in_reports {:type 'Boolean} @@ -771,6 +772,7 @@ :start_date {:type :iso_date} :number {:type 'String} :check_number {:type 'Int} + :numeric_code {:type 'Int} :visible {:type 'Boolean} :include_in_reports {:type 'Boolean} :sort_order {:type 'Int} diff --git a/src/clj/auto_ap/graphql/clients.clj b/src/clj/auto_ap/graphql/clients.clj index 5d8024e5..be2ccfc4 100644 --- a/src/clj/auto_ap/graphql/clients.clj +++ b/src/clj/auto_ap/graphql/clients.clj @@ -98,6 +98,7 @@ :bank-account/visible (:visible %) :bank-account/number (:number %) :bank-account/check-number (:check_number %) + :bank-account/numeric-code (:numeric_code %) :bank-account/sort-order (:sort_order %) :bank-account/locations (:locations %) diff --git a/src/clj/auto_ap/graphql/ledger.clj b/src/clj/auto_ap/graphql/ledger.clj index 4f5d3f1d..e48a6da6 100644 --- a/src/clj/auto_ap/graphql/ledger.clj +++ b/src/clj/auto_ap/graphql/ledger.clj @@ -119,7 +119,7 @@ :where ['[?e :account/name]]} :args [(d/db (d/connect uri) )]}))) - bank-accounts (by :db/id (map first (d/query {:query {:find ['(pull ?e [:db/id :bank-account/name {:bank-account/type [:db/ident]}])] + bank-accounts (by :db/id (map first (d/query {:query {:find ['(pull ?e [:db/id :bank-account/name :bank-account/numeric-code {:bank-account/type [:db/ident]}])] :in ['$] :where ['[?e :bank-account/name]]} :args [(d/db (d/connect uri))]}))) @@ -142,10 +142,7 @@ :bank-account-type/credit :account-type/liability} (:db/ident (:bank-account/type (bank-accounts a))))) :numeric_code (or (:account/numeric-code (accounts a)) - (and (#{:bank-account-type/check :bank-account-type/cash} (:db/ident (:bank-account/type (bank-accounts a)))) - 11100) - (and (#{:bank-account-type/credit} (:db/ident (:bank-account/type (bank-accounts a)))) - 28000))}))) + (:bank-account/numeric-code (bank-accounts a)))}))) (defn full-ledger-for-client [client-id] (->> (d/query diff --git a/src/cljs/auto_ap/events.cljs b/src/cljs/auto_ap/events.cljs index 1105474a..0524f4e1 100644 --- a/src/cljs/auto_ap/events.cljs +++ b/src/cljs/auto_ap/events.cljs @@ -33,7 +33,7 @@ (defn client-query [token] (cond-> [:id :name :signature-file :code :email :matches :week-a-debits :week-a-credits :week-b-debits :week-b-credits :locations [:location-matches [:id :location :match]] - [:bank-accounts [:id :start-date :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id + [:bank-accounts [:id :start-date :numeric-code :code :number :bank-name :bank-code :check-number :name :routing :type :sort-order :visible :yodlee-account-id [:yodlee-account [:name :id :number]] :locations :include-in-reports :current-balance :yodlee-balance-old] ] [:address [:street1 :street2 :city :state :zip]] diff --git a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs index 8dcddf2d..fa2b9935 100644 --- a/src/cljs/auto_ap/views/pages/admin/clients/form.cljs +++ b/src/cljs/auto_ap/views/pages/admin/clients/form.cljs @@ -127,11 +127,13 @@ :identifier identifier :amount amount}) (:forecasted-transactions new-client-data)) - :bank-accounts (map (fn [{:keys [number name check-number include-in-reports type id code start-date bank-name routing bank-code new? sort-order visible yodlee-account-id locations yodlee-account]}] + :bank-accounts (map (fn [{:keys [number name check-number include-in-reports type id code numeric-code start-date bank-name routing bank-code new? sort-order visible yodlee-account-id locations yodlee-account]}] {:number number :name name :check-number (when-not (str/blank? check-number) (js/parseInt check-number)) + :numeric-code (when-not (str/blank? check-number) + (js/parseInt numeric-code)) :include-in-reports include-in-reports :start-date (cond (not start-date) nil @@ -327,10 +329,18 @@ :spec ::entity/code}]]]] [:div.field [:p.control code]])] + + [field "Nickname" [:input.input {:placeholder "BOA Checking #1" :type "text" :field [:bank-accounts sort-order :name]}]] + [horizontal-field + nil + [field "Numeric Code (for finiancials)" + [:input.input {:placeholder "20101" + :type "text" + :field [:bank-accounts sort-order :numeric-code]}]]] [field "Start date" [date-picker {:class-name "input" :class "input" @@ -381,6 +391,7 @@ :entity->text (fn [m] (str (:name m) " - " (:number m))) :type "typeahead-v3" :field [:bank-accounts sort-order :yodlee-account]}]]]) + (when (#{:credit ":credit"} type ) [:div @@ -392,6 +403,7 @@ [:input.input {:placeholder "Bank of America" :type "text" :field [:bank-accounts sort-order :bank-name]}]]] + [horizontal-field nil diff --git a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs index ac8a717b..b411035e 100644 --- a/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs +++ b/src/cljs/auto_ap/views/pages/ledger/balance_sheet.cljs @@ -76,7 +76,7 @@ ["1500 Property and Equipment" 15000 15999] ["1600 Intangible Assets" 16000 16999] ["1700 Other Assets" 17000 19999]] - :liability [["2000 Accounts Payable" 21000 23999] + :liability [["2000 Accounts Payable" 20100 23999] ["2400 Accrued Expenses" 24000 24999] ["2500 Other Liabilities" 25000 25999] ["2600 Split Accounts" 26000 26999]