tweaks
This commit is contained in:
@@ -23,8 +23,58 @@
|
||||
;; :type "credit"})
|
||||
|
||||
|
||||
(dc/q '[:find (pull ?pa [{ :plaid-item/_accounts [*]}])
|
||||
:in $ ?ba
|
||||
:where [?ba :bank-account/plaid-account ?pa]]
|
||||
(dc/db conn)
|
||||
[:bank-account/code "VS-BA6149"])
|
||||
|
||||
(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)
|
||||
|
||||
|
||||
|
||||
(defn import-plaid-int-2 []
|
||||
(let [
|
||||
import-batch (t/start-import-batch :import-source/plaid "Automated plaid user")
|
||||
end (atime/local-now)
|
||||
start (time/plus end (time/days -30))
|
||||
plaid-merchant->vendor-id (build-plaid-merchant->vendor-id)]
|
||||
(try
|
||||
(doseq [[bank-account-id client-id external-id access-token] (get-plaid-accounts (dc/db conn))
|
||||
:when (= bank-account-id 17592234448533)
|
||||
|
||||
:let [_ (println "TRYING INTEGRATION")
|
||||
transaction-result (wrap-integration #(p/get-transactions access-token external-id start end)
|
||||
bank-account-id)
|
||||
_ (println "FOUND" (count (:transactions transaction-result)))
|
||||
accounts-by-id (by :account_id (:accounts transaction-result))]
|
||||
transaction (:transactions transaction-result)]
|
||||
(when (not (:pending transaction))
|
||||
(t/import-transaction! import-batch (doto (assoc (plaid->transaction (assoc transaction
|
||||
:account
|
||||
(accounts-by-id (:account_id transaction)))
|
||||
plaid-merchant->vendor-id)
|
||||
:transaction/bank-account bank-account-id
|
||||
:transaction/client client-id)
|
||||
(#(println (:transaction/date %)))))))
|
||||
(try
|
||||
(rebuild-search-index)
|
||||
(catch Exception e
|
||||
(alog/error ::cant-index-plaid
|
||||
:error e)
|
||||
(println "CANT INDEX")))
|
||||
(t/finish! import-batch)
|
||||
(println "DONE")
|
||||
(catch Exception e
|
||||
(println "FAIL")
|
||||
(t/fail! import-batch e)))))
|
||||
|
||||
(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"])
|
||||
|
||||
@@ -85,35 +85,40 @@
|
||||
(alog/info ::searching-unpaid-invoice
|
||||
:client-id client-id
|
||||
:amount amount)
|
||||
(let [candidate-invoices-vendor-groups (->> (dc/q {:find ['?vendor-id '?e '?outstanding-balance '?d]
|
||||
:in ['$ '?client-id]
|
||||
:where ['[?e :invoice/client ?client-id]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'(not [_ :invoice-payment/invoice ?e])
|
||||
'[?e :invoice/vendor ?vendor-id]
|
||||
'[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
'[?e :invoice/date ?d]]}
|
||||
(dc/db conn) client-id)
|
||||
(sort-by last) ;; sort by scheduled payment date
|
||||
(group-by first) ;; group by vendors
|
||||
vals)
|
||||
considerations (for [candidate-invoices candidate-invoices-vendor-groups
|
||||
invoice-count (range 1 32)
|
||||
consideration (partition invoice-count 1 candidate-invoices)
|
||||
:when (dollars= (reduce (fn [acc [_ _ amount]]
|
||||
(+ acc amount)) 0.0 consideration)
|
||||
(- amount))]
|
||||
consideration)]
|
||||
(alog/info ::unpaid-invoice-considerations-found
|
||||
:client-id client-id
|
||||
:amount amount
|
||||
:count (count considerations))
|
||||
considerations))
|
||||
(try
|
||||
(let [candidate-invoices-vendor-groups (->> (dc/q {:find ['?vendor-id '?e '?outstanding-balance '?d]
|
||||
:in ['$ '?client-id]
|
||||
:where ['[?e :invoice/client ?client-id]
|
||||
'[?e :invoice/status :invoice-status/unpaid]
|
||||
'(not [_ :invoice-payment/invoice ?e])
|
||||
'[?e :invoice/vendor ?vendor-id]
|
||||
'[?e :invoice/outstanding-balance ?outstanding-balance]
|
||||
'[?e :invoice/date ?d]]}
|
||||
(dc/db conn) client-id)
|
||||
(sort-by last) ;; sort by scheduled payment date
|
||||
(group-by first) ;; group by vendors
|
||||
vals)
|
||||
considerations (for [candidate-invoices candidate-invoices-vendor-groups
|
||||
invoice-count (range 1 32)
|
||||
consideration (partition invoice-count 1 candidate-invoices)
|
||||
:when (dollars= (reduce (fn [acc [_ _ amount]]
|
||||
(+ acc amount)) 0.0 consideration)
|
||||
(- amount))]
|
||||
consideration)]
|
||||
(alog/info ::unpaid-invoice-considerations-found
|
||||
:client-id client-id
|
||||
:amount amount
|
||||
:count (count considerations))
|
||||
considerations)
|
||||
(catch Exception e
|
||||
(alog/error ::cant-get-considerations
|
||||
:error e)
|
||||
[])))
|
||||
|
||||
(defn match-transaction-to-single-unfulfilled-autopayments [amount client-id]
|
||||
(let [considerations (match-transaction-to-unfulfilled-autopayments amount client-id)]
|
||||
(if (= 1 (count considerations))
|
||||
(first considerations)
|
||||
(first considerations) ()
|
||||
[])))
|
||||
|
||||
(defn add-new-payment [transaction [[vendor] :as invoice-payments] bank-account-id client-id]
|
||||
|
||||
@@ -90,7 +90,8 @@
|
||||
"access_token" access-token
|
||||
"start_date" (atime/unparse start atime/iso-date)
|
||||
"end_date" (atime/unparse end atime/iso-date)
|
||||
"options" {"account_ids" [account-id]}})})
|
||||
"options" {"account_ids" [account-id]
|
||||
"count" 500}})})
|
||||
:body))
|
||||
|
||||
(comment
|
||||
|
||||
22
src/clj/auto_ap/yodlee/core2.fiddle
Normal file
22
src/clj/auto_ap/yodlee/core2.fiddle
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
(in-ns 'auto-ap.yodlee.core2)
|
||||
|
||||
(map :postDate (get-specific-transactions "NGGG" 17203328))
|
||||
|
||||
(->> (dc/q '[:find ?ba (count ?ya)
|
||||
:in $
|
||||
:where [?ba :bank-account/yodlee-account ?ya]
|
||||
]
|
||||
(dc/db conn))
|
||||
(filter (comp #(> % 1) second)))
|
||||
|
||||
(dc/q '[:find ?ya ?ba ?cd ?ud
|
||||
:in $ ?cd
|
||||
:where
|
||||
[?ba :bank-account/yodlee-account ?y]
|
||||
[(get-else $ ?ba :bank-account/use-date-instead-of-post-date? false) ?ud]
|
||||
[?c :client/bank-accounts ?ba]
|
||||
[?c :client/code ?cd]
|
||||
[?y :yodlee-account/id ?ya]]
|
||||
(dc/db conn)
|
||||
"NGGG")
|
||||
@@ -448,3 +448,23 @@
|
||||
|
||||
|
||||
)
|
||||
|
||||
(dc/q '[:find ?ba (pull ?pa [* {:bank-account/_plaid-account [:db/id { :bank-account/integration-status [*]}]
|
||||
}])
|
||||
:in $ ?ba
|
||||
:where [?ba :bank-account/plaid-account ?pa]]
|
||||
(dc/db conn)
|
||||
[:bank-account/code "VS-BA6149"])
|
||||
|
||||
(init-repl)
|
||||
|
||||
(filter (fn [[_ x]]
|
||||
(> x 1))
|
||||
(dc/q '[:find ?pa (count ?ba)
|
||||
:where [?ba :bank-account/plaid-account ?pa]]
|
||||
(dc/db conn)))
|
||||
|
||||
|
||||
(dc/pull (dc/db conn) '[* {:bank-account/_plaid-account [:bank-account/code]}] 17592310327452)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user