{% extends "cms/admin_home.html" %}
{% load danceschool_tags i18n %}

{% block content %}
<div class="row">
<div class="float-left col-sm-8">
	<dl>
		<dt>{% trans "School Revenues (YTD):" %}</dt><dd>{{ statement.revenues_ytd|floatformat:2 }}</dd>
		<dt{% trans "School Expenses (YTD)" %}:</dt><dd>{{ statement.expenses_ytd|floatformat:2 }}</dd>
		<dt>{% trans "Pending Expenses" %}:</dt>
		<dd>{% trans "Awaiting Approval and Payment" %}: {{ statement.expenses_awaiting_approval|floatformat:2 }}</dd>
		{% if statement.expenses_awaiting_payment > 0 %}
			<dd>{% trans "Approved, Awaiting Payment" %}: {{ statement.expenses_awaiting_payment|floatformat:2 }}</dd>
		{% endif %}
		{% if statement.expenses_paid_notapproved > 0 %}
			<dd>{% trans "Paid, Not Approved" %}: {{ statement.expenses_paid_notapproved|floatformat:2 }}</dd>
		{% endif %}
		<dt>{% trans "Current Balance" %}:</dt><dd>{{ statement.current_balance|floatformat:2 }}</dd>
	</dl>
</div>

{% if perms.financial.export_financial_data %}
<div class="col-sm-4">
	<h5>{% trans "Export Financial Data (CSV)" %}</h5>
	<div class="btn-group" role="group" aria-label="...">
	  <a href="{% url 'financesByEventCSV' %}" class="btn btn-outline-secondary">{% trans "This View" %}</a>
	  <a href="{% url 'allexpensesCSV' current_year %}" class="btn btn-outline-secondary">{% trans "All Expenses" %}</a>
	  <a href="{% url 'allrevenuesCSV' current_year %}" class="btn btn-outline-secondary">{% trans "All Revenues" %}</a>
	</div>
</div>
{% endif %}
</div>


<h3 class="mt-4">{% trans "Details By Event" %}</h3>

<table class="table">
<thead>
	<tr>
		<th rowspan="2" colspan="2">{% trans "Event" %}</th><th colspan="{{ roles|length }}">{% trans "# Registrations" %}</th><th colspan="2">{% trans "Event Revenue" %}</th><th colspan="3">{% trans "Event Expenses" %}</th><th rowspan="2">{% trans "Net Profit" %}</th>
	</tr>
	<tr>
		{% for this_role in roles %}
			<td>{{ this_role|title }}</td>
		{% endfor %}
		<td>{% trans "Gross" %}</td><td>{% trans "Net of Discounts" %}</td><td>{% trans "Instruction" %}</td><td>{% trans "Venue Rental" %}</td><td>{% trans "Total" %}</td>
	</tr>
</thead>
<tbody>
{% for this_event in statement.statementByEvent %}
	<tr>
		<td>{{ this_event.month_name }}</td>
		<td>
			<a href="{% url 'financialEventDetailView' this_event.event.id %}">{{ this_event.event_name }}</a>
			<br />
			<small>
				{% for occurrence in this_event.event.eventoccurrence_set.all %}
					{{occurrence.startTime|date:'N jS' }}{% if not forloop.last %}, {% endif %}
				{% endfor %}
			</small>
		</td>
		{% for this_role in roles %}
			<td>{{ this_event.registrations|get_item:this_role }}</td>
		{% endfor %}
		<td>{{ this_event.revenues.gross|floatformat:2 }}</td>
		<td>{{ this_event.revenues.net|floatformat:2 }}</td>
		<td>{{ this_event.expenses.instruction|floatformat:2 }}</td>
		<td>{{ this_event.expenses.venue|floatformat:2 }}</td>
		<td>{{ this_event.expenses.total|floatformat:2 }}</td>
		<td>{{ this_event.net_profit|floatformat:2 }}</td>
	</tr>
{% endfor %}
</tbody>
</table>

{% if is_paginated %}
    <div class="pagination">
        <span class="page-links">
            {% if page_obj.has_previous %}
                <a href="?page={{ page_obj.previous_page_number }}">{% trans "previous" %}</a>
            {% endif %}
            <span class="page-current">
                {% blocktrans with thisPage=page_obj.number numPages=page_obj.paginator.num_pages %}
                Page {{ thisPage }} of {{ numPages }}.
                {% endblocktrans %}
            </span>
            {% if page_obj.has_next %}
                <a href="?page={{ page_obj.next_page_number }}">next</a>
            {% endif %}
        </span>
    </div>
{% endif %}

{% endblock %}
