shows pending balance
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
{:bank-account/intuit-bank-account [:intuit-bank-account/current-balance
|
||||
[:intuit-bank-account/last-synced :xform clj-time.coerce/from-date]]}
|
||||
{:bank-account/yodlee-account [:yodlee-account/available-balance
|
||||
:yodlee-account/pending-balance
|
||||
[:yodlee-account/last-synced :xform clj-time.coerce/from-date]]}
|
||||
{:bank-account/plaid-account [:plaid-account/balance
|
||||
[:plaid-account/last-synced :xform clj-time.coerce/from-date]]}]}]
|
||||
@@ -71,6 +72,11 @@
|
||||
(-> b :bank-account/yodlee-account :yodlee-account/available-balance)
|
||||
(-> b :bank-account/plaid-account :plaid-account/balance)
|
||||
0.0))]
|
||||
(when-let [pending-balance (-> b :bank-account/yodlee-account :yodlee-account/available-balance)]
|
||||
(list
|
||||
[:div (str n " Pending Balance")]
|
||||
[:div.text-right (format "$%,.2f" pending-balance)]))
|
||||
|
||||
[:div.text-xs.text-gray-400.text-right (or (some-> (:bank-account/intuit-bank-account b)
|
||||
(:intuit-bank-account/last-synced)
|
||||
(atime/unparse-local atime/standard-time)
|
||||
@@ -215,7 +221,6 @@
|
||||
"Income: " (format "$%,.2f" sales)]
|
||||
[:div
|
||||
"Expenses: " (format "$%,.2f" expenses)])))))
|
||||
|
||||
(defn tasks-card [request]
|
||||
(html-response
|
||||
(com/card {:class "w-full h-full p-4"}
|
||||
|
||||
Reference in New Issue
Block a user