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

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

<section>
    <h3>Refinanzierung gesamt</h3>
    <div class="progress-wrap">
        <div class="progress-bar" style="width: {{ total_pct_capped }}%;"></div>
        <span class="progress-label">{{ total_pct }}%</span>
    </div>
    <p class="muted-left">
        Spenden {{ total_donations|euro }} / Ausgaben {{ total_payments|euro }}
    </p>
    <p class="muted-left">
        Bilanz: <b>{{ total_balance|euro }}</b>
    </p>
</section>

<section>
    <h3>Refinanzierung Getränke</h3>
    <div class="progress-wrap">
        <div class="progress-bar" style="width: {{ refinance_pct_capped }}%;"></div>
        <span class="progress-label">{{ refinance_pct }}%</span>
    </div>
    <p class="muted-left">
        Verkaufserlös {{ sales_revenue|euro }} / Einkaufspreis {{ purchase_cost|euro }}
    </p>
    <p class="muted-left">
        Aktueller Gewinn: <b>{{ drinks_profit|euro }}</b>
    </p>
</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</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 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 %}
        {% 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 %}
        {% for f in top_per_day %}
            <li>
                <span class="hist-when">{{ f.label }}</span>
                <span class="hist-what">{{ f.username }}</span>
                <span class="hist-price">{{ f.amount }} Flaschen</span>
            </li>
        {% endfor %}
    </ul>
</section>

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