Commit d70af094 authored by Phil Hofmann's avatar Phil Hofmann

Merge branch 'adminshare-event' into 'master'

adminshare event

See merge request 200ok/easy!10
parents a7025fa1 f75cb2e9
(ns easy.adminshare
(:require [cljs.spec.alpha :as s]
[easy.util :as util :refer [assoc*]]
[easy.common :as common]
[easy.config :refer [config]]
[easy.transform :refer [transform]]
[easy.adminshare.account :as account]))
;; spec
;; required
(s/def ::type #{"adminshare"})
(s/def ::date util/date?)
(s/def ::accounts (s/coll-of ::account/account))
;; optional
(s/def ::iso-date (s/and string? common/match-iso-date))
(s/def ::ledger-template (s/and string? common/match-template))
(s/def ::event (s/keys :req-un [::type
::date
::accounts]))
;; defaults
(def defaults
{})
(def merge-defaults
(partial merge defaults))
;; 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))
......@@ -23,7 +23,8 @@
"refund" ;; Rückerstattung
"reconciliation" ;; Ausgleichsbuchung
"salary" ;; Gehalt
"outlay"}) ;; Spesenabrechnung
"outlay" ;; Spesenabrechnung
"adminshare"}) ;; "200ok Sozialfaktor"
(s/def ::date (s/or :date util/date?
......
......@@ -15,6 +15,7 @@
easy.salary
easy.outlay
easy.settlement
easy.adminshare
[easy.common :as common]
[easy.common.invoice-no :as invoice-no]
[clojure.tools.cli :refer [parse-opts]]
......
......@@ -85,10 +85,20 @@
util/round-currency
(assoc* item :amount)))
(defn- add-amount-with-delcredere [item]
(->> item
:amount
(* 0.9)
util/round-currency
(assoc* item :amount-with-delcredere)))
(defn transform [item]
(-> item
merge-defaults
read-timesheet
prepare-timesheet
add-hours
add-amount))
add-amount
add-amount-with-delcredere))
......@@ -101,9 +101,10 @@
(defn assert-invoice! [{:keys [invoice invoice-no] :as evt} context]
(if (and context (not invoice))
(util/warn (str "No invoice for settlement '" invoice-no "'. Abort."))
(util/exit 1))
evt)
(do
(util/warn (str "No invoice for settlement '" invoice-no "'. Abort."))
(util/exit 1))
evt))
;; this can only be infered when invoice has been resolved
......@@ -304,14 +305,17 @@
(defn add-debug [evt]
(assoc* evt :debug (prn-str evt)))
;; `context` can be a map of types and vectors of events
;;
;; `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
(common/validate! ::event)
merge-defaults
lookup-customer
(resolve-invoice (:invoice context))
;; (assert-invoice! context)
(assert-invoice! context)
add-deferral
common/add-iso-date
add-tax-period
......
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