Commit 13f96dcd authored by phil's avatar phil

cleanup

parent abc55acc
......@@ -6,6 +6,9 @@
[cljs-time.format :as time]))
;; spec
(def match-iso-date (partial re-matches #"^\d{4}-\d\d-\d\d$"))
(def match-template (partial re-matches #".*\.hbs"))
......@@ -34,7 +37,7 @@
(s/def ::events (s/coll-of ::event))
;; transformer
;; helpers
(defn harmonize-date-field [field evt]
......@@ -67,6 +70,9 @@
(util/validate! spec x))
;; transformers
(defn add-iso-date
"Transformer that takes the value of `:date`, builds an iso-date
string from it and assoc's it as `:iso-date`."
......
......@@ -3,8 +3,10 @@
[cljs.spec.alpha :as s]
[easy.util :as util]))
;; spec
(def match-invoice-no (partial re-matches #"^\d+\.\d+\.\d+$"))
(s/def ::invoice-no (s/and string? match-invoice-no))
......@@ -18,7 +20,9 @@
::number
::version])))
;; transform
;; transformers
(defn- add-invoice-no
"Compile `invoice-no` from invoice details like `customer-id`,
......
......@@ -30,7 +30,7 @@
easy.redistribution))
;; commands
;; (sub-)commands
(defn ledger!
......
......@@ -30,17 +30,18 @@
[easy.config :refer [config]]))
;; spec
;; NOTE: minimum 3 maximum 10 characters is a sensible limits for
;; customers' shortnames
(def match-shortname (partial re-matches #"[a-z]{3,10}"))
;; spec - required
(s/def ::year pos-int?) ;; when they became a customer
(s/def ::number pos-int?) ;; a unique customer number
(s/def ::address string?) ;; multiline postal address
(s/def ::shortname (s/and string? match-shortname))
;; spec - optional
(s/def ::discount (s/and float? #(>= % 0) #(< % 100))) ;; a general discount in percentage
(s/def ::contact string?)
(s/def ::rate float?) ;; the default hourly rate for a given customer
......
......@@ -17,14 +17,15 @@
[easy.transform :refer [transform]]))
;; spec - required
;; spec
(s/def ::type #{"expense"})
(s/def ::date util/date?)
(s/def ::account string?)
(s/def ::payer string?)
(s/def ::amount float?)
;; spec - optional
(s/def ::description string?)
(s/def ::ledger-template (s/and string? common/match-template))
......@@ -64,8 +65,8 @@
(assoc* evt :respect-tax-amount)))
(defmethod transform :expense [_ event]
(-> event
(defmethod transform :expense [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
add-respect-tax-rate
......
......@@ -32,15 +32,16 @@
[cljs-time.format :as time]))
;; spec
(def match-invoice-no (partial re-matches #"^\d+\.\d+\.\d+$"))
(def match-period (partial re-matches #"^\d{4}-(H|Q)\d$"))
;; spec - required
(s/def ::type #{"invoice"})
(s/def ::date util/date?)
(s/def ::items (s/coll-of ::item/item))
;; spec - optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::deadline pos-int?) ;; in days
(s/def ::header string?)
......@@ -108,12 +109,12 @@
;; TODO: add pre conditions to all functions
(defn- lookup-customer [{id :customer-id :as event}]
(defn- lookup-customer [{id :customer-id :as evt}]
(->> @config
:customers
(filter #(= id (:number %)))
first
(assoc* event :customer)))
(assoc* evt :customer)))
(defn- resolve-settlement [{:keys [invoice-no] :as evt} ctx]
......@@ -281,8 +282,8 @@
))
(defmethod transform :invoice [context event]
(-> event
(defmethod transform :invoice [context evt]
(-> evt
(common/validate! ::event)
merge-defaults
lookup-customer
......
......@@ -20,12 +20,13 @@
[easy.opening.items :as items]))
;; spec - required
;; spec
(s/def ::type #{"opening"})
(s/def ::date util/date?) ;; TODO: opening should always be on 1st of January
(s/def ::items (s/coll-of ::items/item))
;; spec - optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-template (s/and string? common/match-template))
......@@ -46,11 +47,11 @@
(partial merge defaults))
;; transformer
;; transformers
(defmethod transform :opening [_ event]
(-> event
(defmethod transform :opening [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-template
......
(ns easy.opening.items
(:require [cljs.spec.alpha :as s]))
;; spec
(s/def ::account string?)
(s/def ::amount float?)
(s/def ::item (s/keys :req-un [::account
::amount]))
;; defaults
(def defaults
{})
(def merge-defaults
(partial merge defaults))
......@@ -15,13 +15,14 @@
[easy.transform :refer [transform]]))
;; spec - required
;; spec
(s/def ::type #{"outlay"})
(s/def ::date util/date?)
(s/def ::amount float?)
(s/def ::beneficiary string?)
;; spec - optional
(s/def ::description string?)
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-state #{"*"})
......@@ -47,8 +48,8 @@
;; transformers
(defmethod transform :outlay [_ event]
(-> event
(defmethod transform :outlay [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-state "*") ;; always cleared
......
......@@ -2,9 +2,9 @@
(:require [easy.config :refer [config]]))
(defn- unsettled-invoice [event]
(and (= "revenue" (:type event))
(nil? (:settled event))))
(defn- unsettled-invoice [evt]
(and (= "revenue" (:type evt))
(nil? (:settled evt))))
;;(defn- accumulate-debt [customer event]
......
......@@ -17,14 +17,15 @@
[easy.transform :refer [transform]]))
;; spec - required
;; spec
(s/def ::type #{"plain"})
(s/def ::date util/date?)
(s/def ::source string?)
(s/def ::target string?)
(s/def ::amount float?)
;; spec - optional
(s/def ::description string?)
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-template (s/and string? common/match-template))
......@@ -53,8 +54,8 @@
;; transformers
(defmethod transform :plain [_ event]
(-> event
(defmethod transform :plain [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-template
......
......@@ -17,13 +17,14 @@
[easy.transform :refer [transform]]))
;; spec - required
;; spec
(s/def ::type #{"reconciliation"})
(s/def ::date util/date?)
(s/def ::amount float?)
(s/def ::account string?)
;; spec - optional
(s/def ::description string?)
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-state #{"*"})
......@@ -46,11 +47,11 @@
(partial merge defaults))
;; transformer
;; transformers
(defmethod transform :reconciliation [_ event]
(-> event
(defmethod transform :reconciliation [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-state "*") ;; always cleared
......
......@@ -17,12 +17,13 @@
[easy.redistribution.account :as account]))
;; spec - required
;; spec
(s/def ::type #{"redistribution"})
(s/def ::date util/date?)
(s/def ::accounts (s/coll-of ::account/account))
;; spec - optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-template (s/and string? common/match-template))
......
......@@ -3,11 +3,12 @@
[easy.util :as util :refer [assoc*]]))
;; spec - required
;; spec
(s/def ::payer string?)
(s/def ::amount float?)
;; spec - optional
(s/def ::redistribution-factor float?)
(s/def ::redistribution-amount float?)
......
......@@ -14,13 +14,14 @@
[easy.transform :refer [transform]]))
;; spec - required
;; spec
(s/def ::type #{"refund"})
(s/def ::date util/date?)
(s/def ::amount float?)
(s/def ::beneficiary string?)
;; spec - optional
(s/def ::description string?)
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-state #{"*"})
......@@ -39,15 +40,16 @@
(def defaults
{})
(def merge-defaults
(partial merge defaults))
;; transformer
;; transformers
(defmethod transform :refund [_ event]
(-> event
(defmethod transform :refund [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-state "*") ;; always cleared
......
......@@ -8,12 +8,13 @@
[easy.salary.items :as items]))
;; spec - required
;; spec
(s/def ::type #{"salary"})
(s/def ::date util/date?)
(s/def ::items (s/coll-of ::items/item))
;; spec - optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-template (s/and string? common/match-template))
......@@ -34,11 +35,11 @@
(partial merge defaults))
;; transformer
;; transformers
(defmethod transform :salary [_ event]
(-> event
(defmethod transform :salary [_ evt]
(-> evt
(common/validate! ::event)
common/add-iso-date
(assoc* :ledger-template
......
(ns easy.salary.items
(:require [cljs.spec.alpha :as s]))
;; spec
(s/def ::beneficiary string?)
(s/def ::amount float?)
(s/def ::item (s/keys :req-un [::beneficiary
::amount]))
;; defaults
(def defaults
{})
......
......@@ -23,15 +23,16 @@
[cljs-time.format :as time]))
;; spec
(def match-period (partial re-matches #"^\d{4}-(H|Q)\d$"))
;; spec - required
(s/def ::type #{"settlement"})
(s/def ::date util/date?)
(s/def ::amount float?) ;; this should be equal to the invoice's gross-total
(s/def ::items (s/coll-of ::item/item))
;; spec - optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::tax-rate-in float?)
(s/def ::tax-rate-out float?)
......@@ -272,8 +273,8 @@
;;
;; `context` can also be nil, this is the case if the event is
;; transformed while being resolved for another event
(defmethod transform :settlement [context event]
(-> event
(defmethod transform :settlement [context evt]
(-> evt
(common/validate! ::event)
merge-defaults
lookup-customer
......
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