<!--
    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.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 %}
        {% set vat_rate = taxdocument.vat_rate if taxdocument.vat_rate is not none else setup.vat_rate %}

        <!-- 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.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_record %}
                {{ taxdocument._customer_record.name }}<br>
                {{ tran("{company_idnum}") }}: {{ taxdocument._customer_record.company_idnum }}<br>
                {{ tran("{Vat ID}") }}: {{ taxdocument._customer_record.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>

        {% set ns = namespace(net_total=0.0) %}

        {% for order in taxdocument._orders %}
          <div class="mt-3 mb-2 border-bottom">
              <b>{{ tran("{belongs_to_order_no}") }} {{ order.auto_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 }}&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-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 }}</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 }}</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>
          {% set ns.net_total = ns.net_total + (order._price_total_calculated or 0) %}
        {% endfor %}

        <!-- 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}") }} ({{ vat_rate }}%):</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>
