<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ tran("{Batch protocol}") }} {{ order.auto_number }}</title>

    <!-- Note: To work in reverse proxy, we cannot use an absolute path beginning with / -->
    <link href="{{ url_prefix }}/static/style.css" rel="stylesheet"/>
    <link href="{{ url_prefix }}/static/vendor/bootstrap.min.css" rel="stylesheet" />
  </head>

  <body>

    <div class="container print-repeated" id="main">

        {% include 'printouts/_logo.html' %}

        <!-- Head -->
        <div class="row mb-2 mt-3">

        <div class="col-6">
          <b>{{ setup.company_name }}</b>
          <div class="small">
              {{ setup.company_address }}<br>
              {{ setup.company_zip }}
              {{ setup.company_city }}<br>
              {{ tran("{company_idnum}") }}: {{ setup.company_idnum }}
              {{ tran("{Vat ID}") }}: {{ setup.company_vat_idnum }}<br>
              {{ setup.company_legal }}
          </div>
        </div>

        <div class="col-6">
            <h3 class="text-right">{{ tran("{batch_protocol_title}") }}</h3>
            <div class="big text-right">{{ tran("{for_delivery_sheet_no}") }} {{ order.auto_number }}</div>
        </div>

        </div>

        <!-- Production facility -->
        <div class="row border mb-2">
          <div class="col-4">
              <b>{{ tran("{facility}") }}</b>
              <div class="small">
                  {{ setup.facility_name }}<br>
                  {{ setup.facility_address }}<br>
                  {{ setup.facility_zip }}
                  {{ setup.facility_city }}<br>
                  {{ setup.facility_code }}
              </div>
          </div>
          <div class="col-4">
              <b>{{ tran("{certification}") }}</b>
              <div style="white-space: pre-wrap">{{ setup.certification_text }}</div>
          </div>
          <div class="col-4">
              <b>{{ tran("{datetime_tax}") }}</b><br>
              {{ order._t_human }}
          </div>
        </div>

        <!-- Customer -->
        <div class="row border mb-3">
          <div class="col-4">
              <b>{{ tran("{Customer}") }}</b><br>
              {{ order.customer }}
          </div>
          <div class="col-4">
              <b>{{ tran("{ConstructionSite}") }}</b><br>
              {{ order.construction_site }}
          </div>
        </div>

        {% include 'printouts/_product_header.html' %}

        <!-- Product data -->
        <div class="row mb-2">
          <div class="col-2">
            <h3>{{ delivery._volume }} m³</h3>
          </div>
          <div class="col-6">
              <b>{{ order.r_description }}</b>
          </div>
          <div class="col-2">
              <b>{{ order.r_name }}</b>
          </div>
          <div class="col-2">
              <b>{{ order.r_number }}</b>
          </div>
        </div>

        <!-- materials -->
        <div class="ml-0">
            <table class="w-100">
            {% for batch in batches %}
                <tr>
                    <td>{{ tran("{Batch}") }}</td>
                    <td>{{ tran("{amount}") }}</td>
                    <td>{{ tran("{mixing_duration}") }}</td>
                    <td>{{ tran("{consistency}") }}</td>
                    <td>{{ tran("{water_correction}") }}</td>
                    <td>{{ tran("{additional_water}") }}</td>
                    <td>{{ tran("{temp_cement}") }}</td>
                    <td>{{ tran("{production_end}") }}</td>
                </tr>
                <tr class="border-bottom">
                    <td>{{ batch._batch_sequence_str }}</td>
                    <td>{{ batch.volume }}&nbsp;m³</td>
                    <td>{{ batch._mixing_duration_str }}</td>
                    <td>{{ batch.consistency }}</td>
                    <td>{{ batch.water_correction_e1 or batch.water_correction_rq }}</td>
                    <td>{{ batch.additional_water }}</td>
                    <td>{{ batch._cement_temperature_str }}</td>
                    <td>{{ batch._production_end_t_human }}</td>
                </tr>
                <tr>
                    <td colspan="999" class="pl-3 pr-3">
                        <table class="w-100 mb-4 small">
                            <tr class="bold">
                                <td style="width: 40%">{{ tran("{Material}") }}</td>
                                <td style="width: 15%" class="text-right">{{ tran("{from_recipe}") }}</td>
                                <td style="width: 15%" class="text-right">{{ tran("{requested}") }}</td>
                                <td style="width: 15%" class="text-right">{{ tran("{weighted}") }}</td>
                                <td style="width: 15%" class="text-right">{{ tran("{difference}") }}</td>
                            </tr>
                            {% for material in batch._materials %}
                            <tr>
                                <td>{{ material._material.name }}</td>
                                <td class="text-right">{{ material.weight_recipe }} kg</td>
                                <td class="text-right">{{ material.weight_rq }} kg</td>
                                <td class="text-right">{{ material.weight_e1 }} kg</td>
                                <td class="text-right">{{ material._weight_difference }} kg</td>
                            </tr>
                            {% endfor %}
                        </table>
                    </td>
                </tr>
            {% endfor %}

            {% if batches.__len__() != 1 %}
            <tr class="bold border-bottom">
                <td colspan="6">Celkem</td>
            </tr>
            <tr>
                <td colspan="999" class="pl-3 pr-3">
                    <table class="w-100 mb-4 small">
                        <tr class="bold">
                            <td style="width: 40%">{{ tran("{Material}") }}</td>
                            <td style="width: 15%" class="text-right">{{ tran("{from_recipe}") }}</td>
                            <td style="width: 15%" class="text-right">{{ tran("{requested}") }}</td>
                            <td style="width: 15%" class="text-right">{{ tran("{weighted}") }}</td>
                            <td style="width: 15%" class="text-right">{{ tran("{difference}") }}</td>
                        </tr>
                        {% for t in totals %}
                        <tr>
                            <td>{{ t.name }}</td>
                            <td class="text-right">{{ t.weight_recipe }} kg</td>
                            <td class="text-right">{{ t.weight_rq }} kg</td>
                            <td class="text-right">{{ t.weight_e1 }} kg</td>
                            <td class="text-right">{{ t._weight_difference }} kg</td>
                        </tr>
                        {% endfor %}
                        <tr class="bold border-top">
                            <td></td>
                            <td class="text-right">{{ grand_total.weight_recipe }} {{ grand_total.unit }}</td>
                            <td class="text-right">{{ grand_total.weight_rq }} {{ grand_total.unit }}</td>
                            <td class="text-right">{{ grand_total.weight_e1 }} {{ grand_total.unit }}</td>
                            <td class="text-right">{{ grand_total._weight_difference }} {{ grand_total.unit }}</td>
                        </tr>
                    </table>
                </td>
            </tr>
            {% endif %}

            </table>
        </div>

        <!-- naive separator -->
        <div class="mb-5">&nbsp;</div>

        {% include 'printouts/_footer.html' %}

    </div>

    {% include 'printouts/_control_buttons.html' %}

  </body>
</html>
