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-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 balance_sheets|length == 1 %}
2020-03-20 22:22:47 +11:00
{% if account.name == config['current_year_earnings'] %}
< a href = "/pandl?{{ {'date_end': balance_sheets[0].date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0'}|urlencode }}" >
{% else %}
< a href = "/transactions?{{ {'date': balance_sheets[0].date.strftime('%Y-%m-%d'), 'pstart': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'account': account.name}|urlencode }}" >
{% endif %}
{{ 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 balance_sheet in balance_sheets %}
2020-03-20 22:14:05 +11:00
{% set amount = (-balance_sheet.get_balance(account) if invert else balance_sheet.get_balance(account)).exchange(report_currency, True) %}
2020-03-20 22:22:47 +11:00
< td >
{% if amount != 0 %}
{% if account.name == config['current_year_earnings'] %}
< a href = "/pandl?{{ {'date_end': balance_sheet.date.strftime('%Y-%m-%d'), 'date_beg': balance_sheets[0].pstart.strftime('%Y-%m-%d'), 'compare': '0'}|urlencode }}" >
{% else %}
< a href = "/transactions?{{ {'date': balance_sheet.date.strftime('%Y-%m-%d'), 'pstart': balance_sheet.pstart.strftime('%Y-%m-%d'), 'account': account.name}|urlencode }}" >
{% endif %}
{{ amount|a }}
< / a >
{% 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
{% for child in account.children if child in accounts %}
{{ 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) %}
2020-03-20 22:14:05 +11:00
{% for account_class in root.children if account_class in accounts %}
2020-02-15 11:47:10 +11:00
< tr >
2020-03-20 18:54:01 +11:00
{% if loop.first and year_headers %}
2020-02-15 11:47:10 +11:00
< th class = "h2" > {{ account_class.bits[-1] }} {{ label }}< / th >
2020-02-15 15:50:33 +11:00
{% for balance_sheet in balance_sheets %}< th class = "h2" > {{ balance_sheet.date.strftime('%Y') }} < / th > {% endfor %}
2020-02-15 11:47:10 +11:00
{% else %}
2020-02-15 15:50:33 +11:00
< th class = "h2" colspan = "{{ balance_sheets|length + 1 }}" > {{ account_class.bits[-1] }} {{ label }}< / th >
2020-02-15 11:47:10 +11:00
{% endif %}
< / tr >
{% for account in account_class.children if account in accounts %}
{{ print_rows(account, invert=invert) }}
{% endfor %}
< tr class = "total" >
< td > Total {{ account_class.bits[-1] }} {{ label }}< / td >
2020-03-20 22:14:05 +11:00
{% for balance_sheet in balance_sheets %}< td > {{ (-balance_sheet.get_total(account_class) if invert else balance_sheet.get_total(account_class)).exchange(report_currency, True)|a }}< / td > {% endfor %}
2020-02-15 11:47:10 +11:00
< / tr >
< tr > < td colspan = "2" > < / td > < / tr >
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-03-20 22:14:05 +11:00
{% for balance_sheet in balance_sheets %}< td > {{ (-balance_sheet.get_total(root) if invert else balance_sheet.get_total(root)).exchange(report_currency, True)|a }}< / td > {% endfor %}
2020-02-15 11:47:10 +11:00
< / tr >
2020-01-14 00:06:14 +11:00
{% endmacro %}
<!DOCTYPE html>
< html >
< head >
< meta charset = "utf-8" >
2020-02-15 15:50:33 +11:00
< title > Balance Sheet as at {{ balance_sheets[0].date.strftime('%d %B %Y') }}< / title >
2020-01-14 00:06:14 +11:00
< 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 > Balance Sheet< / h1 >
2020-02-15 15:50:33 +11:00
< h2 > As at {{ balance_sheets[0].date.strftime('%d %B %Y') }}< / h2 >
2020-01-14 00:06:14 +11:00
2020-02-15 15:50:33 +11:00
< table class = "ledger onedesc" >
2020-02-15 11:47:10 +11:00
{# Assets #}
2020-02-15 15:50:33 +11:00
< tr > < th class = "h1" colspan = "{{ balance_sheets|length + 1 }}" > Assets< / th > < / tr >
2020-03-20 22:14:05 +11:00
{{ do_accounts(ledger.get_account(config['assets_account']), 'Assets', False, True) }}
2020-02-15 11:47:10 +11:00
< tr > < td colspan = "2" > < / td > < / tr >
2020-01-14 00:06:14 +11:00
2020-02-15 11:47:10 +11:00
{# Liabilities #}
2020-02-15 15:50:33 +11:00
< tr > < th class = "h1" colspan = "{{ balance_sheets|length + 1 }}" > Liabilities< / th > < / tr >
2020-03-20 22:14:05 +11:00
{{ do_accounts(ledger.get_account(config['liabilities_account']), 'Liabilities', True, False) }}
2020-01-14 00:06:14 +11:00
< tr > < td colspan = "2" > < / td > < / tr >
2020-02-15 11:47:10 +11:00
{# Equity #}
2020-02-15 15:50:33 +11:00
< tr > < th class = "h1" colspan = "{{ balance_sheets|length + 1 }}" > Equity< / th > < / tr >
2020-01-14 00:06:14 +11:00
2020-03-20 22:14:05 +11:00
{% for account in ledger.get_account(config['equity_account']).children if account in accounts %}
2020-02-15 11:47:10 +11:00
{{ print_rows(account, invert=True) }}
{% endfor %}
2020-01-14 00:06:14 +11:00
< tr class = "total" >
< td > Total Equity< / td >
2020-03-20 22:14:05 +11:00
{% for balance_sheet in balance_sheets %}< td > {{ -balance_sheet.get_total(ledger.get_account(config['equity_account'])).exchange(report_currency, True)|a }}< / td > {% endfor %}
2020-01-14 00:06:14 +11:00
< / tr >
< / table >
< / body >
< / html >