<!doctype html>
<html>
  <head>
    <style>
      @page {
        @frame title {
          -pdf-frame-content: title;
          margin: 0.5cm;
          margin-right: 6cm;
        }
        @frame date {
          margin-top: 0.5cm;
          margin-right: 0.5cm;
          -pdf-frame-content: date;
          width: 6cm;
          right: 0cm;
        }
        @frame payee {
          -pdf-frame-content: payee-header;
          top: 2cm;
          left: 1cm;
          width: 9.75cm;
          height: 5cm;
        }
        @frame payer {
          -pdf-frame-content: payer-header;
          top: 2cm;
          margin-right: 1cm;
          width: 9.75cm;
          right: 0px;
        }
        @frame bank {
          -pdf-frame-content: bank-header;
          top: 6cm;
          margin-right: 1cm;
          width: 9.75cm;
          right: 0px;
        }
        @frame footer {
          -pdf-frame-content: footer;
          bottom: 0cm;
          height: 0.5cm;
        }
        @frame {
          top: 6cm;
          margin: 1cm;
        }
      }
      @page then {
        @frame {
          margin: 2cm 1cm;
        }
        @frame footer {
          -pdf-frame-content: footer;
          bottom: 0cm;
          height: 0.5cm;
        }
      }
      h1, div {
        display: block;
      }
      table tr.batch-columns-header td {
        text-align: center;
      }
      #footer {
        text-align: center;
      }
      #title {
        font-size: 1cm;
        line-height: 0cm;
      }
      #date, #identifier {
        text-align: right;
        font-size: 0.35cm;
        line-height: 0cm;
      }
      .head {
        background-color: #EEEEEE;
        vertical-align: middle;
      }
      #content td {
        text-align: center;
      }
      #bank-header {
        height: 3.5cm;
        margin-top: 0.5cm;
      }
      #payee-heade td {
        text-align: left;
      }
      #content  {
        text-align: center;
      }
    </style>
  </head>
  <body>
    <div id="title">Bordereau de facturation</div>
    <div id="date">
      <div>
        Édité le {{ now|date:"d/m/Y" }} à {{ now|time:"H:i:s" }}
      </div>
      <div>
         N&deg;: {{ health_center.accounting_number }}
      </div>
    </div>
    <div id="header-box">
      <div id="payee-header">
          <table style="padding: 3px; border: 0.5px solid black; height: 5cm;">
            <tr style="padding-top: 3px; padding-bottom: 2px; line-height: 50%; background-color: #EEEEEE; margin-bottom: 3cm"><td> Établissement</td></tr>
            <tr><td style="height: 5cm; display: block;">
            {% block payee %}
            {{ service.name }} SAINT ETIENNE</br>
            Finess: 420788606 MT: 19 DMT: 320</br>
            66/68, RUE MARENGO</br>
            42000 SAINT-ETIENNE</br>
            Tél.: 04 77 92 05 70
            </br>
            </br>
            </br>
            </br>
            </br>
            </br>
            {% endblock %}
        </td></tr>
        </table>
      </div>
      <div id="payer-header">
          <table style="padding: 3px; border: 0.5px solid black">
            <tr style="padding-top: 3px; padding-bottom: 2px; line-height: 50%; background-color: #EEEEEE;"><td>Caisse destinataire</td></tr>
            <tr>
              <td>
                {{ health_center.name }}<br/>
                {{ health_center.address }}<br/>
                {% if health_center.address_complement %}
                  {{ health_center.address_complement }}<br/>
                {% endif %}
                {{ health_center.zip_code }} {{ health_center.city }}<br/>
                {% if health_center.phone %}
                Tél.: {{ health_center.phone }}<br/>
                {% endif %}
                N&deg; de compte: {{ health_center.accounting_number }}
        </td></tr>
        </table>
      </div>
      <div id="bank-header">
          <table style="padding: 3px; border: 0.5px solid black">
            <tr style="padding-top: 3px; padding-bottom: 2px; line-height: 50%; background-color: #EEEEEE;"><td>Banque de règlement</td></tr>
            <tr>
              <td>
                {% block bank %}
                Banque&nbsp;:</br>
                RIB&nbsp;:
                {% endblock %}
              </td>
            </tr>
        </table>
      </div>
    </div>
    <div id="content">
      {% for batch in batches %}
      <div style="text-align: left;">
        <h1>Lot n&deg;&nbsp;:&nbsp;{{ batch.number }}</h1>
      </div>
      <div style="border: 0.5px solid black; padding-top: 2px; padding-bottom: 3px; line-height: 50%;">
      <pdf:nexttemplate name="then"/>
      <table>
          <thead style="border: none;">
            <tr class="batch-columns-header" style="background-color: #EEEEEE;">
              <td>Facture</td>
              <td>Nom</td>
              <td>Nir</td>
              <td>D/T</td>
              <td>Début</td>
              <td>Fin</td>
              <td>Somme</td>
            </tr>
          </thead>
          <tbody class="batch-content" style="border: none;">
            {% for invoice in batch.invoices %}
            <tr>
              <td>{{ invoice.number }}</td>
              <td>{{ invoice.patient_first_name}} {{ invoice.patient_last_name|upper }}</td>
              <td>{% firstof invoice.policy_holder_social_security_id_full invoice.patient_social_security_id_full %}</td>
              <td>{% if invoice.kind %}{{ invoice.kind }}{% endif %}</td>
              <td>{{ invoice.start_date|date:"d/m/Y" }}</td>
              <td>{{ invoice.end_date|date:"d/m/Y" }}</td>
              <td>{{ invoice.decimal_amount|floatformat:2 }}</td>
            </tr>
            {% endfor %}
          </tbody>
      </table>
      <div style="text-align: right; border: none;">
        <p><b>Lot n&deg;&nbsp;:&nbsp;{{ batch.number }} [ {{ batch.number_of_invoices }} factures ] [ {{ batch.number_of_acts}} actes ] Total = {{ batch.total|floatformat:2 }} €</b></p>
      </div>
      {% endfor %}
      <div style="text-align: right; border: none;">
        <p><b>Synthèse caisse destinataire&nbsp;:&nbsp;[ {{ synthesis.number_of_invoices }} factures ] [ {{ synthesis.number_of_acts }} actes ] Total = {{ synthesis.total|floatformat:2 }} euros</b></p>
      </div>
      <table style="border: none;">
        <tr><td style="width: 20cm">&nbsp;</td>
          <td style="padding: 3px; text-align:left; border: 1px solid black">
            {% block signature %}
            Signature du directeur:</br>
            </br>
            </br>
            </br>
            </br>
            </br>
            </br>
            {% endblock %}
          </td>
        </tr>
      </table>
    </div>
    <div id="footer">
      {% if counter %}{{ counter.increment }}.{% endif %}<pdf:pagenumber/>
    </div>
  </body>
</html>
