<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ title }}</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 -->

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

            <div class="col-6">
              <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-6 text-right">
                <h3>{{ title }}</h3>
                <div class="italic">{{ note }}</div>
            </div>

        </div>

        <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">
          </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_str }}</td>
                  </tr>
                  <tr>
                      <td class="text-right"><b>{{ tran("{ConstructionSite}") }}:</b></td>
                      <td class="px-2">{{ site }}</td>
                  </tr>
              </table>
          </div>
        </div>

        <!-- data -->
        <table class="mb-4 table">
            <thead class="bold">
              <tr>
                <td>{{ tran("{Customer}") }}</td>
                <td>{{ tran("{ConstructionSite}") }}</td>
                <td>{{ tran("{Recipe}") }}</td>
                <td>{{ tran("{invoice_printout_no}") }}</td>
                <td>{{ tran("{DeliverySheet}") }}</td>
                <td>{{ tran("{t_human}") }}</td>
                <td>{{ tran("{payment_type}") }}</td>
                <td>{{ tran("{volume}") }}</td>
                <td>{{ tran("{price_per_unit}") }}</td>
                <td class="text-right">{{ tran("{price_concrete}") }}</td>
                <td class="text-right">{{ tran("{price_shipping}") }}</td>
                <td class="text-right">{{ tran("{price_services}") }}</td>
                {% if show_pumps %}<td class="text-right">{{ tran("{price_pumps}") }}</td>{% endif %}
                <td class="text-right">{{ tran("{price_sum}") }}</td>
              </tr>
            </thead>
            {% for customer_name, customer in customers.items() %}
              {% set customer_str = customer.str or "---" %}

                {% for site_name, concretes in customer["items"].items() %}
                  {% set site_str = site_name or "---" %}

                    {% for concrete_name, orders in concretes["items"].items() %}

                        {% for order in orders["items"] %}
                        <tr>
                            <td>{{ customer_str }}</td>
                            <td>{{ site_str }}</td>
                            <td>{{ concrete_name }}</td>
                            <td>{{ order.invoice_number or "---" }}</td>
                            <td>{{ order.auto_number }}</td>
                            <td>{{ order._t_human }}</td>
                            <td>{{ tran(order._payment_type_name) }}</td>
                            <td>{{ order._volume_str }}&nbsp;m³</td>
                            <td class="text-right newlines">{{ tran(order._unit_price) }}</td>
                            <td class="text-right">{{ order._price_concrete_calculated }}</td>
                            <td class="text-right">{{ order._price_transport }}</td>
                            <td class="text-right newlines">{{ order._price_surcharges }}{{ order._surcharge_names }}</td>
                            {% if show_pumps %}<td class="text-right">{{ order._price_pumps }}</td>{% endif %}
                            <td class="text-right">{{ order._price_total_calculated }}</td>
                        </tr>
                        {% endfor %} <!-- orders -->
                        <tr class="bold">
                            <td></td>
                            <td></td>
                            <td colspan="4">{{ tran("{total}") }} {{ concrete_name }}</td>
                            <td></td>
                            <td>{{ orders["sum"]["volume"] }}&nbsp;m³</td>
                            <td></td>
                            <td class="text-right">{{ orders["sum"]["price_concrete"] }}</td>
                            <td class="text-right">{{ orders["sum"]["price_transport"] }}</td>
                            <td class="text-right">{{ orders["sum"]["price_surcharges"] }}</td>
                            {% if show_pumps %}<td class="text-right">{{ orders["sum"]["price_pumps"] }}</td>{%  endif %}
                            <td class="text-right">{{ orders["sum"]["price"] }}</td>
                        </tr>
                    {% endfor %} <!-- sites -->
                    <tr class="bold">
                        <td></td>
                        <td colspan="5">{{ tran("{total}") }} {{ site_str }}</td>
                        <td></td>
                        <td>{{ concretes["sum"]["volume"] }}&nbsp;m³</td>
                        <td></td>
                        <td class="text-right">{{ concretes["sum"]["price_concrete"] }}</td>
                        <td class="text-right">{{ concretes["sum"]["price_transport"] }}</td>
                        <td class="text-right">{{ concretes["sum"]["price_surcharges"] }}</td>
                        {% if show_pumps %}<td class="text-right">{{ concretes["sum"]["price_pumps"] }}</td>{%  endif %}
                        <td class="text-right">{{ concretes["sum"]["price"] }}</td>
                    </tr>
                {% endfor %} <!-- customers -->
                    <tr class="bold">
                        <td colspan="6">{{ tran("{total}") }} {{ customer_str }}</td>
                        <td></td>
                        <td>{{ customer["sum"]["volume"] }}&nbsp;m³</td>
                        <td></td>
                        <td class="text-right">{{ customer["sum"]["price_concrete"] }}</td>
                        <td class="text-right">{{ customer["sum"]["price_transport"] }}</td>
                        <td class="text-right">{{ customer["sum"]["price_surcharges"] }}</td>
                        {% if show_pumps %}<td class="text-right">{{ customer["sum"]["price_pumps"] }}</td>{%  endif %}
                        <td class="text-right">{{ customer["sum"]["price"] }}</td>
                    </tr>
            {% endfor %}
                <tr>
                    <td colspan="99"></td>
                </tr>
                <tr class="bold bg-light italic">
                    <td colspan="7">{{ tran("{total}") }}</td>
                    <td>{{ totals["volume"] }}&nbsp;m³</td>
                    <td></td>
                    <td class="text-right">{{ totals["price_concrete"] }}</td>
                    <td class="text-right">{{ totals["price_transport"] }}</td>
                    <td class="text-right">{{ totals["price_surcharges"] }}</td>
                    {% if show_pumps %}<td class="text-right">{{ totals["price_pumps"] }}</td>{%  endif %}
                    <td class="text-right">{{ totals["price"] }}</td>
                </tr>
                <tr>
                    <td colspan="99"></td>
                </tr>
                <tr class="bold bg-light italic">
                    <td>{{ tran("{vat}") }} {{ setup.vat_rate }}%</td>
                    <td colspan="99" class="text-right">{{ supertotal_vat }}</td>
                </tr>
                <tr class="bold bg-light italic">
                    <td>{{ tran("{price_with_vat}") }}</td>
                    <td colspan="99" class="text-right">{{ supertotal_with_vat }}</td>
                </tr>
        </table>

      <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>
