{% load django_ledger %}
{% load i18n %}

<div class="table-container">
    <table class="table is-fullwidth is-narrow is-striped">
        <thead>
        <tr>
            <th>{% trans 'Account Number' %}</th>
            <th>{% trans 'Account Name' %}</th>
            {% if by_unit %}
                <th>{% trans 'Unit' %}</th>
            {% endif %}
            <th>{% trans 'Balance Type' %}</th>
            <th>{% trans 'Balance' %}</th>
        </tr>
        </thead>

        <tbody>
        <tr>
            <td><h2 class="is-size-3">{% trans 'Assets' %}</h2></td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td></td>
        </tr>

        {# ASSETS #}
        {% for acc in tx_digest.group_account.GROUP_ASSETS %}
            <tr>
                <td>{{ acc.code }}</td>
                <td>{{ acc.name }}</td>
                {% if by_unit %}
                    <td>{% if acc.unit_name %}{{ acc.unit_name }}{% endif %}</td>
                {% endif %}
                <td class="has-text-centered">
                    {% if acc.balance_type == 'debit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-down' 24 %}</span>
                    {% elif acc.balance_type == 'credit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-up' 24 %}</span>
                    {% endif %}
                </td>
                <td>{% currency_symbol %}{{ acc.balance | currency_format }}</td>
            </tr>
        {% endfor %}

        <tr class="has-text-weight-bold">
            <td>{% trans 'Total Assets' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_ASSETS | currency_format }}</td>
        </tr>

        <tr>
            <td><h2 class="is-size-3">{% trans 'Liabilities' %}</h2></td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td></td>
        </tr>

        {# LIABILITIES #}
        {% for acc in tx_digest.group_account.GROUP_LIABILITIES %}
            <tr>
                <td>{{ acc.code }}</td>
                <td>{{ acc.name }}</td>
                {% if by_unit %}
                    <td>{% if acc.unit_name %}{{ acc.unit_name }}{% endif %}</td>
                {% endif %}

                <td class="has-text-centered">
                    {% if acc.balance_type == 'debit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-down' 24 %}</span>
                    {% elif acc.balance_type == 'credit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-up' 24 %}</span>
                    {% endif %}
                </td>
                <td>{% currency_symbol %}{{ acc.balance | currency_format }}</td>
            </tr>
        {% endfor %}
        <tr class="has-text-weight-bold">
            <td>{% trans 'Total Liabilities' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_LIABILITIES | currency_format }}</td>
        </tr>

        <tr class="is-primary">
            <td><h2 class="is-size-3">{% trans 'Equity' %}</h2></td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td></td>
        </tr>

        {# CAPITAL #}
        {% for acc in tx_digest.group_account.GROUP_CAPITAL %}
            <tr>
                <td>{{ acc.code }}</td>
                <td>{{ acc.name }}</td>
                {% if by_unit %}
                    <td>{% if acc.unit_name %}{{ acc.unit_name }}{% endif %}</td>
                {% endif %}

                <td class="has-text-centered">
                    {% if acc.balance_type == 'debit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-down' 24 %}</span>
                    {% elif acc.balance_type == 'credit' %}
                        <span class="icon">{% icon 'bi:arrow-bar-up' 24 %}</span>
                    {% endif %}
                </td>
                <td>{% currency_symbol %}{{ acc.balance | currency_format }}</td>
            </tr>
        {% endfor %}

        <tr class="has-text-weight-bold">
            <td>{% trans 'Total Capital' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_CAPITAL | currency_format }}</td>
        </tr>

        <tr class="has-text-weight-bold">
            <td>{% trans 'Retained Earnings' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_EARNINGS | currency_format }}</td>
        </tr>

        <tr class="has-text-weight-bold">
            <td>{% trans 'Total Equity' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_EQUITY | currency_format }}</td>
        </tr>

        <tr class="has-text-weight-bold">
            <td>{% trans 'Total Equity + Liabilities' %}</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_LIABILITIES_EQUITY | currency_format }}</td>
        </tr>
        </tbody>
    </table>
</div>
