Commit f07af27f authored by phil's avatar phil

add example and texinputs-feature

parent 266f825f
/.cpcache
/node_modules
/.classpath
/.lumo_cache/
.cpcache
.classpath
.lumo_cache/
......@@ -65,14 +65,26 @@ like.
** Install
*** lumo via npm
Easy runs on [[http://lumo-cljs.org/][lumo]] and uses node packages available via [[https://www.npmjs.com/][npm]], as well as
ClojureScript packages available via [[https://clojars.org/][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 [[https://clojure.org/guides/deps_and_cli][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
respect-tax-rate:
- rate: 0.077
vat-tax-rate-in:
- rate: 0.08
until: 2017-12-31
- rate: 0.077
since: 2018-01-01
vat-tax-rate-out:
- rate: 0.061
until: 2017-12-31
- rate: 0.059
since: 2018-01-01
templates:
ledger:
invoice: templates/invoice.dat.hbs
settlement: templates/settlement.dat.hbs
output:
overview: templates/overview.txt.hbs
invoice:
report:
template: templates/report.txt.hbs
latex:
template: templates/invoice.tex.hbs
directory: 'customers/{{customer.name}}'
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
=customers/schaf=.
#+BEGIN_SRC shell
../bin/collect events | ../bin/easy invoice -n 1.1.1
#+END_SRC
And this will show the balance:
#+BEGIN_SRC shell
../bin/collect events | ../bin/easy -y 2019 ledger | ledger -f - bal
#+END_SRC
---
# - `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
items:
- 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}}
Ertrag:3400-Dienstleistungsertrag:T-{{tax-period}}:P-{{period}}
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}}
{{/each}}
{{iso-date}} * ({{uuid}}) TP R-{{invoice-no}} Verbindl. Mwst
Ertrag:3809-Saldosteuer {{tax-out}}
Passiva:2300-Passive-Rechnungsabgrenzung
{{/if}}
\documentclass[letter_{{customer.contact}}]{scrlttr2}
\setkomavar{yourref}{}
\setkomavar{yourmail}{}
\setkomavar{myref}{}
\setkomavar{customer}{ {{~customer.year-number~}} }
\setkomavar{invoice}{ {{~invoice-no~}} }
%\setkomavar{specialmail}{Einschreiben}
\setkomavar{date}{ {{~iso-date~}} }
\setkomavar{subject}{Rechnung}
\setlength{\parindent}{0pt}
\begin{document}
\begin{letter}
{ {{~customer.address-for-latex~}} }
\opening{}
{{#if header}}{{{header}}}\bigskip{{/if}}
{
\renewcommand{\arraystretch}{1}
\begin{tabularx}{\textwidth}{rlXlr}
Nr. & Datum & Leistung & Einheit & Betrag\\
\hline
\hline
{{#each items}}
{{add @index 1}} &
{{../iso-date}} &
Beratung {{beneficiary}} ({{rate}} CHF/Std.) &
{{hours}} Std. &
CHF {{toFixed amount 2}}\\
{{/each}}
\hline
& & Summe & & CHF {{toFixed net-total 2}}\\
{{#if discount}}
& & Rabatt & {{discount}}\% & CHF -{{toFixed discount-amount 2}}\\
& & Zwischensumme & & CHF {{toFixed sub-total 2}}\\
{{/if}}
& & MwSt Betrag & {{multiply tax-rate-in 100}}\% & CHF {{toFixed tax-in 2}} \\
\hline
& & \textbf{Rechnungstotal} & & \textbf{CHF {{toFixed gross-total 2 ~}} }\\
\end{tabularx}
}
\vspace{5mm}
Zahlungsfrist: {{deadline}} Tage
\vspace{5mm}
{{{footer}}}
{{#each items}}
{{#if timesheet-prepared}}
\begin{minipage}{\textwidth}
\textbf{Beratung {{beneficiary~}} }
\begin{center}
\begin{tabularx}{\textwidth}{rXr}
Datum & Beschreibung & Std.\\
\hline
{{#each timesheet-prepared}}
{{./date}} &
{{{description}}} &
{{duration}}\\
{{/each}}
\hline
& Gesamt & {{sum-hours}}\\
\end{tabularx}
\quad\vspace{1cm}
\end{center}
\end{minipage}
{{/if}}
{{/each}}
\closing{Mit freundlichen Grüssen}
\end{letter}
\end{document}
\ProvidesFile{brief.lco}[2002/07/09 v0.9a LaTeX2e unsupported letter-class-option]
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ngerman]{babel}
\usepackage{lmodern}
\usepackage{tabularx}
\setkomavar{fromname}{Hausverwaltung Raffzahn GmbH}
\newcommand\addrsecrow{}
\newcommand\rechtsform{}
\setkomavar{fromaddress}{Abzocker-Str. 666\\XX-12345 Fassohneboden}
%\setkomavar{fromphone}{Tel: +1 555 555 55 55}
\setkomavar{fromfax}{}
\setkomavar{fromemail}{info@example.com}
%\setkomavar{signature}{}
\newcommand\ustid{XXX-666.666.666 MWST}
\setkomavar{frombank}{Bankverbindung\\
Finanzkrisebank\\
%Bankenclearing-Nr. (BC-Nr.) ???\\
Bankkonto-Nr. 66-666666-6\\
IBAN XX66 0000 0000 0000 6666 6
}
%\KOMAoptions{fromlogo=true}
%\setkomavar{fromlogo}{\includegraphics[width=5in,height=1cm]{200ok_logo.png}}
%\pagestyle{myheadings}
%\@addtoplength{firstfootvpos}{1mm}
%\@setplength{firstheadvpos}{12mm}
%\addtolength{\textheight}{15mm}
\@addtoplength{firstfootvpos}{-8mm}
\setkomafont{backaddress}{\scriptsize}
\typeout{\scdefault}
\DeclareFixedFont{\fa}{\encodingdefault}{cmr}{m}{\scdefault}{8}
\DeclareFixedFont{\cc}{\encodingdefault}{cmr}{m}{\scdefault}{30}
\firsthead{\hfill Logo}
\firstfoot{
\scriptsize{
\parbox{\useplength{firstfootwidth}}{
\rule{170mm}{0.5pt}
\begin{tabular}{ll}
\usekomavar{fromname}\\
%\rechtsform\\
\usekomavar{fromaddress}\\
\end{tabular}\hfill
\begin{tabular}{cc}
\usekomavar{fromemail}\\
\usekomavar{fromphone}\\
\usekomavar{fromfax}\\
\ustid
\end{tabular}\hfill
\begin{tabular}{rr}
\usekomavar{frombank}\\
\end{tabular}
}}
}
\nextfoot{
\parbox{\useplength{firstfootwidth}}{
\begin{tabular}{ll}
\usekomavar{fromname}
\end{tabular}\hfill
\begin{tabular}{cc}
\today
\end{tabular}\hfill
\begin{tabular}{rr}
\thepage
\end{tabular}
}
}
\endinput
Easy generated invoice: {{invoice-no}}
DETAILS
Customer name: {{customer.name}}
Customer number: {{customer.year-number}}
Customer contact: {{customer.contact}}
Invoice date: {{iso-date}}
Period: {{period}}
Payment deadline: {{deadline}}
{{#if items}}
Items
{{#each items}}
{{hours}}h x {{rate}} CHF/h {{beneficiary}} CHF {{amount}}
{{/each}}
{{/if}}
Net total: CHF {{net-total}}
Tax (Incoming): CHF {{tax-in}}
Gross total: CHF {{gross-total}}
ARTIFACTS
TEX: {{latex-directory}}/{{latex-filename}}
PDF: {{latex-directory}}/{{replace latex-filename ".tex" ".pdf"}}
COMMANDS
{{{pdflatex-cmd}}}
; -*- mode: ledger -*-
; «utf8», file: {{ledger-template}}
{{iso-date}} * ({{uuid}}) < R-{{invoice-no}} {{invoice/description}}
Aktiva:1100-Forderungen-aus-Lieferungen-und-Leistungen
Aktiva:1010-Postfinance {{amount}}
(ProfitCenter:Eingang) {{amount}}
{{iso-date}} * ({{uuid}}) R-{{invoice-no}} {{invoice/description}}
Passiva:2201-Abrechnungskonto-MWST:{{period}}:MWST
Ertrag:3809-Saldosteuer {{tax-out}}
{{iso-date}} * ({{uuid}}) Verbindlichkeit Mwst
[ProfitCenter:Eingang]
[ProfitCenter:Steuer] {{tax-out}}
{{#if tax-win}}
{{iso-date}} * ({{uuid}}) Profit d. Saldoverfahren
[ProfitCenter:Eingang]
[ProfitCenter:Research] {{tax-win}}
{{/if}}
{{#each distribution}}
{{../iso-date}} * ({{uuid}}) R-{{../invoice-no}}/{{beneficiary}} ({{hours}}x{{rate}})
[ProfitCenter:Eingang]
[ProfitCenter:{{beneficiary}}] {{amount}}
{{/each}}
{{#if remaining}}
{{iso-date}} * ({{uuid}}) Abweichung R-{{invoice-no}}
Aktiva:1100-Forderungen-aus-Lieferungen-und-Leistungen
Ertrag:3800-Verluste-Forderungen {{remaining}}
{{/if}}
......@@ -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
latex-filename
texinputs-directory]
:as evt}]
(->> (str "(cd " latex-directory
" && TEXINPUTS=.:" texinputs-directory ":"
" pdflatex " latex-filename ")")
(assoc* evt :pdflatex-cmd)))
......@@ -269,6 +280,8 @@
evt)
;; 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
order-items-by-amount
......@@ -276,6 +289,7 @@
add-latex-directory
add-latex-filename
write-latex!
add-texinputs-directory
add-pdflatex-cmd
run-pdflatex!
;; 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