{% extends "admin/base_site.html" %}
{% load i18n admin_urls static %}

{% block extrahead %}
    {{ block.super }}
    {{ media }}
    <script src="{% static 'admin/js/cancel.js' %}" async></script>
    <script type="text/javascript" src="{% static "admin/js/vendor/jquery/jquery.js" %}"></script>
    <script type="text/javascript" src="{% static "admin/js/jquery.init.js" %}"></script>
{% endblock %}

{% block bodyclass %}{{ block.super }} app-{{ opts.app_label }} model-{{ opts.model_name }} admin-view
{% endblock %}

{% block breadcrumbs %}
<div class="breadcrumbs">
<a href="{% url 'admin:index' %}">{% translate 'Home' %}</a>
&rsaquo; <a href="{% url 'admin:app_list' app_label=opts.app_label %}">{{ opts.app_config.verbose_name }}</a>
&rsaquo; <a href="{% url opts|admin_urlname:'changelist' %}">{{ opts.verbose_name_plural|capfirst }}</a>
&rsaquo; <a href="{% url opts|admin_urlname:'change' statement.pk|admin_urlquote %}">{{ statement|truncatewords:"18" }}</a>
&rsaquo; {% translate 'Overview' %}
</div>
{% endblock %}

{% block content %}
<h2>{% translate "Bills" %}</h2>

<p>
<table>
    <th>
        <td>{% trans "Amount" %}</td>
        <td>{% trans "Covered by association" %}</td>
    </th>
    {% for bill in statement.bill_set.all %}
        <tr>
            <td>
            {{bill.short_description}}
            </td>
            <td>
            {{ bill.amount }}€.
            </td>
            <td>
                {{ bill.costs_covered }}
            </td>
        </tr>
    {% endfor %}
</table>
</p>

<p>{% blocktrans %}The total amount is {{total_bills}} €.{% endblocktrans %}</p>

{% if statement.excursion %}

<h2>{% trans "Excursion" %}</h2>

<p>
{% blocktrans %}This excursion featured {{ staff_count }} youth leader(s), each costing{% endblocktrans %}
</p>
<p>
<ul>
    <li>
        {% blocktrans %}{{ nights }} nights for {{ price_per_night }}€ per night making a total of {{ nights_per_yl }}€.{% endblocktrans %}
    </li>
    <li>
        {% blocktrans %}{{ duration }} days for {{ allowance_per_day }}€ per day making a total of {{ allowance_per_yl }}€.{% endblocktrans %}
    </li>
    <li>
        {% blocktrans %}{{ kilometers_traveled }} km by {{ means_of_transport }} ({{euro_per_km}} € / km) making a total of {{ transportation_per_yl }}€.{% endblocktrans %}
    </li>
</ul>
</p>
<p>
{% blocktrans %}In total this is {{ total_per_yl }}€ times {{ staff_count }}, giving {{ total_staff }}€.{% endblocktrans %}
</p>

{% endif %}

<h2>{% trans "Total" %}</h2>

<p>
{% blocktrans %}This results in a total amount of {{ total }}€{% endblocktrans %}
</p>

<h2>{% trans 'Transactions' %}</h2>

{% if statement.transaction_set.count == 0 %}
{% blocktrans %}Currently, no transactions are planned. You can auto generate them from the data, by clicking the following button.{% endblocktrans %}
<form method="post">
    {% csrf_token %}
    <input class="default other" type="submit" name="generate_transactions" value="{% translate 'Generate transactions' %}">
</form>
{% else %}

{% blocktrans %}Currently the following transactions are planned.{% endblocktrans %}
<p>
<table>
    <th>
        <td>{% trans "Amount" %}</td>
        <td>{% trans "Reference" %}</td>
        <td>{% trans "Ledger" %}</td>
    </th>
    {% for transaction in statement.transaction_set.all %}
    <tr>
    <td>
        {{ transaction.member }}
    </td>
    <td>
        {{ transaction.amount }}€
    </td>
    <td>
        {{ transaction.reference }}
    </td>
    <td>
        {{ transaction.ledger }}
    </td>
    </tr>
    {% endfor %}
</table>
{% comment %}
<ul>
{% for transaction in statement.transaction_set.all %}
<li>
    {{ transaction.member }}
    {% trans "receives" %}
    {{ transaction.amount }}€
    {% trans "for" %}
    {{ transaction.reference }},
    {% trans "paid with" %}
    {{ transaction.ledger }}.
</li>
{% endfor %}
</ul>
{% endcomment%}
</p>

{% if transaction_issues|length == 0 %}
{% blocktrans %}These transactions match the calculated costs.{% endblocktrans %}
{% else %}
<p>
{% blocktrans %}The current transactions do not reflect all costs in this statement. Please fix the following issues:{% endblocktrans %}
</p>
<p>
<table>
    <th>
        <td>{% trans "Currently receiving" %}</td>
        <td>{% trans "Actual costs" %}</td>
        <td>{% trans "Difference" %}</td>
    </th>
    {% for issue in transaction_issues %}
    <tr>
        <td>
        {{ issue.member }}
        </td>
        <td>
        {{ issue.current }}€
        </td>
        <td>
        {{ issue.target }}€
        </td>
        <td>
        {{ issue.difference }}€
        </td>
    </tr>
    {% endfor %}
</table>
</p>
{% endif %}

{% endif %}

<form action="" method="post">
    {% csrf_token %}
    <input type="hidden" name="action" value="submit_statement">
    <input class="default confirm" type="submit" name="confirm" value="{% translate 'Accept' %}">
    <input class="default danger" type="submit" name="reject" value="{% translate 'Reject' %}">

    {% url opts|admin_urlname:'change' original.pk|admin_urlquote as change_url %}
    <a class="button cancel-link" href="{% add_preserved_filters change_url %}">{% trans 'Cancel' %}</a>
</form>
{% endblock %}
