Adds ability to query for snapshots

This commit is contained in:
2024-10-02 09:28:05 -07:00
parent 41167a24a7
commit cf81e3999c
5 changed files with 145 additions and 5 deletions

View File

@@ -163,3 +163,30 @@
(defn ident [x]
(:db/ident x))
(defn account-snapshot [db client-id end]
(for [ running-balance-set (->> (dc/index-range db :journal-entry-line/running-balance-tuple [client-id] [(inc client-id)])
(seq)
(partition-by (fn [{[current-client current-account current-location current-date debit credit running-balance]
:v}]
[current-client current-account current-location])))
:let [{id :e [client-id account-id location date _ _ current-balance] :v} (->> running-balance-set
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
[current-date id]))
(take-while (fn [{id :e [_ _ _ current-date] :v}]
(<= (.compareTo current-date end) 0)))
last)]
:when id]
[client-id account-id location date current-balance]))
#_(account-snapshot (dc/db auto-ap.datomic/conn)
(auto-ap.datomic/pull-id (dc/db auto-ap.datomic/conn)
[:client/code "NGOP"])
#inst "2022-01-01")
#_(seq (dc/q '[:find ?c ?a ?l ?date ?balance
:in $
:where [?c :client/code "NGOP"]
[(iol-ion.query/account-snapshot $ ?c #inst "2023-01-01") [?x ...]]
[(untuple ?x) [_ ?a ?l ?date ?balance]]]
(dc/db auto-ap.datomic/conn)))