<!--
    TaxDocument printout. Available variables:

        taxdocument ... <class TaxDocument> tax document with linked orders
        setup       ... <class Setup> setup
-->
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>{{ tran("{taxdocument_printout_no}") }} {{ taxdocument._full_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' %}

        {% set currency = taxdocument.currency or setup.currency_symbol %}

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

            <div class="col-4 text-right">
                <h3 class="mb-0">{{ tran("{taxdocument_printout_no}") }} {{ taxdocument._full_number }}</h3>
                <br>
                <b>{{ tran("{datetime_tax}") }}</b><br>
                {{ taxdocument._date_str }}
            </div>

        </div>

        <!-- Customer -->
        <div class="row border mb-2 py-2">
          <div class="col-6">
              <b>{{ tran("{Customer}") }}</b><br>
              {% if taxdocument._customer %}
                {{ taxdocument._customer.name }}<br>
                {{ tran("{company_idnum}") }}: {{ taxdocument._customer.company_idnum }}<br>
                {{ tran("{Vat ID}") }}: {{ taxdocument._customer.vat_idnum }}<br>
              {% endif %}
          </div>
          <div class="col-6">
              <b>{{ tran("{payment_type}") }}</b>: {{ tran(taxdocument._payment_type_name) }}<br>
              {% if taxdocument.note %}
                <b>{{ tran("{note}") }}</b>: {{ taxdocument.note }}
              {% endif %}
          </div>
        </div>

        {% if taxdocument._orders %}
        {% for order in taxdocument._orders %}
          <div class="mt-3 mb-2 border-bottom">
              <b>{{ tran("{belongs_to_order_no}") }} {{ order._full_number }}</b>
              &nbsp;|&nbsp; {{ order._t_human }}
              {% if order.construction_site_name %}
                &nbsp;|&nbsp; {{ tran("{ConstructionSite}") }}: {{ order.construction_site_name }}
              {% endif %}
              {% if order.deliveries %}
                &nbsp;|&nbsp; {{ tran("{Car}") }}: {{ order.deliveries[0].car_registration_number }}
              {% endif %}
          </div>

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

          <!-- Product data -->
          <div class="row mb-2">
            <div class="col-2">
                <h3>{{ order._volume_str }}&nbsp;m³</h3>
            </div>
            <div class="col-6">
                <b>{{ order.recipe_description }}</b>
            </div>
            <div class="col-2">
                <b>{{ order.recipe_name }}</b>
            </div>
            <div class="col-2">
                <b>{{ order.recipe_number }}</b>
            </div>
          </div>

          <!-- prices -->
          <div class="mt-3">
              <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>
                  </tr>
                  <tr>
                      <td style="width:20%;" class="py-1">{{ tran("{price_concrete}").capitalize() }}:</td>
                      <td class="py-1">{{ order._volume_str }}</td>
                      <td class="py-1">m³</td>
                      <td class="py-1 text-right">{{ order._best_price_str }}&nbsp;{{ currency }}</td>
                      <td class="py-1 text-right">{{ order._price_concrete_calculated_str }}&nbsp;{{ currency }}</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;{{ currency }}</td>
                          <td class="py-1 text-right">{{ order._price_transport_str }}&nbsp;{{ currency }}</td>
                      </tr>
                  {% endif %}
                  {% for surcharge in order._surcharges %}
                  <tr>
                      <td class="py-1">{{ tran("{Surcharge}") }} - {{ surcharge.name }}:</td>
                      {% if surcharge.price_type == 0 %}
                          <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;{{ currency }}</td>
                      {% endif %}
                      {% if surcharge.price_type == 1 %}
                          <td class="py-1">{{ order._volume_str }}</td>
                          <td class="py-1">m³</td>
                          <td class="py-1 text-right">{{ surcharge._price_amount_str }}&nbsp;{{ currency }}</td>
                      {% endif %}
                      {% if surcharge.price_type == 2 %}
                          <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;{{ currency }}</td>
                      {% endif %}
                      {% if surcharge.price_type == 3 %}
                          <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;{{ currency }}
                      </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;{{ currency }}</td>
                      <td class="py-1 text-right">{{ order._price_surcharges_correction_str }}&nbsp;{{ currency }}</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;{{ currency }}</td>
                  </tr>
              </table>
          </div>
        {% endfor %}
        {% endif %}

        {% if taxdocument._pump_orders %}
        {% for pump_order in taxdocument._pump_orders %}
          <div class="mt-3 mb-2 border-bottom">
              <b>{{ tran("{taxdocument_belongs_to_pump_order_no}") }} {{ pump_order._full_number }}</b>
              &nbsp;|&nbsp; {{ pump_order._t_human }}
              {% if pump_order.construction_site_name %}
                &nbsp;|&nbsp; {{ tran("{ConstructionSite}") }}: {{ pump_order.construction_site_name }}
              {% endif %}
              {% if pump_order.pump_registration_number %}
                &nbsp;|&nbsp; {{ tran("{Pump}") }}: {{ pump_order.pump_registration_number }}
              {% endif %}
              {% if pump_order.driver_name %}
                &nbsp;|&nbsp; {{ tran("{Driver}") }}: {{ pump_order.driver_name }}
              {% endif %}
          </div>

          <!-- pump prices -->
          <div class="mt-3">
              <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>
                  </tr>
                  {% if pump_order.hours %}
                  <tr>
                      <td style="width:20%;" class="py-1">{{ tran("{hours}") }}:</td>
                      <td class="py-1">{{ pump_order._hours_str }}</td>
                      <td class="py-1">h</td>
                      <td class="py-1 text-right">{{ pump_order._pump_price_per_hour_str }}&nbsp;{{ currency }}</td>
                      <td class="py-1 text-right">{{ pump_order._price_hours_str }}&nbsp;{{ currency }}</td>
                  </tr>
                  {% endif %}
                  {% if pump_order.kms %}
                  <tr>
                      <td style="width:20%;" class="py-1">{{ tran("{kms}") }}:</td>
                      <td class="py-1">{{ pump_order._kms_str }}</td>
                      <td class="py-1">km</td>
                      <td class="py-1 text-right">{{ pump_order._pump_price_per_km_str }}&nbsp;{{ currency }}</td>
                      <td class="py-1 text-right">{{ pump_order._price_kms_str }}&nbsp;{{ currency }}</td>
                  </tr>
                  {% endif %}
                  {% for surcharge in pump_order._surcharges %}
                  <tr>
                      <td class="py-1">{{ tran("{Surcharge}") }} - {{ surcharge.name }}:</td>
                      {% if surcharge.price_type == 0 %}
                          <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;{{ currency }}</td>
                      {% elif surcharge.price_type == 2 %}
                          <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;{{ currency }}</td>
                      {% else %}
                          <td class="py-1">—</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;{{ currency }}
                      </td>
                  </tr>
                  {% endfor %}
                  <tr class="bold">
                      <td colspan="4" style="width:20%;" class="py-1">{{ tran("{total}") }}:</td>
                      <td class="py-1 text-right">{{ pump_order._price_total_str }}&nbsp;{{ currency }}</td>
                  </tr>
              </table>
          </div>
        {% endfor %}
        {% endif %}

        <!-- Document totals -->
        <div class="mt-4">
            <table class="w-100 table table-bordered">
                <tr class="bold">
                    <td style="width:60%;" class="py-1 text-right">{{ tran("{total}") }} ({{ tran("{Without Vat}") if false else tran("{price_total}") }}):</td>
                    <td class="py-1 text-right">{{ taxdocument._price_net_str }}&nbsp;{{ currency }}</td>
                </tr>
                <tr>
                    <td style="width:60%;" class="py-1 text-right">{{ tran("{vat}") }} ({{ taxdocument._vat_rate_str }}%):</td>
                    <td class="py-1 text-right">{{ taxdocument._price_vat_str }}&nbsp;{{ currency }}</td>
                </tr>
                <tr class="bold">
                    <td style="width:60%;" class="py-1 text-right">{{ tran("{grand_total_to_be_paid}") }}:</td>
                    <td class="py-1 text-right">{{ taxdocument._price_grand_total_str }}&nbsp;{{ currency }}</td>
                </tr>
            </table>

            <div class="pl-4">
                {{ tran("{payment_type}") }}: {{ tran(taxdocument._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">{{ taxdocument.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>
