{% extends "base.html" %}

{% block app_content %}
{% if establishment %}
{% if current_user.id == establishment.owner %}
<button type="button" class="btn btn-outline-dark px-2" data-bs-toggle="button" autocomplete="off"
    onclick="window.location.href='{{ url_for('establishment.payment.insert_payment', establishment_id=establishment.id) }}'">
    Zahlung hinzufügen
</button>
<button type="button" class="btn btn-outline-dark px-2" data-bs-toggle="button" autocomplete="off"
    onclick="window.location.href='{{ url_for('receipts.upload.upload_receipt', establishment=establishment.id) }}'">
    Quittung hinzufügen
</button>
{% endif %}
{% endif %}
{% for user in results %}
<div class="card">
    <button class="btn btn-primary" data-bs-toggle="collapse" data-bs-target="#b{{ user.id }}" aria-expanded="true">
        <div class="card-header">
            <h3>{{ user.email }}: {{ (user.sum | int)/100 }} €</h3>
        </div>
    </button>
    {% if user.id %}
    <div class="collapse" id="b{{ user.id }}">
        {% for item_infos in user.item_infos %}
        <div class="card-body">
            <div class="col-sm-1"></div>
            <div class="col">
                <h4>{{ item_infos.date }}</h4>
                {% for item in item_infos.item_list %}
                <div class="row">
                    <div class="col-sm-1"></div>
                    <div class="col">
                        {{ item.amount }}x {{ item.name }} je {{ item.price/100 }} €
                    </div>
                </div>
                {% endfor %}
            </div>
        </div>
        {% endfor %}
        {% if user.payments %}
        <h3>Einzahlungen</h3>
        {% for payments in user.payments %}
        <div class="card-body">
            <div class="col-sm-1"></div>
            <div class="col">
                <h4>{{ payments.date }}</h4>
                <div class="row">
                    <div class="col-sm-1"></div>
                    <div class="col">
                        {{ payments.amount/100 }} €
                    </div>
                </div>
            </div>
        </div>
        {% endfor %}
        {% endif %}
    </div>
    {% endif %}
</div>
{% endfor %}
{% endblock %}