<!-- Load internationalisation utils-->
{% load i18n %}
{% load static %}
{% load rules %}

{% has_perm 'sous_chef.edit' request.user as can_edit_data %}
<table id="generated-orders" class="ui very basic stripped compact celled table">
  <thead>
    <th class="">{% trans 'Order' %}
            <i class="help-text question grey icon link" data-content="{% trans 'A unique identifier for the order.' %}"></i>
    </th>
    <th class="">{% trans 'Client' %}
        <i class="help-text question grey icon link" data-content="{% trans 'Quickly access the client file.' %}"></i>
    </th>
    <th class="">{% trans 'Delivery Date' %}
        <i class="help-text question grey icon link" data-content="{% trans 'The delivery date planned for the order.' %}"></i>
    </th>
    <th class="">{% trans 'Route' %}
        <i class="help-text question grey icon link" data-content="{% trans 'The delivery route.' %}"></i>
    </th>
    <th class="center aligned">{% trans 'Status' %}
        <i class="help-text question grey icon link" data-content="{% trans 'Display only Ordered orders.' %}"></i>
    </th>
    <th class="center aligned">{% trans 'Amount' %}
        <i class="help-text question grey icon link" data-content="{% trans 'Total amount in $CAD.' %}"></i>
    </th>
    <th class=""></th>
  </thead>
  <tbody>
    {% for order in orders %}
      {% if order.status == 'O' %}
      <tr {% if not order.client.is_geolocalized or not order.client.route %}class="error"{% endif %}>
        <td class="center aligned"><strong><i class="hashtag icon"></i>{{order.id}}</strong></td>
        <td><a href="{% url 'member:client_information' pk=order.client.id %}">{{order.client.member}}</a>
        </td>
        <td>{{order.delivery_date}}</td>
        <td>
          {% if order.client.route %}
            {{order.client.route}}
            {% if not order.client.is_geolocalized %}
            <a href="{% url 'member:member_update_address_information' pk=order.client.id %}?next={% url 'delivery:order' %}" title="{% trans 'Please fix geolocalization. Otherwise this client will be excluded in the next steps.' %}"><i class="warning sign red icon"></i></a>
            {% endif %}
          {% else %}
            <a href="{% url 'member:member_update_address_information' pk=order.client.id %}?next={% url 'delivery:order' %}" title="{% trans 'Please fix delivery route. Otherwise this client will be excluded in the next steps.' %}"><i class="warning sign red icon"></i></a>
          {% endif %}
        </td>
        <td class="center aligned">{{order.get_status_display}}</td>
        <td class="center aligned"><i class="dollar icon"></i>{{order.price}}</td>
        <td>
            <a class="ui basic icon button" title="{% trans 'Review or change the status of the order.' %}"  href="{% url 'order:view' pk=order.id %}"><i class="icon unhide"></i></a>
            {% if can_edit_data %}
              <a class="ui basic icon button" title="{% trans 'Change the details of the order.' %}" href="{% url 'order:update' pk=order.id %}"><i class="icon edit"></i></a>
              <a class="ui basic icon order cancel button" title="{% trans 'Cancel the order.' %}" data-url="{% url 'order:update_status' pk=order.id %}"><i class="icon ban"></i></a>
            {% endif %}
        </td>
      </tr>
      {% endif %}
    {% endfor %}
  </tbody>
</table>

{% if can_edit_data %}
  <div class="ui modal status"></div>
{% endif %}
