{% extends "pretixplugins/banktransfer/import_base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% block inner %}
    {% if no_more_payments %}
        <div class="alert alert-danger">
            {% blocktrans trimmed with date=request.event.settings.payment_term_last|date:"SHORT_DATE_FORMAT" %}
                In the payment settings of your event, you set the {{ date }} as the last date of any payments.
                Therefore, you won't be able to mark any order as paid here.
            {% endblocktrans %}
        </div>
    {% else %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Upload a new file" %}</h3>
            </div>
            <div class="panel-body">
                <p>{% blocktrans trimmed %}
                    This page allows you to upload bank statement files to process incoming payments.
                {% endblocktrans %}</p>
                <p>{% blocktrans trimmed %}
                    Currently, this feature supports <code>.csv</code> files and files in the MT940 format.
                {% endblocktrans %}</p>
                {% if job_running %}
                    <div class="alert alert-info" data-job-waiting data-job-waiting-url="{% url "plugins:banktransfer:import.job" event=request.event.slug organizer=request.event.organizer.slug job=job_running.pk %}?ajax=1">
                        <span class="fa fa-cog fa-spin"></span>
                        {% trans "An import is currently being processed, please try again in a few minutes." %}
                    </div>
                {% else %}
                    <form action="" method="post" enctype="multipart/form-data" class="form-inline">
                        {% csrf_token %}
                        <div class="form-group">
                            <label for="file">{% trans "Import file" %}: </label> <input id="file" type="file" name="file"/>
                        </div>
                        <div class="clearfix"></div>
                        <button class="btn btn-primary pull-right" type="submit">
                            <span class="icon icon-upload"></span> {% trans "Start upload" %}
                        </button>
                    </form>
                {% endif %}
            </div>
        </div>
    {% endif %}
    {% if transactions_unhandled|length > 0 or request.GET.search %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Unresolved transactions" %}</h3>
            </div>
            <div class="panel-body">
                <p>
                <form class="form-inline helper-display-inline" action="" method="get">
                    <input type="text" name="search" class="form-control" placeholder="{% trans "Search" %}"
                           value="{{ request.GET.search }}">
                    <button class="btn btn-primary" type="submit">{% trans "Filter" %}</button>
                </form>
                {% if not request.GET.search %}
                    <form action="" method="post" class="helper-display-inline pull-right">
                        {% csrf_token %}
                        <button class="btn btn-danger" type="submit" name="discard" value="all">
                            <span class="fa fa-trash"></span>
                            {% trans "Discard all" %}
                        </button>
                    </form>
                {% endif %}
                </p>

                {% if transactions_unhandled|length > 0 %}
                    {% include "pretixcontrol/pagination.html" %}
                    {% include "pretixplugins/banktransfer/transaction_list.html" with list=transactions_unhandled %}
                    {% include "pretixcontrol/pagination.html" %}
                {% else %}
                    <div>{% trans "Your search matched no transactions." %}</div>
                {% endif %}
            </div>
        </div>
    {% endif %}
{% endblock %}
