{% extends "cms/home.html" %}
{% load cms_tags danceschool_tags sekizai_tags i18n %}

{% block content %}

{% getReturnPage prior=True as returnPage %}
{% if returnPage.url %}
	<p><a class="btn btn-outline-secondary float-right" href="{{ returnPage.url }}">&laquo;&nbsp;{% trans "Return to" %} {{ returnPage.title }}</a></p>
{% endif %}

<h1>{% blocktrans %}Invoice for {{ businessName }}{% endblocktrans %}:</h1>

<dl>
	<dt>{% trans "Invoice Number" %}:</dt>
	<dd>
		{{ object.id }}
		{% if "core.change_invoice" in perms %}&nbsp;<a class="btn btn-outline-secondary btn-sm" href="{% url 'admin:core_invoice_change' object.id %}">{% trans "Edit Invoice" %}</a>{% endif %}
	</dd>
	{% if object.firstName or object.lastName or object.email %}
	<dt>{% trans "Recipient" %}:</dt>
	<dd>{% if object.firstName or object.lastName %}{{ object.firstName }} {{ object.lastName }}: {% endif %}{{ object.email|default:"unknown email" }}
	{% if "core.send_invoices" in perms and object.email %}<a class="btn btn-outline-secondary btn-sm" href="{% url 'sendInvoiceNotifications' object.id %}">{% trans "Notify Recipient" %}</a>{% endif %}
	</dd>
	{% endif %}

	<dt>{% trans "Invoice Status" %}:</dt>
	<dd>{{ object.get_status_display }}</dd>

	{% if object.amountPaid %}
		<dt>{% trans "Amount Paid" %}:</dt>
		<dd>{{ currencySymbol }}{{ object.amountPaid|floatformat:"2" }}</dd>
	{% endif %}

	{% if object.outstandingBalance %}
		<dt>{% trans "Outstanding Balance" %}:</dt>
		<dd>{{ currencySymbol }}{{ object.outstandingBalance|floatformat:"2" }}</dd>
	{% endif %}
</dl>

<table class="table">
<tr>
	<td>{% trans "Initial Price" %}</td>
	<td>{{ currencySymbol }}{{ object.grossTotal|floatformat:"2" }}</td>
</tr>
<tr>
	<td>{% trans "Net Price" %}</td>
	<td>{{ currencySymbol }}{{ object.total|floatformat:"2" }}</td>
</tr>
<tr>
	<td>{% trans "Taxes" %}</td>
	<td>{{ currencySymbol }}{{ object.taxes|floatformat:"2" }}</td>
</tr>
<tr>
	<td>{% trans "Fees" %}</td>
	<td>{{ currencySymbol }}{{ object.fees|floatformat:"2" }}</td>
</tr>
<tr>
	<td>{% trans "Adjustments/Refunds" %}</td>
	<td>{{ currencySymbol }}{{ object.adjustments|floatformat:"2" }}</td>
</tr>

</table>

<hr />

<h2>{% trans "Item Details" %}</h2>

{% if 'core.change_registration' in perms and object.registration %}
	<a class="btn btn-secondary" href="{% url 'admin:core_registration_change' object.registration.id %}">{% trans "View Registration" %}</a>
{% endif %}

<table class="table">
<thead>
	<tr>
		<th>{% trans "Name" %}</th>
		<th>{% trans "Inital Price" %}</th>
		<th>{% trans "Price with Discounts" %}</th>
		<th>{% trans "Taxes" %}</th>
		<th>{% trans "Fees" %}</th>
		<th>{% trans "Adjustments" %}</th>
		{% if 'financial.change_revenueitem' in perms %}
		<th>{% trans "Links" %}</th>
		{% endif %}
	</tr>
</thead>
<tbody>
{% for item in object.invoiceitem_set.all %}
	<tr>
		<td>{{ item.name }}</td>
		<td>{{ currencySymbol }}{{ item.grossTotal|floatformat:"2" }}</td>
		<td>{{ currencySymbol }}{{ item.total|floatformat:"2" }}</td>
		<td>{{ currencySymbol }}{{ item.taxes|floatformat:"2" }}</td>
		<td>{{ currencySymbol }}{{ item.fees|floatformat:"2" }}</td>
		<td>{{ currencySymbol }}{{ item.adjustments|floatformat:"2" }}</td>
		{% if 'financial.change_revenueitem' in perms %}
			<td>
				{% if item.revenueitem %}
					<a class="btn btn-outline-secondary btn-sm" href="{% url 'admin:financial_revenueitem_change' item.revenueitem.id %}">{% trans "Rev. Item" %}</a>
				{% endif %}
			</td>
		{% endif %}
	</tr>
{% endfor %}
<tbody>
</table>

{% if payments %}
	<hr />

	<h2>{% trans "Payment Details" %}</h2>

	{% if 'core.process_refunds' in perms %}
		<a class="btn btn-secondary" href="{% url 'refundProcessing' object.id %}">{% trans "Refund" %}</a>
	{% endif %}

	<table class="table">
		<thead>
			<tr>
				<th>{% trans "Payment Method" %}</th>
				<th>{% trans "Transaction ID" %}</th>
				<th>{% trans "Amount" %}</th>
			</tr>
		</thead>
		{% for payment in payments %}
			<tr>
				<td>{{ payment.methodName }}</td>
				<td>{{ payment.recordId }}</td>
				<td>{{ currencySymbol }}{{ payment.netAmountPaid|floatformat:"2" }}</td>
			</tr>
		{% endfor %}
		</table>
{% endif %}

<div class="card">
<h4 class="card-header">{% trans "Comments/Notes" %}</h4>
<div class="card-body">
	<pre>{{ object.comments }}</pre>
</div>
</div>

{% if object.outstandingBalance %}
	<hr />
	<h2>{% trans "Pay Invoice" %}</h2>

	{% if user_has_permissions and not user_has_validation_string %}
		{% static_placeholder "registration_payatdoor_placeholder" %}
	{% else %}
		{% static_placeholder "registration_payment_placeholder" %}
	{% endif %}
{% endif %}

{% if returnPage.url %}
	<p class="my-4 clearfix"><a class="btn btn-outline-secondary float-right" href="{{ returnPage.url }}">&laquo;&nbsp;{% trans "Return to" %} {{ returnPage.title }}</a></p>
{% endif %}

{% endblock %}