Commit f75cb2e9 authored by Alain M. Lafon's avatar Alain M. Lafon

Pairing: Calculate adminshare

parent 5a58331a
......@@ -3,7 +3,8 @@
[easy.util :as util :refer [assoc*]]
[easy.common :as common]
[easy.config :refer [config]]
[easy.transform :refer [transform]]))
[easy.transform :refer [transform]]
[easy.adminshare.account :as account]))
;; spec
......@@ -12,7 +13,7 @@
;; required
(s/def ::type #{"adminshare"})
(s/def ::date util/date?)
;; (s/def ::accounts ...)
(s/def ::accounts (s/coll-of ::account/account))
;; optional
......@@ -21,8 +22,7 @@
(s/def ::event (s/keys :req-un [::type
::date
;;::accounts
])
::accounts]))
;; defaults
......@@ -38,14 +38,27 @@
;; transformer
(defn transform-accounts [evt]
(update evt :accounts (partial map account/transform)))
(defn add-amount [evt]
(let [div #(/ % (-> evt :accounts count))]
(->> evt
:accounts
(map :adminshare-amount)
(reduce +)
div
util/round-currency
(assoc* evt :amount))))
(defmethod transform :adminshare [_ event]
(-> event
(common/validate! ::event)
common/add-iso-date
;; ...
transform-accounts
add-amount
(assoc* :ledger-template
(get-in @config [:templates :ledger :adminshare]))
(common/validate! ::event)))
(ns easy.adminshare.account
(:require [cljs.spec.alpha :as s]
[testdouble.cljs.csv :as csv]
[easy.util :as util :refer [assoc*]]))
(s/def ::payer string?)
(s/def ::amount float?)
(s/def ::adminshare-amount float?)
(s/def ::account (s/keys :req-un [::payer
::amount]
:opt-un [::adminshare-amount]))
(def defaults
{})
;; ------------------------------------------------------------
;; transforms
(def ^:private merge-defaults
(partial merge defaults))
(defn- add-adminshare-amount [account]
(->> account
:amount
(* 0.1)
util/round-currency
(assoc* account :adminshare-amount)))
(defn transform [account]
(-> account
merge-defaults
add-adminshare-amount))
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