Improves balance sheet, starts moving it to new layout

This commit is contained in:
2024-10-11 20:36:23 -07:00
parent d41837db83
commit 427f50fb6b
9 changed files with 212 additions and 1194 deletions

View File

@@ -164,23 +164,59 @@
(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)])
(defn account-sets [db client-id]
(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)]
[current-client current-account current-location]))) ]
(->> running-balance-set
(sort-by (fn [{id :e [_ _ _ current-date] :v}]
[current-date id])))))
(defn account-snapshot [db client-id end]
(for [running-balance-set (account-sets db client-id)
:let [{id :e [client-id account-id location date _ _ current-balance] :v}
(->> running-balance-set
(take-while (fn [{id :e [_ _ _ current-date] :v}]
(<= (.compareTo current-date end) 0)))
last)]
:when id]
[client-id account-id location date current-balance]))
(defn detailed-account-snapshot [db client-id end]
(for [running-balance-set (account-sets db client-id)
:let [{:keys [account-id client-id location current-balance debits credits count]}
(->> running-balance-set
(take-while (fn [{id :e [_ _ _ current-date] :v}]
(<= (.compareTo current-date end) 0)))
(reduce
(fn [acc {id :e [current-client current-account current-location current-date debit credit balance] :v}]
(-> acc
(update :count inc)
(update :debits + (or debit 0.0))
(update :credits + (or credit 0.0))
(assoc :current-balance balance
:account-id current-account
:client-id current-client
:location current-location)))
{:count 0
:debits 0.0
:credits 0.0
:current-balance 0.0}))]
:when client-id]
[client-id account-id location debits credits current-balance count]))
(comment
#_(account-snapshot (dc/db auto-ap.datomic/conn)
(detailed-account-snapshot (dc/db auto-ap.datomic/conn)
(auto-ap.datomic/pull-id (dc/db auto-ap.datomic/conn)
[:client/code "NGOP"])
#inst "2024-01-01")
(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")