{% extends "pretixcontrol/base.html" %}
{% load i18n %}
{% load eventurl %}
{% load urlreplace %}
{% load money %}
{% load bootstrap3 %}
{% block title %}{% trans "Payment search" %}{% endblock %}
{% block content %}
    <h1>{% trans "Payment search" %}</h1>
    <div class="panel panel-default">
        <div class="panel-heading">
            <h3 class="panel-title">
                {% trans "Filter" %}
            </h3>
        </div>
        <form class="panel-body filter-form" action="" method="get">
            <div class="row">
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="row">
                        <div class="col-md-6 col-sm-12 col-xs-12">
                            {% bootstrap_field filter_form.query %}
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.completed_from %}
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.completed_until %}
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-3 col-sm-3 col-xs-4">
                            {% bootstrap_field filter_form.amount %}
                        </div>
                        <div class="col-md-5 col-sm-5 col-xs-8">
                            {% bootstrap_field filter_form.provider %}
                        </div>
                        <div class="col-md-4 col-sm-4 col-xs-12">
                            {% bootstrap_field filter_form.state %}
                        </div>
                    </div>
                </div>
                <div class="col-md-12 col-sm-12 col-xs-12">
                    <div class="row">
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.organizer %}
                        </div>
                        <div class="col-md-6 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.event %}
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.created_from %}
                        </div>
                        <div class="col-md-3 col-sm-6 col-xs-12">
                            {% bootstrap_field filter_form.created_until %}
                        </div>
                    </div>
                </div>
            </div>
            <div class="text-right flip">
                <button class="btn btn-primary btn-lg" type="submit">
                    <span class="fa fa-filter"></span>
                    {% trans "Filter" %}
                </button>
            </div>
        </form>
    </div>

    <div class="table-responsive">
        <table class="table table-condensed table-hover">
            <thead>
            <tr>
                <th>
                    {% trans "Payment ID" %}
                </th>
                <th>
                    {% trans "Order" %}
                    <a href="?{% url_replace request 'ordering' '-order' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'order' %}"><i class="fa fa-caret-up"></i></a>
                </th>
                <th>
                    {% trans "Start date" %}
                    <a href="?{% url_replace request 'ordering' '-created' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'created' %}"><i class="fa fa-caret-up"></i></a>
                </th>
                <th>
                    {% trans "Confirmation date" %}
                    <a href="?{% url_replace request 'ordering' '-payment_date' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'payment_date' %}"><i class="fa fa-caret-up"></i></a>
                </th>
                <th>
                    {% trans "Payment provider" %}
                    <a href="?{% url_replace request 'ordering' '-provider' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'provider' %}"><i class="fa fa-caret-up"></i></a>
                </th>
                <th class="text-right flip">
                    {% trans "Amount" %}
                    <a href="?{% url_replace request 'ordering' '-amount' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'amount' %}"><i class="fa fa-caret-up"></i></a>
                </th>
                <th class="text-right flip">
                    {% trans "Status" %}
                    <a href="?{% url_replace request 'ordering' '-state' %}"><i class="fa fa-caret-down"></i></a>
                    <a href="?{% url_replace request 'ordering' 'state' %}"><i class="fa fa-caret-up"></i></a>
                </th>
            </tr>
            </thead>
            <tbody>
            {% for p in payments %}
                <tr>
                    <td>{{ p.full_id }}</td>
                    <td>
                        <strong>
                            <a href="{% url "control:event.order" event=p.order.event.slug organizer=p.order.event.organizer.slug code=p.order.code %}">
                                {{ p.order.full_code }}</a>
                        </strong>
                        {% if p.order.testmode %}
                            <span class="label label-warning">{% trans "TEST MODE" %}</span>
                        {% endif %}
                    </td>
                    <td>
                        {% if p.migrated %}
                            <span class="label label-default" data-toggle="tooltip"
                            title="{% trans "This payment was created with an older version of pretix, therefore accurate data might not be available." %}">
                                {% trans "MIGRATED" %}
                            </span>
                        {% else %}
                            {{ p.created|date:"SHORT_DATETIME_FORMAT" }}
                        {% endif %}
                    </td>
                    <td>{{ p.payment_date|date:"SHORT_DATETIME_FORMAT" }}</td>
                    <td>{{ p.payment_provider.verbose_name }}</td>
                    <td class="text-right flip">{{ p.amount|money:p.order.event.currency }}</td>
                    <td class="text-right flip">
                        <span class="label label-{% if p.state == "created" or p.state == "pending" %}warning{% elif p.state == "confirmed" %}success{% else %}danger{% endif %}">
                            {{ p.get_state_display }}
                        </span>
                    </td>
                </tr>
            {% if staff_session %}
                <tr>
                    <td colspan="1"></td>
                    <td colspan="6">
                        <a href="" class="btn btn-default btn-xs" data-expandpayment data-id="{{ p.pk }}">
                            <span class="fa-eye fa fa-fw"></span>
                            {% trans "Inspect" %}
                        </a>
                    </td>
                </tr>
            {% endif %}
            {% empty %}
                <tr>
                    <td colspan="7" class="text-center"><em>
                        {% trans "We couldn't find any payments that you have access to and that match your search query." %}
                    </em></td>
                </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>

    {% include "pretixcontrol/pagination_huge.html" %}
{% endblock %}
