{% load i18n %}
{% load translations %}
{% with projects=billing.projects.all %}
<div class="container-fluid">
<div class="row">

<div class="col-lg-6" id="billing-{{ billing.pk }}">
<div class="panel {% if not billing.is_active %}panel-default{% elif not billing.paid %}panel-danger{% elif not billing.in_limits %}panel-warning{% else %}panel-primary{% endif %}">
  <div class="panel-heading">
  {% if billing.payment.recurring %}
  <span class="pull-right flip badge">{% trans "Recurring payment" %}</span>
  {% endif %}
  {% if not billing.is_active %}
  <span class="pull-right flip badge">{% trans "Expired" %}</span>
  {% elif not billing.paid %}
  <span class="pull-right flip badge">{% trans "Past due date" %}</span>
  {% elif not billing.in_limits %}
  <span class="pull-right flip badge">{% trans "Exceeds limits" %}</span>
  {% endif %}
  <h4 class="panel-title">{% trans "Billing plan" %}</h4>
  </div>
  {% include "billing/status.html" %}
{% if billing.is_active %}
  <div class="panel-footer">
  <form method="post" action="{% url 'billing' %}">
  {% csrf_token %}
  {% if payment_enabled %}
    <a href="{% url 'create-billing' %}?billing={{ billing.pk }}&amp;upgrade=1" class="btn btn-primary">
    {% if billing.payment.recurring %}
    {% trans "Change payment plan" %}
    {% else %}
    {% trans "Perform payment" %}
    {% endif %}
    </a>
  {% endif %}
  {% if billing.payment.recurring %}
  <button type="submit" name="recurring" value="{{ billing.pk }}" class="btn btn-warning">{% trans "Terminate recurring payment" %}</button>
  {% endif %}
  <button type="submit" name="terminate" value="{{ billing.pk }}" class="btn btn-danger"
  {% if projects %}
  title="{% trans "To terminate billing you have to remove all projects first." %}"
  disabled
  {% endif %}
  >{% trans "Terminate billing plan" %}</button>
  </div>
{% endif %}
</div>
</div>

<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Invoices" %}</h4></div>
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Invoice period" %}</th>
<th>{% trans "Invoice amount" %}</th>
<th>{% trans "Download invoice" %}</th>
</tr>
</thead>
<tbody>
{% for invoice in billing.invoice_set.order %}
<tr>
<td>{{ invoice.start|date:"SHORT_DATE_FORMAT" }} - {{ invoice.end|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ invoice.amount }} {{ invoice.get_currency_display }}</td>
<td>
{% if invoice.ref and invoice.filename_valid %}
<a href="{% url 'invoice-download' pk=invoice.pk %}">{{ invoice.filename }}</a>
{% elif invoice.ref %}
{{ invoice.filename }}
{% else %}
{% trans "Not available" %}
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="3">{% trans "No invoices found." %}</td/></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>

</div>
{% endwith %}
