{% load i18n %}
{% load translations %}
{% load icons %}
{% with projects=billing.projects.all %}
<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 or not billing.in_limits %}panel-danger{% else %}panel-default{% endif %}">
  <div class="panel-heading">
  <h4 class="panel-title">
    <a class="pull-right flip doc-link" href="https://weblate.org/hosting/">{% icon "info.svg" %}</a>
    {% trans "Billing plan" %}
    {% if billing.payment.recurring %}
    <span class="badge">{% trans "Recurring payment" %}</span>
    {% endif %}
    {% if not billing.is_active %}
    <span class="badge">{% trans "Expired" %}</span>
    {% elif not billing.paid %}
    <span class="badge">{% trans "Past due date" %}</span>
    {% elif not billing.in_limits %}
    <span class="badge">{% trans "Exceeds limits" %}</span>
    {% endif %}
  </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 and billing.can_be_paid %}
    <a href="{% url 'create-billing' %}?billing={{ billing.pk }}&amp;upgrade=1" class="btn btn-primary">
    {% trans "Change plan or payment method" %}
    </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>
  </form>
  </div>
{% endif %}
</div>
</div>

<div class="col-lg-6">
<div class="panel panel-default">
  <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>

{% endwith %}
