2020-01-14 00:06:14 +11:00
|
|
|
{#
|
|
|
|
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/>.
|
|
|
|
#}
|
|
|
|
|
2020-03-20 23:20:39 +11:00
|
|
|
{% extends 'base_report.html' %}
|
|
|
|
|
2020-02-15 11:47:10 +11:00
|
|
|
{% macro print_rows(account, invert=False, level=0) %}
|
2020-01-14 00:06:14 +11:00
|
|
|
<tr>
|
2020-02-15 15:50:33 +11:00
|
|
|
<td style="padding-left: calc(2px + {{ level }}em);">
|
|
|
|
{% if pandls|length == 1 %}
|
2020-04-01 11:58:35 +11:00
|
|
|
<a href="/transactions?{{ {'date_end': pandls[0].date.strftime('%Y-%m-%d'), 'date_beg': pandls[0].pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode }}">{{ account.bits[-1] }}</a>
|
2020-02-15 15:50:33 +11:00
|
|
|
{% else %}
|
|
|
|
{{ account.bits[-1] }}
|
|
|
|
{% endif %}
|
|
|
|
</td>
|
2020-02-15 11:47:10 +11:00
|
|
|
{% for pandl in pandls %}
|
2020-04-04 04:15:32 +11:00
|
|
|
{% set amount = (-pandl.get_balance(account) if invert else pandl.get_balance(account)).exchange(report_commodity, True) %}
|
2020-04-15 13:42:34 +10:00
|
|
|
<td>{% if not amount.near_zero %}{{ amount|a('/transactions?' + {'date_end': pandl.date.strftime('%Y-%m-%d'), 'date_beg': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode) }}{% endif %}</td>
|
2020-02-15 11:47:10 +11:00
|
|
|
{% endfor %}
|
2020-01-14 00:06:14 +11:00
|
|
|
</tr>
|
2020-02-15 11:47:10 +11:00
|
|
|
|
2020-03-23 00:51:13 +11:00
|
|
|
{% for child in account.children|sort(attribute='name') if child in accounts %}
|
2020-02-15 11:47:10 +11:00
|
|
|
{{ print_rows(child, invert, level + 1) }}
|
|
|
|
{% endfor %}
|
2020-01-14 00:06:14 +11:00
|
|
|
{% endmacro %}
|
|
|
|
|
2020-02-15 11:47:10 +11:00
|
|
|
{% macro do_accounts(root, label, invert, year_headers) %}
|
|
|
|
<tr>
|
|
|
|
{% if year_headers %}
|
|
|
|
{# CSS hackery to centre-align the heading #}
|
2020-02-15 15:50:33 +11:00
|
|
|
<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') }} </th>{% endfor %}
|
2020-02-15 11:47:10 +11:00
|
|
|
{% else %}
|
2020-02-15 15:50:33 +11:00
|
|
|
<th class="h1" colspan="{{ pandls|length + 1 }}">{{ label }}</th>
|
2020-02-15 11:47:10 +11:00
|
|
|
{% endif %}
|
|
|
|
</tr>
|
|
|
|
|
2020-03-23 00:51:13 +11:00
|
|
|
{% for account in root.children|sort(attribute='name') if account in accounts %}
|
2020-02-15 11:47:10 +11:00
|
|
|
{{ print_rows(account, invert=invert) }}
|
2020-01-14 00:06:14 +11:00
|
|
|
{% endfor %}
|
2020-02-15 11:47:10 +11:00
|
|
|
|
|
|
|
<tr class="total">
|
|
|
|
<td>Total {{ label }}</td>
|
2020-04-04 04:15:32 +11:00
|
|
|
{% for pandl in pandls %}<td>{{ (-pandl.get_total(root) if invert else pandl.get_total(root)).exchange(report_commodity, True)|a }}</td>{% endfor %}
|
2020-02-15 11:47:10 +11:00
|
|
|
</tr>
|
2020-01-14 00:06:14 +11:00
|
|
|
{% endmacro %}
|
|
|
|
|
2020-03-20 23:20:39 +11:00
|
|
|
{% block title %}Income Statement for the {{ period }}{% endblock %}
|
|
|
|
|
|
|
|
{% block report %}
|
|
|
|
<h1>Income Statement</h1>
|
|
|
|
<h2>For the {{ period }}</h2>
|
|
|
|
|
|
|
|
<table class="ledger onedesc">
|
2020-04-01 13:48:14 +11:00
|
|
|
{# Profit and loss #}
|
|
|
|
{% if scope != 'oci' %}
|
|
|
|
{{ do_accounts(ledger.get_account(config['income_account']), 'Income', True, True) }}
|
|
|
|
<tr><td colspan="{{ pandls|length + 1}}"> </td></tr>
|
|
|
|
|
|
|
|
{{ do_accounts(ledger.get_account(config['expenses_account']), 'Expenses', False, False) }}
|
|
|
|
<tr><td colspan="{{ pandls|length + 1}}"> </td></tr>
|
|
|
|
|
|
|
|
<tr class="total">
|
|
|
|
<td>Net Profit (Loss)</td>
|
2020-04-04 04:15:32 +11:00
|
|
|
{% for pandl in pandls %}<td>{{ -(pandl.get_total(ledger.get_account(config['income_account'])) + pandl.get_total(ledger.get_account(config['expenses_account']))).exchange(report_commodity, True)|a }}</td>{% endfor %}
|
2020-04-01 13:48:14 +11:00
|
|
|
</tr>
|
|
|
|
{% else %}
|
|
|
|
<tr>
|
|
|
|
<th></th>
|
|
|
|
{% for pandl in pandls %}<th class="h2">{{ pandl.date.strftime('%Y') }} </th>{% endfor %}
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td>Net Profit (Loss)</td>
|
2020-04-04 04:15:32 +11:00
|
|
|
{% for pandl in pandls %}<td>{{ -(pandl.get_total(ledger.get_account(config['income_account'])) + pandl.get_total(ledger.get_account(config['expenses_account']))).exchange(report_commodity, True)|a }}</td>{% endfor %}
|
2020-04-01 13:48:14 +11:00
|
|
|
</tr>
|
|
|
|
{% endif %}
|
2020-01-14 00:06:14 +11:00
|
|
|
|
2020-04-01 13:48:14 +11:00
|
|
|
{# Other comprehensive income #}
|
|
|
|
{% if scope != 'pandl' %}
|
|
|
|
<tr><td colspan="{{ pandls|length + 1}}"> </td></tr>
|
|
|
|
<tr><th class="{% if scope == 'both' %}h1{% else %}h2{% endif %}" colspan="{{ pandls|length + 1 }}">Other Comprehensive Income</th></tr>
|
|
|
|
{% for child in ledger.get_account(config['oci_account']).children|sort(attribute='name') if child in accounts %}
|
|
|
|
{{ print_rows(child, True, 0) }}
|
|
|
|
{% endfor %}
|
|
|
|
|
|
|
|
<tr class="total">
|
|
|
|
<td>Total Other Comprehensive Income</td>
|
2020-04-04 04:15:32 +11:00
|
|
|
{% for pandl in pandls %}<td>{{ -pandl.get_total(ledger.get_account(config['oci_account'])).exchange(report_commodity, True)|a }}</td>{% endfor %}
|
2020-04-01 13:48:14 +11:00
|
|
|
</tr>
|
|
|
|
<tr><td colspan="{{ pandls|length + 1}}"> </td></tr>
|
|
|
|
|
|
|
|
<tr class="total">
|
|
|
|
<td>Total Comprehensive Income</td>
|
2020-04-04 04:15:32 +11:00
|
|
|
{% for pandl in pandls %}<td>{{ -(pandl.get_total(ledger.get_account(config['income_account'])) + pandl.get_total(ledger.get_account(config['expenses_account'])) + pandl.get_total(ledger.get_account(config['oci_account']))).exchange(report_commodity, True)|a }}</td>{% endfor %}
|
2020-04-01 13:48:14 +11:00
|
|
|
</tr>
|
|
|
|
{% endif %}
|
2020-03-20 23:20:39 +11:00
|
|
|
</table>
|
|
|
|
{% endblock %}
|