From 8774ca46dfb62caddbb315c66841a205e8ce12be Mon Sep 17 00:00:00 2001 From: Wolfgang Hottgenroth Date: Mon, 27 Feb 2023 13:01:15 +0100 Subject: [PATCH] billing --- .gitignore | 2 + generate.py | 36 +++++++++++++++++ rechnung.tex | 60 ++++++++++++++++++++++++++++ rechnung/billingPreprocessor.py | 22 ++++++++++ rechnung/rechnung-sample-input.json | 8 ++++ rechnung/rechnung.tmpl | 62 +++++++++++++++++++++++++++++ requirements.txt | 1 + vorlage.tex | 46 ++------------------- 8 files changed, 194 insertions(+), 43 deletions(-) create mode 100644 generate.py create mode 100644 rechnung.tex create mode 100644 rechnung/billingPreprocessor.py create mode 100644 rechnung/rechnung-sample-input.json create mode 100644 rechnung/rechnung.tmpl create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore index 3eec47d..2f24e73 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.aux *.log *.pdf +.venv/ +__pycache__/ diff --git a/generate.py b/generate.py new file mode 100644 index 0000000..9ed7d6c --- /dev/null +++ b/generate.py @@ -0,0 +1,36 @@ +import argparse +import json +from Cheetah.Template import Template +import importlib + + +parser = argparse.ArgumentParser(description='LetterGenerator') +parser.add_argument('--input', '-i', + help = 'Input file in JSON format', + required = True) +parser.add_argument('--template', '-t', + help = 'Template file in Cheetah format', + required = True) +parser.add_argument('--output', '-o', + help = 'Output file', + required = True) +parser.add_argument('--preprocessor', '-p', + help = 'Preprocessor module', + required = False) +args = parser.parse_args() +inputFile = args.input +templateFile = args.template +outputFile = args.output +preprocessor = args.preprocessor + +with open(inputFile) as f: + inputData = json.load(f) + +if preprocessor: + preprocessorMod = importlib.import_module(preprocessor) + inputData = preprocessorMod.perform(inputData) + +tmpl = Template(file=templateFile, searchList=[ inputData ]) + +with open(outputFile, 'w') as f: + f.write(str(tmpl)) diff --git a/rechnung.tex b/rechnung.tex new file mode 100644 index 0000000..e8976e8 --- /dev/null +++ b/rechnung.tex @@ -0,0 +1,60 @@ +\documentclass[12pt]{dinbrief} +\usepackage{german} +\usepackage{eurosym} +\usepackage{longtable} + + +\address{Ingenieurbüro\\ + Wolfgang Hottgenroth\\ + Eupenstr. 20\\ + 45259 Essen} +\backaddress{Ingenieurbüro W.\ Hottgenroth, Eupenstr. 20, 45259 Essen} +\signature{W.\ Hottgenroth} %% Hier Unterschrift einfuegen +\nowindowrules +% \yourmail{yourmail} +% \sign{sign} +\writer{wh} %% Hier eigenen Namen oder Kuerzel einfuegen +\phone{0174}{3072474} %% Hier eigene Telefon einfuegen + +\bottomtext{\sffamily\footnotesize wh@ib-hottgenroth.de\\ + Bankverbindung: IBAN DE96 3505 0105 0001 5037 05, Sparkasse Essen} +\begin{document} + %% Hier Adresse des Empfaengers einfuegen + \begin{letter}{Herrn Max Mustermann\\Dingsstr.\ 1\\12345 Dorf} + %% Hier Betreff einfuegen + \subject{Rechnung Nr. 2023-1} + %% Hier Anrede einfuegen + \opening{Hallo Max,} + +für Ingenieurdienstleistungen erlaube ich mir entsprechend folgender Spezifikation die Rechnung zu stellen. +Ich bitte um Zahlung binnen zwei Wochen an unten angegebene Bankverbindung. + +\begin{longtable}{|p{0.7cm}|p{2.5cm}|p{5.5cm}|p{1cm}|p{2.2cm}|p{2.2cm}|} + \hline \bf{Nr.} & \bf{Datum} & \bf{Leistung} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline + \endfirsthead + \hline \bf{Nr.} & \bf{Datum} & \bf{Leistung} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline + \endhead + \multicolumn{6}{r}{\em{b.w.}} + \endfoot + \hline \hline + \multicolumn{4}{| p{10cm} |}{Zwischensumme} & & \hfill \tt{220.00 \euro{}}\\ \hline + \multicolumn{4}{| p{10cm} |}{MwSt.} & \hfill \tt{19 \%} & \hfill \tt{41.80 \euro{}}\\ \hline + \multicolumn{4}{| p{10cm} |}{\bf{Summe}} & & \hfill \tt{261.80 \euro{}}\\ \hline + \endlastfoot + + \tt{1}& + \tt{01.01.2023}& + \tt{Bla1}& + \tt{\hfill{}2}& + \tt{\hfill{}110.00 \euro{}}& + \tt{\hfill{}220.00 \euro{}} + \\ \hline + +\end{longtable} + + + + \closing{Mit freundlichen Gr"u"sen} +% \encl{encl} +\end{letter} +\end{document} diff --git a/rechnung/billingPreprocessor.py b/rechnung/billingPreprocessor.py new file mode 100644 index 0000000..1631585 --- /dev/null +++ b/rechnung/billingPreprocessor.py @@ -0,0 +1,22 @@ +from decimal import Decimal + +MwSt_TAX_RATE = Decimal(0.19) + +def perform(inputData): + inputData['totalBeforeTaxes'] = Decimal(0) + for entry in inputData['entries']: + entry['totalprice'] = Decimal(entry['count']) * Decimal(entry['unitprice']) + inputData['totalBeforeTaxes'] += entry['totalprice'] + inputData['totalBeforeTaxes'] = inputData['totalBeforeTaxes'] + inputData['taxes'] = inputData['totalBeforeTaxes'] * MwSt_TAX_RATE + inputData['total'] = inputData['totalBeforeTaxes'] + inputData['taxes'] + + for entry in inputData['entries']: + entry['totalprice'] = f"{entry['totalprice']:.2f}" + entry['unitprice'] = f"{entry['unitprice']:.2f}" + inputData['totalBeforeTaxes'] = f"{inputData['totalBeforeTaxes']:.2f}" + inputData['taxes'] = f"{inputData['taxes']:.2f}" + inputData['total'] = f"{inputData['total']:.2f}" + + return inputData + diff --git a/rechnung/rechnung-sample-input.json b/rechnung/rechnung-sample-input.json new file mode 100644 index 0000000..f4bcfba --- /dev/null +++ b/rechnung/rechnung-sample-input.json @@ -0,0 +1,8 @@ +{ + "billingNo": "2023-1", + "receipient": "Herrn Max Mustermann\\\\Dingsstr.\\ 1\\\\12345 Dorf", + "salutation": "Hallo Max", + "entries": [ + { "no": 1, "date": "01.01.2023", "description": "Bla1", "count": 2, "unitprice": 110.0 } + ] +} \ No newline at end of file diff --git a/rechnung/rechnung.tmpl b/rechnung/rechnung.tmpl new file mode 100644 index 0000000..943095d --- /dev/null +++ b/rechnung/rechnung.tmpl @@ -0,0 +1,62 @@ +\documentclass[12pt]{dinbrief} +\usepackage{german} +\usepackage{eurosym} +\usepackage{longtable} + + +\address{Ingenieurbüro\\ + Wolfgang Hottgenroth\\ + Eupenstr. 20\\ + 45259 Essen} +\backaddress{Ingenieurbüro W.\ Hottgenroth, Eupenstr. 20, 45259 Essen} +\signature{W.\ Hottgenroth} %% Hier Unterschrift einfuegen +\nowindowrules +% \yourmail{yourmail} +% \sign{sign} +\writer{wh} %% Hier eigenen Namen oder Kuerzel einfuegen +\phone{0174}{3072474} %% Hier eigene Telefon einfuegen + +\bottomtext{\sffamily\footnotesize wh@ib-hottgenroth.de\\ + Bankverbindung: IBAN DE96 3505 0105 0001 5037 05, Sparkasse Essen} +\begin{document} + %% Hier Adresse des Empfaengers einfuegen + \begin{letter}{${receipient}} + %% Hier Betreff einfuegen + \subject{Rechnung Nr. ${billingNo}} + %% Hier Anrede einfuegen + \opening{${salutation},} + +für Ingenieurdienstleistungen erlaube ich mir entsprechend folgender Spezifikation die Rechnung zu stellen. +Ich bitte um Zahlung binnen zwei Wochen an unten angegebene Bankverbindung. + +\begin{longtable}{|p{0.7cm}|p{2.5cm}|p{5.5cm}|p{1cm}|p{2.2cm}|p{2.2cm}|} + \hline \bf{Nr.} & \bf{Datum} & \bf{Leistung} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline + \endfirsthead + \hline \bf{Nr.} & \bf{Datum} & \bf{Leistung} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline + \endhead + \multicolumn{6}{r}{\em{b.w.}} + \endfoot + \hline \hline + \multicolumn{4}{| p{10cm} |}{Zwischensumme} & & \hfill \tt{${totalBeforeTaxes} \euro{}}\\ \hline + \multicolumn{4}{| p{10cm} |}{MwSt.} & \hfill \tt{19 \%} & \hfill \tt{${taxes} \euro{}}\\ \hline + \multicolumn{4}{| p{10cm} |}{\bf{Summe}} & & \hfill \tt{${total} \euro{}}\\ \hline + \endlastfoot + + #for $entry in $entries + \tt{$entry['no']}& + \tt{$entry['date']}& + \tt{$entry['description']}& + \tt{\hfill{}$entry['count']}& + \tt{\hfill{}$entry['unitprice'] \euro{}}& + \tt{\hfill{}$entry['totalprice'] \euro{}} + \\ \hline + #end for + +\end{longtable} + + + + \closing{Mit freundlichen Gr"u"sen} +% \encl{encl} +\end{letter} +\end{document} diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b191199 --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +Cheetah3==3.2.6.post1 diff --git a/vorlage.tex b/vorlage.tex index 0d182f1..73f9fc5 100644 --- a/vorlage.tex +++ b/vorlage.tex @@ -8,8 +8,8 @@ Wolfgang Hottgenroth\\ Eupenstr. 20\\ 45259 Essen} -\backaddress{Ingenieurbüro Hottgenroth, Eupenstr. 20, 45259 Essen} -\signature{xxx} %% Hier Unterschrift einfuegen +\backaddress{Ingenieurbüro W.\ Hottgenroth, Eupenstr. 20, 45259 Essen} +\signature{W.\ Hottgenroth} %% Hier Unterschrift einfuegen \nowindowrules % \yourmail{yourmail} % \sign{sign} @@ -17,7 +17,7 @@ \phone{0174}{3072474} %% Hier eigene Telefon einfuegen \bottomtext{\sffamily\footnotesize wh@ib-hottgenroth.de\\ - Bankverbindung: IBAN DE96 3505 0105 0001 5987 62, Sparkasse Essen} + Bankverbindung: IBAN DE96 3505 0105 0001 5037 05, Sparkasse Essen} \begin{document} %% Hier Adresse des Empfaengers einfuegen \begin{letter}{vorname nachname\\ @@ -32,46 +32,6 @@ Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. -\begin{longtable}{|p{1cm}|p{2cm}|p{6cm}|p{1cm}|p{2cm}|p{2cm}|} - \hline \bf{Nr.} & \bf{Datum} & \bf{Gegenstand} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline - \endfirsthead - \hline \bf{Nr.} & \bf{Datum} & \bf{Gegenstand} & \bf{Anz.} & \bf{Einzel} & \bf{Summe} \\ \hline \hline - \endhead - \multicolumn{6}{r}{\em{b.w.}} - \endfoot - \hline \hline - \multicolumn{4}{| p{10cm} |}{Zwischensumme} & & \hfill 1 \euro{}\\ \hline - \multicolumn{4}{| p{10cm} |}{MwSt.} & 19 \% & \hfill 2 \euro{}\\ \hline - \multicolumn{4}{| p{10cm} |}{\bf{Summe}} & & \hfill \bf{3 \euro{}}\\ \hline - \endlastfoot - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline - \tt{1} & \tt{2} & \tt{3} & \hfill \tt{4} & \hfill \tt{5 \euro{}} & \hfill \tt{6 \euro{}} \\ \hline -\end{longtable} - - \closing{Mit freundlichen Gr"u"sen} % \encl{encl}