diff --git a/.gitignore b/.gitignore index 36e5602..8f72355 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ ENV api/config/dbconfig.ini api/config/authservice.pub cli/config/dbconfig.ini +cli/output/ *~ .*~ .vscode/ diff --git a/cli/AccountStatement.py b/cli/AccountStatement.py index 9feaf73..fb71ab1 100644 --- a/cli/AccountStatement.py +++ b/cli/AccountStatement.py @@ -1,4 +1,4 @@ -from db import dbGetMany +from db import dbGetMany, dbGetOne from loguru import logger import datetime import iso8601 @@ -15,11 +15,40 @@ def perform(dbh, params): "params": { 'year': year } - + } + ) + + overview = dbGetMany( + dbh, + { + "statement": "select sum(amount), category from account_statement_v where fiscal_year = %(year)s group by category", + "params": { + 'year': year + } + } + ) + + sum_related = dbGetOne( + dbh, + { + "statement": "select coalesce(sum(amount), 0::numeric(10,2)) as sum from account_statement_v where fiscal_year = %(year)s and category != 'nicht abrechenbare Positionen'", + "params": { + 'year': year + } + } + ) + + sum_unrelated = dbGetOne( + dbh, + { + "statement": "select coalesce(sum(amount), 0::numeric(10,2)) as sum from account_statement_v where fiscal_year = %(year)s and category = 'nicht abrechenbare Positionen'", + "params": { + 'year': year + } } ) template = getParam(params, 'template', 'accountStatement.tmpl') - input = { 'year': year, 'entries': accountEntries } + input = { 'year': year, 'entries': accountEntries, 'overview': overview, 'related': sum_related, 'unrelated': sum_unrelated } tmpl = Template(file=template, searchList=[ input ]) print(tmpl) diff --git a/cli/AccountStatement.sh b/cli/AccountStatement.sh index 9998ddd..db015bb 100755 --- a/cli/AccountStatement.sh +++ b/cli/AccountStatement.sh @@ -32,7 +32,12 @@ if [ "$YEAR" = "" ]; then exit 1 fi -python3.10 hv2cli.py -o AccountStatement -p '{"year":'$YEAR'}' > $YEAR.tex +python3.10 hv2cli.py -o AccountStatement -p '{"year":'$YEAR'}' > ./output/$YEAR.tex + +pushd ./output + +pdflatex $YEAR.tex +pdflatex $YEAR.tex pdflatex $YEAR.tex if [ "$SHOW" = "1" ]; then @@ -43,3 +48,4 @@ if [ "$PRINT" = "1" ]; then lpr $PRINTER $YEAR.pdf fi +popd diff --git a/cli/accountStatement.tmpl b/cli/accountStatement.tmpl index 1aa7d2a..2916c08 100644 --- a/cli/accountStatement.tmpl +++ b/cli/accountStatement.tmpl @@ -9,12 +9,12 @@ \begin{document} -\subsection*{Kontoauszug $year} +\subsection*{Account Statement $year} -\begin{longtable}{|r|r|p{5cm}|r|r|r|p{3cm}|r|p{5cm}|} - \hline \textcolor{blue}{\tt{id}} & \textcolor{blue}{\tt{date}} & \textcolor{blue}{\tt{description}} & \textcolor{blue}{\tt{amount}} & \textcolor{blue}{\tt{docNo}} & \textcolor{blue}{\tt{year}} & \textcolor{blue}{\tt{category}} & \textcolor{blue}{\tt{isRef}} & \textcolor{blue}{\tt{baseAccount}} \\ \hline \hline +\begin{longtable}{|r|r|p{6cm}|r|r|r|p{3cm}|r|p{5cm}|} + \hline \textcolor{blue}{\bf{ID}} & \textcolor{blue}{\bf{Date}} & \textcolor{blue}{\bf{Description}} & \textcolor{blue}{\bf{Amount}} & \textcolor{blue}{\bf{DocNo}} & \textcolor{blue}{\bf{Year}} & \textcolor{blue}{\bf{Category}} & \textcolor{blue}{\bf{IsRef}} & \textcolor{blue}{\bf{BaseAccount}} \\ \hline \hline \endfirsthead - \hline \textcolor{blue}{\tt{id}} & \textcolor{blue}{\tt{date}} & \textcolor{blue}{\tt{description}} & \textcolor{blue}{\tt{amount}} & \textcolor{blue}{\tt{docNo}} & \textcolor{blue}{\tt{year}} & \textcolor{blue}{\tt{category}} & \textcolor{blue}{\tt{isRef}} & \textcolor{blue}{\tt{baseAccount}} \\ \hline \hline + \hline \textcolor{blue}{\bf{ID}} & \textcolor{blue}{\bf{Date}} & \textcolor{blue}{\bf{Description}} & \textcolor{blue}{\bf{Amount}} & \textcolor{blue}{\bf{DocNo}} & \textcolor{blue}{\bf{Year}} & \textcolor{blue}{\bf{Category}} & \textcolor{blue}{\bf{IsRef}} & \textcolor{blue}{\bf{BaseAccount}} \\ \hline \hline \endhead \multicolumn{9}{r}{\em{to be continued}} \endfoot @@ -26,7 +26,7 @@ #if $entry['amount'] <= 0 \textcolor{red}{#slurp #end if -\tt{$entry['amount']}#slurp +\tt{$entry['amount']} \,\euro{}#slurp #if $entry['amount'] <= 0 }#slurp #end if @@ -34,4 +34,26 @@ #end for \end{longtable} +\pagebreak +\subsection*{Overviews} + +\begin{tabular}{|l|r|} \hline +\hline \textcolor{blue}{\bf{category}} & \textcolor{blue}{\bf{sum}} \\ +#for $entry in $overview +\hline \tt{$entry['category']} & #slurp +#if $entry['sum'] <= 0 +\textcolor{red}{#slurp +#end if +\tt{$entry['sum']} \,\euro{}#slurp +#if $entry['sum'] <= 0 +}#slurp +#end if +\\ +#end for + +\hline \hline related & \tt{$related['sum']} \,\euro{} \\ +\hline unrelated & \tt{$unrelated['sum']} \,\euro{} \\ +\hline \hline +\end{tabular} + \end{document} diff --git a/schema/account-statement.sql b/schema/account-statement.sql index 449181b..c289d94 100644 --- a/schema/account-statement.sql +++ b/schema/account-statement.sql @@ -18,3 +18,6 @@ create or replace view account_statement_v as ae.base_account = bac.id and ac.id = 1000 order by created_at; + +grant select on account_statement_v to hv2; +