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

{% block title %}Commandes{% endblock %}
{% block header-title %}Commandes{% endblock %}

{% block fixed %}

<aside>
  <div class="heading">
    {{ orders|length }}
    <span class="sub">commande{{ orders|length|pluralize }}</span>
  </div>
</aside>

{% endblock %}

{% block main %}

<section>
  <h2>Fournisseurs</h2>
  <div class="table-responsive">
    <table class="table table-hover table-condensed">
      <thead>
        <tr>
          <td></td>
          <td>Nom</td>
          <td>Mail</td>
          <td>Tél.</td>
          <td>Adresse</td>
          <td>Commentaire</td>
      <tbody>
        {% for supplier in suppliers %}
        <tr>
          <td class="no-padding">
            <a href="{% url 'kfet.order.new' supplier.pk %}" class="btn btn-default">
              Commander
            </a>
          </td>
          <td>
            <a href="{% url 'kfet.order.supplier.update' supplier.pk %}">
              {{ supplier.name }}
            </a>
          </td>
          <td>{{ supplier.email }}</td>
          <td>{{ supplier.phone }}</td>
          <td>{{ supplier.address }}</td>
          <td>{{ supplier.comment }}</td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</section>

<section>
  <h2>Liste des commandes</h2>
  <div class="table-responsive">
    <table
        class="table table-hover table-condensed sortable"
        {# Initial sort: [(at,desc)] #}
        data-sortlist="[[1,1]]">
      <thead>
        <tr>
          <td data-sorter="false"></td>
          <td data-parser="shortDate">Date</td>
          <td>Fournisseur</td>
          <td>Inventaire</td>
        </tr>
      </thead>
      <tbody>
        {% for order in orders %}
        <tr>
          <td class="no-padding">
            {% if not order.inventory %}
              <a href="{% url 'kfet.order.to_inventory' order.pk %}" class="btn btn-default">
                Générer inventaire
              </a>
            {% endif %}
          </td>
          <td tile="{{ order.at }}">
            <a href="{% url 'kfet.order.read' order.pk %}">
              {{ order.at|date:'d/m/Y H:i' }}
            </a>
          </td>
          <td>{{ order.supplier }}</td>
          <td>
            {% if order.inventory %}
              <a href="{% url 'kfet.inventory.read' order.inventory.pk %}">
                #{{ order.inventory.pk }}
              </a>
            {% endif %}
          </td>
        </tr>
        {% endfor %}
      </tbody>
    </table>
  </div>
</section>

{% endblock %}
