{% extends basetpl %}
{% load i18n %}
{% load bootstrap3 %}
{% load static %}
{% 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 %}
                        {% if currencies|length > 1 %}
                            <div class="form-group helper-display-block">
                                <label for="currency">{% trans "Currency" %}: </label>
                                <select required name="currency" class="form-control">
                                    <option></option>
                                    {% for c in currencies %}
                                        <option value="{{c}}">{{c}}</option>
                                    {% endfor %}
                                </select>
                            </div>
                        {% endif %}
                        <div class="form-group">
                            <label for="file">{% trans "Import file" %}: </label>
                            <input id="file" type="file" name="file" required />
                        </div>
                        <div class="clearfix"></div>
                        <button class="btn btn-primary pull-right flip" type="submit">
                            <span class="icon icon-upload"></span> {% trans "Start upload" %}
                        </button>
                    </form>
                {% endif %}
            </div>
        </div>
    {% endif %}
    {% if transactions_unhandled|length > 0 or filter_form.is_valid %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Unresolved transactions" %}</h3>
            </div>
            <div class="panel-body">
                {% if request.event %}
                    <p>
                        {% blocktrans trimmed %}
                            On this page, you can import banking data on a per-event level. You also only see
                            unmatched transactions imported directly for this event.
                        {% endblocktrans %}
                        <a href="{% url "plugins:banktransfer:import" organizer=request.organizer.slug %}"
                           class="btn btn-default btn-xs">{% trans "Go to organizer-level import" %}</a>
                    </p>
                {% endif %}

                <div class="row">
                    <form class="form-inline helper-display-inline" action="" method="get">
                        <div class="col-md-3">
                            {% trans "Amount from" %}
                            {{ filter_form.amount_min }}
                            {% trans "up to" %}
                            {{ filter_form.amount_max }}
                        </div>
                        <div class="col-md-3">
                            {% trans "Date from" %}
                            {{ filter_form.date_min }}
                            {% trans "up to" %}
                            {{ filter_form.date_max }}
                        </div>
                        <div class="col-md-4">
                            {{ filter_form.search_text }}
                            <button class="btn btn-primary" type="submit">{% trans "Filter" %}</button>
                            <a class="btn btn-default" href="{{ request.path }}">{% trans "Clear" %}</a>
                        </div>
                    </form>
                    <div class="col-md-2">
                        {% if not filter_form.is_valid %}
                            <form action="" method="post" class="helper-display-inline pull-right flip">
                                {% 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 %}
                    </div>
                </div>

                {% 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 %}
    <script type="application/javascript" src="{% static "pretixplugins/banktransfer/ui.js" %}"></script>
{% endblock %}
