fixed errors.

This commit is contained in:
2022-04-06 09:16:02 -07:00
parent 54de896c6c
commit 2dbafd157a
5 changed files with 48 additions and 68 deletions

View File

@@ -10,6 +10,7 @@
[datomic.api :as d]
[mount.core :as mount]
[unilog.context :as lc]
#_{:clj-kondo/ignore [:unused-namespace]}
[yang.scheduler :as scheduler]))
(defn datums->impacted-entity [db [e changes]]
@@ -291,21 +292,20 @@
'[?lia :account/name]
'[?e :transaction/amount ?amt]
'[(not= ?amt 0.0)]]}
:args [(d/db auto-ap.datomic/conn)]}))
]
(filter
(fn [[e accounts]] (not= accounts (get jel-accounts e)))
transaction-accounts)
(filter (fn [[e]]
(let [[tx-date] (d/q '[:find [(max ?d) ...]
:in $ ?t
:where
[?t _ _ ?tx]
[?tx :db/txInstant ?d]]
(d/history (d/db auto-ap.datomic/conn))
e)]
(t/before? (c/to-date-time tx-date)
(t/minus (t/now) (t/hours 1))))))))
:args [(d/db auto-ap.datomic/conn)]}))]
(->> transaction-accounts
(filter
(fn [[e accounts]] (not= accounts (get jel-accounts e))))
(filter (fn [[e]]
(let [[tx-date] (d/q '[:find [(max ?d) ...]
:in $ ?t
:where
[?t _ _ ?tx]
[?tx :db/txInstant ?d]]
(d/history (d/db auto-ap.datomic/conn))
e)]
(t/before? (c/to-date-time tx-date)
(t/minus (t/now) (t/hours 1)))))))))
(defn unbalanced-transactions []
(->> (d/query {:query {:find ['?je '?a '(sum ?debit) '(sum ?credit)]
@@ -398,7 +398,7 @@
(doseq [[m] mismatched-ts]
(touch-transaction m))
(statsd/gauge "data.mismatched_transactions" (count (mismatched-transactions))))
(statsd/gauge "data.mismatched_transactions" 0)))
(statsd/gauge "data.mismatched_transactions" 0.0)))
(log/info "Attempting to fix transactions that are in the ledger but debits/credits don't add up")
(let [unbalanced-ts (unbalanced-transactions)]
(if (seq unbalanced-ts)
@@ -407,7 +407,7 @@
(doseq [m unbalanced-ts]
(touch-transaction m))
(statsd/gauge "data.unbalanced_transactions" (count (unbalanced-transactions))))
(statsd/gauge "data.unbalanced_transactions" 0)))
(statsd/gauge "data.unbalanced_transactions" 0.0)))
(log/info "Finished fixing transactions that are in the ledger but are wrong")
(let [mismatched-is (mismatched-invoices)]
(if (seq mismatched-is)
@@ -416,7 +416,7 @@
(doseq [[m] mismatched-is]
(touch-invoice m))
(statsd/gauge "data.mismatched_invoices" (count (mismatched-invoices))))
(statsd/gauge "data.mismatched_invoices" 0)))
(statsd/gauge "data.mismatched_invoices" 0.0)))
(log/info "Attempting to fix transactions that are in the ledger but debits/credits don't add up")
(let [unbalanced-invoices (unbalanced-invoices)]
(if (seq unbalanced-invoices)
@@ -425,7 +425,7 @@
(doseq [m unbalanced-invoices]
(touch-invoice m))
(statsd/gauge "data.unbalanced_invoices" (count (unbalanced-invoices))))
(statsd/gauge "data.unbalanced_invoices" 0)))
(statsd/gauge "data.unbalanced_invoices" 0.0)))
(log/info "Finish fixing invoices that are in the ledger but are wrong")
(statsd/event {:title "Finished Reconciling Ledger"