Kontoauszug

This commit is contained in:
Wolfgang Hottgenroth 2022-02-13 12:30:10 +01:00
parent 1c6fe0dd16
commit 25f6de1c11
4 changed files with 68 additions and 0 deletions

29
cli/AccountStatement.py Normal file
View File

@ -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))

37
cli/accountStatement.tmpl Normal file
View File

@ -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}

View File

@ -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,

1
schema/changes02.sql Normal file
View File

@ -0,0 +1 @@
alter table account_entry_category_t add column income boolean;