<!--
    Invoice printout. Available variables:

        order       ... <class Order> order
        setup       ... <class Setup> setup
-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ tran("{invoice_printout_no}") }} {{ order.invoice_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-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 class="mb-0">{{ tran("{invoice_printout_no}") }} {{ order.invoice_number }}</h3>
                {{ tran("{invoice_belongs_to_ds}") }} {{ order.auto_number }}<br>
                <br>
                <b>{{ tran("{datetime_tax}") }}</b><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>
          <div class="col-4">
              <b>{{ tran("{Car}") }}</b><br>
              {% if order.deliveries %}
                {{ order.deliveries[0].car_registration_number }}
                {% if order.deliveries[0].car_car_type %}
                    ({{ order.deliveries[0].car_car_type }})
                {% endif %}
              {% endif %}
          </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-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>

        <!-- prices -->
        <div class="mt-4">
            <table class="w-100 table table-bordered">
                <tr class="bold">
                    <td class="py-1">{{ tran("{item}") }}</td>
                    <td class="py-1">{{ tran("{amount}") }}</td>
                    <td class="py-1">{{ tran("{unit}") }}</td>
                    <td class="py-1 text-right">{{ tran("{price_per_unit}") }}</td>
                    <td class="py-1 text-right">{{ tran("{price_total}") }}</td>
                    <td class="py-1">{{ tran("{vat_rate}") }}</td>
                    <td class="py-1 text-right">{{ tran("{vat}") }}</td>
                    <td class="py-1 text-right">{{ tran("{price_with_vat}") }}</td>
                </tr>
                <tr>
                    <td style="width:20%;" class="py-1">{{ tran("{price_concrete}").capitalize() }}:</td>
                    <td class="py-1">{{ order.volume }}</td>
                    <td class="py-1">m³</td>
                    <td class="py-1 text-right">{{ order._best_price_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ order._price_concrete_calculated_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1">{{ setup.vat_rate }}%</td>
                    <td class="py-1 text-right">{{ order._price_concrete_calculated_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ order._price_concrete_calculated_with_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
                {% if order._price_transport and (order._price_transport > 0) %}
                    <tr>
                        <td style="width:20%;" class="py-1">{{ tran("{transport}") }}:</td>
                        <td class="py-1">1</td>
                        <td class="py-1">x</td>
                        <td class="py-1 text-right">{{ order._price_transport_str }}&nbsp;{{ setup.currency_symbol }}</td>
                        <td class="py-1 text-right">{{ order._price_transport_str }}&nbsp;{{ setup.currency_symbol }}</td>
                        <td class="py-1">{{ setup.vat_rate }}%</td>
                        <td class="py-1 text-right">{{ order._price_transport_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                        <td class="py-1 text-right">{{ order._price_transport_with_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    </tr>
                {% endif %}
                {% for surcharge in order._surcharges %}
                <tr>
                    <td class="py-1">{{ tran("{Surcharge}") }} - {{ surcharge.name }}:</td>
                    {% if surcharge.price_type == 0 %} <!-- fixed price -->
                        <td class="py-1">1</td>
                        <td class="py-1">x</td>
                        <td class="py-1 text-right">{{ surcharge._price_total_calculated_amount_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    {% endif %}
                    {% if surcharge.price_type == 1 %} <!-- per m3 -->
                        <td class="py-1">{{ order.volume }}</td>
                        <td class="py-1">m³</td>
                        <td class="py-1 text-right">{{ surcharge._price_amount_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    {% endif %}
                    {% if surcharge.price_type == 2 %} <!-- per other unit -->
                        <td class="py-1">{{ surcharge.amount }}</td>
                        <td class="py-1">{{ surcharge.unit_name }}</td>
                        <td class="py-1 text-right">{{ surcharge._price_amount_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    {% endif %}
                    {% if surcharge.price_type == 3 %} <!-- percentage of concrete price -->
                        <td class="py-1">{{ surcharge.percentage }}</td>
                        <td class="py-1">%</td>
                        <td class="py-1"></td>
                    {% endif %}
                    <td class="py-1 text-right">
                        {{ surcharge._price_total_calculated_amount_str }}&nbsp;{{ setup.currency_symbol }}
                    </td>
                    <td class="py-1">{{ setup.vat_rate }}%</td>
                    <td class="py-1 text-right">{{ surcharge._price_total_calculated_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ surcharge._price_total_calculated_with_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
                {% endfor %}
                {% if order._price_surcharges_correction %}
                <tr>
                    <td style="width:20%;" class="py-1">{{ tran("{price_surcharges_correction}") }}:</td>
                    <td class="py-1">1</td>
                    <td class="py-1">x</td>
                    <td class="py-1 text-right">{{ order._price_surcharges_correction_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ order._price_surcharges_correction_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1">{{ setup.vat_rate }}%</td>
                    <td class="py-1 text-right">{{ order._price_surcharges_correction_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ order._price_surcharges_correction_with_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
                {% endif %}
                <tr class="bold">
                    <td colspan="4" style="width:20%;" class="py-1">{{ tran("{total}") }}:</td>
                    <td class="py-1 text-right">{{ order._price_total_calculated_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1">{{ setup.vat_rate }}%</td>
                    <td class="py-1 text-right">{{ order._price_total_calculated_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                    <td class="py-1 text-right">{{ order._price_total_calculated_with_vat_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
                <tr class="italic">
                    <td colspan="7" style="width:20%;" class="py-1">{{ tran("{rounding}") }}:</td>
                    <td class="py-1 text-right">{{ order._rounding_calculated_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
                <tr class="bold">
                    <td colspan="7" style="width:20%;" class="py-1">{{ tran("{grand_total_to_be_paid}") }}:</td>
                    <td class="py-1 text-right">{{ order._price_grand_total_calculated_str }}&nbsp;{{ setup.currency_symbol }}</td>
                </tr>
            </table>

            <div class="pl-4">
                {{ tran("{payment_type}") }}: {{ tran(order._payment_type_name) }}
            </div>
        </div>

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

        <!-- Footer table 2 -->
        <table class="w-100 table table-bordered">
          <tr>
            <td style="width:50%;">
                <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:50%;">
                <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>
            </td>
          </tr>
        </table>

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

    </div>

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

  </body>
</html>
