data cleanup, new metrics for data integrity, preventing bad clients that swap bank accounts.
This commit is contained in:
@@ -24,6 +24,9 @@
|
||||
(f updated)))
|
||||
(println "success!"))
|
||||
|
||||
|
||||
|
||||
|
||||
(let [invoices-without-clients (check-fn '[:find ?i
|
||||
:in $
|
||||
:where
|
||||
@@ -78,58 +81,62 @@
|
||||
[?t :invoice-payment/amount]
|
||||
(not [?t :invoice-payment/invoice ])]
|
||||
#(= (count %) 0))
|
||||
banks-without-types (check-fn '[:find ?ba
|
||||
:in $
|
||||
:where [?ba :bank-account/name]
|
||||
(not [?ba :bank-account/type])]
|
||||
#(= (count %) 0))
|
||||
|
||||
transaction
|
||||
(->> [[:db/retractEntity [:client/code "CBC"]]]
|
||||
(into (map (fn [[i]]
|
||||
[:db/retractEntity i])
|
||||
(d/q '[:find ?i
|
||||
:in $
|
||||
:where (or [?i :invoice/client [:client/code "CBC"]]
|
||||
[?i :vendor-usage/client [:client/code "CBC"]]
|
||||
[?i :transaction/client [:client/code "CBC"]]
|
||||
[?i :payment/client [:client/code "CBC"]]
|
||||
[?i :transaction-rule/client [:client/code "CBC"]]
|
||||
[?i :journal-entry/client [:client/code "CBC"]]
|
||||
[?i :user/clients [:client/code "CBC"]])]
|
||||
(d/db c))))
|
||||
(into (map (fn [[i]]
|
||||
[:db/retractEntity i])
|
||||
(d/q '[:find ?ip
|
||||
:in $
|
||||
:where [?i :invoice/client [:client/code "CBC"]]
|
||||
[?ip :invoice-payment/invoice ?i]]
|
||||
(d/db c)))))]
|
||||
transaction fix-transaction
|
||||
]
|
||||
|
||||
(check-transaction [invoices-without-clients transactions-without-clients
|
||||
account-overide-without-clients vendor-schedule-payment-dom
|
||||
payments-without-clients vendor-usage-without-client
|
||||
journal-entries-without-client userless-users
|
||||
invoice-payments-without-invoices]
|
||||
invoice-payments-without-invoices banks-without-types]
|
||||
transaction)
|
||||
(auto-ap.datomic/audit-transact-batch transaction {:user/role "admin"
|
||||
:user/name "Removing CBC"}))
|
||||
)
|
||||
|
||||
(clojure.pprint/pprint (get-idents))
|
||||
(get-schema "invoice-payment")
|
||||
(def fix-transaction
|
||||
(d/transact c (into [{:db/id "datomic.tx"
|
||||
:db/doc "Fixing issue with a transaction that was adjusting bank accounts"}]
|
||||
(->>
|
||||
(d/pull (d/db c) '[*] 17592250556002)
|
||||
:transaction/accounts
|
||||
(group-by #(dissoc % :db/id))
|
||||
(vals)
|
||||
(mapcat rest)
|
||||
(map :db/id)
|
||||
(map (fn [to-delete]
|
||||
[:db/retractEntity to-delete]))
|
||||
))))
|
||||
|
||||
|
||||
|
||||
(d/q '[:find ?n
|
||||
:in $
|
||||
:where [_ ?a 17592186046483]
|
||||
[?a :db/ident ?n]]
|
||||
(d/db c))
|
||||
|
||||
(->> (d/q '[:find ?ip
|
||||
:in $
|
||||
:where [?ip :invoice-payment/amount]
|
||||
(not [?ip :invoice-payment/invoice])
|
||||
#_(not [?ip :invoice-payment/payment])]
|
||||
(d/db c))
|
||||
(map (fn [[ip]]
|
||||
[:db/retractEntity ip]))
|
||||
(into [{:db/id "datomic.tx" :db/doc "Removing payments that were disconnected from invoices"}])
|
||||
(d/transact c)
|
||||
deref
|
||||
)
|
||||
|
||||
|
||||
|
||||
(comment
|
||||
(defn delete-client []
|
||||
(->> [[:db/retractEntity [:client/code "NGGL"]]]
|
||||
(into (map (fn [[i]]
|
||||
[:db/retractEntity i])
|
||||
(d/q '[:find ?i
|
||||
:in $
|
||||
:where (or [?i :invoice/client [:client/code "NGGL"]]
|
||||
[?i :vendor-usage/client [:client/code "NGGL"]]
|
||||
[?i :transaction/client [:client/code "NGGL"]]
|
||||
[?i :payment/client [:client/code "NGGL"]]
|
||||
[?i :transaction-rule/client [:client/code "NGGL"]]
|
||||
[?i :journal-entry/client [:client/code "NGGL"]]
|
||||
[?i :user/clients [:client/code "NGGL"]])]
|
||||
(d/db c))))
|
||||
(into (map (fn [[i]]
|
||||
[:db/retractEntity i])
|
||||
(d/q '[:find ?ip
|
||||
:in $
|
||||
:where [?i :invoice/client [:client/code "NGGL"]]
|
||||
[?ip :invoice-payment/invoice ?i]]
|
||||
(d/db c)))))))
|
||||
|
||||
Reference in New Issue
Block a user