Matches checks based on amount
This commit is contained in:
@@ -68,12 +68,14 @@
|
|||||||
:else
|
:else
|
||||||
q)))
|
q)))
|
||||||
|
|
||||||
(defn base-graphql [{:keys [company-id vendor-id check-number bank-account-id]}]
|
(defn base-graphql [{:keys [company-id vendor-id check-number bank-account-id status amount]}]
|
||||||
(cond-> base-query
|
(cond-> base-query
|
||||||
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
|
(not (nil? company-id)) (helpers/merge-where [:= :company-id company-id])
|
||||||
(not (nil? bank-account-id)) (helpers/merge-where [:= :bank-account-id bank-account-id])
|
(not (nil? bank-account-id)) (helpers/merge-where [:= :bank-account-id bank-account-id])
|
||||||
(not (nil? vendor-id)) (helpers/merge-where [:= :vendor-id vendor-id])
|
(not (nil? vendor-id)) (helpers/merge-where [:= :vendor-id vendor-id])
|
||||||
(not (nil? check-number)) (helpers/merge-where [:= :check-number check-number])))
|
(not (nil? check-number)) (helpers/merge-where [:= :check-number check-number])
|
||||||
|
(not (nil? status)) (helpers/merge-where [:= :status status])
|
||||||
|
(not (nil? amount)) (helpers/merge-where [:= :amount amount])))
|
||||||
|
|
||||||
(defn get-graphql [{:keys [start sort-by asc] :as args}]
|
(defn get-graphql [{:keys [start sort-by asc] :as args}]
|
||||||
(query
|
(query
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
(sql/format (-> (helpers/insert-into :transactions)
|
(sql/format (-> (helpers/insert-into :transactions)
|
||||||
(helpers/values [row])
|
(helpers/values [row])
|
||||||
(postgres-helpers/upsert (-> (postgres-helpers/on-conflict :id)
|
(postgres-helpers/upsert (-> (postgres-helpers/on-conflict :id)
|
||||||
(postgres-helpers/do-update-set :post_date :status)))))))
|
(postgres-helpers/do-update-set :post_date :status :check_id)))))))
|
||||||
|
|
||||||
(def base-query (sql/build :select :*
|
(def base-query (sql/build :select :*
|
||||||
:from :transactions))
|
:from :transactions))
|
||||||
|
|||||||
@@ -9,13 +9,27 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn transaction->check-id [_ check-number company-id bank-account-id]
|
(defn transaction->check-id [_ check-number company-id bank-account-id amount]
|
||||||
(when check-number
|
(cond (and check-number company-id bank-account-id)
|
||||||
(-> (checks/get-graphql {:company-id company-id
|
(-> (checks/get-graphql {:company-id company-id
|
||||||
:bank-account-id bank-account-id
|
:bank-account-id bank-account-id
|
||||||
:check-number check-number})
|
:check-number check-number
|
||||||
first
|
:status "pending"})
|
||||||
:id)))
|
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}]
|
(defn extract-check-number [{{description-original :original} :description}]
|
||||||
(if-let [[_ check-number] (re-find #"(?i)check[^0-9]+([0-9]*)" description-original)]
|
(if-let [[_ check-number] (re-find #"(?i)check[^0-9]+([0-9]*)" description-original)]
|
||||||
@@ -34,9 +48,6 @@
|
|||||||
(companies/get-all))
|
(companies/get-all))
|
||||||
account->company (by :yodlee-account-id :company-id all-bank-accounts)
|
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)]
|
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
|
(doseq [transaction transactions
|
||||||
:let [{post-date :postDate
|
:let [{post-date :postDate
|
||||||
account-id :accountId
|
account-id :accountId
|
||||||
@@ -53,7 +64,7 @@
|
|||||||
check-number (extract-check-number transaction)
|
check-number (extract-check-number transaction)
|
||||||
company-id (account->company account-id)
|
company-id (account->company account-id)
|
||||||
bank-account-id (yodlee-account-id->bank-account-id 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
|
(try
|
||||||
@@ -77,3 +88,21 @@
|
|||||||
|
|
||||||
(catch Exception e
|
(catch Exception e
|
||||||
(println 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