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