feat(transactions): port manual bank-transaction import to SSR #8

Closed
notid wants to merge 133 commits from integreat-add-transaction-manual into master
2 changed files with 16 additions and 21 deletions
Showing only changes of commit e5a2d0bbba - Show all commits

View File

@@ -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.
### Running the Application

View File

@@ -114,27 +114,17 @@
{}
line-items)
total-line-amount (reduce + 0.0 (vals expense-accounts))
accounts (if (zero? total-line-amount)
[]
(vec (for [[account amount] expense-accounts]
(let [ratio (/ amount total-line-amount)
cents (int (Math/round (* ratio abs-total 100)))]
#:invoice-expense-account {:db/id (random-tempid)
:account account
:location (:invoice/location invoice)
:amount (* 0.01 cents)}))))
accounts (mapv
(fn [a]
(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)))
[])]
leftover (- abs-total total-line-amount)
food-cost-account (get-line-account nil)
adjusted-accounts (if (zero? leftover)
expense-accounts
(update expense-accounts food-cost-account (fnil + 0.0) leftover))
accounts (vec (for [[account amount] adjusted-accounts]
#:invoice-expense-account {:db/id (random-tempid)
:account account
:location (:invoice/location invoice)
:amount (with-precision 2
(double (.setScale (bigdec amount) 2 java.math.RoundingMode/HALF_UP)))}))]
(dissoc (assoc invoice :invoice/expense-accounts accounts) :line-items))))
(defn maybe-code-line-items [invoice]