{% load main_extras transaction_extras %}
{% load i18n %}
<div id="transactions" class="table">
  <table class="full-width">
    <colgroup>
      <col class="icon">
      <col class="date">
      <col class="desc">
      <col class="value">
      <col class="value">
      <col class="desc">
      {% if not hide_category %}<col class="desc">{% endif %}
      {% if not hide_account %}<col class="desc">{% endif %}
    </colgroup>
    <thead>
      <tr>
        <th>{{ "attachment"|remix }}</th>
        <th>{% translate "Date" %}</th>
        <th>{% translate "Name" %}</th>
        <th>{% translate "Expenses" %}</th>
        <th>{% translate "Income" %}</th>
        <th>{% translate "Trader" %}</th>
        {% if not hide_category %}
          <th>{% translate "Category" %}</th>
        {% endif %}
        {% if not hide_account %}
          <th>{% translate "Account" %}</th>
        {% endif %}
      </tr>
    </thead>
    <tbody>
      {% for trans in transactions %}
        <tr>
          <td class="c">
            {% for invoice in trans.invoice_set.all %}
              <a class="i" href="{{ invoice.file.url }}">{{ "attachment"|remix }}</a>
            {% endfor %}
          </td>
          <td class="date">
            <time datetime="{{ trans.date|date:"Y-m-d" }}">
              {% if month %}
                {{ trans.date|date:"l d"|capfirst }}
              {% elif year %}
                {{ trans.date|date:"d F" }}
              {% else %}
                {{ trans.date|date:"Y-m-d" }}
              {% endif %}
            </time>
          </td>
          <th scope="row" class="l">
            <a href="{{ trans.get_absolute_url }}">{{ trans.name }}</a>
          </th>
          {% if trans.value >= 0 %}<td></td>{% endif %}
          <td class="value">{{ trans.value|pmvalue }}</td>
          {% if trans.value < 0 %}<td></td>{% endif %}
          <td>{{ trans.trader|default_if_none:"" }}</td>
          {% if not hide_category %}
            <td>
              {% if trans.category %}
                <a href="{{ trans.category.get_absolute_url }}">{{ trans.category.icon|remix }}{{ trans.category }}</a>
              {% endif %}
            </td>
          {% endif %}
          {% if not hide_account %}
            <td>
              {% if trans.account %}
                <a href="{{ trans.account.get_absolute_url }}">{{ trans.account.icon|remix }}{{ trans.account|default_if_none:"" }}</a>
              {% endif %}
            </td>
          {% endif %}
        </tr>
      {% empty %}
        <tr>
          <td class="empty" colspan="{{ ncol }}">{% translate "No transaction" %}</td>
        </tr>
      {% endfor %}
    </tbody>
    {% if transactions_url %}
      <tfoot>
        <tr class="more">
          <td colspan="{{ ncol }}">
            <a href="{{ transactions_url }}">{% translate "View all transactions" %}</a>
          </td>
        </tr>
      </tfoot>
    {% endif %}
  </table>
</div>
