Commit 22827567 authored by phil's avatar phil

adminshare event

parent a7025fa1
(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]]))
;; spec
;; required
(s/def ::type #{"adminshare"})
(s/def ::date util/date?)
;; (s/def ::accounts ...)
;; 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
(defmethod transform :adminshare [_ event]
(-> event
(common/validate! ::event)
common/add-iso-date
;; ...
(assoc* :ledger-template
(get-in @config [:templates :ledger :adminshare]))
(common/validate! ::event)))
......@@ -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