Matches checks based on amount
This commit is contained in:
@@ -9,13 +9,27 @@
|
||||
|
||||
|
||||
|
||||
(defn transaction->check-id [_ check-number company-id bank-account-id]
|
||||
(when check-number
|
||||
(-> (checks/get-graphql {:company-id company-id
|
||||
:bank-account-id bank-account-id
|
||||
:check-number check-number})
|
||||
first
|
||||
:id)))
|
||||
(defn transaction->check-id [_ check-number company-id bank-account-id amount]
|
||||
(cond (and check-number company-id bank-account-id)
|
||||
(-> (checks/get-graphql {:company-id company-id
|
||||
:bank-account-id bank-account-id
|
||||
:check-number check-number
|
||||
:status "pending"})
|
||||
first
|
||||
:id)
|
||||
|
||||
(and company-id bank-account-id amount)
|
||||
|
||||
(let [matching-checks (checks/get-graphql {:company-id company-id
|
||||
:bank-account-id bank-account-id
|
||||
:amount amount
|
||||
:status "pending"})]
|
||||
(if (= 1 (count matching-checks))
|
||||
(:id (first matching-checks))
|
||||
nil))
|
||||
|
||||
:else
|
||||
nil))
|
||||
|
||||
(defn extract-check-number [{{description-original :original} :description}]
|
||||
(if-let [[_ check-number] (re-find #"(?i)check[^0-9]+([0-9]*)" description-original)]
|
||||
@@ -34,9 +48,6 @@
|
||||
(companies/get-all))
|
||||
account->company (by :yodlee-account-id :company-id all-bank-accounts)
|
||||
yodlee-account-id->bank-account-id (by :yodlee-account-id :bank-account-id all-bank-accounts)]
|
||||
(println "importing " (count transactions) "transactions")
|
||||
(println "yodlee account->company" account->company)
|
||||
(println "yodlee account->bank-account-id" yodlee-account-id->bank-account-id)
|
||||
(doseq [transaction transactions
|
||||
:let [{post-date :postDate
|
||||
account-id :accountId
|
||||
@@ -53,7 +64,7 @@
|
||||
check-number (extract-check-number transaction)
|
||||
company-id (account->company account-id)
|
||||
bank-account-id (yodlee-account-id->bank-account-id account-id)
|
||||
check-id (transaction->check-id transaction check-number company-id bank-account-id)
|
||||
check-id (transaction->check-id transaction check-number company-id bank-account-id amount)
|
||||
]]
|
||||
|
||||
(try
|
||||
@@ -77,3 +88,21 @@
|
||||
|
||||
(catch Exception e
|
||||
(println e))))))
|
||||
|
||||
#_(defn match-old-checks []
|
||||
(let [transactions (transactions/get-unmatched)]
|
||||
(doseq [transaction transactions]
|
||||
(when-let (transaction->check-id transaction
|
||||
(:check-number transaction)
|
||||
(:company-id transaction)
|
||||
(:band-account-id transaction)
|
||||
(:amount transaction))
|
||||
(transactions/upsert!
|
||||
{:id id
|
||||
:check-id check-id})
|
||||
(when check-id
|
||||
(checks/update! {:id check-id :status "cleared"}))
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user