{% extends "admin/change_form.html" %}
{% load admin_urls i18n %}

{% block object-tools %}
{% if change %}{% if not is_popup %}
  {% url opts|admin_urlname:'history' original.pk|admin_urlquote as history_url %}
  <ul class="object-tools"><li><a href="{{ history_url }}" class="historylink">{% trans "History" %}</a></li>
  {% if has_absolute_url %}<li><a href="../../../r/{{ content_type_id }}/{{ object_id }}/" class="viewsitelink">{% trans "View on site" %}</a></li>{% endif%}
  {% if not original.periodicite %}
  <li><a href="{% url "admin:eo_facture_contrat_duplicate" original.id %}">Dupliquer</a></li>
  {% endif %}
  <li><a href="{% url "admin:eo_facture_facture_changelist" %}?contrat={{ original.id }}">Factures</a></li>
  {% if original.has_echeance_to_bill %}
  <li><a href="javascript:document.getElementById('facturer_echeance_form').submit();">Facturer</a></li>
  <form id="facturer_echeance_form" method="post" action="{% url "admin:eo_facture_contrat_facturer_echeance" original.id %}">
    {% csrf_token %}
    <input type="hidden" name="echeance" value="{{ original.next_echeance_to_bill }}"/>
  </form>
  </li>
  {% endif %}
  {% if not original.periodicite %}
  <li><a href="{% url "admin:eo_facture_facture_add" %}?contrat={{ original.id }}&client={{ original.client.id }}&taux_tva={{ original.tva }}">Ajouter une facture</a></li>
  <li><a href="{% url "admin:eo_facture_facture_add_simple" %}?contrat={{ original.id }}">Ajouter une facture comme pourcentage du total</a></li>
  {% endif %}
  </ul>
{% endif %}{% endif %}
{% endblock %}

{% block after_field_sets %}
{% if original.periodicite and original.periodicite_debut %}
<fieldset class="module">
    <h2>Échéances</h2>
    <div>
        <ul>
            {% for echeance in original.periodicite_echeances %}
                <li>du {{ echeance.1 }} au {{ echeance.2 }}</li>
            {% endfor %}
        </ul>
    </div>
</fieldset>
{% endif %}
{% endblock %}
