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

{% block content %}

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

<dl>
	<dt>{% trans "Invoice Number" %}:</dt>
	<dd>{{ object.id }}</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-secondary btn-sm" href="{% url 'sendInvoiceNotifications' object.id %}">{% trans "Notify Recipient" %}</a>{% endif %}
	</dd>
	{% endif %}

	<dt>{% trans "Invoice Status" %}:</dt>
	<dd>{{ object.statusLabel }}</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.finalRegistration %}
	<a class="btn btn-secondary" href="{% url 'admin:core_registration_change' object.finalRegistration.id %}">{% trans "View Registration" %}</a>
{% elif 'core.change_temporaryregistration' in perms and object.temporaryRegistration %}
	<a class="btn btn-secondary" href="{% url 'admin:core_temporaryregistration_change' object.temporaryRegistration.id %}">{% trans "View Temporary 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-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>

	{% static_placeholder "registration_payment_placeholder" %}
{% endif %}

{% endblock %}