{% extends "suff/base.html" %}
{% load money %}

{% block content %}
<h2>Dashboard {{ year }}</h2>

<section>
    <h3>Finanzen</h3>
    <div class="progress-wrap">
        <div class="progress-bar" style="width: {{ finance_pct_capped }}%;"></div>
        <span class="progress-label">{{ finance_pct }}%</span>
    </div>
    <ul class="history">
        <li class="fin-row">
            <span class="hist-what"><b>Ausgaben gesamt</b></span>
            <span class="hist-price"><b>{{ total_costs|euro }}</b></span>
        </li>
        <li class="fin-row">
            <span class="hist-what"><b>Einnahmen gesamt</b></span>
            <span class="hist-price"><b>{{ income_total|euro }}</b></span>
        </li>
        <li class="fin-row">
            <span class="hist-what"><b>Bilanz</b></span>
            <span class="hist-price"><b>{{ finance_balance|euro }}</b></span>
        </li>
    </ul>
    <ul class="history history-sub">
        <li class="fin-row">
            <span class="hist-what">Spenden (Donations)</span>
            <span class="hist-price">{{ total_donations|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Cashless (User-Tab)</span>
            <span class="hist-price">{{ user_payments_total|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Kasse (bar, nach Vorschuss)</span>
            <span class="hist-price">{{ cash_net|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Kassen-Vorschuss</span>
            <span class="hist-price">{{ cash_prefill|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Einkaufspreis Getränke</span>
            <span class="hist-price">{{ purchase_cost|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Verkaufserlös Getränke</span>
            <span class="hist-price">{{ sales_revenue|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Gratis-Getränke (EK-Wert)</span>
            <span class="hist-price">{{ free_drinks_value|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Unverkauft (EK-Wert)</span>
            <span class="hist-price">{{ unsold_purchase_value|euro }}</span>
        </li>
        <li class="fin-row">
            <span class="hist-what">Unverkauft (potenzieller VK)</span>
            <span class="hist-price">{{ unsold_sale_value|euro }}</span>
        </li>
    </ul>
</section>

<section>
    <h3>Getränke</h3>
    <ul class="history">
        {% for d in drink_rows %}
            <li class="dash-row">
                <span class="hist-what"><b>{{ d.name }}</b></span>
                <span class="hist-when">{{ d.sold }}/{{ d.total }} verkauft</span>
                <span class="hist-price">{{ d.balance|euro }}</span>
            </li>
        {% endfor %}
    </ul>
</section>

<section>
    <h3>Offene Beträge</h3>
    {% if user_rows %}
        <ul class="history">
            {% for u in user_rows %}
                <li>
                    <span class="hist-when">{{ u.username }}</span>
                    <span class="hist-what">{{ u.consumed|euro }} − {{ u.paid|euro }}</span>
                    <span class="hist-price">{{ u.open|euro }}</span>
                </li>
            {% endfor %}
        </ul>
    {% else %}
        <p class="muted-left">Niemand hat etwas konsumiert.</p>
    {% endif %}
</section>

<section>
    <h3>Fun Facts: Trinker</h3>
    <ul class="history">
        {% if top_spender %}
            <li>
                <span class="hist-when">Top-Zecher</span>
                <span class="hist-what">{{ top_spender.username }}</span>
                <span class="hist-price">{{ top_spender.total|euro }}</span>
            </li>
        {% endif %}
        {% if variety_champ %}
            <li>
                <span class="hist-when">Vielfalt-Champion</span>
                <span class="hist-what">{{ variety_champ.user__username }}</span>
                <span class="hist-price">{{ variety_champ.distinct }} Sorten</span>
            </li>
        {% endif %}
        {% for f in top_per_day %}
            <li>
                <span class="hist-when">Top {{ f.label }}</span>
                <span class="hist-what">{{ f.username }}</span>
                <span class="hist-price">{{ f.amount }} Flaschen</span>
            </li>
        {% endfor %}
    </ul>
</section>

<section>
    <h3>Fun Facts: Getränke</h3>
    <ul class="history">
        {% if top_drink %}
            <li>
                <span class="hist-when">Top-Getränk</span>
                <span class="hist-what">{{ top_drink.name }}</span>
                <span class="hist-price">{{ top_drink.amount }}x</span>
            </li>
        {% endif %}
        <li>
            <span class="hist-when">Bier-Anteil</span>
            <span class="hist-what">am Konsum</span>
            <span class="hist-price">{{ beer_share }}%</span>
        </li>
        {% if alcfree_top %}
            <li>
                <span class="hist-when">{{ alcfree_top.label }}</span>
                <span class="hist-what">{{ alcfree_top.username }}</span>
                <span class="hist-price">{{ alcfree_top.amount }} Flaschen</span>
            </li>
        {% endif %}
        {% if radler_top %}
            <li>
                <span class="hist-when">{{ radler_top.label }}</span>
                <span class="hist-what">{{ radler_top.username }}</span>
                <span class="hist-price">{{ radler_top.amount }} Flaschen</span>
            </li>
        {% endif %}
        {% if water_top %}
            <li>
                <span class="hist-when">{{ water_top.label }}</span>
                <span class="hist-what">{{ water_top.username }}</span>
                <span class="hist-price">{{ water_top.amount }} Flaschen</span>
            </li>
        {% endif %}
    </ul>
</section>

<section>
    <h3>Fun Facts: Zeit</h3>
    <ul class="history">
        {% if first_cons %}
            <li>
                <span class="hist-when">Erste Buchung</span>
                <span class="hist-what">{{ first_cons.user.username }} – {{ first_cons.drink.name }}</span>
                <span class="hist-price">{{ first_cons.created_at|date:"d.m. H:i" }}</span>
            </li>
        {% endif %}
        {% if last_cons %}
            <li>
                <span class="hist-when">Letzter Schluck</span>
                <span class="hist-what">{{ last_cons.user.username }} – {{ last_cons.drink.name }}</span>
                <span class="hist-price">{{ last_cons.created_at|date:"d.m. H:i" }}</span>
            </li>
        {% endif %}
        {% if earliest_per_user %}
            <li>
                <span class="hist-when">Frühaufsteher</span>
                <span class="hist-what">{{ earliest_per_user.user__username }}</span>
                <span class="hist-price">{{ earliest_per_user.t|date:"d.m. H:i" }}</span>
            </li>
        {% endif %}
        {% if latest_per_user %}
            <li>
                <span class="hist-when">Nachtschwärmer</span>
                <span class="hist-what">{{ latest_per_user.user__username }}</span>
                <span class="hist-price">{{ latest_per_user.t|date:"d.m. H:i" }}</span>
            </li>
        {% endif %}
        {% if golden_hour %}
            <li>
                <span class="hist-when">Goldene Stunde</span>
                <span class="hist-what">{{ golden_hour.label }}</span>
                <span class="hist-price">{{ golden_hour.amount }} Flaschen</span>
            </li>
        {% endif %}
        {% if busiest_day %}
            <li>
                <span class="hist-when">Härtester Tag</span>
                <span class="hist-what">{{ busiest_day.label }}</span>
                <span class="hist-price">{{ busiest_day.amount }} Flaschen</span>
            </li>
        {% endif %}
    </ul>
</section>

<section>
    <h3>Fun Facts: Geld</h3>
    <ul class="history">
        {% if biggest_tip %}
            <li>
                <span class="hist-when">Bigspender-Trinkgeld</span>
                <span class="hist-what">{{ biggest_tip.username }}</span>
                <span class="hist-price">{{ biggest_tip.tip|euro }}</span>
            </li>
        {% endif %}
        <li>
            <span class="hist-when">Eintrittsspenden gesamt</span>
            <span class="hist-what">aus Überzahlungen</span>
            <span class="hist-price">{{ total_entry|euro }}</span>
        </li>
        {% for method, sum in method_split.items %}
            <li>
                <span class="hist-when">Zahlungen {{ method }}</span>
                <span class="hist-what"></span>
                <span class="hist-price">{{ sum|euro }}</span>
            </li>
        {% endfor %}
    </ul>
</section>

<section>
    <h3>Fun Facts: Gratis</h3>
    <ul class="history">
        <li>
            <span class="hist-when">Aufmerksamkeit des Hauses</span>
            <span class="hist-what">Gratis-Flaschen</span>
            <span class="hist-price">{{ free_total_count }}x</span>
        </li>
        {% if top_free_recipient %}
            <li>
                <span class="hist-when">Glücklicher Empfänger</span>
                <span class="hist-what">{{ top_free_recipient.user__username }}</span>
                <span class="hist-price">{{ top_free_recipient.amount }} gratis</span>
            </li>
        {% endif %}
    </ul>
</section>

<div class="logout-form">
    <a href="{% url 'suff:me' %}" class="link-btn link-btn-secondary">Zurück</a>
</div>
{% endblock %}
