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

{# This div will be replaced by new content when the user clics on "Generate orders". #}
<div id="generated-orders">

{% has_perm 'sous_chef.edit' request.user as can_edit_data %}
{% if has_ordered_orders %}
<table id="generated-orders-table" class="ui very basic stripped compact celled table">
  {% include 'partials/generated_orders_table_head.html' %}
  <tbody>
    {# Display orders in error at top #}
    {% for order in orders %}
      {% if order.status == 'O' and order.is_in_error_for_the_kitchen_count %}
      <tr class="error">
        {% include 'partials/generated_orders_order_row_content.html' %}
      </tr>
      {% endif %}
    {% endfor %}

    {# Then display orders not in error #}
    {% for order in orders %}
      {% if order.status == 'O' and not order.is_in_error_for_the_kitchen_count %}
      <tr>
        {% include 'partials/generated_orders_order_row_content.html' %}
      </tr>
      {% endif %}
    {% endfor %}
  </tbody>
</table>
{% endif %}

{% if has_cancelled_orders %}
<h2 class="ui header">{% trans "Cancelled Orders" %}</h2>
<p>{% trans 'These clients will not receive a meal today, but their order can be enabled if needed (by viewing the order and setting the status to "Ordered").' %}</p>

<table class="ui very basic stripped compact celled table">
  {% include 'partials/generated_orders_table_head.html' %}
  <tbody>
    {% for order in orders %}
    {% if order.status == 'C' %}
      <tr class="warning">
        <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>
          {% if order.client_planned_status_at_delivery != 'A' %}
          ({{ order.client_planned_status_at_delivery_verbose }})
          {% endif %}
        </td>
        <td>{{order.delivery_date}}</td>
        <td>{{order.client.route}}</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>
        </td>
      </tr>
    {% endif %}
    {% endfor %}
  </tbody>
</table>
{% endif %}

{% if not has_ordered_orders and not has_cancelled_orders %}
<p>{% trans 'No orders found.' %}</p>
{% endif %}

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

</div>
