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