shows pending balance

This commit is contained in:
2024-09-25 23:34:16 -07:00
parent 85c0e21daf
commit d86492cd8d
6 changed files with 107 additions and 74 deletions

View File

@@ -318,6 +318,7 @@
(defprotocol ImportBatch
(import-transaction! [this transaction])
(get-stats [this ])
(get-pending-balance [this])
(finish! [this])
(fail! [this error]))
@@ -333,6 +334,7 @@
:import-batch/error 0
:import-batch/not-ready 0
:import-batch/extant 0})
pending-balance (atom {})
extant-cache (atom (cache/ttl-cache-factory {} :ttl 60000 ))
import-id (get (:tempids @(dc/transact-async conn [{:db/id "import-batch"
:import-batch/date (coerce/to-date (t/now))
@@ -351,6 +353,17 @@
extant (get (swap! extant-cache cache/through-cache (:transaction/bank-account transaction) get-existing)
(:transaction/bank-account transaction))
action (categorize-transaction transaction bank-account extant)]
(try
(when (not= "POSTED" (:transaction/status transaction))
(swap! pending-balance (fn [pb]
(update pb
(:transaction/bank-account transaction)
(fnil + 0.0)
(:transaction/amount transaction)))))
(catch Exception e
(alog/warn ::cant-capture-pending
:error e)))
(swap! stats
#(update % (condp = action
:import :import-batch/imported
@@ -376,6 +389,8 @@
(get-stats [_]
@stats)
(get-pending-balance [_ bank-account]
(get @pending-balance bank-account))
(fail! [_ error]
(alog/error ::cant-complete-import

View File

@@ -71,7 +71,15 @@
:transaction/client [:client/code client-code])))
(alog/info ::finished-import)
(t/finish! import-batch))
(t/finish! import-batch)
(doseq [[yodlee-account bank-account] account-lookup]
(try
@(dc/transact auto-ap.datomic/conn
[{:db/id yodlee-account
:yodlee-account/pending-balance (t/get-pending-balance import-batch bank-account)}])
(catch Exception e
(alog/error ::cant-persist-yodlee-account-pending-balance
:error e)))))
(statsd/event {:title "Yodlee2 import Finished"
:text (pr-str (t/get-stats import-batch))
:priority :low}