ledger-pyreport/ledger_pyreport/jinja2/pandl.html

86 lines
3.3 KiB
HTML

{#
ledger-pyreport
Copyright © 2020 Lee Yingtong Li (RunasSudo)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
#}
{% macro print_rows(account, invert=False, level=0) %}
<tr>
<td style="padding-left: calc(2px + {{ level }}em);">
{% if pandls|length == 1 %}
<a href="/transactions?{{ {'date': pandls[0].date.strftime('%Y-%m-%d'), 'pstart': pandls[0].pstart.strftime('%Y-%m-%d'), 'account': account.name}|urlencode }}">{{ account.bits[-1] }}</a>
{% else %}
{{ account.bits[-1] }}
{% endif %}
</td>
{% for pandl in pandls %}
{% set amount = pandl.get_balance(account.name) * (-1 if invert else 1) %}
<td>{% if amount != 0 %}<a href="/transactions?{{ {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name}|urlencode }}">{{ amount|a }}</a>{% endif %}</td>
{% endfor %}
</tr>
{% for child in account.children if child in accounts %}
{{ print_rows(child, invert, level + 1) }}
{% endfor %}
{% endmacro %}
{% macro do_accounts(root, label, invert, year_headers) %}
<tr>
{% if year_headers %}
{# CSS hackery to centre-align the heading #}
<th class="h1" style="padding-left: calc(2px + {{ pandls|length * 6 }}em);">{{ label }}</th>
{% for pandl in pandls %}<th class="h2">{{ pandl.date.strftime('%Y') }}&nbsp;</th>{% endfor %}
{% else %}
<th class="h1" colspan="{{ pandls|length + 1 }}">{{ label }}</th>
{% endif %}
</tr>
{% for account in pandls[0].get_account(root).children if account in accounts %}
{{ print_rows(account, invert=invert) }}
{% endfor %}
<tr class="total">
<td>Total {{ label }}</td>
{% for pandl in pandls %}<td>{{ (pandl.get_total(root) * (-1 if invert else 1))|a }}</td>{% endfor %}
</tr>
{% endmacro %}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Income Statement for the {{ period }}</title>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.min.css" integrity="sha256-l85OmPOjvil/SOvVt3HnSSjzF1TUMyT9eV0c2BzEGzU=" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='main.css') }}">
</head>
<body>
<h1>Income Statement</h1>
<h2>For the {{ period }}</h2>
<table class="ledger onedesc">
{{ do_accounts(config['income_account'], 'Income', True, True) }}
<tr><td colspan="2">&nbsp;</td></tr>
{{ do_accounts(config['expenses_account'], 'Expenses', False, False) }}
<tr><td colspan="2">&nbsp;</td></tr>
<tr class="total">
<td>Net Surplus (Loss)</td>
{% for pandl in pandls %}<td>{{ -(pandl.get_total(config['income_account']) + pandl.get_total(config['expenses_account']))|a }}</td>{% endfor %}
</tr>
</table>
</body>
</html>