{% extends "base.html" %}
{% block title %}Spendenbericht{{ " - " + app_name() }}{% endblock %}

{% block content %}
<div class="page-header">
    <h1>Spendenbericht</h1>
    <div class="btn-group">
        <a href="/spenden/bericht/export/csv" role="button" class="btn-sm outline">CSV Export</a>
        <a href="/spenden" role="button" class="btn-sm outline">Zurück</a>
    </div>
</div>

<div class="kpi-grid">
    <div class="kpi-card">
        <div class="kpi-value">{{ '%.2f'|format(gesamt_summe) }}</div>
        <div class="kpi-label">Gesamt (EUR)</div>
    </div>
    <div class="kpi-card">
        <div class="kpi-value">{{ anzahl_spenden }}</div>
        <div class="kpi-label">Anzahl Spenden</div>
    </div>
    <div class="kpi-card">
        <div class="kpi-value">{{ anzahl_spender }}</div>
        <div class="kpi-label">Spender</div>
    </div>
</div>

{% if pro_jahr %}
<div class="card">
    <div class="card-header"><h3>Summe pro Jahr</h3></div>
    <table class="data-table">
        <thead><tr><th>Jahr</th><th style="text-align: right;">Betrag</th><th style="text-align: right;">Anzahl</th></tr></thead>
        <tbody>
            {% for jahr in pro_jahr %}
            <tr>
                <td>{{ jahr.jahr }}</td>
                <td style="text-align: right; font-weight: 600;">{{ '%.2f'|format(jahr.summe) }} EUR</td>
                <td style="text-align: right;">{{ jahr.anzahl }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}

{% if pro_projekt %}
<div class="card">
    <div class="card-header"><h3>Summe pro Projekt</h3></div>
    <table class="data-table">
        <thead><tr><th>Projekt</th><th style="text-align: right;">Betrag</th><th style="text-align: right;">Anzahl</th></tr></thead>
        <tbody>
            {% for p in pro_projekt %}
            <tr>
                <td>{{ p.projekt or 'Ohne Projekt' }}</td>
                <td style="text-align: right; font-weight: 600;">{{ '%.2f'|format(p.summe) }} EUR</td>
                <td style="text-align: right;">{{ p.anzahl }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}

{% if pro_kampagne %}
<div class="card">
    <div class="card-header"><h3>Summe pro Kampagne</h3></div>
    <table class="data-table">
        <thead><tr><th>Kampagne</th><th style="text-align: right;">Betrag</th><th style="text-align: right;">Anzahl</th></tr></thead>
        <tbody>
            {% for row in pro_kampagne %}
            <tr>
                <td><a href="/kampagnen/{{ row.kampagne_id }}">{{ row.titel }}</a></td>
                <td style="text-align: right; font-weight: 600;">{{ '%.2f'|format(row.summe) }} EUR</td>
                <td style="text-align: right;">{{ row.anzahl }}</td>
            </tr>
            {% endfor %}
        </tbody>
    </table>
</div>
{% endif %}
{% endblock %}
