{% extends basetpl %}
{% load i18n %}
{% load money %}
{% load static %}
{% block title %}{% trans "Export bank transfer refunds" %}{% endblock %}
{% block content %}
    <h1>{% trans "Export bank transfer refunds" %}</h1>
    <p>
        {% blocktrans trimmed %}
            <strong>{{ num_new }}</strong> Bank transfer refunds have been placed and are not yet part of an export.
        {% endblocktrans %}
    </p>
    {% if request.event.testmode %}
        <div class="alert alert-warning">
            {% trans "In test mode, your exports will only contain test mode orders." %}
        </div>
    {% elif request.event %}
        <div class="alert alert-info">
            {% trans "If you want, you can now also create these exports for multiple events combined." %}
            <strong>
                <a href="{% url "plugins:banktransfer:refunds.list" organizer=request.organizer.slug %}">
                    {% trans "Go to organizer-level exports" %}
                </a>
            </strong>
        </div>
    {% endif %}

    {% if num_new > 0 %}
        <form action="" method="post">
            {% csrf_token %}
            <button class="btn btn-primary">
                {% trans "Create new export file" %}
            </button>
            <div class="form-group">
                <div class="checkbox">
                    <label for="id_unite_transactions">
                        <input type="checkbox" name="unite_transactions" id="id_unite_transactions" checked>
                        {% trans "Aggregate transactions to the same bank account" %}
                    </label>
                </div>
            </div>
            <p>
                {% blocktrans %}
                    Beware that refunds will be marked as done once an export is created.
                    Make sure to download the export and execute the refunds.
                {% endblocktrans %}
            </p>
        </form>
    {% endif %}
    <h2>{% trans "Exported files" %}</h2>
    <div class="table-responsive">
        <table class="table table-hover">
            <thead>
            <tr>
                <th>{% trans "Export date" %}</th>
                <th>{% trans "Number of orders" %}</th>
                <th>{% trans "Total amount" %}</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            {% for export in exports %}
                <tr>
                    <td>
                        {{ export.datetime|date:"SHORT_DATETIME_FORMAT" }}
                        {% if export.testmode %}
                            <span class="label label-warning">{% trans "TEST MODE" %}</span>
                        {% endif %}
                    </td>
                    <td>{{ export.cnt }}</td>
                    <td>
                        {% if export.currency %}
                        {{ export.sum|default_if_none:0|money:export.currency }}
                        {% else %}
                        {{ export.sum|default_if_none:0|floatformat:2 }}
                        {% endif %}
                    </td>
                    <td class="text-right">
                        {% if not export.downloaded %}
                            <span class="label label-warning">{% trans "not downloaded" %}</span>
                        {% endif %}
                        {% if export.event %}
                            <a class="btn btn-primary"
                               href="{% url "plugins:banktransfer:refunds.download" organizer=request.organizer.slug event=export.event.slug id=export.id %}">
                                <span class="fa fa-download"></span> {% trans "Download CSV" %}
                            </a>
                            {% if export.currency == "EUR" %}
                                <a class="btn btn-default"
                                   href="{% url "plugins:banktransfer:refunds.sepa" organizer=request.organizer.slug event=export.event.slug id=export.id %}">
                                    {% trans "SEPA XML" %}
                                </a>
                            {% endif %}
                        {% else %}
                            <a class="btn btn-primary"
                               href="{% url "plugins:banktransfer:refunds.download" organizer=export.organizer.slug id=export.id %}">
                                <span class="fa fa-download"></span> {% trans "Download CSV" %}
                            </a>
                            {% if export.currency == "EUR" %}
                                <a class="btn btn-default"
                                   href="{% url "plugins:banktransfer:refunds.sepa" organizer=export.organizer.slug id=export.id %}">
                                    {% trans "SEPA XML" %}
                                </a>
                            {% endif %}
                        {% endif %}
                    </td>
                </tr>
            {% empty %}
                <tr>
                    <td colspan="3">
                        {% trans "No exports have been created yet." %}
                    </td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
{% endblock %}
