{% extends "invoices/base-wide.html" %}
{% load invoice_tags %}
{% load perm_tags %}
{% load base_filters %}
{% load i18n %}

{% block title %}{{ block.super }}{% if obj_name %}{{ obj_name|capfirst }}{% endif %} Invoice{% endblock %}


{% block extra_head %}
{{ block.super }}
<link rel="stylesheet" href="{{ STATIC_URL }}css/invoices.css">
{% endblock %}

{% block body %}
<div class="t">
{% invoice_nav  invoice %}
{% has_perm request.user invoices.change_invoice as can_edit_invoice %}
<h1>{% if obj_name %}{{ obj_name|capfirst }}{% endif %} Invoice</h1>

{% if SITE_GLOBAL_SITEMAILINGADDRESS %}
<address class="invoice-site-address">{{ SITE_GLOBAL_SITEMAILINGADDRESS }}</address>
{% endif %}

{% if request.user.is_superuser or can_edit_invoice %}
<div class="invoice-options">
  <ul>
    {% if invoice.is_tendered %}
      <li><a class="admin-option" href="{%url invoice.adjust invoice.id %}">{% trans "Adjust Invoice" %}</a></li>
    {% endif%}
    <li><a class="admin-option" href="{% url invoice.detail invoice.id%}">{% trans "Accounting Entries" %}</a></li>
    <li><a class="admin-option" href="{% url invoice.detail invoice.id%}" onclick="$('.invoice-admin-notes').toggle(); return false;">{% trans "Make Notes" %}</a></li>
  </ul>
</div>
{% endif %}

{% if invoice.balance > 0 %}
<div class="invoice-options">
    <ul>
        <li><a class="admin-options" href="{% url invoice.mark_as_paid invoice.pk %}">{% trans "Mark as Paid" %}</a></li>
    </ul>
</div>
{% endif %}

{% if request.user.is_superuser and invoice.payments_credits > 0 %}
<div class="invoice-options">
    <ul>
        <li><a class="admin-option" href="{% url invoice.void_payment invoice.id %}"> {% trans "Void Payment" %}</a></li>
    </ul>
</div>
{% endif %}

<div class="invoice-options">
    <ul>
      <li><a href="{% url invoice.print_view invoice.id guid %}">Print Invoice</a></li>
    </ul>
</div>

{% if request.user.is_superuser or can_edit_invoice %}
<div class="invoice-admin-notes">
    <form method="post" action=".">
    {% csrf_token %}
    <p>{{ form.admin_notes }}</p>
    <input type="submit" name="submit" value="Update Notes" />
    </form>
</div>
{% endif %}

{% with invoice.get_object as object %}
<div class="invoice-meta">
	<table border="0" cellspacing="0" cellpadding="0">
	  <tr>
	    <td>Invoice #</td>
	    <td class="td-right">{{ invoice.id }}</td>
	  </tr>
	  {% if object %}
	    <tr>
	      <td>{% trans "Invoice For" %}</td>
	      <td class="td-right">
	  {% if object.event.pk %}
	      <a href="{% url event.registration_confirmation object.event.pk object.pk %}">{{ object }}</a><br>
	  <strong>Event Date:</strong> {{ object.event.start_dt }}
	      {% else %}
	  {{ SITE_GLOBAL_SITEDISPLAYNAME }}
	  <br>
	  {% if invoice.bill_to_first_name %} {{ invoice.bill_to_first_name }} {% endif %} {% if invoice.bill_to_last_name %}{{ invoice.bill_to_last_name }}<br> {% endif %}
	  {% if invoice.bill_to_address %} {{ invoice.bill_to_address }}<br>{% endif %}
	  {% if invoice.bill_to_city %}{{ invoice.bill_to_city}},{% endif %} {% if invoice.bill_to_state %}{{ invoice.bill_to_state }}{% endif %} {% if invoice.bill_to_zip_code %}{{ invoice.bill_to_zip_code }}{% endif %}
	      {% endif %}
	      </td>
	    </tr>
	  {% endif %}
	  <tr>
	    <td>{% trans "Invoice Date" %}</td>
	    <td class="td-right">{{ invoice.create_dt|date:'N j, Y h:i a' }}</td>
	  </tr>
	  <tr>
	    <td>{% trans "Invoice Status" %}</td>
	    {% if invoice.is_tendered %}
	      <td class="invoice-status td-right">{% blocktrans with invoice.tender_date|date:'N j, Y h:i a' as tenddate %} Tendered {{ tenddate }} {% endblocktrans %}</td>
	    {% else %}
	      <td class="invoice-status-red td-right">{% trans "Estimate" %}</td>
	    {% endif %}
	  </tr>
	  <tr class="invoice-meta-amount">
	    <td>{% trans "Invoice Amount" %}</td>
	    <td class="td-right">{{ invoice.total|format_currency }}</td>
	  </tr>
	</table>
	</div>
{% endwith %}

<div class="invoice-table">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr class="invoice-table-header">
        <td>Description</td>
        <td class="td-right">Line Amount</td>
      </tr>
      {% invoice_object_display request invoice %}
    </table>
</div>

<div class="invoice-total-wrap">
    <div class="invoice-total">
      {% invoice_total_display request invoice %}
    </div>
</div>
<div style="clear: both"></div>
<div class="payment-table">
	{% payment_history_display request invoice %}
</div>
</div>
{% endblock %}
