Commit f07af27f authored by phil's avatar phil

add example and texinputs-feature

parent 266f825f
......@@ -65,14 +65,26 @@ like.
** Install
*** lumo via npm
Easy runs on [[][lumo]] and uses node packages available via [[][npm]], as well as
ClojureScript packages available via [[][clojars]] (maven).
Hence you will need to install the npm dependencies via =npm install=.
*** clojars via Clojure's CLI
ClojureScript dependencies tracked in =deps.edn= are installed via
=clj= (aka. Clojure CLI). Please install =clj= as described [[][here]].
*** Debian packages
To render invcoice via latex you need to have at least the follwoing
packages installed (Debian naming):
- texlive-latex-base
- texlive-latex-recommended
** Usage
Easy provides two command line utilities: =easy= itself and =collect=.
......@@ -86,11 +98,11 @@ the example directory of this repo and to run these examples.
Render ledger entries from events and run the through ledger to create
a balance:
=easy ledger -i example.yml | ledger bal -f -=
=easy ledger -i events/invoices.yml | ledger bal -f -=
Render invoice 18.2.1 to latex:
=easy invoice -i example.yml -n 18.2.1=
=easy invoice -i events/invoices.yml -n 1.1.1=
Sidenote: Easy invoice identifiers (invoice-no) are divided into three
segments ~<customer-id>.<invoice-number>.<version>~. In events thei
......@@ -100,20 +112,20 @@ can be given as =invoice-no= in aggregated form or separately as
Run a transform to see the transformed events, which is handy for
writing templates:
=easy transform -i example.yml=
=easy transform -i events/invoices.yml=
Or, just validate the input and exit:
=easy validate -i example.yml=
=easy validate -i events/invoices.yml=
Easy alternatively takes events via STDIN:
=cat example.yml | easy transform=
=cat events/invoices.yml | easy transform=
This comes in particularly handy, when working with multiple event
sources (i.e. YAML files)
=cat invoices.yml settlements.yml | easy ledger | ledger -f - bal=
=cat events/*.yml | easy ledger | ledger -f - bal=
(Please be ware that concatinating YAML files for easy only works if
the files lack the YAML's document prefix =---=. The reason for this
......@@ -126,9 +138,9 @@ it will find all files matching =*.yml=, load these, annotate each
event with its origin (for locating issues quickly), and outputs a
sorted stream of events.
=collect ./events/ | easy ledger -y 2018=
=collect events | easy ledger -y 2019=
Yes, you guessed it, you can use `-y <year>` to filter events by year.
Yes, you guessed it, you can use =-y <year>= to filter events by year.
** On Frontmatter Templates
customers: customers.yml
coverage-tolerance: 0.02
- rate: 0.077
- rate: 0.08
until: 2017-12-31
- rate: 0.077
since: 2018-01-01
- rate: 0.061
until: 2017-12-31
- rate: 0.059
since: 2018-01-01
invoice: templates/invoice.dat.hbs
settlement: templates/settlement.dat.hbs
overview: templates/overview.txt.hbs
template: templates/report.txt.hbs
template: templates/invoice.tex.hbs
directory: 'customers/{{}}'
filename: '{{iso-date}}_{{replace invoice-no "." "_"}}.tex'
# this is where the .lco files are
texinputs-directory: templates
* Example
The following command should create an invoice (PDF) in
#+BEGIN_SRC shell
../bin/collect events | ../bin/easy invoice -n 1.1.1
And this will show the balance:
#+BEGIN_SRC shell
../bin/collect events | ../bin/easy -y 2019 ledger | ledger -f - bal
# - `name` is used for the path to store files associated with a
# customer.
# - `year` is the year the customer received its first invoice.
# - `number` is a running sequence.
# - `contact` is the primary contact for the given customer
# and is used to select a preset for the invoices.
- name: schaf
year: 2019
number: 1
address: |
Familie Schaf
Auf der grünen Weide 1
54321 Schäferhausen
contact: info
- type: invoice
date: 2019-01-18
description: "Interne Beschreibung"
invoice-no: 1.1.1
- rate: 200.0
hours: 8.0
beneficiary: Coworker1
header: >-
Bitte zahlt bald!
footer: >-
Uns geht das Geld aus.
deadline: 14
- type: settlement
date: 2019-02-18
description: Interne Beschreibung
invoice-no: 1.1.1
amount: 1723.20
; -*- mode: ledger -*-
; «utf8», file: {{ledger-template}}
{{iso-date}} * ({{uuid}}) {{#if deferral}}TA{{/if}} > R-{{invoice-no}} {{description}}
Aktiva:1100-Forderungen-aus-Lieferungen-und-Leistungen {{gross-total}}
{{#if deferral}}
; the invoice is not yet settled, hence we will make temporary
; bookings for profit centers, but we will only book 90% to account
; for "Delkredere"
{{#each items}}
{{../iso-date}} * ({{uuid}}) R-{{../invoice-no}}/{{beneficiary}} ({{hours}}x{{rate}}) prov. 90%
(ProfitCenter:{{beneficiary}}) {{amount-with-delcredere}}
{{iso-date}} * ({{uuid}}) TP R-{{invoice-no}} Verbindl. Mwst
Ertrag:3809-Saldosteuer {{tax-out}}
\setkomavar{customer}{ {{~customer.year-number~}} }
\setkomavar{invoice}{ {{~invoice-no~}} }
\setkomavar{date}{ {{~iso-date~}} }
{ {{~customer.address-for-latex~}} }
{{#if header}}{{{header}}}\bigskip{{/if}}
Nr. & Datum & Leistung & Einheit & Betrag\\
{{#each items}}
{{add @index 1}} &
{{../iso-date}} &
Beratung {{beneficiary}} ({{rate}} CHF/Std.) &
{{hours}} Std. &
CHF {{toFixed amount 2}}\\
& & Summe & & CHF {{toFixed net-total 2}}\\
{{#if discount}}
& & Rabatt & {{discount}}\% & CHF -{{toFixed discount-amount 2}}\\
& & Zwischensumme & & CHF {{toFixed sub-total 2}}\\
& & MwSt Betrag & {{multiply tax-rate-in 100}}\% & CHF {{toFixed tax-in 2}} \\
& & \textbf{Rechnungstotal} & & \textbf{CHF {{toFixed gross-total 2 ~}} }\\
Zahlungsfrist: {{deadline}} Tage
{{#each items}}
{{#if timesheet-prepared}}
\textbf{Beratung {{beneficiary~}} }
Datum & Beschreibung & Std.\\
{{#each timesheet-prepared}}
{{./date}} &
{{{description}}} &
& Gesamt & {{sum-hours}}\\
\closing{Mit freundlichen Grüssen}
\ProvidesFile{brief.lco}[2002/07/09 v0.9a LaTeX2e unsupported letter-class-option]
\setkomavar{fromname}{Hausverwaltung Raffzahn GmbH}
\setkomavar{fromaddress}{Abzocker-Str. 666\\XX-12345 Fassohneboden}
%\setkomavar{fromphone}{Tel: +1 555 555 55 55}
\newcommand\ustid{XXX-666.666.666 MWST}
%Bankenclearing-Nr. (BC-Nr.) ???\\
Bankkonto-Nr. 66-666666-6\\
IBAN XX66 0000 0000 0000 6666 6
\firsthead{\hfill Logo}
Easy generated invoice: {{invoice-no}}
Customer name: {{}}
Customer number: {{customer.year-number}}
Customer contact: {{}}
Invoice date: {{iso-date}}
Period: {{period}}
Payment deadline: {{deadline}}
{{#if items}}
{{#each items}}
{{hours}}h x {{rate}} CHF/h {{beneficiary}} CHF {{amount}}
Net total: CHF {{net-total}}
Tax (Incoming): CHF {{tax-in}}
Gross total: CHF {{gross-total}}
TEX: {{latex-directory}}/{{latex-filename}}
PDF: {{latex-directory}}/{{replace latex-filename ".tex" ".pdf"}}
; -*- mode: ledger -*-
; «utf8», file: {{ledger-template}}
{{iso-date}} * ({{uuid}}) < R-{{invoice-no}} {{invoice/description}}
Aktiva:1010-Postfinance {{amount}}
(ProfitCenter:Eingang) {{amount}}
{{iso-date}} * ({{uuid}}) R-{{invoice-no}} {{invoice/description}}
Ertrag:3809-Saldosteuer {{tax-out}}
{{iso-date}} * ({{uuid}}) Verbindlichkeit Mwst
[ProfitCenter:Steuer] {{tax-out}}
{{#if tax-win}}
{{iso-date}} * ({{uuid}}) Profit d. Saldoverfahren
[ProfitCenter:Research] {{tax-win}}
{{#each distribution}}
{{../iso-date}} * ({{uuid}}) R-{{../invoice-no}}/{{beneficiary}} ({{hours}}x{{rate}})
[ProfitCenter:{{beneficiary}}] {{amount}}
{{#if remaining}}
{{iso-date}} * ({{uuid}}) Abweichung R-{{invoice-no}}
Ertrag:3800-Verluste-Forderungen {{remaining}}
......@@ -205,6 +205,12 @@
(get-in @config [:templates :ledger :invoice]))))
(defn add-texinputs-directory [evt]
(->> (get-in @config [:texinputs-directory])
(str (process.cwd) "/") ;; TODO: make this less horrible
(assoc* evt :texinputs-directory)))
(defn order-items-by-amount [evt]
(merge evt
{:items (reverse (sort-by :amount (:items evt)))}))
......@@ -244,6 +250,7 @@
filename :latex-filename
content :latex-content
:as evt}]
(util/sh "mkdir -p" directory)
;; TODO: use some path join here
(-> (str directory "/" filename)
(util/spit content))
......@@ -256,10 +263,14 @@
;; (apply util/spit)))
(defn add-pdflatex-cmd [{directory :latex-directory
filename :latex-filename
:as evt}]
(->> (str "(cd " directory " && pdflatex " filename ")")
(defn add-pdflatex-cmd
[{:keys [latex-directory
:as evt}]
(->> (str "(cd " latex-directory
" && TEXINPUTS=.:" texinputs-directory ":"
" pdflatex " latex-filename ")")
(assoc* evt :pdflatex-cmd)))
......@@ -269,6 +280,8 @@
;; TODO: why use a different transform here, this should move into the
;; main transform, except for write-latex! and run-pdflatex!
(defn transform-latex! [evt]
(-> evt
......@@ -276,6 +289,7 @@
;; TODO: run xdg-open on the pdf file
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