diff --git a/cli/AccountStatement.py b/cli/AccountStatement.py new file mode 100644 index 0000000..c3aa0c2 --- /dev/null +++ b/cli/AccountStatement.py @@ -0,0 +1,29 @@ +from db import dbGetMany +from loguru import logger +import datetime +import iso8601 +from utils import getParam +from Cheetah.Template import Template + +def perform(dbh, params): + year = getParam(params, 'year', datetime.datetime.today().year) + + accountEntries = dbGetMany( + dbh, + { + "statement": "SELECT * FROM account_statement_v WHERE fiscal_year = %(year)s", + "params": { + 'year': year + } + + } + ) + + template = getParam(params, 'template', 'accountStatement.tmpl') + prefix = getParam(params, 'prefix', 'accountStatement') + suffix = getParam(params, 'suffix', 'tex') + input = { 'year': year, 'entries': accountEntries } + outputFile = f"{prefix}-{year}.{suffix}" + tmpl = Template(file=template, searchList=[ input ]) + with open(outputFile, 'w') as f: + f.write(str(tmpl)) diff --git a/cli/accountStatement.tmpl b/cli/accountStatement.tmpl new file mode 100644 index 0000000..d72b41e --- /dev/null +++ b/cli/accountStatement.tmpl @@ -0,0 +1,37 @@ +\documentclass[10pt]{article} +\usepackage{german} +\usepackage{eurosym} +\usepackage[a4paper, landscape=true, left=2cm, right=2cm, top=2cm]{geometry} +\usepackage{icomma} +\usepackage{longtable} +\usepackage{color} +\setlength{\parindent}{0pt} + +\begin{document} + +\subsection*{Kontoauszug $year} + +\begin{longtable}{rrp{5cm}rrrp{3cm}l} + \bf{id} & \bf{createdAt} & \bf{description} & \bf{amount} & \bf{documentNo} & \bf{fiscalYear} & \bf{category} & \bf{account} \\ \hline + \endfirsthead + \bf{id} & \bf{createdAt} & \bf{description} & \bf{amount} & \bf{documentNo} & \bf{fiscalYear} & \bf{category} & \bf{account} \\ \hline + \endhead + \hline \multicolumn{8}{r}{\em{to be continued}} + \endfoot + \hline + \endlastfoot + + #for $entry in $entries +\tt{$entry['id']} & \tt{$entry['created_at']} & \tt{$entry['description']} & #slurp +#if not $entry['income'] +\textcolor{red}{#slurp +#end if +\tt{$entry['amount']}#slurp +#if not $entry['income'] +}#slurp +#end if +& \tt{$entry['document_no']} & \tt{$entry['fiscal_year']} & \tt{$entry['category']} & \tt{{ $entry['account'].replace('_', '\\textunderscore ') }} \\ + #end for +\end{longtable} + +\end{document} diff --git a/schema/account-statement.sql b/schema/account-statement.sql index c48934d..fc61444 100644 --- a/schema/account-statement.sql +++ b/schema/account-statement.sql @@ -6,6 +6,7 @@ create or replace view account_statement_v as ae.document_no as document_no, ae.fiscal_year as fiscal_year, aec.description as category, + aec.income as income, ac.description as account from account_entry_t ae, account_entry_category_t aec, diff --git a/schema/changes02.sql b/schema/changes02.sql new file mode 100644 index 0000000..dc8c2d4 --- /dev/null +++ b/schema/changes02.sql @@ -0,0 +1 @@ +alter table account_entry_category_t add column income boolean; \ No newline at end of file