updating chart of accounts.

This commit is contained in:
Bryce Covert
2020-05-01 06:38:04 -07:00
parent 98db75e329
commit e162f06c75
2 changed files with 371 additions and 336 deletions

View File

@@ -49,8 +49,7 @@
:transaction/approval-status :transaction-approval-status/excluded}))
(partition-all 100))]
@(d/transact conn p)
(println "process 100"))))
@(d/transact conn p) (println "process 100"))))
(defn unapprove-all []
(let [conn (d/connect uri)]
@@ -81,21 +80,23 @@
:args [(d/db conn)]})))
also-merge-txes (fn [also-merge old-account-id]
(let [[sunset-account]
(first (d/query {:query {:find ['?a ]
:in ['$ '?ac ]
:where ['[?a :account/numeric-code ?ac]]}
:args [(d/db conn) also-merge ]}))]
(into (mapv
(fn [[entity id sunset-account]]
[:db/add entity id old-account-id])
(d/query {:query {:find ['?e '?id '?a ]
:in ['$ '?ac ]
:where ['[?a :account/numeric-code ?ac]
'[?e ?at ?a]
'[?at :db/ident ?id]]}
:args [(d/db conn) also-merge ]}))
[[:db/retractEntity sunset-account]])))
(if old-account-id
(let [[sunset-account]
(first (d/query {:query {:find ['?a ]
:in ['$ '?ac ]
:where ['[?a :account/numeric-code ?ac]]}
:args [(d/db conn) also-merge ]}))]
(into (mapv
(fn [[entity id sunset-account]]
[:db/add entity id old-account-id])
(d/query {:query {:find ['?e '?id '?a ]
:in ['$ '?ac ]
:where ['[?a :account/numeric-code ?ac]
'[?e ?at ?a]
'[?at :db/ident ?id]]}
:args [(d/db conn) also-merge ]}))
[[:db/retractEntity sunset-account]]))
[]))
txes (transduce
(comp
@@ -130,6 +131,7 @@
(mapcat (fn ->tx [{:keys [old-account-id new-account-number name location also-merge account-type applicability]}]
(let [tx [(cond-> {:account/name name
:account/type account-type
:account/account-set "default"
:account/applicability applicability
:account/numeric-code new-account-number}
old-account-id (assoc :db/id old-account-id)
@@ -144,5 +146,42 @@
conj
[]
rows)]
@(d/transact conn txes))
@(d/transact conn txes)))
(defn find-bad-accounts []
(set (map second (d/query {:query {:find ['(pull ?x [*]) '?z]
:in ['$]
:where ['[?e :account/numeric-code ?z]
'[(<= ?z 9999)]
'[?x ?a ?e]]}
:args [(d/db (d/connect uri))]}))))
(defn delete-4-digit-accounts []
@(d/transact (d/connect uri)
(transduce
(comp
(map first)
(map (fn [old-account-id]
[:db/retractEntity old-account-id])))
conj
[]
(d/query {:query {:find ['?e]
:in ['$]
:where ['[?e :account/numeric-code ?z]
'[(<= ?z 9999)]]}
:args [(d/db (d/connect uri))]})))
)
(defn find-conflicting-accounts []
(filter
(fn [[k v]]
(> (count v) 1))
(reduce
(fn [acc [e z]]
(update acc z conj e))
{}
(d/query {:query {:find ['?e '?z]
:in ['$]
:where ['[?e :account/numeric-code ?z]]}
:args [(d/db (d/connect uri))]}))))