{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load bootstrap3 %}
{% load order_overview %}
{% block title %}{% trans "Order overview" %}{% endblock %}
{% block content %}
    {% url "control:event.orders" organizer=request.event.organizer.slug event=request.event.slug as listurl %}
    <div class="pull-right flip">
        <div class="btn-group" role="group" id="sumtoggle">
            <button type="button" data-target=".count" class="btn btn-default active">{% trans "Sales" %}</button>
            <button type="button" data-target=".sum-gross" class="btn btn-default">{% trans "Revenue (gross)" %}</button>
            <button type="button" data-target=".sum-net" class="btn btn-default">{% trans "Revenue (net)" %}</button>
        </div>
    </div>
	<h1>
        {% trans "Order overview" %}
        <a href="{% url "control:event.orders.export" event=request.event.slug organizer=request.event.organizer.slug %}?identifier=pdfreport"
           class="btn btn-default" target="_blank">
            <span class="fa fa-download"></span>
            {% trans "PDF" %}
        </a>
    </h1>
    <div class="row filter-form">
        <form class="" action="" method="get">
            {% if request.event.has_subevents %}
                <div class="col-lg-2 col-sm-3 col-xs-6">
                    {% bootstrap_field filter_form.subevent layout='inline' %}
                </div>
                <div class="col-lg-2 col-sm-3 col-xs-6">
                    {% bootstrap_field filter_form.date_axis layout='inline' %}
                </div>
            {% else %}
                <div class="col-lg-4 col-sm-6 col-xs-6">
                    {% bootstrap_field filter_form.date_axis layout='inline' %}
                </div>
            {% endif %}
            <div class="col-lg-2 col-sm-6 col-xs-6">
                {% bootstrap_field filter_form.date_from layout='inline' %}
            </div>
            <div class="col-lg-2 col-sm-6 col-xs-6">
                {% bootstrap_field filter_form.date_until layout='inline' %}
            </div>
            <div class="col-lg-1 col-lg-offset-3 col-sm-6 col-xs-6">
                <button class="btn btn-primary btn-block" type="submit">
                    <span class="fa fa-filter"></span>
                    <span class="hidden-md">
                        {% trans "Filter" %}
                    </span>
                </button>
            </div>
        </form>
    </div>
    {% if subevent_warning %}
        <div class="alert alert-info">
            {% blocktrans trimmed context "subevent" %}
                If you select a single date, fees will not be listed here as it might not be clear which
                date they belong to.
            {% endblocktrans %}
        </div>
    {% endif %}
    <div class="table-responsive">
        <table class="table table-condensed table-hover table-product-overview">
            <thead>
                <tr>
                    <th>{% trans "Product" %}</th>
                    <th>{% trans "Canceled" %}¹</th>
                    <th>{% trans "Expired" %}</th>
                    <th>{% trans "Approval pending" %}</th>
                    <th colspan="3" class="text-center">{% trans "Purchased" %}</th>
                </tr>
                <tr>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th></th>
                    <th>{% trans "Pending" %}</th>
                    <th>{% trans "Paid" %}</th>
                    <th>{% trans "Total" %}</th>
                </tr>
            </thead>
            <tbody>
                {% for tup in items_by_category %}
                    {% if tup.0 %}
                        <tr class="category">
                            <th>{{ tup.0 }}</th>
                            <th>{{ tup.0.num.canceled|togglesum:request.event.currency }}</th>
                            <th>{{ tup.0.num.expired|togglesum:request.event.currency }}</th>
                            <th>{{ tup.0.num.unapproved|togglesum:request.event.currency }}</th>
                            <th>{{ tup.0.num.pending|togglesum:request.event.currency }}</th>
                            <th>{{ tup.0.num.paid|togglesum:request.event.currency }}</th>
                            <th>{{ tup.0.num.total|togglesum:request.event.currency }}</th>
                        </tr>
                    {% endif %}
                    {% for item in tup.1 %}
                        <tr class="item {% if tup.0 %}categorized{% endif %}">
                            <td>{{ item }}</td>
                            <td>
                                <a href="{{ listurl }}?item={{ item.id }}&amp;status=c&amp;provider={{ item.provider }}">
                                    {{ item.num.canceled|togglesum:request.event.currency }}
                                </a>
                            </td>
                            <td>
                                <a href="{{ listurl }}?item={{ item.id }}&amp;status=e&amp;provider={{ item.provider }}">
                                    {{ item.num.expired|togglesum:request.event.currency }}
                                </a>
                            </td>
                            <td>
                                <a href="{{ listurl }}?item={{ item.id }}&amp;status=pa&amp;provider={{ item.provider }}">
                                    {{ item.num.unapproved|togglesum:request.event.currency }}
                                </a>
                            </td>
                            <td>
                                <a href="{{ listurl }}?item={{ item.id }}&amp;status=na&amp;provider={{ item.provider }}">
                                    {{ item.num.pending|togglesum:request.event.currency }}
                                </a>
                            </td>
                            <td>
                                <a href="{{ listurl }}?item={{ item.id }}&amp;status=p&amp;provider={{ item.provider }}">
                                    {{ item.num.paid|togglesum:request.event.currency }}
                                </a>
                            </td>
                            <td>
                                {{ item.num.total|togglesum:request.event.currency }}
                            </td>
                        </tr>
                        {% if item.has_variations %}
                            {% for var in item.all_variations %}
                                <tr class="variation {% if tup.0 %}categorized{% endif %}">
                                    <td>{{ var }}</td>
                                    <td>
                                        <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=c&amp;provider={{ item.provider }}">
                                            {{ var.num.canceled|togglesum:request.event.currency }}
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=e&amp;provider={{ item.provider }}">
                                            {{ var.num.expired|togglesum:request.event.currency }}
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=pa&amp;provider={{ item.provider }}">
                                            {{ var.num.unapproved|togglesum:request.event.currency }}
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=na&amp;provider={{ item.provider }}">
                                            {{ var.num.pending|togglesum:request.event.currency }}
                                        </a>
                                    </td>
                                    <td>
                                        <a href="{{ listurl }}?item={{ item.id }}-{{ var.id }}&amp;status=p&amp;provider={{ item.provider }}">
                                            {{ var.num.paid|togglesum:request.event.currency }}
                                        </a>
                                    </td>
                                    <td>
                                        {{ var.num.total|togglesum:request.event.currency }}
                                    </td>
                                </tr>
                            {% endfor %}
                        {% endif %}
                    {% endfor %}
                {% endfor %}
            </tbody>
            <tfoot>
                <tr class="total">
                    <th>{% trans "Total" %}</th>
                    <th>{{ total.num.canceled|togglesum:request.event.currency }}</th>
                    <th>{{ total.num.expired|togglesum:request.event.currency }}</th>
                    <th>{{ total.num.unapproved|togglesum:request.event.currency }}</th>
                    <th>{{ total.num.pending|togglesum:request.event.currency }}</th>
                    <th>{{ total.num.paid|togglesum:request.event.currency }}</th>
                    <th>{{ total.num.total|togglesum:request.event.currency }}</th>
                </tr>
            </tfoot>
        </table>
    </div>
    <p class="help-block">
        ¹ {% trans "If you click links in this column, you will only find orders that are canceled completely, while the numbers also include single canceled positions within valid orders." %}
    </p>
{% endblock %}
