Commit ae0cf1e7 authored by phil's avatar phil

discount feature

parent cce80e8c
......@@ -159,16 +159,31 @@
(defn transform-items [evt]
(update evt :items (partial map item/transform)))
(update evt :items (partial map #(item/transform % evt))))
(defn add-net-total [evt]
(defn add-net-total-before-discount [evt]
(->> evt
:items
(map :amount)
(reduce +)
;; TODO: calculate and subtract discount
util/round-currency
(assoc* evt :net-total-before-discount)))
(defn add-discount-amount [evt]
(->> evt
:net-total-before-discount
(* (/ (get evt :discount 0) 100))
util/round-currency
(assoc* evt :discount-amount)))
(defn add-net-total [evt]
(->> evt
:discount-amount
(- (evt :net-total-before-discount))
;; util/round-currency
(assoc* evt :net-total)))
......@@ -309,6 +324,8 @@
add-tax-rate-in
add-tax-rate-out
transform-items
add-net-total-before-discount
add-discount-amount
add-net-total
add-tax-in
add-gross-total
......
......@@ -10,7 +10,6 @@
(s/def ::rate float?)
(s/def ::hours float?)
(s/def ::beneficiary string?)
(s/def ::discount float?)
(s/def ::amount float?)
(s/def ::timesheet (s/and string? #(.endsWith % ".csv")))
......@@ -35,15 +34,13 @@
:opt-un [::hours
::timesheet
::timesheet-data
::discount
::amount]))
;; defaults
(def defaults
{:discount 0})
(def defaults {})
(def ^:private merge-defaults
......@@ -98,24 +95,24 @@
(defn- add-amount [item]
(->> (map item [:rate :hours])
(apply *)
;; TODO: calculate and subtract discount
util/round-currency
(assoc* item :amount)))
(defn- add-amount-with-delcredere [item]
(->> item
:amount
(* 0.9)
(defn- add-amount-with-discount-and-delcredere [item invoice]
(->> (/ (invoice :discount) 100)
(* (item :amount))
(- (item :amount))
(* 0.9) ;; the famous delcredere constant
util/round-currency
(assoc* item :amount-with-delcredere)))
(assoc* item :amount-with-discount-and-delcredere)))
(defn transform [item]
(defn transform [item invoice]
(-> item
merge-defaults
read-timesheet
prepare-timesheet
add-hours
add-amount
add-amount-with-delcredere))
(add-amount-with-discount-and-delcredere invoice)))
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