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

{% 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|render_bool }}
            </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 {{ theoretical_total_staff }}€.{% endblocktrans %}
</p>
<h2>{% trans "Payment of subsidies and allowances" %}</h2>
{% if allowances_paid > 0 %}
<p>
{% blocktrans %}The allowance of {{ allowance_per_yl }}€ per person should be paid to:{% endblocktrans %}
<table>
    <th>
        <td>{% trans "IBAN valid" %}</td>
    </th>
    {% for member in statement.allowance_to.all %}
    <tr>
        <td>{{ member.name }}</td>
        <td>{{ member.iban_valid|render_bool }}</td>
    </tr>
    {% endfor %}
</table>
</p>
{% if allowances_paid < real_staff_count %}
<p>{% blocktrans %}Only {{ allowances_paid }} of the {{ real_staff_count }} youth leaders have requested the outpayment of their allowance.{% endblocktrans %}</p>
{% endif %}

{% else %}
<p>{% blocktrans %}No receivers of the allowance were provided. Allowance will not be used.{% endblocktrans %}</p>
{% endif %}
{% if statement.subsidy_to %}
<p>
{% blocktrans %}The subsidies for night and transportation costs of {{ total_subsidies }}€ should be paid to:{% endblocktrans %}
<table>
    <th>
        <td>{% trans "IBAN valid" %}</td>
    </th>
    <tr>
        <td>{{ statement.subsidy_to.name }}</td>
        <td>{{ statement.subsidy_to.iban_valid|render_bool }}</td>
    </tr>
</table>
</p>

{% else %}
<p>{% blocktrans %}No receivers of the subsidies were provided. Subsidies will not be used.{% endblocktrans %}</p>
{% endif %}

{% if total_org_fee %}
<h3>{% trans "Org fee" %}</h3>
{% blocktrans %}Since overaged people where part of the excursion, an organisational fee of {{ org_fee }}€ per person per day has to be paid. This totals to {{ total_org_fee_theoretical }}€. This organisational fee will be accounted against allowances and subsidies.{% endblocktrans %}

{% endif %}


{% if statement.ljp_to %}
<h3>{% trans "LJP contributions" %}</h3>
<p>
{% blocktrans %} The youth leaders have documented interventions worth of {{ total_seminar_days }} seminar 
days for {{ participant_count }} eligible participants. Taking into account the maximum contribution quota 
of 90% and possible taxes ({{ ljp_tax }}%), this results in a total of {{ paid_ljp_contributions }}€. 
Once their proposal was approved, the ljp contributions of should be paid to:{% endblocktrans %}
<table>
    <th>
        <td>{% trans "IBAN valid" %}</td>
    </th>
    <tr>
        <td>{{ statement.ljp_to.name }}</td>
        <td>{{ statement.ljp_to.iban_valid|render_bool }}</td>
    </tr>
</table>
</p>
{% endif %}


{% endif %}


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


<table>
    <tr>
        <td>
            {% trans "Covered bills" %}
        </td>
        <td>
            {{ total_bills }}€
        </td>
    </tr>
    <tr>
        <td>
            {% trans "Allowance" %}
        </td>
        <td>
            {{ total_allowance }}€
        </td>
    </tr>
    <tr>
        <td>
            {% trans "Contributions by the association" %}
        </td>
        <td>
            {{ total_subsidies }}€
        </td>
    </tr>
    <tr>
        <td>
            {% trans "Org fee" %}
        </td>
        <td>
            -{{ total_org_fee }}€
        </td>
    </tr>
    <tr>
        <td>
            {% trans "ljp contributions" %}
        </td>
        <td>
            {{ paid_ljp_contributions }}€
        </td>
    </tr>
</table>

<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 %}
