Simplify sysco line item allocation: use actual amounts, default unmatched to food cost (50000)
This commit is contained in:
@@ -20,6 +20,11 @@ clj-nrepl-eval -p PORT "(+ 1 2 3)" # evaluate clojure code
|
|||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Editing clojure
|
||||||
|
|
||||||
|
When editing clojure, use the clojure-mcp editing tools, or ask @clojure-author to make the change. It is critical that you
|
||||||
|
do not use the file editing tools unless absolutely necessary.
|
||||||
|
|
||||||
Often times, if a file won't compile, first clj-paren-repair on the file, then try again. If it doesn't wor still, try cljfmt check.
|
Often times, if a file won't compile, first clj-paren-repair on the file, then try again. If it doesn't wor still, try cljfmt check.
|
||||||
|
|
||||||
### Running the Application
|
### Running the Application
|
||||||
|
|||||||
@@ -114,27 +114,17 @@
|
|||||||
{}
|
{}
|
||||||
line-items)
|
line-items)
|
||||||
total-line-amount (reduce + 0.0 (vals expense-accounts))
|
total-line-amount (reduce + 0.0 (vals expense-accounts))
|
||||||
accounts (if (zero? total-line-amount)
|
leftover (- abs-total total-line-amount)
|
||||||
[]
|
food-cost-account (get-line-account nil)
|
||||||
(vec (for [[account amount] expense-accounts]
|
adjusted-accounts (if (zero? leftover)
|
||||||
(let [ratio (/ amount total-line-amount)
|
expense-accounts
|
||||||
cents (int (Math/round (* ratio abs-total 100)))]
|
(update expense-accounts food-cost-account (fnil + 0.0) leftover))
|
||||||
#:invoice-expense-account {:db/id (random-tempid)
|
accounts (vec (for [[account amount] adjusted-accounts]
|
||||||
:account account
|
#:invoice-expense-account {:db/id (random-tempid)
|
||||||
:location (:invoice/location invoice)
|
:account account
|
||||||
:amount (* 0.01 cents)}))))
|
:location (:invoice/location invoice)
|
||||||
accounts (mapv
|
:amount (with-precision 2
|
||||||
(fn [a]
|
(double (.setScale (bigdec amount) 2 java.math.RoundingMode/HALF_UP)))}))]
|
||||||
(update a :invoice-expense-account/amount
|
|
||||||
#(with-precision 2
|
|
||||||
(double (.setScale (bigdec %) 2 java.math.RoundingMode/HALF_UP)))))
|
|
||||||
accounts)
|
|
||||||
leftover (with-precision 2 (.round (bigdec (- abs-total
|
|
||||||
(reduce + 0.0 (map :invoice-expense-account/amount accounts))))
|
|
||||||
*math-context*))
|
|
||||||
accounts (if (seq accounts)
|
|
||||||
(update-in accounts [(dec (count accounts)) :invoice-expense-account/amount] #(+ % (double leftover)))
|
|
||||||
[])]
|
|
||||||
(dissoc (assoc invoice :invoice/expense-accounts accounts) :line-items))))
|
(dissoc (assoc invoice :invoice/expense-accounts accounts) :line-items))))
|
||||||
|
|
||||||
(defn maybe-code-line-items [invoice]
|
(defn maybe-code-line-items [invoice]
|
||||||
|
|||||||
Reference in New Issue
Block a user