<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ tran("{Production by orders}") }}</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="w-100 p-4 print-repeated">

        {% 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("{Production by orders}") }}</h3>
        </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("{produced total}") }}</b><br>
              {{ total_volume_str }}&nbsp;m³<br>
              {{ total_tonnes_str }}&nbsp;t
          </div>
          <div class="col-4">
              <table>
                  <tr>
                      <td class="text-right"><b>{{ tran("{since}") }}:</b></td>
                      <td class="px-2">{{ datetime_since }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{until}") }}:</b></td>
                      <td class="px-2">{{ datetime_until }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{Customer}") }}:</b></td>
                      <td class="px-2">{{ customer_name }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{ConstructionSite}") }}:</b></td>
                      <td class="px-2">{{ construction_site_name }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{Recipe}") }}:</b></td>
                      <td class="px-2">{{ recipe_name }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{registration_number}") }}:</b></td>
                      <td class="px-2">{{ vehicle_registration_number }}</td>
                  </tr>
              </table>
          </div>
        </div>

        {% if group_by_delivery %}
        <!-- deliveries -->
        <table class="mb-4 small table table-bordered table-striped">
            <thead class="bold">
                <td>{{ tran("{t_human}") }}</td>
                <td>{{ tran("{Customer}") }}</td>
                <td>{{ tran("{ConstructionSite}") }}</td>
                <td>{{ tran("{registration_number}") }}</td>
                <td>{{ tran("{Recipe}") }}</td>
                <td>m³</td>
                <td>t</td>
                {% for name in material_names %}
                    <td class="text-right">{{ name }}</td>
                {% endfor %}
            </thead>
            {% for d in deliveries %}
            <tr>
                <td>{{ d.delivery._t_human }}</td>
                <td>{{ d.order.customer_name }}</td>
                <td>{{ d.order.construction_site_name }}</td>
                <td>{{ d.delivery.car_registration_number }}</td>
                <td>{{ d.order.r_name }}</td>
                <td class="text-right">{{ d.volume_sum }}</td>
                <td class="text-right">{{ d.tonnes_sum }}</td>
                {% for name in material_names %}
                    <td class="text-right">{{ d.material_sums[name] }}</td>
                {% endfor %}
            </tr>
            {% endfor %}
        </table>
        {% else %}
        <!-- batches -->
        <table class="mb-4 small table table-bordered table-striped">
            <thead class="bold">
                <td>{{ tran("{t_human}") }}</td>
                <td>{{ tran("{Customer}") }}</td>
                <td>{{ tran("{ConstructionSite}") }}</td>
                <td>{{ tran("{registration_number}") }}</td>
                <td>{{ tran("{Recipe}") }}</td>
                <td>m³</td>
                <td>{{ tran("{sequence}") }}</td>
                <td>m³ {{ tran("{tot.}") }}</td>
                <td>t</td>
                {% for name in material_names %}
                    <td class="text-right">{{ name }}</td>
                {% endfor %}
            </thead>
            {% for batch in batches %}
            <tr>
                <td>{{ batch._production_start_t_human }}</td>
                <td>{{ batch._delivery_order.customer_name }}</td>
                <td>{{ batch._delivery_order.construction_site_name }}</td>
                <td>{{ batch._delivery.car_registration_number }}</td>
                <td>{{ batch._delivery_order.r_name }}</td>
                <td class="text-right">{{ volume_str_by_batch[batch.id] }}</td>
                <td>{{ batch._batch_sequence_str }}</td>
                <td class="text-right">{{ order_volume_str_by_batch[batch.id] }}</td>
                <td class="text-right">{{ tonnes_str_by_batch[batch.id] }}</td>
                {% for name in material_names %}
                    <td class="text-right">{{ consumption_str_by_batch_and_material[(batch.id, name)] }}</td>
                {% endfor %}
            </tr>
            {% endfor %}
        </table>
        {% endif %}

      <div class="row printout-mini">
          <div class="col-5">{{ tran("{ORIGINAL}") }}</div>
          <div class="col-7 text-right">{{ tran("{asterix_footer}") }} {{ datetime_now }}</div>
      </div>

    </div>

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

  </body>
</html>
