{% extends "kfet/base_col_1.html" %}
{% load widget_tweaks %}

{% block title %}Nouvelle commande{% endblock %}
{% block header-title %}Création d'une commande {{ supplier.name }}{% endblock %}

{% block main-size %}col-lg-8 col-lg-offset-2{% endblock %}

{% block main %}

<form action="" method="post">
  {% csrf_token %}
  <div class="table-responsive">
  <table
      class="table table-hover table-condensed table-condensed-input text-center table-striped sortable"
      {# Initial sort: [(name,asc)] #}
      data-sortlist="[[0,0]]">
    <thead>
      <tr>
        <td rowspan="2">Article</td>
        <td colspan="{{ scale|length }}">
          Ventes
          <i class='glyphicon glyphicon-question-sign' title="Ventes des 5 dernières semaines" data-placement="bottom"></i>
        </td>
        <td rowspan="2">
          V. moy.
          <br>
          <i class='glyphicon glyphicon-question-sign' title="Moyenne des ventes" data-placement="bottom"></i>
        </td>
        <td rowspan="2" data-sorter="false">
          E.T.
          <br>
          <i class='glyphicon glyphicon-question-sign' title="Écart-type des ventes" data-placement="bottom"></i>
        </td>
        <td rowspan="2">
          Prév.
          <br>
          <i class='glyphicon glyphicon-question-sign' title="Prévision de ventes" data-placement="bottom"></i>
        </td>
        <td rowspan="2">Stock</td>
        <td rowspan="2" data-sorter="false">
          Box
          <br>
          <i class='glyphicon glyphicon-question-sign' title="Capacité d'une boite" data-placement="bottom"></i>
        </td>
        <td rowspan="2">
          Rec.
          <br>
          <i class='glyphicon glyphicon-question-sign' title="Quantité conseillée" data-placement="bottom"></i>
        </td>
        <td rowspan="2" data-sorter="false" class="small-width">
          Commande
        </td>
      </tr>
      <tr>
        {% for label in scale.get_labels %}
        <td class="sm-padding">{{ label }}</td>
        {% endfor %}
      </tr>
    </thead>
    {% regroup formset by is_sold as is_sold_list %}
	 {% for condition in is_sold_list %}
		<tbody class="tablesorter-no-sort">
        <tr class='section text-center'>
			  <td colspan="{{ scale|length|add:'8' }}">{% if condition.grouper %} Vendu {% else %} Non vendu {% endif %}</td>
        </tr>
      </tbody>
		{% regroup condition.list by category_name as category_list %}
		{% for category in category_list %}
			<tbody class="tablesorter-no-sort">
			<tr class='section text-left'>
				<td colspan="{{ scale|length|add:'8' }}">{{ category.grouper }}</td>
			</tr>
			</tbody>
			<tbody>
			{% for form in category.list %}
				<tr>
					{{ form.article }}
					<td class="text-left">{{ form.name }}</td>
					{% for v_chunk in form.v_all %}
					<td>{{ v_chunk }}</td>
					{% endfor %}
					<td>{{ form.v_moy }}</td>
					<td>{{ form.v_et }}</td>
					<td>{{ form.v_prev }}</td>
					<td>{{ form.stock }}</td>
					<td>{{ form.box_capacity|default:"" }}</td>
					<td>{{ form.c_rec }}</td>
					<td class="nopadding">{{ form.quantity_ordered|add_class:"form-control" }}</td>
				</tr>
			{% endfor %}
			</tbody>
		{% endfor %}
    {% endfor %}
  </table>
  </div>
  {{ formset.management_form }}
  {% if not perms.kfet.add_inventory %}
  <div class='auth-form form-horizontal'>
    {% include "kfet/form_authentication_snippet.html" %}
  </div>
  {% endif %}
  <input type="submit" value="Enregistrer" class="btn btn-primary btn-lg btn-block">
</form>

<script type='text/javascript'>
$(document).ready(function () {
    $('.glyphicon-question-sign').tooltip({'html': true}) ;
});
</script>

{% endblock %}
