<h2>Income</h2>
{% set income = tax_report[tax_year]['Income'] %}
{% for asset in income.assets|sort %}
    {% set asset_totals = namespace(events=0, quantity=0, amount=0, fees=0) %}
    <table repeat="1" width="100%">
        <tr>
            <th align="left">Asset</th>
            <th align="left">Date</th>
            <th align="left">Income Type</th>
            <th align="right">Quantity</th>
            <th align="right">Amount</th>
            <th align="right">Fees</th>
            <th></th>
            <th></th>
        </tr>
        {% for te in income.assets[asset] %}
            {% set asset_totals.events = asset_totals.events + 1 %}
            <tr>
                <td>{{te.asset}}</td>
                <td>{{te.date|datefilter}}</td>
                <td width="25%">{{te.type}}</td>
                <td align="right">{{te.quantity|quantityfilter}}</td>
                {% set asset_totals.quantity = asset_totals.quantity + te.quantity %}
                <td align="right">{{te.amount|valuefilter}}</td>
                {% set asset_totals.amount = asset_totals.amount + te.amount %}
                <td align="right">{{te.fees|valuefilter}}</td>
                {% set asset_totals.fees = asset_totals.fees + te.fees %}
                <td></td>
                <td></td>
            </tr>
        {% endfor %}
        {% if asset_totals.events > 1 %}
            <tr>
                <td align="left">Total</td>
                <td align="left"></td>
                <td align="left"></td>
                <td align="right">{{asset_totals.quantity|quantityfilter}}</td>
                <td align="right">{{asset_totals.amount|valuefilter}}</td>
                <td align="right">{{asset_totals.fees|valuefilter}}</td>
                <td></td>
                <td></td>
            </tr>
        {% endif %}
    </table>
    <br>
{% endfor %}
<table repeat="1" width="100%">
    <tr>
        <th align="left">Income Type</th>
        <th></th>
        <th width="25%"></th>
        <th></th>
        <th align="right">Amount</th>
        <th align="right">Fees</th>
        <th></th>
        <th></th>
    </tr>
    {% for i_type in income.type_totals|sort %}
        <tr>
            <td>{{i_type}}</td>
            <td></td>
            <td width="25%"></td>
            <td></td>
            <td align="right">{{income.type_totals[i_type]['amount']|valuefilter}}</td>
            <td align="right">{{income.type_totals[i_type]['fees']|valuefilter}}</td>
            <td></td>
            <td></td>
        </tr>
    {% endfor %}
</table>
<table>
    <tr class="total_row">
        <td align="left">Total</td>
        <td align="left"></td>
        <td align="left" width="25%"></td>
        <td align="right"></td>
        <td align="right">{{income.totals['amount']|valuefilter}}</td>
        <td align="right">{{income.totals['fees']|valuefilter}}</td>
        <td></td>
        <td></td>
    </tr>
</table>
