{% load account_keeping_tags humanize i18n libs_tags %}
{% for transaction in transactions %}
    <tr class="{% if transaction.transaction_type == transaction_types.withdrawal %}danger{% else %}success{% endif %}">
        <td><a href="{% url "account_keeping_transaction_update" pk=transaction.pk %}">{{ transaction.pk }}</a></td>
        <td>{{ transaction.transaction_date|date:"Y-m-d" }}</td>
        <td>{{ transaction.get_description|linebreaksbr }}</td>
        <td>
            {% for invoice in transaction.get_invoices %}
                {% if invoice %}
                    <a href="{% url "account_keeping_invoice_update" pk=invoice.pk %}">{{ invoice.invoice_number|default:invoice.pk }}</a>
                {% elif transaction.invoice_number %}
                    {{ transaction.invoice_number }}
                {% else %}
                    {% trans "n/a" %}
                {% endif %}
                {% if not forloop.last %}, {% endif %}
            {% endfor %}
        </td>
        <td>
            {% for invoice in transaction.get_invoices %}
                {% if invoice.pdf %}<a href="{{ MEDIA_URL }}{{ invoice.pdf }}"><span class="glyphicon glyphicon-file"></span></a>{% else %}n/a{% endif %}
            {% endfor %}
        </td>
        <td><a href="{% url "admin:account_keeping_payee_change" transaction.payee.pk %}">{{ transaction.payee }}</a></td>
        <td><a href="{% url "admin:account_keeping_category_change" transaction.category.pk %}">{{ transaction.category }}</a></td>
        <td>{% if transaction.transaction_type == 'w' %}{% trans "DR" %}{% else %}{% trans "CR" %}{% endif %}</td>
        <td>{{ transaction.amount_net|currency:transaction.currency }}</td>
        <td>{{ transaction.vat }}</td>
        <td>{{ transaction.amount_gross|currency:transaction.currency }}</td>
        {% if show_balance %}
            <td>{{ BALANCE|currency:transaction.currency }}</td>
            {% sum "BALANCE" transaction.value_gross multiplier=-1 %}
        {% endif %}
        <td class="text-right">
          <a class="btn btn-default btn-xs" href="{% url "account_keeping_transaction_create" %}?parent={{ transaction.pk }}">{% trans "Add transaction" %}</a>
        </td>
    </tr>
{% endfor %}
