<!--
    Delivery sheet printout. Available variables:

        order       ... <class Order> order
        setup       ... <class Setup> setup
        materials   ... materials used in order, grouped by material type.
                        Usage: materials["Cement"] etc. (contains <list of class OrderMaterial>)
                        Supported are following types (warning: names ARE case sensitive)
                          "Admixture", "Aggregate", "Cement", "Water", "Addition"
        unload_time_minutes_str ... time of unload in minutes, formatted

-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ tran("{DeliverySheet}") }} {{ 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: company, production facility, sheet number and date -->
        <div class="row mb-3 mt-3">

            <div class="col-4">
              <b>{{ setup.company_name }}</b>
              <div>
                  {{ 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-4">
              <b>{{ tran("{facility}") }}</b>
              <div>
                  {{ setup.facility_name }}<br>
                  {{ setup.facility_address }}<br>
                  {{ setup.facility_zip }}
                  {{ setup.facility_city }}<br>
                  {{ setup.facility_code }}
              </div>
              <div class="mt-2">
                  <b>{{ tran("{Contract}") }}:</b> {{ order.contract_name }}
              </div>
            </div>

            <div class="col-4 text-right">
                <h3>{{ tran("{delivery_sheet_no}") }} {{ order.auto_number }}</h3>
                  <b>{{ tran("{datetime_tax}") }}</b><br>
                  {{ tran("{datetime_production_process_start}") }}<br>
                  {{ order._t_human }}
            </div>

        </div>

        <!-- Customer -->
        <div class="row border mb-2 py-2">
          <div class="col-4">
              <b>{{ tran("{Customer}") }}</b><br>
              {{ order.customer_name }}<br>
              {{ tran("{company_idnum}") }}: {{ order._customer_record.company_idnum }}<br>
              {{ tran("{Vat ID}") }}: {{ order._customer_record.vat_idnum }}<br>
          </div>
          <div class="col-4">
              <b>{{ tran("{ConstructionSite}") }}</b><br>
              {{ order.construction_site_name }}
              <div class="row">
                  <div class="col-6">
                      <b>{{ tran("{transport}") }}</b><br>
                      {{ tran("{Yes}") }}<br>
                      <small>{{ tran("{distance_driven}") }}: <b>{{ order._distance_driven_calculated }}</b> km</small>
                  </div>
                  <div class="col-6"><b>{{ tran("{Car}") }}</b><br>
                      {% if delivery %}
                        {{ delivery.car_registration_number }}
                        {% if delivery.car_car_type %}
                            ({{ delivery.car_car_type }})
                        {% endif %}
                      {% endif %}</div>
              </div>
          </div>
          <div class="col-4">
              <b>{{ tran("{contacts}") }}</b>
              <div>
                  <b>{{ tran("{Driver}") }}</b><br>
                  {% if delivery %}
                     {{ delivery.driver_name }}
                     {{ delivery.driver_contact }}
                  {% endif %}
              </div>
          </div>
        </div>

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

        <!-- Product data -->
        <div class="row mb-2">
          <div class="col-2">
              <h3>{{ order.volume }}&nbsp;m³</h3>
          </div>
          <div class="col-5">
              {{ order.r_description }}
              {% if order.r_ufi_code %}
                {% if order.r_description %}
                  <br>
                {% endif %}
                {{ tran("{ufi_code}") }} {{ order.r_ufi_code }}
              {% endif %}
          </div>
          <div class="col-3">
              <b>{{ order.r_name }}</b>
          </div>
          <div class="col-2">
              <b>{{ order.r_number }}</b>
          </div>
        </div>

        <!-- Extra data -->
        <table class="w-100 table table-bordered">
            <tr>
                <td style="padding: 5px;">{{ tran("{dmax}") }}</td>
                <td style="padding: 5px;">{{ tran("{CL content}") }}</td>
                <td style="padding: 5px;">{{ tran("{Air content}") }}</td>
                <td style="padding: 5px;">{{ tran("{W/C}") }}</td>
                <td style="padding: 5px;">{{ tran("{CementMin}") }}</td>
                <td style="padding: 5px;">{{ tran("{temp_air}") }}</td>
                <td style="padding: 5px;">{{ tran("{cement_water_contact}") }}</td>
                <td style="padding: 5px;">{{ tran("{workability_time}") }}</td>
            </tr>
            <tr>
                <td style="padding: 5px;">{{ order.r_d_max }}</td>
                <td style="padding: 5px;">{{ order.r_cl_content }}</td>
                <td style="padding: 5px;">{{ order.r_air_content }}</td>
                <td style="padding: 5px;">{{ order.r_vc }}</td>
                <td style="padding: 5px;">{{ order.r_cement_min }}</td>
                <td style="padding: 5px;">{{ order._temperature_air_str }}</td>
                <td style="padding: 5px;">{{ delivery._water_cement_contact_t_human }}</td>
                <td style="padding: 5px;">{{ tran(order._r_workability_time_str) }}&nbsp;</td>
            </tr>
        </table>

        <!-- materials -->
        <div class="ml-3 mb-2 materials-table-cutoff d-flex">
            <table class="w-50 mw-50">
            {% for m in materials['Cement'] %}
                <tr>
                    <td>{{ m.name_for_print or m.long_name or m.name or m.type }} ({{ m.weight }} kg)</td>
                </tr>
            {% endfor %}
            {% for m in materials['Admixture'] %}
                <tr>
                    <td>{{ m.name_for_print or m.long_name or m.name or m.type }} ({{ m.weight }} kg)</td>
                </tr>
            {% endfor %}
            </table>
            <b class="pr-1">{{ tran('{CompanySurcharges}:') }}</b>
            <table class="w-50 mw-50" style="table-layout: fixed;">
            {% for surcharge in order._surcharges %}
                <tr>
                    <td class="overflow-hidden text-truncate">{{ surcharge.name }}</td>
                </tr>
            {% endfor %}
            </table>
        </div>

        <!-- Footer table 1 -->
        <table class="w-100 table table-bordered">
          <tr>
              <td style="width:14%;" colspan="2">{{ tran("{datetime_site_arrival}") }}<br>
                  <br>
                  {% if delivery %}{{ delivery._construction_site_arrival_t_human }}{% endif %}<br>
              </td>
              <td style="width:14%;" colspan="2">{{ tran("{datetime_unloading_start}") }}<br>
                  <br>
                  {% if delivery %}{{ delivery._unload_start_t_human }}{% endif %}
              </td>
              <td style="width:14%;" colspan="2">{{ tran("{datetime_unloading_end}") }}<br>
                  <br>
                  {% if delivery %}{{ delivery._unload_end_t_human }}{% endif %}
              </td>
              <td style="width:18%;">{{ tran("{datetime_unloading_duration}") }}<br>
                  <br>
                  {{ unload_time_minutes_str }}
              </td>
              <td style="width:20%;">{{ tran("{waitings_count}") }}</td>
            <td style="width:20%;" rowspan="2">
                <div><b>{{ tran("{customer_consent}") }}</b></div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="border-top-dashed text-center">{{ tran("{signature_hand}") }}</div>
            </td>
          </tr>

          <tr>
              <td colspan="3">{{ tran("{onsite_water}") }}</td>
              <td colspan="3">{{ tran("{onsite_admixtures}") }}</td>
              <td>{{ tran("{returned_m3}") }}</td>
            <td class="p-0">
                <table class="w-100" >
                    <tr>
                        <td colspan="3" style="padding: 2px;" class="text-center">{{ tran("{waitings_count}") }}</td>
                    </tr>
                    <tr>
                        <td style="width: 33%; padding: 2px;">{{ tran("{wait_under_60}") }}</td>
                        <td style="width: 33%; padding: 2px;">{{ tran("{wait_over_60}") }}</td>
                        <td style="width: 33%; padding: 2px;">{{ tran("{wait_free}") }}<br><br><br></td>
                    </tr>
                </table>
            </td>
          </tr>

        </table>

        <!-- Note -->
        <table class="w-100 table table-bordered">
          <tr>
            <td>
                <b>{{ tran("{Note}") }}:</b><br>
                {{ order.comment }}
            </td>
          </tr>
        </table>

        <!-- Footer table 2 -->
        <table class="w-100 table table-bordered">
          <tr>
            <td style="width:30%;">
                <div><b>{{ tran("{issued_by}") }}</b></div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="border-top-dashed text-center">{{ order.audit_changed_by }}</div>
            </td>
            <td style="width:30%;">
                <div><b>{{ tran("{Driver}") }}</b></div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="border-top-dashed text-center">{% if delivery %}{{ delivery.driver_name }}{% endif %}</div>
            </td>
            <td style="width:20%;"><div><b>{{ tran("{others_on_site}") }}</b></div></td>
            <td rowspan="2" style="width:20%;">
                <div><b>{{ tran("{took_over}") }}</b></div>
                <div class="mb-6">&nbsp;</div>
                <div class="mb-6">&nbsp;</div>
                <div class="border-top-dashed text-center">{{ tran("{signature_hand}") }}</div>
                <div class="mb-6">&nbsp;</div>
                <img style="width: 100%" src="{{ url_prefix }}/static/hochtief-qr.png">
            </td>
          </tr>
          <tr>
            <td>
                <div class="printout-mini">
                {% include 'printouts/_cement_warning.html' %}
                </div>
            </td>
            <td class="printout-mini" colspan="2">
                <b>{{ tran("{customer_affirmation}") }}:</b><br>
                <div style="white-space: pre-wrap">{{ setup.customer_consent }}</div>
                <br>
                <b>{{ tran("{certification}") }}:</b>
                <div style="white-space: pre-wrap">{{ setup.certification_text }}</div>
            </td>
          </tr>
        </table>

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

    </div>

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

  </body>
</html>
