visible for payment added back

This commit is contained in:
2024-03-06 08:18:15 -08:00
parent b40b2e5086
commit e5426d4b25
3 changed files with 174 additions and 16 deletions

View File

@@ -29,19 +29,19 @@
amount)
date (atime/parse date "YYYY-MM-dd")]
#:transaction
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
:id (di/sha-256 (str id))
:db/id (random-tempid)
:raw-id (str id)
:account-id account-id
:date (if use-date-instead-of-post-date?
(coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
(coerce/to-date date))
:amount (double amount)
:description-original (some-> description-original (str/replace #"\s+" " "))
:description-simple (some-> description-simple (str/replace #"\s+" " "))
:type type
:status status}))
{:post-date (coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
:id (di/sha-256 (str id))
:db/id (random-tempid)
:raw-id (str id)
:account-id account-id
:date (if use-date-instead-of-post-date?
(coerce/to-date (atime/parse post-date "YYYY-MM-dd"))
(coerce/to-date date))
:amount (double amount)
:description-original (some-> description-original (str/replace #"\s+" " "))
:description-simple (some-> description-simple (str/replace #"\s+" " "))
:type type
:status status}))
(defn import-yodlee2-int []
(statsd/event {:title "Yodlee2 import started"
@@ -64,6 +64,8 @@
:let [_ (alog/info ::getting-transactions-for :code client-code)]
transaction (wrap-integration #(client2/get-specific-transactions client-code yodlee-account)
bank-account)]
(alog/info ::importing-single-transaction)
(t/import-transaction! import-batch (assoc (yodlee->transaction transaction use-date-instead-of-post-date?)
:transaction/bank-account bank-account
:transaction/client [:client/code client-code])))
@@ -88,4 +90,3 @@
(def import-yodlee2 (allow-once import-yodlee2-int))

View File

@@ -92,6 +92,7 @@
:bank-account/numeric-code
:bank-account/name
:bank-account/include-in-reports
:bank-account/visible
:bank-account/number
:bank-account/bank-code
:bank-account/sort-order
@@ -264,6 +265,10 @@
[:boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]
[:bank-account/visible {:default false}
[:boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]
[:bank-account/use-date-instead-of-post-date? {:default false}
[:boolean {:decode/string {:enter #(if (= % "on") true
@@ -335,6 +340,10 @@
[:boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]
[:bank-account/visible {:default false}
[:boolean {:decode/string {:enter #(if (= % "on") true
(boolean %))}}]]
[:bank-account/use-date-instead-of-post-date? {:default false}
[:boolean {:decode/string {:enter #(if (= % "on") true
@@ -803,7 +812,13 @@
(com/checkbox {:name (fc/field-name)
:value (boolean (fc/field-value))
:checked (fc/field-value)}
"Include in reports"))])
"Include in reports"))
[:div
(fc/with-field :bank-account/visible
(com/checkbox {:name (fc/field-name)
:value (boolean (fc/field-value))
:checked (fc/field-value)}
"Visible for payment"))]])
@@ -941,6 +956,13 @@
:checked (fc/field-value)}
"Include in reports"))
[:div
(fc/with-field :bank-account/visible
(com/checkbox {:name (fc/field-name)
:value (boolean (fc/field-value))
:checked (fc/field-value)}
"Visible for payment"))]
[:h2.text-lg "Bank details"]
(fc/with-field :bank-account/bank-name
(com/validated-field {:errors (fc/field-errors)
@@ -1034,6 +1056,13 @@
:checked (fc/field-value)}
"Include in reports"))
[:div
(fc/with-field :bank-account/visible
(com/checkbox {:name (fc/field-name)
:value (boolean (fc/field-value))
:checked (fc/field-value)}
"Visible for payment"))]
[:h2.text-lg "Bank details"]
(fc/with-field :bank-account/bank-name
(com/validated-field {:errors (fc/field-errors)
@@ -1292,7 +1321,8 @@
{:db/id (str (java.util.UUID/randomUUID))
:new? true}
bank-account-type (assoc :bank-account/type (keyword "bank-account-type" bank-account-type)))))
bank-account-type (assoc :bank-account/type (keyword "bank-account-type" bank-account-type)
:bank-account/visible true))))
mm/Discardable
(can-discard? [_ step-params]

View File

@@ -199,3 +199,130 @@
(println ba)
[(-> ba :client/_bank-accounts :client/code) (:bank-account/code ba) (:bank-account/name ba)]))
(#(clojure.data.csv/write-csv *out* % :separator \tab))))
(comment
(init-repl)
(entity-history 17592317777728)
(entity-history-with-revert 17592310252806)
(sort (dc/q '[:find ?d ?tx
:in $ $$
:where [?v :vendor/plaid-merchant _]
(not [?v :vendor/name])
[$$ ?v :vendor/plaid-merchant _ ?tx true]
[?tx :db/txInstant ?d]]
(dc/db conn)
(dc/history (dc/db conn))))
(map (juxt :e (fn [d] (auto-ap.datomic/pull-attr (dc/db conn) :db/ident (:a d))) :v)
(:data (first (dc/tx-range (dc/log conn)
13194263741698
13194263741699))))
@(dc/transact conn
(->>
(dc/q '[:find ?v
:where [?v :vendor/plaid-merchant _]
(not [?v :vendor/name])]
(dc/db conn))
(map (fn [[v]]
[:db/retractEntity v])))))
(comment
(->> (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) 17592232545948)
(sort-by last) ;; sort by scheduled payment date
(group-by first) ;; group by vendors
vals
count))
(comment
(init-repl)
(defn delete-transactions [all-ids]
(let [db (dc/db conn)]
(auto-ap.logging/info ::bulk-delete-transactions
:count (count all-ids)
:sample (take 3 all-ids))
(auto-ap.datomic/audit-transact-batch
(mapcat (fn [i]
(let [transaction (dc/pull db [:transaction/payment
:transaction/expected-deposit
:db/id] i)
payment-id (-> transaction :transaction/payment :db/id)
expected-deposit-id (-> transaction :transaction/expected-deposit :db/id)]
(cond->> [[:db/retractEntity [:journal-entry/original-entity i]]]
payment-id (into [{:db/id payment-id
:payment/status :payment-status/pending}
[:db/retract (:db/id transaction) :transaction/payment payment-id]])
expected-deposit-id (into [{:db/id expected-deposit-id
:expected-deposit/status :expected-deposit-status/pending}
[:db/retract (:db/id transaction) :transaction/expected-deposit expected-deposit-id]]))))
all-ids)
{:user/name "Cleaning up bad transactions that are duplicates"})
(auto-ap.datomic/audit-transact-batch
(mapcat (fn [i]
(let [transaction-tx [:db/retractEntity i]]
[transaction-tx
[:db/retractEntity [:journal-entry/original-entity i]]]))
all-ids)
{:user/name "Cleaning up bad transactions that are duplicates"})
{:message (str "Succesfully deleted " (count all-ids) " transactions.")}))
(def bank-accounts (dc/q '[:find ?ba ?ya
:where [?ba :bank-account/yodlee-account ?ya]
[?ba :bank-account/plaid-account]]
(dc/db conn)))
(def bank-accounts (dc/q '[:find ?ba
:in $ [?client-code ...]
:where [?c :client/code ?client-code]
[?c :client/bank-accounts ?ba]]
(dc/db conn)
[ "SKPL" "NGFT" "NGFN" "NGLM"]))
(let [yodlee-accounts (->> bank-accounts
(map (fn [[ba ya]]
[:db/retract ba :bank-account/yodlee-account ya])))
bad-transactions (->> (dc/q '[:find ?t
:in $ [?ba ...]
:where [(ground #inst "2024-01-25") ?start-date]
[?ib :import-batch/source :import-source/yodlee2]
[?ib :import-batch/date ?d]
[(>= ?d ?start-date)]
[?ib :import-batch/entry ?t]
[?t :transaction/bank-account ?ba]]
(dc/db conn)
(map first bank-accounts)
#_[[:bank-account/code "NGFN-CB6375"]])
(map first))]
(delete-transactions bad-transactions)
#_(count bad-transactions))
#_(seq (dc/tx-range (dc/log conn) #inst "2024-02-28T19:25:00-08:00"
#inst "2024-02-29T19:35:00-08:00"))
#_(dc/pull (dc/db conn) [:transaction/payment
:transaction/expected-deposit
:db/id] 17592317964222)
#_(dc/pull (dc/db conn) '[*] 17592302069146)
@(dc/transact conn [{:bank-account/code "NGKG-AMEX81007" :bank-account/visible true}])
)