reverts behavior if the totals don't match.
This commit is contained in:
@@ -67,6 +67,11 @@
|
|||||||
io/reader
|
io/reader
|
||||||
csv/read-csv))
|
csv/read-csv))
|
||||||
|
|
||||||
|
(defn check-okay-amount? [i]
|
||||||
|
(dollars=
|
||||||
|
(:invoice/total i)
|
||||||
|
(reduce + 0.0 (map :invoice-expense-account/amount (:invoice/expense-accounts i)))))
|
||||||
|
|
||||||
(defn code-individual-items [invoice csv-rows tax]
|
(defn code-individual-items [invoice csv-rows tax]
|
||||||
(let [items (->> csv-rows
|
(let [items (->> csv-rows
|
||||||
butlast
|
butlast
|
||||||
@@ -81,14 +86,18 @@
|
|||||||
)
|
)
|
||||||
items-with-tax (update items (get-line-account "TAX")
|
items-with-tax (update items (get-line-account "TAX")
|
||||||
(fnil + 0.0)
|
(fnil + 0.0)
|
||||||
tax)]
|
tax)
|
||||||
|
updated-invoice (assoc invoice :invoice/expense-accounts
|
||||||
(assoc invoice :invoice/expense-accounts
|
|
||||||
(for [[account amount] items-with-tax]
|
(for [[account amount] items-with-tax]
|
||||||
#:invoice-expense-account {:db/id (random-tempid)
|
#:invoice-expense-account {:db/id (random-tempid)
|
||||||
:account account
|
:account account
|
||||||
:location (:invoice/location invoice)
|
:location (:invoice/location invoice)
|
||||||
:amount amount}))))
|
:amount amount}))]
|
||||||
|
(if (check-okay-amount? updated-invoice)
|
||||||
|
updated-invoice
|
||||||
|
(do (alog/warn ::itemized-expenses-not-adding-up
|
||||||
|
:invoice updated-invoice)
|
||||||
|
invoice))))
|
||||||
|
|
||||||
(defn extract-invoice-details [csv-rows sysco-vendor]
|
(defn extract-invoice-details [csv-rows sysco-vendor]
|
||||||
(let [[header-row & csv-rows] csv-rows
|
(let [[header-row & csv-rows] csv-rows
|
||||||
@@ -177,20 +186,17 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defn check-okay-amount? [i]
|
|
||||||
(dollars=
|
|
||||||
(:invoice/total i)
|
|
||||||
(reduce + 0.0 (map :invoice-expense-account/amount (:invoice/expense-accounts i)))))
|
|
||||||
|
|
||||||
(comment
|
(comment
|
||||||
(with-bindings { #'bucket-name "data.prod.app.integreatconsult.com"}
|
(with-bindings { #'bucket-name "data.prod.app.integreatconsult.com"}
|
||||||
(doall
|
(doall
|
||||||
(for [n (range 800 940 )
|
(for [n (range 930 940 )
|
||||||
:let [result (-> (get-test-invoice-file n)
|
:let [result (-> (get-test-invoice-file n)
|
||||||
read-sysco-csv
|
read-sysco-csv
|
||||||
(extract-invoice-details (get-sysco-vendor))
|
(extract-invoice-details (get-sysco-vendor))
|
||||||
)]
|
)]
|
||||||
:when (not (check-okay-amount? result))]
|
#_#_:when (not (check-okay-amount? result))]
|
||||||
|
|
||||||
result)))
|
result)))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user