Commit 18926d02 authored by phil's avatar phil

for settlement take tax rates from invoice and for coverage compare gross instead of net

parent 2de66e6a
......@@ -53,9 +53,12 @@
(defn add-period
"The period is when the vat is due."
[evt]
(let [date (-> evt :date)
year (.getFullYear date)
([evt] (add-period evt [:date]))
([evt date-path]
(if-let [date (get-in evt date-path)]
(let [year (.getFullYear date)
semester (if (< (.getMonth date) 6) 1 2)
period (str year "-H" semester)]
(assoc* evt :period period)))
(assoc* evt :period period))
;; no date found, in context of a nested transform, that's ok
evt)))
......@@ -102,7 +102,7 @@
evt
(->> context
(filter #(= invoice-no (:invoice-no %)))
first
first ;; TODO: assert-exactly-one
(safe-transform nil)
(assoc* evt :invoice))))
......@@ -123,26 +123,16 @@
evt))
(defn add-tax-rate-in [evt]
(->> (tax/lookup-rate :vat-tax-rate-in evt)
(assoc* evt :tax-rate-in)))
(defn add-tax-rate-out [evt]
(->> (tax/lookup-rate :vat-tax-rate-out evt)
(assoc* evt :tax-rate-out)))
(defn add-tax-in [evt]
(->> (:net-total evt)
(* (:tax-rate-in evt))
(* (-> evt :invoice :tax-rate-in))
util/round-currency
(assoc* evt :tax-in)))
(defn add-tax-out [evt]
(->> (:net-total evt)
(* (:tax-rate-out evt))
(* (-> evt :invoice :tax-rate-out))
util/round-currency
(assoc* evt :tax-out)))
......@@ -240,13 +230,15 @@
;; this can only be calculated if invoice is already resolved
(defn add-coverage [evt]
(if (:invoice evt)
(let [settlement-total (:net-total evt)
invoice-total (->> evt :invoice :net-total)
coverage (/ settlement-total invoice-total)]
(let [settlement-total (:amount evt) ;; gross-total
invoice-total (-> evt :invoice :gross-total)
coverage (/ settlement-total invoice-total)
tolerance (-> @config :coverage-tolerance)]
(if (and (not (common/ignore-warning? evt :coverage))
(or (< coverage 0.98)
(> coverage 1.02)))
(util/warn (str "Coverage " coverage " on settlement for " (:invoice-no evt) " " (-> evt :invoice :description))))
(or (< coverage (- 1 tolerance))
(> coverage (+ 1 tolerance))))
(util/warn (str "Coverage " coverage " on settlement for "
(:invoice-no evt) " " (-> evt :invoice :description))))
(assoc* evt :coverage coverage))
evt))
......@@ -290,8 +282,6 @@
add-deferral
common/add-iso-date
tax/add-period
add-tax-rate-in
add-tax-rate-out
transform-items
add-net-total
add-coverage
......
......@@ -28,7 +28,8 @@
(defn safe-transform [ctx evt]
(if (-> @config :options :options :debug)
(prn (str "TRANSFORM " (:type evt))))
(println (str "------------------------------" "TRANSFORM " (:type evt) "\n"
(util/indent (util/write-yaml evt) 2))))
(try
(transform ctx evt)
(catch :default e
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment