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

@@ -31,7 +31,6 @@
(auto-ap.datomic/pull-attr (dc/db conn) :db/id [:bank-account/code "VS-BA6149"])
(p/get-transactions "access-production-1aee2c7d-0a57-403d-83dc-28a252fb92b4" "jZrAPpjMoLU55oZdpPVVuk8D7XVjXnuv1EJy6" (clj-time.coerce/to-date-time #inst "2024-05-01") (clj-time.coerce/to-date-time #inst "2024-05-15"))
(user/init-repl)
@@ -76,5 +75,12 @@
(import-plaid-int-2)
{:transaction/bank-account 17592234448533, :transaction/date #inst "2024-05-14T07:00:00.000-00:00", :transaction/client 17592234448526, :transaction/status "POSTED", :transaction/plaid-merchant {:plaid-merchant/name "Integreat Restau", :db/id "99cb3ac3-1326-4090-8e36-721a0db3a7cf"}, :db/id "89d4fb46-bb17-436f-b1f9-505bfd67e3ec", :transaction/id "0c56701d74584f800b19b1ce6c7b15212b420626a0d0d28761bab4fec4e10ee8", :transaction/description-original "INTEGREAT RESTAU DES:ACH ID:408-340-3111 INDN:PALA UMBERTO CO ID:XXXXX03620 CCD", :transaction/amount -275.0, :transaction/raw-id "drKydaj39qUPPaR0DQyyHVrD4zb8XBIyxe9QJ"}
(auto-ap.datomic/pull-attr (dc/db conn) :db/id [:bank-account/code "NGGG-CB"])
(auto-ap.datomic/pull-attr (dc/db conn) :db/id [:bank-account/code "SCCB-2888CB"])
(dc/q '[:find (pull ?pa [{ :plaid-item/_accounts [*]}])
:in $ ?ba
:where [?ba :bank-account/plaid-account ?pa]]
(dc/db conn)
[:bank-account/code "SCCB-2888CB"])
(user/init-repl)
(p/get-transactions "access-production-bbd2330c-af72-4dd4-b3e1-afdca396b3d5" "bYEM58wRZRsJzyr5D6DkTE0nMyjdmPHDrkLAz" (clj-time.coerce/to-date-time #inst "2024-09-01") (clj-time.coerce/to-date-time #inst "2024-09-25"))

View File

@@ -1,7 +1,63 @@
(in-ns 'auto-ap.yodlee.core2)
(map :postDate (get-specific-transactions "NGGG" 17203328))
(get-specific-transactions "SCCB" 14356804)
(get-transactions "SCCB")
(get-accounts "SCCB")
(user/init-repl)
(let [start
(->> (get-specific-transactions "SCCB" 20130531)
(reduce
(fn [acc tx]
(-> acc
(update-in [(:postDate tx) :amount] (fnil + 0.0) (:amount (:amount tx)))
(update-in [(:postDate tx) :count] (fnil inc 0))))
{}))
final (reduce
(fn [acc [id a c]]
(-> acc
(assoc-in [id :iol-amount] a)
(assoc-in [id :iol-count] c)))
start
(dc/q '[:find ?id (sum ?a2) (count ?tx)
:in $ ?ba
:where [?tx :transaction/bank-account ?ba]
[?tx :transaction/date ?d]
[(>= ?d #inst "2024-08-26")]
[(iol-ion.query/iso-date ?d) ?id]
[?tx :transaction/amount ?a]
[(Math/abs ?a) ?a2]]
(dc/db conn)
[:bank-account/code "SCCB-USB9598"]))]
(filter
(fn [x]
(not (auto-ap.utils/dollars= (or (:amount x) 0.0)
(or (:iol-amount x) 0.0)
)))
(vals final)))
(map (juxt (comp :amount :amount) :postDate :status)
)
(- 264112 (reduce + 0.0 (map first [
[4538.11 "2024-09-25" "POSTED"]
[3129.85 "2024-09-25" "POSTED"]
[4782.11 "2024-09-25" "POSTED"]
[28380.29 "2024-09-25" "POSTED"]
[10000.0 "2024-09-25" "POSTED"]
[2352.82 "2024-09-25" "PENDING"]
[1012.18 "2024-09-25" "PENDING"]
[30996.0 "2024-09-24" "POSTED"]
[275.0 "2024-09-24" "POSTED"]
[7353.78 "2024-09-24" "POSTED"]
])))
(->> (dc/q '[:find ?ba (count ?ya)
:in $

View File

@@ -701,4 +701,55 @@
1
(init-repl)
(seq (dc/q '[:find ?v ?vn
:in $ ?vn
:where [?v :vendor/name ?vn]]
(dc/history (dc/db conn))
"Golden Brands San Jose"))
(sort (dc/q '[:find ?d2 ?in
:in $ ?v
:where [$ ?i :invoice/vendor ?v ?tx true]
[?i :invoice/date ?d]
[(iol-ion.query/iso-date ?d) ?d2]
[?i :invoice/invoice-number ?in] ]
(dc/history (dc/db conn))
17592332212252))
(dc/q '[:find (sample 3 ?d) (count ?d)
:in $
:where [?d :journal-entry-line/dirty false]
[?d :journal-entry-line/account]
]
(dc/db conn))
(let [[[count debit credit]]
(dc/q '[:find (count ?d) (sum ?debit) (sum ?credit)
:in $ ?ba
:where
#_[?a :account/numeric-code "11309"]
[?d :journal-entry-line/account ?ba]
[(get-else $ ?d :journal-entry-line/debit 0.0) ?debit]
[(get-else $ ?d :journal-entry-line/credit 0.0) ?credit]]
(dc/db conn)
[:bank-account/code "SCCB-USB9598"])]
(- debit credit))
(let [ db (dc/db conn)
account-needing-rebuild
{:client [:client/code "SCCB" ]
:account (auto-ap.datomic/pull-id db [:bank-account/code "SCCB-USB9598"])
:starting-at #inst "2000-01-01"
:location "A"}
lookup (auto-ap.ledger/build-account-lookup (:client account-needing-rebuild))]
[lookup (-> account-needing-rebuild
(assoc :build-from (auto-ap.ledger/find-running-balance-start account-needing-rebuild db))
(assoc :dirty-entries (auto-ap.ledger/get-dirty-entries account-needing-rebuild db))
(assoc :account-type (:account_type ((auto-ap.ledger/build-account-lookup (:client account-needing-rebuild)) (:account account-needing-rebuild))))
(auto-ap.ledger/compute-running-balance))])