Commit abc55acc authored by phil's avatar phil

cleanup

parent 18926d02
......@@ -3,6 +3,10 @@
[testdouble.cljs.csv :as csv]
[easy.util :as util :refer [assoc*]]))
;; spec
(s/def ::rate float?)
(s/def ::hours float?)
(s/def ::beneficiary string?)
......@@ -10,7 +14,7 @@
(s/def ::amount float?)
(s/def ::timesheet (s/and string? #(.endsWith % ".csv")))
;; TODO Write a spec for timesheet-data. It can look like this, e.g.
;; TODO: Write a spec for timesheet-data. It can look like this, e.g.
;;
;; (["date" "duration" "hashtags" "title" "id\r"]
;; ["2019-01-16" "3" "#sva" "#sva" "4uuu4j65cltg6up20c8jmidul6@google.com\r"]
......@@ -18,13 +22,13 @@
;;
;; (s/def ::timesheet-data
;; TODO Write a spec for timesheet-prepared. It can look like this, e.g.
;; TODO: Write a spec for timesheet-prepared. It can look like this, e.g.
;;
;; [{:date "2019-01-16" :duration "3" :description "#sva"}]
;;
;; (s/def ::timesheet-prepared
;; TODO how do I spec: either hours or timesheet has to be present?
;; TODO: how do I spec: either hours or timesheet has to be present?
(s/def ::item (s/keys :req-un [::rate
::beneficiary]
......@@ -34,15 +38,21 @@
::discount
::amount]))
;; defaults
(def defaults
{:discount 0})
;; ------------------------------------------------------------
;; transforms
(def ^:private merge-defaults
(partial merge defaults))
;; helpers
(defn- read-timesheet [item]
(if-let [timesheet (:timesheet item)]
(->> timesheet
......@@ -51,11 +61,12 @@
(assoc* item :timesheet-data))
item))
(defn- prepare-timesheet [item]
(if-let [data (:timesheet-data item)]
(->> data
(drop 1)
;; TODO refactor these out into a transform-timesheet-entry
;; TODO: refactor these out into a transform-timesheet-entry
(map #(take 4 %))
(map #(interleave [:date :duration :hashtags :description] %))
(map #(apply hash-map %))
......@@ -63,6 +74,7 @@
(assoc* item :timesheet-prepared))
item))
(defn- sum-time [timesheet-data]
(->> timesheet-data
(drop 1) ;; drop header
......@@ -70,6 +82,10 @@
(map js/parseFloat) ;; coerce to float
(reduce +))) ;; sum
;; transformers
(defn- add-hours [item]
(if-let [timesheet-data (:timesheet-data item)]
(let [sum (sum-time timesheet-data)]
......@@ -78,10 +94,11 @@
(assoc* :hours sum))) ;; this might be overridden
item))
(defn- add-amount [item]
(->> (map item [:rate :hours])
(apply *)
;; TODO calculate and subtract discount
;; TODO: calculate and subtract discount
util/round-currency
(assoc* item :amount)))
......
......@@ -3,6 +3,15 @@
[testdouble.cljs.csv :as csv]
[easy.util :as util :refer [assoc*]]))
;; TODO: This file has some code duplication with invoice items. In
;; fact if might not be needed at all! Because settlements get all
;; required "item" details from their associated invoice.
;; spec
(s/def ::rate float?)
(s/def ::hours float?)
(s/def ::beneficiary string?)
......@@ -10,7 +19,7 @@
(s/def ::amount float?)
(s/def ::timesheet (s/and string? #(.endsWith % ".csv")))
;; TODO Write a spec for timesheet-data. It can look like this, e.g.
;; TODO: Write a spec for timesheet-data. It can look like this, e.g.
;;
;; (["date" "duration" "hashtags" "title" "id\r"]
;; ["2019-01-16" "3" "#sva" "#sva" "4uuu4j65cltg6up20c8jmidul6@google.com\r"]
......@@ -18,13 +27,13 @@
;;
;; (s/def ::timesheet-data
;; TODO Write a spec for timesheet-prepared. It can look like this, e.g.
;; TODO: Write a spec for timesheet-prepared. It can look like this, e.g.
;;
;; [{:date "2019-01-16" :duration "3" :description "#sva"}]
;;
;; (s/def ::timesheet-prepared
;; TODO how do I spec: either hours or timesheet has to be present?
;; TODO: how do I spec: either hours or timesheet has to be present?
(s/def ::item (s/keys :req-un [::rate
::beneficiary]
......@@ -34,15 +43,21 @@
::discount
::amount]))
;; defaults
(def defaults
{:discount 0})
;; ------------------------------------------------------------
;; transforms
(def ^:private merge-defaults
(partial merge defaults))
;; helpers
(defn- read-timesheet [item]
(if-let [timesheet (:timesheet item)]
(->> timesheet
......@@ -51,11 +66,12 @@
(assoc* item :timesheet-data))
item))
(defn- prepare-timesheet [item]
(if-let [data (:timesheet-data item)]
(->> data
(drop 1)
;; TODO refactor these out into a transform-timesheet-entry
;; TODO: refactor these out into a transform-timesheet-entry
(map #(take 4 %))
(map #(interleave [:date :duration :hashtags :description] %))
(map #(apply hash-map %))
......@@ -63,6 +79,7 @@
(assoc* item :timesheet-prepared))
item))
(defn- sum-time [timesheet-data]
(->> timesheet-data
(drop 1) ;; drop header
......@@ -70,18 +87,24 @@
(map js/parseFloat) ;; coerce to float
(reduce +))) ;; sum
;; transformers
(defn- add-hours [item]
(if-let [timesheet-data (:timesheet-data item)]
(assoc* item :hours (sum-time timesheet-data))
item))
(defn- add-amount [item]
(->> (map item [:rate :hours])
(apply *)
;; TODO calculate and subtract discount
;; TODO: calculate and subtract discount
util/round-currency
(assoc* item :amount)))
(defn transform [item]
(-> item
merge-defaults
......
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