{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load eventurl %}
{% load urlreplace %}
{% block title %}{% trans "Orders" %}{% endblock %}
{% block content %}
    <h1>{% trans "Orders" %}</h1>
    {% if not filtered and orders|length == 0 %}
        <div class="empty-collection">
            <p>
                {% blocktrans trimmed %}
                    Nobody ordered a ticket yet.
                {% endblocktrans %}
            </p>

            {% if not request.event.live %}
                <a href="{% url "control:event.live" event=request.event.slug organizer=request.event.organizer.slug %}"
                        class="btn btn-primary btn-lg">
                    {% trans "Take your shop live" %}
                </a>
            {% else %}
                <a href="{% eventurl request.event "presale:event.index" %}" class="btn btn-primary btn-lg">
                    {% trans "Go to the ticket shop" %}
                </a>
            {% endif %}
        </div>
    {% else %}
        <p>
        <form class="form-inline helper-display-inline"
                action="{% url "control:event.orders.go" event=request.event.slug organizer=request.event.organizer.slug %}">
            <div class="input-group">
                <input type="text" name="code" class="form-control" placeholder="{% trans "Order code" %}" autofocus>
                <span class="input-group-btn">
                    <button class="btn btn-primary" type="submit">{% trans "Go!" %}</button>
                </span>
            </div>
        </form>
        <form class="form-inline helper-display-inline" action="" method="get">
            <select name="status" class="form-control">
                <option value="">{% trans "All orders" %}</option>
                <option value="p" {% if request.GET.status == "p" %}selected="selected"{% endif %}>{% trans "Paid" %}</option>
                <option value="n" {% if request.GET.status == "n" %}selected="selected"{% endif %}>{% trans "Pending" %}</option>
                <option value="o" {% if request.GET.status == "o" %}selected="selected"{% endif %}>{% trans "Pending (overdue)" %}</option>
                <option value="e" {% if request.GET.status == "e" %}selected="selected"{% endif %}>{% trans "Expired" %}</option>
                <option value="ne" {% if request.GET.status == "ne" %}selected="selected"{% endif %}>{% trans "Pending or expired" %}</option>
                <option value="c" {% if request.GET.status == "c" %}selected="selected"{% endif %}>{% trans "Canceled" %}</option>
                <option value="r" {% if request.GET.status == "r" %}selected="selected"{% endif %}>{% trans "Refunded" %}</option>
            </select>
            <select name="item" class="form-control">
                <option value="">{% trans "All products" %}</option>
                {% for item in items %}
                    <option value="{{ item.id }}"
                            {% if request.GET.item|add:0 == item.id %}selected="selected"{% endif %}>
                        {{ item.name }}
                    </option>
                {% endfor %}
            </select>
            <select name="provider" class="form-control">
                <option value="">{% trans "All payment providers" %}</option>
                {% for p in providers %}
                    <option value="{{ p.name }}"
                            {% if request.GET.provider == p.name %}selected="selected"{% endif %}>
                        {{ p.verbose_name }}
                    </option>
                {% endfor %}
            </select>
            <input type="text" name="user" class="form-control" placeholder="{% trans "Search user" %}" value="{{ request.GET.user }}">
            <button class="btn btn-primary" type="submit">{% trans "Filter" %}</button>
        </form>
        </p>
        {% include "pretixcontrol/pagination.html" %}
        <div class="table-responsive">
            <table class="table table-condensed table-hover">
                <thead>
                <tr>
                    <th>{% trans "Order code" %} <a href="?{% url_replace request 'ordering' '-code'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'code'%}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "User" %} <a href="?{% url_replace request 'ordering' '-email'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'email'%}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Order total" %} <a href="?{% url_replace request 'ordering' '-total'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'total'%}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Order date" %} <a href="?{% url_replace request 'ordering' '-datetime'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'datetime'%}"><i class="fa fa-caret-up"></i></a></th>
                    <th>{% trans "Status" %} <a href="?{% url_replace request 'ordering' '-status'%}"><i class="fa fa-caret-down"></i></a>
                      <a href="?{% url_replace request 'ordering' 'status'%}"><i class="fa fa-caret-up"></i></a></th>
                </tr>
                </thead>
                <tbody>
                {% for o in orders %}
                    <tr>
                        <td><strong><a
                                href="{% url "control:event.order" event=request.event.slug organizer=request.event.organizer.slug code=o.code %}"
                        >{{ o.code }}</a></strong></td>
                        <td>{{ o.email }}</td>
                        <td>{{ o.total|floatformat:2 }} {{ request.event.currency }}</td>
                        <td>{{ o.datetime|date:"SHORT_DATETIME_FORMAT" }}</td>
                        <td>{% include "pretixcontrol/orders/fragment_order_status.html" with order=o %}</td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
        {% include "pretixcontrol/pagination.html" %}
    {% endif %}
{% endblock %}
