{% if language == 'en' %}
  {% if number == 'lettre' %}
    {% set title = 'Letter' %}
  {% else %}
    {% set name = 'Quotation' if quotation else 'Invoice' %}
    {% set title = '{} #{}'.format(name, number) %}
  {% endif %}
  {% set date_string = 'Date' %}
  {% set number_string = 'Number' %}
  {% set description_string = 'Description' %}
  {% set unit_price_string = 'Unit Price' %}
  {% set quantity_string = 'Quantity' %}
  {% set total_string = 'Total' %}
  {% set total_to_pay_string = 'Total to pay' %}
{% else %}
  {% if number == 'lettre' %}
    {% set title = 'Lettre' %}
  {% else %}
    {% set name = 'Devis' if quotation else 'Facture' %}
    {% set title = '{} n°{}'.format(name, number) %}
  {% endif %}
  {% set date_string = 'Date' %}
  {% set number_string = 'Numéro' %}
  {% set description_string = 'Désignation' %}
  {% set unit_price_string = 'Prix unitaire' %}
  {% set quantity_string = 'Quantité' %}
  {% set total_string = 'Total' %}
  {% set total_to_pay_string = 'Total à payer' %}
{% endif %}

<!DOCTYPE html>
<html lang="fr">
  <head>
    <meta charset="UTF-8"/>
    <title>AFPY − {{ title }}</title>
    <link type="text/css" rel="stylesheet" href="../commun/style.css" />
  </head>

  <body>
    <header>
      <address id="from">
        {%- block address_from -%}
          Association Francophone Python
          2, rue Professeur Zimmermann
          69007 LYON
          FRANCE
          504 398 355 00017
        {%- endblock address_from -%}
      </address>
      <address id="to">
        {%- block address_to -%}
        {%- endblock address_to -%}
      </address>
    </header>

    {% block content %}
      {% if name %}
        <h1>{{ name }}</h1>
      {% endif %}
      <dl>
        <dt>{{ date_string }}</dt>
        <dd>{{ date }}</dd>
        <dt>{{ number_string }}</dt>
        <dd>{{ number }}</dd>
      </dl>

      <table>
        {% set total = [0] %}
        {% for designation, price, quantity in lines %}
          {% if loop.first %}
            <thead>
              <th>{{ description_string }}</th>
              <th>{{ unit_price_string }}</th>
              <th>{{ quantity_string }}</th>
              <th>{{ total_string }}</th>
            </thead>
            <tbody>
          {% endif %}

          <tr>
            <td>{{ designation }}</td>
            <td>{{ price }} €</td>
            <td>{{ quantity }}</td>
            <td>{{ quantity * price }} €</td>
          </tr>
          {{ total.append(quantity * price) or '' }}

          {% if loop.last %}
            </tbody>
            <tfoot>
              <th colspan="3">{{ total_to_pay_string }}</th>
              <td>{{ total | sum }} €</td>
            </tfoot>
          {% endif %}
        {% endfor %}
      </table>
    {% endblock content %}

    <footer>
      {% block footer %}
        <p>
          {% if language == 'en' %}
            Value added tax not applicable.
          {% else %}
            Taxe sur la valeur ajoutée non applicable, article 293 B du CGI.
          {% endif %}
        </p>
        {% if quotation %}
          <p>
            {% if language == 'en' %}
              This quotation is valid for 1 month.
            {% else %}
              Ce devis est valable 1 mois.
            {% endif %}
          </p>
        {% endif %}
        {% if paypal %}
          <p>
            {% if language == 'en' %}
              Please pay on our PayPal account: tresorier@afpy.org.
            {% else %}
              En votre aimable règlement, au comptant, sur notre compte PayPal : tresorier@afpy.org.
            {% endif %}
          </p>
        {% else %}
          <p>
            {% if language == 'en' %}
              Please pay by bank transfer.
            {% else %}
              En votre aimable règlement, au comptant par virement.
            {% endif %}
          </p>

          <address>
            Société Générale Lyon République
            6, rue de la République
            69206 Lyon
            France
          </address>

          <dl>
            <dt>IBAN</dt>
            <dd>FR76 3000 3031 2000 0507 6517 116</dd>
            <dt>BIC/SWIFT</dt>
            <dd>SOGEFRPPLPC</dd>
          </dl>
        {% endif %}
      {% endblock footer %}
    </footer>
  </body>
</html>
