Adds ability for bank accounts to have numeric accounts

This commit is contained in:
2021-09-03 07:12:23 -07:00
parent e661c03206
commit e9c22d2279
9 changed files with 68 additions and 16 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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]}})

View File

@@ -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}

View File

@@ -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 %)

View File

@@ -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

View File

@@ -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]]

View File

@@ -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

View File

@@ -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]