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

<div class="table-container">
    <table class="table is-fullwidth is-narrow is-striped">
        <tr>
            <th>Account Number</th>
            <th>Description</th>
            {% if by_unit %}
                <th>Unit</th>
            {% endif %}
            <th>Balance Type</th>
            <th>Balance</th>
        </tr>
        <tr>
            <td><h2 class="is-size-3">{% trans 'Income' %}</h2></td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td></td>
        </tr>
        {% for acc in tx_digest.group_account.GROUP_INCOME %}
            <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>Total Income</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_INCOME | currency_format }}</td>
        </tr>


        <tr>
            <td><h2 class="is-size-3">{% trans 'Expenses' %}</h2></td>
            <td></td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
        </tr>
        {% for acc in tx_digest.group_account.GROUP_EXPENSES %}
            <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 | reverse_sing | currency_format }}</td>
            </tr>
        {% endfor %}
        <tr class="has-text-weight-bold">
            <td>Total Expenses</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_EXPENSES | reverse_sing | currency_format }}</td>
        </tr>

        <tr class="has-text-weight-bold">
            <td>Total Income (Loss)</td>
            <td></td>
            {% if by_unit %}
                <td></td>
            {% endif %}
            <td></td>
            <td>{% currency_symbol %}{{ tx_digest.group_balance.GROUP_EARNINGS | currency_format }}</td>
        </tr>


    </table>
</div>
