{% extends "kfet/base_col_2.html" %}

{% block title %}Commande #{{ order.pk }}{% endblock %}
{% block header-title %}Commande #{{ order.pk }}{% endblock %}

{% block fixed %}

<aside>
  <div class="text">
    <ul class="list-unstyled">
      <li><b>Créée le:</b> {{ order.at }}</li>
      <li>
        <b>Fournisseur:</b>
        <a href="{% url "kfet.order.supplier.update" order.supplier.id %}">
          {{ order.supplier.name }}
        </a>
      </li>
      {% if order.inventory %}
      <li>
        <b>Inventaire relatif:</b>
        <a href="{% url "kfet.inventory.read" order.inventory.pk %}">
          #{{ order.inventory.pk }}
        </a>
      </li>
      {% endif %}
    </ul>
  </div>
</aside>

{% if not order.inventory %}
<div class="buttons">
  <a class="btn btn-primary" href="{% url 'kfet.order.to_inventory' order.pk %}">
    Générer inventaire
  </a>
</div>
{% endif %}

{% endblock %}

{% block main %}

<section>
  <h2>Détails</h2>
  <div class="table-responsive">
    <table
        class="table table-condensed table-hover table-striped sortable"
        {# Initial sort: [(article.name,asc)] #}
        data-sortlist="[[0,0]]">
      <thead>
        <tr>
          <td>Article</td>
          <td>Commandé</td>
          <td>Commandé (#box)</td>
          <td>Reçu</td>
        </tr>
      </thead>
      {% regroup orderarts by article.category as category_list %}
      {% for category in category_list %}
        <tbody class="tablesorter-no-sort">
          <tr class="section">
            <td colspan="4">{{ category.grouper.name }}</td>
          </tr>
        </tbody>
        <tbody>
          {% for orderart in category.list %}
            <tr>
              <td>
                <a href="{% url "kfet.article.read" orderart.article.id %}">
                  {{ orderart.article.name }}
                </a>
              </td>
              <td>{{ orderart.quantity_ordered }}</td>
              <td>
                {% if orderart.article.box_capacity %}
                  {# c'est une division ! #}
                  {% widthratio orderart.quantity_ordered orderart.article.box_capacity 1 %}
                {% endif %}
              </td>
              <td>
                {{ orderart.quantity_received|default_if_none:'' }}
              </td>
            </tr>
          {% endfor %}
        </tbody>
      {% endfor %}
    </table>
  </div>
</section>

<section>
  <h2>Mail</h2>
  <div class="full">
    <textarea class="form-control" style="height:500px;">{{ mail }}</textarea>
  </div>
</section>

{% endblock %}
