{# 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 . #} {% extends 'base_report.html' %} {% macro print_rows(account, invert=False, level=0) %} {% if pandls|length == 1 %} {{ account.bits[-1] }} {% else %} {{ account.bits[-1] }} {% endif %} {% for pandl in pandls %} {% set amount = (-pandl.get_balance(account) if invert else pandl.get_balance(account)).exchange(report_commodity, True) %} {% if not amount.near_zero %}{{ amount|a('/transactions?' + {'date': pandl.date.strftime('%Y-%m-%d'), 'pstart': pandl.pstart.strftime('%Y-%m-%d'), 'account': account.name, 'cash': 'on' if cash else ''}|urlencode) }}{% endif %} {% endfor %} {% for child in account.children|sort(attribute='name') if child in accounts %} {{ print_rows(child, invert, level + 1) }} {% endfor %} {% endmacro %} {% macro do_accounts(root, label, invert, year_headers) %} {% if year_headers %} {# CSS hackery to centre-align the heading #} {{ label }} {% for pandl in pandls %}{{ pandl.date.strftime('%Y') }} {% endfor %} {% else %} {{ label }} {% endif %} {% for account in root.children|sort(attribute='name') if account in accounts %} {{ print_rows(account, invert=invert) }} {% endfor %} Total {{ label }} {% for pandl in pandls %}{{ (-pandl.get_total(root) if invert else pandl.get_total(root)).exchange(report_commodity, True)|a }}{% endfor %} {% endmacro %} {% block title %}Income Statement for the {{ period }}{% endblock %} {% block report %}

Income Statement

For the {{ period }}

{# Profit and loss #} {% if scope != 'oci' %} {{ do_accounts(ledger.get_account(config['income_account']), 'Income', True, True) }} {{ do_accounts(ledger.get_account(config['expenses_account']), 'Expenses', False, False) }} {% for pandl in pandls %}{% endfor %} {% else %} {% for pandl in pandls %}{% endfor %} {% for pandl in pandls %}{% endfor %} {% endif %} {# Other comprehensive income #} {% if scope != 'pandl' %} {% for child in ledger.get_account(config['oci_account']).children|sort(attribute='name') if child in accounts %} {{ print_rows(child, True, 0) }} {% endfor %} {% for pandl in pandls %}{% endfor %} {% for pandl in pandls %}{% endfor %} {% endif %}
 
 
Net Profit (Loss){{ -(pandl.get_total(ledger.get_account(config['income_account'])) + pandl.get_total(ledger.get_account(config['expenses_account']))).exchange(report_commodity, True)|a }}
{{ pandl.date.strftime('%Y') }} 
Net Profit (Loss){{ -(pandl.get_total(ledger.get_account(config['income_account'])) + pandl.get_total(ledger.get_account(config['expenses_account']))).exchange(report_commodity, True)|a }}
 
Other Comprehensive Income
Total Other Comprehensive Income{{ -pandl.get_total(ledger.get_account(config['oci_account'])).exchange(report_commodity, True)|a }}
 
Total Comprehensive Income{{ -(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 }}
{% endblock %}