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

<style>
    table.financial-statement thead th:last-child,
    table.financial-statement tbody td:last-child,
    table.financial-statement tfoot td:last-child {
        text-align: right;
    }

    table.financial-statement tfoot td {
        font-weight: 700;
    }
</style>

<div class="table-container">

    {# OPERATING ACTIVITIES #}
    <table class="table is-fullwidth is-narrow is-striped is-hoverable is-bordered financial-statement">
        <thead>
        <tr>
            <td class="has-text-weight-light is-size-3">{% trans 'Cash from Operating Activities' %}</td>
            <td class="has-text-right has-text-weight-bold">{% trans 'Total' %}</td>
        </tr>
        </thead>

        <tbody>

        <tr>
            <td class="has-text-weight-bold is-size-5">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_NET_INCOME.description }}
            </td>
            <td class="has-text-weight-bold has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_NET_INCOME.balance | currency_format }}</td>
        </tr>

        {# Non-cash Charges to Non-current Accounts #}
        <tr>
            <td class="is-size-5 has-text-weight-light has-text-centered">{% trans 'Noncash Charges to Non-current Accounts' %}</td>
            <td></td>
        </tr>

        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_DEPRECIATION_AMORTIZATION.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_DEPRECIATION_AMORTIZATION.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVESTMENT_GAINS.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVESTMENT_GAINS.balance | currency_format }}</td>
        </tr>

        {# Non-cash Charges to Current Accounts #}
        <tr>
            <td class="is-size-5 has-text-weight-light has-text-centered">{% trans 'Noncash Charges to Current Accounts' %}</td>
            <td></td>
        </tr>

        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_ACCOUNTS_RECEIVABLE.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_ACCOUNTS_RECEIVABLE.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVENTORY.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_INVENTORY.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_ACCOUNTS_PAYABLE.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_ACCOUNTS_PAYABLE.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_OTHER_CURRENT_ASSETS_ADJUSTMENT.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_OTHER_CURRENT_ASSETS_ADJUSTMENT.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_OTHER_CURRENT_LIABILITIES_ADJUSTMENT.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.operating.GROUP_CFS_OP_OTHER_CURRENT_LIABILITIES_ADJUSTMENT.balance | currency_format }}</td>
        </tr>

        </tbody>
        <tfoot>
        <tr>
            <td class="has-text-weight-bold is-size-5">{% trans 'Net Cash Provided by Operating Activities' %}</td>
            <td class="has-text-weight-bold has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.net_cash_by_activity.OPERATING | currency_format }}</td>
        </tr>
        </tfoot>
    </table>

    {# FINANCING ACTIVITIES #}
    <table class="table is-fullwidth is-narrow is-striped is-hoverable is-bordered financial-statement">
        <thead>
        <tr>
            <td class="has-text-weight-light is-size-3">{% trans 'Cash from Financing Activities' %}</td>
            <td></td>
        </tr>
        </thead>

        <tbody>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_ISSUING_EQUITY.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_ISSUING_EQUITY.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_DIVIDENDS.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_DIVIDENDS.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_ST_DEBT_PAYMENTS.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_ST_DEBT_PAYMENTS.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_LT_DEBT_PAYMENTS.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.financing.GROUP_CFS_FIN_LT_DEBT_PAYMENTS.balance | currency_format }}</td>
        </tr>


        </tbody>
        <tfoot>
        <tr>
            <td class="has-text-weight-bold is-size-5">{% trans 'Net Cash Provided by Financing Activities' %}</td>
            <td class="has-text-weight-bold has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.net_cash_by_activity.FINANCING | currency_format }}</td>
        </tr>
        </tfoot>
    </table>

    {# INVESTING ACTIVITIES #}
    <table class="table is-fullwidth is-narrow is-striped is-hoverable is-bordered financial-statement">
        <thead>
        <tr>
            <td class="has-text-weight-light is-size-3">{% trans 'Cash from Investing Activities' %}</td>
            <td></td>
        </tr>
        </thead>
        <tbody>

        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.investing.GROUP_CFS_INVESTING_PPE.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.investing.GROUP_CFS_INVESTING_PPE.balance | currency_format }}</td>
        </tr>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {{ tx_digest.cash_flow_statement.investing.GROUP_CFS_INVESTING_SECURITIES.description }}
            </td>
            <td class="has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.investing.GROUP_CFS_INVESTING_SECURITIES.balance | currency_format }}</td>
        </tr>

        </tbody>


        <tfoot>
        <tr>
            <td class="has-text-weight-bold is-size-5">{% trans 'Net Cash Provided by Investing Activities' %}</td>
            <td class="has-text-weight-bold has-text-right">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.net_cash_by_activity.INVESTING | currency_format }}</td>
        </tr>
        </tfoot>


    </table>

    {# NET CASH #}
    <table class="table is-fullwidth is-narrow is-striped is-hoverable is-bordered financial-statement">
        <thead>
        <tr>
            <td class="has-text-weight-light is-size-3">{% trans 'Net Cashflow' %}</td>
            <td></td>
        </tr>
        </thead>

        <tbody>
        <tr>
            <td class="has-text-right has-text-weight-light">
                {% trans 'Net Cash From' %} {{ tx_digest.from_date }} -> {{ tx_digest.to_date }}
            </td>
            <td class="has-text-weight-bold has-text-right is-size-5">
                {% currency_symbol %}{{ tx_digest.cash_flow_statement.net_cash | currency_format }}</td>
        </tr>

        </tbody>

    </table>
</div>
