{% extends 'admin/print.html' %}
{% load i18n static admin_urls simpelcore_tags simpelsettings_tags simpelauth_tags %}

{% block content_wrapper %}

{% get_settings %}

<div>
  <div class="row mb-3">
    <div  class="col-lg-9 mb-3">
      <div class="row">
        <div class="row-label col-lg-3 fw-bold">{% trans "Status" %}</div>
        <div class="flex-fill">: {{ object.get_status_display }}</div>
      </div>
      <div class="d-flex mb-3">
        <div class="row-label col-lg-3 fw-bold">{% trans "Created at" %}</div>
        <div class="flex-fill">: {{ object.created_at|date:"d M Y" }}</div>
      </div>
      <div class="d-flex">
        <div class="row-label col-lg-3 fw-bold">{% trans "Customer ID" %}</div>
        <div class="flex-fill">: {{ object.customer.inner_id }}</div>
      </div>

      <div class="d-flex mb-3">
        <div class="row-label col-lg-3 fw-bold">{% trans "Customer Name" %}</div>
        <div class="flex-fill">: {{ object.customer.name }}</div>
      </div>

      {% if object.data.sampling_options %}
        <div class="d-flex">
          <div class="row-label col-lg-3 fw-bold">{% trans "Sampling" %}</div>
          <div class="flex-fill">: {% trans "Yes" %} / {{ object.data.sampling_estimation }} {% trans "Days" %}</div>
        </div>
        <div class="d-flex">
          <div class="row-label col-lg-3 fw-bold">{% trans "Scheduled At" %}</div>
          <div class="flex-fill">: {{ object.data.sampling_schedule }}</div>
        </div>
      {% else %}
        <div class="d-flex">
          <div class="row-label col-lg-3 fw-bold">{% trans "Sampling" %}</div>
          <div class="flex-fill">: {% trans "No" %}</div>
        </div>
      {% endif %}
    </div>
    <div class="col-lg-3 mb-3">
      {% with object.qrcode.qrcode.url as qr_url %}
        {% if qr_url %}
          <img class="float-end" width="125" src="{{ site_root }}{{ qr_url }}" alt="">
        {% endif %}
      {% endwith %}
    </div>
    </div>
    <div class="clear"></div>
  </div>
  <div class="row mb-3">
    <div  class="col-lg-6 mb-3">
      <div class="fw-bold">{% trans "Billing Address" %}</div>
      <div>
        {% if object.billing_address %}
          <div>{{ object.billing_address.name|title }}{% if object.billing_address.phone %}, {{ object.billing_address.phone }}{% endif %}</div>
          <div>{{ object.billing_address.text_line_1 }}</div>
          <div>{{ object.billing_address.text_line_2 }}</div>
        {% else %}
          <div>{% trans "Billing address not set." %}</div>
        {% endif %}
      </div>
    </div>
    <div  class="col-lg-6 mb-3">
      <div class="fw-bold">{% trans "Shipping Address" %}</div>
      <div>
        {% if object.shipping_address %}
          <div>{{ object.shipping_address.name|title }}{% if object.shipping_address.phone %}, {{ object.shipping_address.phone }}{% endif %}</div>
          <div>{{ object.shipping_address.text_line_1 }}</div>
          <div>{{ object.shipping_address.text_line_2 }}</div>
        {% else %}
          <div>{% trans "Shipping address not set." %}</div>
        {% endif %}
      </div>
    </div>
    <div class="clear"></div>
  </div>
  {% if object.note %}
  <div class="col-12 mb-3">
    <div class="px-4 border-start border-3">
      <div>{% trans "Note" %}</div>
      <div class="small">{{ object.note }}</div>
    </div>
  </div>
  {% endif %}
  <div class="col-12 order-lg-3 mb-5">
    <table class="table border small">
      <thead>
        <tr>
          <th class="align-middle" width="110">{% trans "#" %}</th>
          <th class="align-middle">{% trans "Item" %}</th>
          <th class="align-middle text-end">{% trans "Price" %}</th>
          <th class="align-middle text-end">{% trans "Quantity" %}</th>
          <th class="align-middle text-end">{% trans "Total" %}</th>
        </tr>
      </thead>
      <tbody>
        {% include 'admin/simpel_sales/order_row.html' %}
        <tr class="thin">
          <td colspan="2" rowspan="5" class="align-top p-3 border-0">
            <strong>Terbilang:</strong>
            <p>{{ object.grand_total|number_to_text|title }}{% if object.grand_total > 0 %} Rupiah{% endif %}</p>
          </td>
          <td colspan="2" class="align-middle"><strong>{% trans "Total" %}</strong></td>
          <td class="align-middle text-end">{{ object.total|currency }}</td>
        </tr>
        <tr class="thin">
          <td colspan="2" class="align-middle"><strong>{% trans "Discount" %}</strong></td>
          <td class="align-middle text-end">{{ object.discount|currency }}</td>
        </tr>
        <tr class="thin">
          <td colspan="2" class="align-middle border-0"><strong>{% trans "Grand Total" %}</strong></td>
          <td class="align-middle text-end border-0">{{ object.grand_total|currency }}</td>
        </tr>
      </tbody>
    </table>
  </div>
  <div class="row">
    <div class="col-lg-6">&nbsp</div>
    <div class="col-lg-6 text-center">
      <div>{% trans "Staff Invoicing" %}</div>
      <div>{{ settings.simpel_core.GeneralSetting.name }}</div>
      <br/><br/><br/><br/>
      <div class="fw-bold">{{ object.user.get_full_name }}</div>
    </div>
    <div class="clear"></div>
  </div>
</div>

<div class="pagebreak-after"></div>

<h2 class="fw-bold">{{ object.opts.verbose_name|title }} {% trans "Item details" %}</h2>
<p class="mb-5">{{ object.inner_id }} - {{ object.created_at }}</p>

{% for item in object.items.all %}
  {% include 'admin/simpel_sales/order_item_print.html' with object=item show_deliverable=True %}
{% endfor %}

{% endblock %}
