{% extends "pretixcontrol/event/base.html" %}
{% load i18n %}
{% load compress %}
{% load static %}
{% load escapejson %}
{% load money %}
{% load getitem %}
{% block title %}{% trans "Statistics" %}{% endblock %}
{% block content %}
    <h1>{% trans "Statistics" %}</h1>
    {% if request.event.has_subevents %}
        <form class="form-inline helper-display-inline" action="" method="get">
            {% include "pretixcontrol/event/fragment_subevent_choice_simple.html" %}
        </form>
    {% endif %}
    {% if has_orders %}
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Orders by day" %}</h3>
            </div>
            <div class="panel-body">
                <div id="obd_chart" class="chart"></div>
                <p class="help-block">
                    <small>
                        {% blocktrans trimmed %}
                            Orders paid in multiple payments are shown with the date of their last payment.
                        {% endblocktrans %}
                    </small>
                </p>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Revenue over time" %}</h3>
            </div>
            <div class="panel-body">
                <div id="rev_chart" class="chart"></div>
                {% if request.GET.subevent %}
                    <div class="alert alert-info">
                        {% blocktrans trimmed context "subevent" %}
                            If you select a single date, payment method fees will not be listed here as it might not be clear which
                            date they belong to.
                        {% endblocktrans %}
                    </div>
                {% endif %}
                <p class="help-block">
                    <small>
                        {% blocktrans trimmed %}
                            Only fully paid orders are counted.
                            Orders paid in multiple payments are shown with the date of their last payment.
                        {% endblocktrans %}
                    </small>
                </p>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-heading">
                <h3 class="panel-title">{% trans "Orders by product" %}</h3>
            </div>
            <div class="panel-body">
                <div id="obp_chart" class="chart"></div>
            </div>
        </div>
        {% if seats %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">{% trans "Seating Overview" %}</h3>
                </div>
                <div class="panel-body">
                    <div class="dashboard">
                        <div class="widget-container widget-small">
                            <div class="numwidget">
                                <span class="num">{{ seats.purchased_seats }}</span>
                                <span class="text">{% trans "Sold Seats" %}</span>
                            </div>
                        </div>
                        <div class="widget-container widget-small">
                            <div class="numwidget">
                                <span class="num">{{ seats.blocked_seats }}</span>
                                <span class="text">{% trans "Blocked Seats" %}</span>
                            </div>
                        </div>
                        <div class="widget-container widget-small">
                            <div class="numwidget">
                                <span class="num">{{ seats.free_seats }}</span>
                                <span class="text">{% trans "Free Seats" %}</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">{% trans "Seating Sales Potentials" %}</h3>
                </div>
                <div class="panel-body">
                    <table class="table table-condensed table-hover table-product-overview">
                        <thead>
                            <tr>
                                <th>{% trans "Product" %}</th>
                                <th></th>
                                <th colspan="2" class="text-center">{% trans "Unsold Seats" %}</th>
                                <th colspan="2" class="text-center">{% trans "Potential Profits" %}</th>
                            </tr>
                            <tr>
                                <th></th>
                                <th>{% trans "Minimum Price" %}</th>
                                <th>{% trans "Blocked" %}</th>
                                <th>{% trans "Available" %}</th>
                                <th>{% trans "Blocked" %}</th>
                                <th>{% trans "Available" %}</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr class="category">
                                <th>{% trans "On Sale" %}</th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                            </tr>
                            {% for item, props in seats.products.items %}
                                {% if item is not None %}
                                    <tr class="item categorized">
                                        <td>{{ item }}</td>
                                        <td>{{ props.price|money:request.event.currency }}</td>
                                        <td>{{ props.blocked.seats }}</td>
                                        <td>{{ props.free.seats }}</td>
                                        <td>{{ props.blocked.potential|money:request.event.currency }}</td>
                                        <td>{{ props.free.potential|money:request.event.currency }}</td>
                                    </tr>
                                {% endif %}
                            {% endfor %}
                            <tr class="category">
                                <th>{% trans "Not on Sale" %}</th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                                <th></th>
                            </tr>
                            {% if None in seats.products %}
                                {% with seats.products|getitem:None as unattributed %}
                                    <tr class="item categorized">
                                        <td>{% trans "Seats not attributed to any specific product" %}</td>
                                        <td></td>
                                        <td>{{ unattributed.blocked.seats }}</td>
                                        <td>{{ unattributed.free.seats }}</td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                {% endwith %}
                            {% endif %}
                        </tbody>
                    </table>
                </div>
            </div>
        {% endif %}
        <script type="application/json" id="obd-data">{{ obd_data|escapejson }}</script>
        <script type="application/json" id="rev-data">{{ rev_data|escapejson }}</script>
        <script type="application/json" id="obp-data">{{ obp_data|escapejson }}</script>
        <script type="application/text" id="currency">{{ request.event.currency }}</script>
        <script type="application/javascript" src="{% static "pretixplugins/statistics/statistics.js" %}"
                defer></script>
    {% else %}
        <div class="empty-collection">
            <p>
                <span class="fa big-grey-icon fa-line-chart"></span>
            </p>
            <p>
                {% blocktrans trimmed %}
                    We will show you a variety of statistics about your sales right here, as soon as the first orders
                    are submitted!
                {% endblocktrans %}
            </p>
        </div>
    {% endif %}
{% endblock %}

