From 3e4a2b7322b669de8464a383b0fa72b4951e32d3 Mon Sep 17 00:00:00 2001 From: Bryce Date: Fri, 26 Apr 2024 22:42:32 -0700 Subject: [PATCH] prepare dashboard --- src/clj/auto_ap/import/plaid.clj | 27 ++++++++++++++++++++++++++- src/clj/auto_ap/ssr/dashboard.clj | 5 ++++- src/clj/user.fiddle | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/clj/auto_ap/import/plaid.clj b/src/clj/auto_ap/import/plaid.clj index e39646b8..4af3d1a9 100644 --- a/src/clj/auto_ap/import/plaid.clj +++ b/src/clj/auto_ap/import/plaid.clj @@ -14,7 +14,8 @@ [digest :as di] [manifold.deferred :as de] [manifold.executor :as ex] - [clojure.string :as str])) + [clojure.string :as str] + [auto-ap.ezcater.core :as e])) (defn get-plaid-accounts ([db] @@ -84,6 +85,30 @@ {"id" (:db/id result) "name" (:plaid-merchant/name result)})))) +(defn upsert-accounts [] +(try + (doseq [[bank-account-id client-id external-id access-token] (get-plaid-accounts (dc/db conn)) + ] + + (try + (let [accounts (p/get-accounts access-token)] + @(dc/transact + conn + (for [a (:accounts accounts)] + {:plaid-account/external-id (:account_id a) + :plaid-account/balance (or (some-> a + :balances + :current + double) + 0.0) })) + ) + (catch Exception e + (alog/warn ::couldnt-upsert-account :error e)))) + + + (catch Exception e + (alog/warn ::couldnt-upsert-accounts :error e)))) + (defn import-plaid-int [] (let [import-batch (t/start-import-batch :import-source/plaid "Automated plaid user") end (atime/local-now) diff --git a/src/clj/auto_ap/ssr/dashboard.clj b/src/clj/auto_ap/ssr/dashboard.clj index 02d799e5..cb3d3f35 100644 --- a/src/clj/auto_ap/ssr/dashboard.clj +++ b/src/clj/auto_ap/ssr/dashboard.clj @@ -24,7 +24,9 @@ {: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/last-synced :xform clj-time.coerce/from-date]]}]}] + [:yodlee-account/last-synced :xform clj-time.coerce/from-date]]} + {:bank-account/plaid-account [:plaid-account/balance + #_[:yodlee-account/last-synced :xform clj-time.coerce/from-date]]}]}] (:db/id c)))] [:div.flex.flex-col.p-4.border-l-2 [:div (:client/name c)] @@ -35,6 +37,7 @@ (#(str "Synced " %))) ] [:div.inline-flex.justify-between [:div "Source Balance"] (format "$%,.2f" (or (-> b :bank-account/intuit-bank-account :intuit-bank-account/current-balance) (-> b :bank-account/yodlee-account :yodlee-account/available-balance) + (-> b :bank-account/plaid-account :plaid-account/balance) 0.0))] [:div.inline-flex.justify-end.text-xs.text-gray-400.it (or (some-> (:bank-account/intuit-bank-account b) (:intuit-bank-account/last-synced) diff --git a/src/clj/user.fiddle b/src/clj/user.fiddle index 766c1b10..027f9fe2 100644 --- a/src/clj/user.fiddle +++ b/src/clj/user.fiddle @@ -367,3 +367,25 @@ (ffirst (dc/q '[:find ?v :where [?v :vendor/name "CCP Doordash"]] db)))) :separator \tab) + + + +(def taptelis-clients (->> (dc/q '[:find ?c + :where [?u :user/name ?n] + [?u :user/clients ?c] + [?c :client/code ?cc] + [(clojure.string/includes? ?n "Nick Taptelis")]] + (dc/db conn)) + (map first) + set)) + +(clojure.data.csv/write-csv *out* (dc/q '[:find ?v ?cnt + :in $ [?c ...] + :where [?vu :vendor-usage/vendor ?v] + [?vu :vendor-usage/client ?c] + [?vu :vendor-usage/count ?cnt] + [(> ?cnt 0)]] + (dc/db conn) + taptelis-clients) + :separator \tab) +