minor fixes.

This commit is contained in:
Bryce Covert
2020-07-17 12:46:44 -07:00
parent 976cd1e7c3
commit 3737cfa628
6 changed files with 348 additions and 148 deletions

View File

@@ -117,7 +117,7 @@
'[?e2 :transaction/amount ?a2]
'[?e2 :transaction/bank-account ?ba]
'[(auto-ap.utils/dollars= ?a1 ?a2)]
'(not [?e2 :transaction/type])]}
'[?e2 :transaction/type]]}
:args [(d/since (d/db (d/connect uri)) #inst "2020-04-01")]})
vec
(map (fn [[e1 e2]]
@@ -127,23 +127,27 @@
:transaction/date :transaction/id :transaction/amount
:transaction/description-original
:transaction/approval-status
:transaction/type
{:transaction/client [:client/code]}
{:transaction/bank-account [:bank-account/code]}
{:journal-entry/_original-entity ['*]}]
#_{:journal-entry/_original-entity ['*]}]
e1)
(d/pull (d/db (d/connect uri))
[:db/id
:transaction/date :transaction/id :transaction/amount
:transaction/description-original
:transaction/type
:transaction/approval-status
{:transaction/client [:client/code]}
{:transaction/bank-account [:bank-account/code]}
{:journal-entry/_original-entity ['*]}]
#_{:journal-entry/_original-entity ['*]}]
e2)
]))
))
(count matches-to-repair2)
(count (filter #(= "SCSJ" (:client/code (:transaction/client (first %)))) matches-to-repair2))
(sha-256 (str "2020-05-08" "-" "SCSJ-USBMAIN2974" "-" "CHECK-5075" "-" "5000.0" "-" "0" "-" "SCSJ"))
(defn repair-transaction [[t-auto t-manual]]
(into
@@ -158,7 +162,171 @@
(defn map-new-transaction-id [[t-auto t-manual]]
[[:db/add (:db/id t-manual) :transaction/id (:transaction/id t-auto)]])
(map-new-transaction-id (first matches-to-repair))
#_(map-new-transaction-id (first matches-to-repair))
(doseq [t matches-to-repair]
#_(doseq [t matches-to-repair]
@(d/transact (d/connect uri) (map-new-transaction-id t)))
#_(comment
(get-accounts)
(get-provider-accounts)
(update-provider-account 18611904)
(get-provider-account-detail 11194727)
(get-specific-transactions 24370737)
[{"field" [
{"id" "SQandA--QUESTION_1-12370368"
"value" "Oprah"}
{"id" "SQandA--QUESTION_1-12369757"
"value" "Betelgeuse"}] }]
(perform-additional-authentication 18611904 {"loginForm" {"row"
[{"field" [{"id" "SQandA--txtAlphaNum--1"
"value" "Christian"}]}]}})
{"field" [{"id" "SQandA--QUESTION_1-12370368"
"value" "Oprah"}
{"id" "SQandA--QUESTION_1-12369757"
"value" "Betelgeuse"}]}
(json/write-str )
*e
(get-provider-accounts-with-accounts)
(get-provider-account-detail 18611901)
@(d/transact (d/connect uri) (fix-transactions-without-locations "NGE1" "UC"))
(->> (d/query {:query {:find ['?e '?tx '?yai '?d]
:in ['$]
:where ['[?e :bank-account/yodlee-account-id ?yai ?tx true]
'[?tx :db/txInstant ?d]]}
:args [(d/history (d/db (d/connect uri)))]})
(filter (fn [[_ _ y]]
(not= y 0)))
(group-by first)
(filter (fn [[k v]]
(> (count v) 1)))
(map (fn [[k vs]]
(let [[yodlee-id & old] (->> vs
(sort-by second)
(map (fn [[_ _ yodlee-id date]]
[yodlee-id date]))
(reverse))]
[k {:new-yodlee-id yodlee-id
:defunct-yodlee-ids (clojure.set/difference (set old) #{yodlee-id})}])))
(mapv (fn [[bank-account history]]
(d/query {:query {:find '[?t] #_['(pull $2 ?t [*]) '(pull $2 ?t2 [*])]
:in ['$ '$2 '?bank-account '?before]
:where ['[?t :transaction/bank-account ?bank-account]
'[?t :transaction/date ?date]
'[?t :transaction/amount ?tx-amount ?tx true]
'[?tx :db/txInstant ?tx-date]
'[(< ?tx-date ?before)]
'[?t2 :transaction/bank-account ?bank-account]
'[?t2 :transaction/amount ?tx-amount2 ?tx2 true]
'[?tx2 :db/txInstant ?tx2-date]
'[?t2 :transaction/date ?date]
'[(auto-ap.utils/dollars= ?tx-amount ?tx-amount2)]
'[(not= ?t ?t2)]
'[(> ?tx2-date ?before)]
]}
:args [(d/history (d/db (d/connect uri))) (d/db (d/connect uri)) bank-account (second (:new-yodlee-id history))]})))
)
20186866 24265567 24370736
(auto-ap.yodlee.core/get-specific-transactions 24265567)
(def bad-account-ids (->> (d/query {:query {:find ['?e '?tx '?yai '?d]
:in ['$]
:where ['[?e :bank-account/yodlee-account-id ?yai ?tx true]
'[?tx :db/txInstant ?d]]}
:args [(d/history (d/db (d/connect uri)))]})
(filter (fn [[_ _ y]]
(not= y 0)))
(group-by first)
(filter (fn [[k v]]
(> (count v) 1)))
(keys)))
(count
(->> (d/query {:query {:find ['?bank-account '?date '?tx-amount '?tx-account]
:in ['$]
:where ['[?t :transaction/client [:client/code "NGO"]]
'[?t :transaction/bank-account ?bank-account]
'[?t :transaction/date ?date]
'[?t :transaction/amount ?tx-amount ]
'[?t :transaction/account-id ?tx-account ]
]}
:args [(d/db (d/connect uri))]})
(group-by (fn [[ba date amount _]]
[ba date amount]))
(mapv (fn [[k v]]
[k (set (map last v))]))
(filter (fn [[k v]]
(> (count v) 1)))))
;; FINDS TRANSACTIONS THAT COME FROM DIFFERENT YODLEE IDS
(reduce
(fn [acc [k v]]
(update acc k conj v)
)
{}
(mapcat (fn [ba]
(->> (d/query {:query {:find ['?code '?date '?tx-amount '?t '?tx-account ]
:in ['$ '?bank-account]
:where ['[?t :transaction/bank-account ?bank-account]
'[?bank-account :bank-account/code ?code]
'[?t :transaction/date ?date]
'[?t :transaction/amount ?tx-amount ]
'[?t :transaction/account-id ?tx-account ]
'[(>= ?date #inst "2020-01-01")]
]}
:args [(d/db (d/connect uri) ) ba]})
(group-by (fn [[ba date amount _]]
[ba date amount]))
(filter (fn [[k v]]
(> (count (set (map last v))) 1)))
(map second)
(mapcat identity)
(map (fn [[ba _ _ id act]]
[[ba act] id]))
#_(map (fn [[_ []]]))
#_(mapv (fn [[k v]]
[k (reduce
(fn [acc [_ _ _ act id]]
(assoc acc act id ))
{}
v)]))
#_(map second)
))
bad-account-ids))
;; delete
(->> (d/pull-many (d/db (d/connect uri)) '[:db/id {:journal-entry/_original-entity [:db/id]}] '(17592232564344))
(mapcat (fn [x]
[[:db/retractEntity (:db/id x)]
[:db/retractEntity (:db/id (first (:journal-entry/_original-entity x)))]]))
(d/transact (d/connect uri) )
deref))

View File

@@ -58,53 +58,58 @@
(or (:db/ident (:account/type (accounts a)))
({:bank-account-type/check :account-type/asset
:bank-account-type/credit :account-type/liability}
(:db/ident (:bank-account/type (bank-accounts a))))))]
(->> (d/query
{:query {:find ['?d '?jel '?account '?location '?debit '?credit ]
:in ['$ '?client-id]
:where ['[?e :journal-entry/client ?client-id]
'[?e :journal-entry/date ?d]
'[(<= ?d #inst "2020-09-01")]
'[?e :journal-entry/line-items ?jel]
'[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
'[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
'[(get-else $ ?jel :journal-entry-line/location "") ?location]]
}
:args [(d/db (d/connect uri)) client-id]})
(sort-by first)
(:db/ident (:bank-account/type (bank-accounts a))))))
all-ledger-entries (->> (d/query
{:query {:find ['?d '?jel '?account '?location '?debit '?credit ]
:in ['$ '?client-id]
:where ['[?e :journal-entry/client ?client-id]
'[?e :journal-entry/date ?d]
'[(<= ?d #inst "2020-09-01")]
'[?e :journal-entry/line-items ?jel]
'[(get-else $ ?jel :journal-entry-line/account :account/unknown) ?account]
'[(get-else $ ?jel :journal-entry-line/debit 0.0) ?debit]
'[(get-else $ ?jel :journal-entry-line/credit 0.0) ?credit]
'[(get-else $ ?jel :journal-entry-line/location "") ?location]]
}
:args [(d/db (d/connect uri)) client-id]})
(sort-by first))]
(reduce
(fn [acc [_ _ account location debit credit]]
(-> acc
(update-in [[location account] :debit] (fnil + 0.0) debit)
(update-in [[location account] :credit] (fnil + 0.0) credit)
(update-in [[location account] :count] (fnil + 0) 1))
)
{})
(reduce-kv
(fn [acc [location account] {:keys [debit credit count]}]
(let [account-type (account->type account)]
(conj acc {:name (if-not (= "A" location)
(str (account->name account) "-" location)
(account->name account))
:id (str account "-" location)
:numeric_code (account->numeric-code account)
:location (or location "")
:amount (if account-type (if (#{:account-type/asset
:account-type/dividend
:account-type/expense} account-type)
(- debit credit)
(- credit debit)
)
0.0)
:account_type account-type}))
)
(reduce
(fn [acc bracket]
(println (first all-ledger-entries))
(assoc acc bracket (->> all-ledger-entries
(filter (fn [[d]]
(<= (compare d bracket) 0)))
(reduce
(fn [acc [_ _ account location debit credit]]
(-> acc
(update-in [[location account] :debit] (fnil + 0.0) debit)
(update-in [[location account] :credit] (fnil + 0.0) credit)
(update-in [[location account] :count] (fnil + 0) 1))
)
{})
(reduce-kv
(fn [acc [location account] {:keys [debit credit count]}]
(let [account-type (account->type account)]
(conj acc {:name (if-not (= "A" location)
(str (account->name account) "-" location)
(account->name account))
:id (str account "-" location)
:numeric_code (account->numeric-code account)
:location (or location "")
:amount (if account-type (if (#{:account-type/asset
:account-type/dividend
:account-type/expense} account-type)
(- debit credit)
(- credit debit)
)
0.0)
:account_type account-type}))
)
[])
#_(map (juxt :name :count (comp int :amount)))
#_(sort-by first)
))
[]))))
{}
brackets))
)
;; 9804