{% extends "modal_form.html" %}
{% load i18n %}
{% load inventree_extras %}
{% load status_codes %}

{% block form %}

{% trans "Receive outstanding parts for" %} <b>{{ order }}</b> - <i>{{ order.description }}</i>

<form method='post' action='' class='js-modal-form' enctype='multipart/form-data'>
    {% csrf_token %}
    {% load crispy_forms_tags %}

    <label class='control-label'>{% trans "Parts" %}</label>
    <p class='help-block'>{% trans "Select parts to receive against this order" %}</p>

    <table class='table table-striped'>
        <tr>
            <th>{% trans "Part" %}</th>
            <th>{% trans "Order Code" %}</th>
            <th>{% trans "On Order" %}</th>
            <th>{% trans "Received" %}</th>
            <th>{% trans "Receive" %}</th>
            <th>{% trans "Status" %}</th>
            <th></th>
        </tr>
        {% for line in lines %}
        <tr id='line_row_{{ line.id }}'>
            {% if line.part %}
            <td>
                {% include "hover_image.html" with image=line.part.part.image hover=False %}
                {{ line.part.part.full_name }}
            </td>
            <td>{{ line.part.SKU }}</td>
            {% else %}
            <td colspan='2'>{% trans "Error: Referenced part has been removed" %}</td>
            {% endif %}
            <td>{% decimal line.quantity %}</td>
            <td>{% decimal line.received %}</td>
            <td>
                <div class='control-group'>
                    <div class='controls'>
                        <input class='numberinput' type='number' min='0' value='{% decimal line.receive_quantity %}' name='line-{{ line.id }}'/>
                    </div>
                </div>
            </td>
            <td>
                <div class='control-group'>
                    <select class='select' name='status-{{ line.id }}'>
                        {% for code in StockStatus.RECEIVING_CODES %}
                        <option value="{{ code }}" {% if code|add:"0" == line.status_code|add:"0" %}selected="selected"{% endif %}>{% stock_status_text code %}</option>
                        {% endfor %}
                    </select>
                </div>
            </td>
            <td>
                <button class='btn btn-default btn-remove' onClick="removeOrderRowFromOrderWizard()" id='del_item_{{ line.id }}' title='Remove line' type='button'>
                    <span row='line_row_{{ line.id }}' class='fas fa-times-circle icon-red'></span>
                </button>
            </td>
        </tr>
        {% endfor %}
    </table>

    {% crispy form %}
</form>

{% endblock %}