{% load account_keeping_tags i18n %}
<table class="table table-hover table-condensed small">
  <thead>
  <tr>
    <th>{% trans "ID" %}</th>
    <th>{% trans "Date" %}</th>
    <th>{% trans "Invoice number" %}</th>
    <th>{% trans "PDF" %}</th>
    <th>{% trans "Description" %}</th>
    <th>{% trans "Currency" %}</th>
    <th>{% trans "Amount (net)" %}</th>
    <th>{% trans "VAT" %}</th>
    <th>{% trans "Amount (gross)" %}</th>
    <th>{% trans "Balance" %}</th>
    <th colspan="2">{% trans "Transactions" %}</th>
  </tr>
  </thead>
  <tbody>
    {% for invoice in invoices %}
      <tr class="{% if invoice.invoice_type == transaction_types.withdrawal %}danger{% else %}success{% endif %}">
        <td><a href="{% url "account_keeping_invoice_update" pk=invoice.pk %}">{{ invoice.pk }}</a></td>
        <td>{{ invoice.invoice_date|date:"Y-m-d" }}</td>
        <td>{{ invoice.invoice_number|default:"n/a" }}</td>
        <td>{% if invoice.pdf %}<a href="{{ MEDIA_URL }}{{ invoice.pdf }}"><span class="glyphicon glyphicon-file"></span></a>{% else %}n/a{% endif %}</td>
        <td>{{ invoice.description|default:"n/a" }}</td>
        <td>{{ invoice.currency.iso_code }}</td>
        <td>{{ invoice.amount_net|currency:invoice.currency }}</td>
        <td>{{ invoice.vat }}</td>
        <td>{{ invoice.amount_gross|currency:invoice.currency }}</td>
        <td><span class="text-{% if invoice.balance >= 0 %}success{% else %}danger{% endif %}">{{ invoice.balance|currency:invoice.currency }}</span></td>
        <td>
          {% for transaction in invoice.transactions.all %}
            <a href="{% url "account_keeping_transaction_update" pk=transaction.pk %}">{{ transaction.pk }}</a>{% if not forloop.last %}, {% endif %}
          {% endfor %}
        </td>
        <td class="text-right">
          <a class="btn btn-default btn-xs" href="{% url "account_keeping_transaction_create" %}?invoice={{ invoice.pk }}">{% trans "Add transaction" %}</a>
        </td>
      </tr>
    {% endfor %}
  </tbody>
</table>
