<commit_before>{% set entry_types = ['open', 'close', 'transaction', 'balance', 'note', 'document', 'pad', 'query', 'custom', 'budget'] %}
{% set transaction_types = ['cleared', 'pending', 'other'] %}
{% set flags_to_types = {'*': 'cleared', '!': 'pending'} %}
{% set document_types = ['discovered', 'statement'] %}
{% set default_show_type = {
    'open':        'open' in ledger.fava_options['journal-show'],
    'close':       'close' in ledger.fava_options['journal-show'],
    'balance':     'balance' in ledger.fava_options['journal-show'],
    'note':        'note' in ledger.fava_options['journal-show'],
    'pad':         'pad' in ledger.fava_options['journal-show'],
    'query':       'query' in ledger.fava_options['journal-show'],
    'custom':      'custom' in ledger.fava_options['journal-show'],
    'budget':      'budget' in ledger.fava_options['journal-show'],

    'transaction': 'transaction' in ledger.fava_options['journal-show'],
    'cleared':     'cleared' in ledger.fava_options['journal-show-transaction'],
    'pending':     'pending' in ledger.fava_options['journal-show-transaction'],
    'other':       'other' in ledger.fava_options['journal-show-transaction'],

    'document':    'document' in ledger.fava_options['journal-show'],
    'discovered':  'discovered' in ledger.fava_options['journal-show-document'],
    'statement':   'statement' in ledger.fava_options['journal-show-document'],

    'metadata':    'metadata' in ledger.fava_options['journal-show'],
    'postings':    'postings' in ledger.fava_options['journal-show'],
} %}
{% if request.args.get('show', False) %}
    {% set _list = request.args.getlist('show') %}
    {% set show_type = {
        'open':        'open' in _list,
        'close':       'close' in _list,
        'balance':     'balance' in _list,
        'note':        'note' in _list,
        'pad':         'pad' in _list,
        'query':       'query' in _list,
        'custom':      'custom' in _list,
        'budget':      'budget' in _list,

        'transaction': 'transaction' in _list,
        'cleared':     'cleared' in _list,
        'pending':     'pending' in _list,
        'other':       'other' in _list,

        'document':    'document' in _list,
        'discovered':  'discovered' in _list,
        'statement':   'statement' in _list,

        'metadata':     'metadata' in _list,
        'postings':         'postings' in _list,
    } %}
{% else %}
    {% set show_type = default_show_type %}
{% endif %}
{% set transaction_type_buttons = {
    'cleared': ('*', _('Cleared Transactions')),
    'pending': ('!', _('Pending Transactions')),
    'other':   ('x', _('Other Transactions')),
}
%}
{% set document_type_buttons = {
    'discovered': ('D', _('Documents discovered by beancount')),
    'statement': ('S', _('Statements from metadata'))
}
%}
<form id="entry-filters" class="journal-entry-filters wide-form">
    {% for type in entry_types %}
        {% if type != 'budget' or ledger.budgets %}
    <button type="button" title="Toggle {{ type|capitalize }} entries" data-type="{{ type }}"{% if not show_type[type] %} class="inactive"{% endif %}>{{ type|capitalize }}</button>
            {% if type == 'transaction' %}
                {% for txn_type in transaction_types %}
    <button type="button" title="{{ transaction_type_buttons[txn_type].1 }}" data-type="{{ txn_type }}" class="txn-toggle{% if not show_type[txn_type] or not show_type['transaction'] %} inactive{% endif %}">{{ transaction_type_buttons[txn_type].0 }}</button>
                {% endfor %}
            {% endif %}
            {% if type == 'document' %}
                {% for doc_type in document_types %}
    <button type="button" title="{{ document_type_buttons[doc_type].1 }}" data-type="{{ doc_type }}" class="doc-toggle{% if not show_type[doc_type] or not show_type['document'] %} inactive{% endif %}">{{ document_type_buttons[doc_type].0 }}</button>
                {% endfor %}
            {% endif %}
        {% endif %}
    {% endfor %}
    <button type="button" title="Toggle metadata" data-type="metadata"{% if not show_type['metadata'] %} class="inactive"{% endif %}>Metadata</button>
    <button type="button" title="Toggle postings" data-type="postings" {% if not show_type['postings'] %} class="inactive"{% endif %}>Postings</button>
</form>

{% set context_url = url_for('context', ehash='REPLACEME') %}
{% set account_url = url_for('account', name='REPLACEME') %}

{% macro account_link(name) -%}
<a class="account-link" href="{{ account_url.replace('REPLACEME', name) }}">
    {% set levels = name|account_level %}
    {%- for level in range(0, levels) -%}
        {% set subaccount_name = name.rsplit(':', maxsplit=levels-loop.index)[0] %}
        {% set subaccount_part = name.split(':')[level] %}

        {%- if loop.last -%}
            <span>{{ subaccount_part }}</span>
        {%- else -%}
            {{ subaccount_part }}:
        {%- endif -%}
    {%- endfor -%}
</a>
{%- endmacro %}

{% macro render_inventory(inv) -%}
    {% for pos in inv.units() %}
        {{ pos.units|format_amount }}<br>
    {% endfor %}
{%- endmacro %}

{% macro render_metadata(metadata, show_metadata, entry=None) -%}
{% if metadata %}
    <dl class="metadata{% if not show_metadata %} hidden{% endif %}">
        {% for key, value in metadata.items() %}
            <dt>{{ key }}</dt>
            <dd>
                {%- if key.startswith('statement') %}
                    <a href="{{ url_for('statement', filename=entry.meta.filename, lineno=entry.meta.lineno, key=key) }}">
                {% endif -%}
                {{ value }}
                {%- if key.startswith('statement') %}</a>{% endif -%}
            </dd>
        {% endfor %}
    </dl>
{% endif %}
{%- endmacro %}

{% set tag_url = url_for_current(tag='#REPLACEME,'+(g.filters['tag'] or '')) %}
{% set link_url = url_for_current(tag='^REPLACEME,'+(g.filters['tag'] or '')) %}
{% macro render_tags_links(entry) -%}
    {% for tag in entry.tags or [] %}
<a class="tag" href="{{ tag_url.replace('REPLACEME', tag) }}">#{{ tag }}</a>
    {% endfor %}
    {% for link_ in entry.links or [] %}
<a class="link" href="{{ link_url.replace('REPLACEME', link_) }}">^{{ link_ }}</a>
    {% endfor %}
{%- endmacro %}

<ol id="journal-table" class="journal-table">
    <li class="head">
        <p>
        <span class="datecell" data-sort="string" data-order="asc">{{ _('Date') }}</span>
        <span class="flag" data-sort="string">{{ _('F') }}</span>
        <span class="description" data-sort="string">{{ _('Narration/Payee') }}</span>
        <span class="num">{{ _('Position') }}</span>
        <span class="num">{{ _('Price') }}</span>
        <span class="num">{{ _('Cost') }}</span>
        {% if show_change_and_balance %}
        <span class="num">{{ _('Change') }}</span>
        <span class="num">{{ _('Balance') }}</span>
        {% endif %}
        </p>
    </li>
{% for entry in journal %}
    {% if show_change_and_balance %}
        {% set entry, _, change, balance = entry %}
    {% endif %}<commit_msg>journal: reverse default sort order<commit_after>{% set entry_types = ['open', 'close', 'transaction', 'balance', 'note', 'document', 'pad', 'query', 'custom', 'budget'] %}
{% set transaction_types = ['cleared', 'pending', 'other'] %}
{% set flags_to_types = {'*': 'cleared', '!': 'pending'} %}
{% set document_types = ['discovered', 'statement'] %}
{% set default_show_type = {
    'open':        'open' in ledger.fava_options['journal-show'],
    'close':       'close' in ledger.fava_options['journal-show'],
    'balance':     'balance' in ledger.fava_options['journal-show'],
    'note':        'note' in ledger.fava_options['journal-show'],
    'pad':         'pad' in ledger.fava_options['journal-show'],
    'query':       'query' in ledger.fava_options['journal-show'],
    'custom':      'custom' in ledger.fava_options['journal-show'],
    'budget':      'budget' in ledger.fava_options['journal-show'],

    'transaction': 'transaction' in ledger.fava_options['journal-show'],
    'cleared':     'cleared' in ledger.fava_options['journal-show-transaction'],
    'pending':     'pending' in ledger.fava_options['journal-show-transaction'],
    'other':       'other' in ledger.fava_options['journal-show-transaction'],

    'document':    'document' in ledger.fava_options['journal-show'],
    'discovered':  'discovered' in ledger.fava_options['journal-show-document'],
    'statement':   'statement' in ledger.fava_options['journal-show-document'],

    'metadata':    'metadata' in ledger.fava_options['journal-show'],
    'postings':    'postings' in ledger.fava_options['journal-show'],
} %}
{% if request.args.get('show', False) %}
    {% set _list = request.args.getlist('show') %}
    {% set show_type = {
        'open':        'open' in _list,
        'close':       'close' in _list,
        'balance':     'balance' in _list,
        'note':        'note' in _list,
        'pad':         'pad' in _list,
        'query':       'query' in _list,
        'custom':      'custom' in _list,
        'budget':      'budget' in _list,

        'transaction': 'transaction' in _list,
        'cleared':     'cleared' in _list,
        'pending':     'pending' in _list,
        'other':       'other' in _list,

        'document':    'document' in _list,
        'discovered':  'discovered' in _list,
        'statement':   'statement' in _list,

        'metadata':     'metadata' in _list,
        'postings':         'postings' in _list,
    } %}
{% else %}
    {% set show_type = default_show_type %}
{% endif %}
{% set transaction_type_buttons = {
    'cleared': ('*', _('Cleared Transactions')),
    'pending': ('!', _('Pending Transactions')),
    'other':   ('x', _('Other Transactions')),
}
%}
{% set document_type_buttons = {
    'discovered': ('D', _('Documents discovered by beancount')),
    'statement': ('S', _('Statements from metadata'))
}
%}
<form id="entry-filters" class="journal-entry-filters wide-form">
    {% for type in entry_types %}
        {% if type != 'budget' or ledger.budgets %}
    <button type="button" title="Toggle {{ type|capitalize }} entries" data-type="{{ type }}"{% if not show_type[type] %} class="inactive"{% endif %}>{{ type|capitalize }}</button>
            {% if type == 'transaction' %}
                {% for txn_type in transaction_types %}
    <button type="button" title="{{ transaction_type_buttons[txn_type].1 }}" data-type="{{ txn_type }}" class="txn-toggle{% if not show_type[txn_type] or not show_type['transaction'] %} inactive{% endif %}">{{ transaction_type_buttons[txn_type].0 }}</button>
                {% endfor %}
            {% endif %}
            {% if type == 'document' %}
                {% for doc_type in document_types %}
    <button type="button" title="{{ document_type_buttons[doc_type].1 }}" data-type="{{ doc_type }}" class="doc-toggle{% if not show_type[doc_type] or not show_type['document'] %} inactive{% endif %}">{{ document_type_buttons[doc_type].0 }}</button>
                {% endfor %}
            {% endif %}
        {% endif %}
    {% endfor %}
    <button type="button" title="Toggle metadata" data-type="metadata"{% if not show_type['metadata'] %} class="inactive"{% endif %}>Metadata</button>
    <button type="button" title="Toggle postings" data-type="postings" {% if not show_type['postings'] %} class="inactive"{% endif %}>Postings</button>
</form>

{% set context_url = url_for('context', ehash='REPLACEME') %}
{% set account_url = url_for('account', name='REPLACEME') %}

{% macro account_link(name) -%}
<a class="account-link" href="{{ account_url.replace('REPLACEME', name) }}">
    {% set levels = name|account_level %}
    {%- for level in range(0, levels) -%}
        {% set subaccount_name = name.rsplit(':', maxsplit=levels-loop.index)[0] %}
        {% set subaccount_part = name.split(':')[level] %}

        {%- if loop.last -%}
            <span>{{ subaccount_part }}</span>
        {%- else -%}
            {{ subaccount_part }}:
        {%- endif -%}
    {%- endfor -%}
</a>
{%- endmacro %}

{% macro render_inventory(inv) -%}
    {% for pos in inv.units() %}
        {{ pos.units|format_amount }}<br>
    {% endfor %}
{%- endmacro %}

{% macro render_metadata(metadata, show_metadata, entry=None) -%}
{% if metadata %}
    <dl class="metadata{% if not show_metadata %} hidden{% endif %}">
        {% for key, value in metadata.items() %}
            <dt>{{ key }}</dt>
            <dd>
                {%- if key.startswith('statement') %}
                    <a href="{{ url_for('statement', filename=entry.meta.filename, lineno=entry.meta.lineno, key=key) }}">
                {% endif -%}
                {{ value }}
                {%- if key.startswith('statement') %}</a>{% endif -%}
            </dd>
        {% endfor %}
    </dl>
{% endif %}
{%- endmacro %}

{% set tag_url = url_for_current(tag='#REPLACEME,'+(g.filters['tag'] or '')) %}
{% set link_url = url_for_current(tag='^REPLACEME,'+(g.filters['tag'] or '')) %}
{% macro render_tags_links(entry) -%}
    {% for tag in entry.tags or [] %}
<a class="tag" href="{{ tag_url.replace('REPLACEME', tag) }}">#{{ tag }}</a>
    {% endfor %}
    {% for link_ in entry.links or [] %}
<a class="link" href="{{ link_url.replace('REPLACEME', link_) }}">^{{ link_ }}</a>
    {% endfor %}
{%- endmacro %}

<ol id="journal-table" class="journal-table">
    <li class="head">
        <p>
        <span class="datecell" data-sort="string" data-order="desc">{{ _('Date') }}</span>
        <span class="flag" data-sort="string">{{ _('F') }}</span>
        <span class="description" data-sort="string">{{ _('Narration/Payee') }}</span>
        <span class="num">{{ _('Position') }}</span>
        <span class="num">{{ _('Price') }}</span>
        <span class="num">{{ _('Cost') }}</span>
        {% if show_change_and_balance %}
        <span class="num">{{ _('Change') }}</span>
        <span class="num">{{ _('Balance') }}</span>
        {% endif %}
        </p>
    </li>
{% for entry in journal|reverse %}
    {% if show_change_and_balance %}
        {% set entry, _, change, balance = entry %}
    {% endif %}
{'fraction_non_alphanumeric': 0.20252985654724048, 'fraction_numerical': 0.0008479966080135679, 'mean_word_length': 3.0238839920386695, 'pattern_counts': {'":': 0, '<': 103, '<?xml version=': 0, '>': 103, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6626647', 'n_tokens_mistral': 4884, 'n_tokens_neox': 4561, 'n_words': 992}