{% import 'macros/_account_macros.html' as account_macros %} {% import 'macros/_commodity_macros.html' as commodity_macros %} {% macro render_diff_and_number(balance, cost, currency, invert=False) %} {% set num = balance.pop(currency, 0) %} {% if currency in cost %} {% set cost_num = cost.pop(currency, 0) %} {% set diff = num - cost_num %} {% if invert %} {% set diff = -diff %} {% endif %} {% if diff %} ({{ diff|format_currency(currency) }}) {% endif %} {% endif %} {{ num|format_currency(currency, invert=invert) }} {% endmacro %} {% macro tree(account_node, invert=False) %}
  1. {% for currency in ledger.options.operating_currency %} {{ currency }} {% endfor %} {{ _('Other') }}

  2. {% set end_date = g.filtered.end_date %} {% for account in ([account_node] if account_node.name else account_node.children) if account|should_show recursive %} {% set balance = account.balance|cost_or_value(end_date) %} {% set balance_children = account.balance_children|cost_or_value(end_date) %} {% set cost = account.balance|cost if g.conversion == 'at_value' else {} %} {% set cost_children = account.balance_children|cost if g.conversion == 'at_value' else {} %} {% for currency in ledger.options.operating_currency %} {{ render_diff_and_number(balance, cost, currency, invert=invert) }} {{ render_diff_and_number(balance_children, cost_children, currency, invert=invert) }} {% endfor %} {% for currency in balance.keys()|sort %} {{ render_diff_and_number(balance, cost, currency, invert=invert) }} {{ commodity_macros.render_currency(ledger, currency) }}
    {% endfor %}
    {% for currency in balance_children.keys()|sort %} {{ render_diff_and_number(balance_children, cost_children, currency, invert=invert) }} {{ commodity_macros.render_currency(ledger, currency) }}
    {% endfor %}

    {% if account.children %}
      {{ loop(account.children|sort(attribute='name')) }}
    {% endif %} {% endfor %}
{% endmacro %} {% macro render_budget(budget, currency, number=0) %} {% if currency in budget %} {% set diff = budget[currency] - number %} ({{ diff|format_currency(currency, show_if_zero=True) }}{{ ' '+currency if not number else '' }}) {% endif %} {% endmacro %} {% macro account_tree(account_name, interval_balances, dates, accumulate) %}
  1. {% for begin_date, end_date in dates %} {% if accumulate %} {% set time_filter = dates[-1][0]|format_date_filter + ' - ' + begin_date|format_date_filter %} {% else %} {% set time_filter = begin_date|format_date_filter %} {% endif %} {{ begin_date|format_date }} {% endfor %}

  2. {% for account in [interval_balances[0]|get_or_create(account_name)] recursive %}

    {% for begin_date, end_date in dates %} {% if accumulate %}{% set begin_date = dates[-1][0] %}{% endif %} {% set budget = ledger.budgets.calculate(account.account, begin_date, end_date) %} {% set budget_children = ledger.budgets.calculate_children(account.account, begin_date, end_date) %} {% set current_account = interval_balances[loop.index0]|get_or_create(account.account) %} {% set balance = current_account.balance|cost_or_value(end_date) %} {% set balance_children = current_account|balance_children|cost_or_value(end_date) %} {% for pos in balance %} {{ render_budget(budget, pos.units.currency, pos.units.number) }} {{ commodity_macros.render_amount(ledger, pos.units, 'number') }} {% endfor %} {% for currency, number in budget.items() if currency not in balance.currencies() %} {{ render_budget(budget, currency) }} {% endfor %} {% for pos in balance_children %} {{ render_budget(budget_children, pos.units.currency, pos.units.number) }} {{ commodity_macros.render_amount(ledger, pos.units, 'number') }} {% endfor %} {% for currency, number in budget_children.items() if currency not in balance_children.currencies() %} {{ render_budget(budget_children, currency) }} {% endfor %} {% endfor %}

      {{ loop(account.values()|sort(attribute='account')) }}
    {% endfor %}
{% endmacro %}