{% set userData = app.session.get('userData') %}
<form id="form-purchaseOrderBreakdown" method="POST">
    <h4>{{ page_title }}</h4>
    <div id="flash-messages-content-modal"></div>
    <p class="form-hint-text">Enter basic information below</p>
    <div class="row">
        <div class="large-4 large-text-right columns">
            {{ form_label(form.purchase_order_no) }}
        </div>
        <div class="large-8 columns">
            {{ form_widget(form.purchase_order_no) }}
        </div>
    </div>
    <div class="row">
        <div class="large-4 large-text-right columns">
            {{ form_label(form.payment_method) }}
        </div>
        <div class="large-8 columns">
            {{ form_widget(form.payment_method) }}
        </div>
    </div>
    <table class="display responsive" id="purchaseOrderItem-datalist" width="100%">
        <thead>
        <tr>
            <th>Item</th>
            <th>Required Quantity</th>
            <th>Quantity With PO</th>
            <th>Quantity</th>
        </tr>
        </thead>
        <tbody>
        {% for key,purchaseOrderItem in purchaseOrder.purchaseorderitems %}
            {% set quantity = 0 %}
            {% if action == 'u' and purchaseOrderBreakdown %}
                {% for purchaseOrderBreakdownItem in purchaseOrderBreakdown.purchaseorderbreakdownitems %}
                    {% if purchaseOrderItem == purchaseOrderBreakdownItem.purchaseorderitem %}
                        {% set quantity = purchaseOrderBreakdownItem.quantity %}
                    {% endif %}
                {% endfor %}
            {% endif %}
            <tr>
                <td>{{ purchaseOrderItem.materialrequisitionitem.item.description }}</td>
                <td>{{ purchaseOrderItem.quantity }}</td>
                <td>{{ purchaseOrderItem.quantitywithpo }}</td>
                <td>
                    <input type="hidden" name="purchaseOrderItems[{{ key }}][id]" value="{{ purchaseOrderItem.id }}" />
                    <input type="hidden" name="purchaseOrderItems[{{ key }}][purchaseOrderBreakdownItem_quantity]" value="{{ quantity }}" />
                    <input type="text" class="amount" name="purchaseOrderItems[{{ key }}][quantity]" value="{{ quantity }}" />
                </td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    <br/>
    <div class="row max-width-initial">
        <div class="small-12 columns no-padding-right">
            <div class="button-container clearfix">
                <button type="button" class="button just-continue href-purchaseOrderBreakdown-action float-right" name="action" value="{{ action }}"
                        data-message="Are you sure you want to save this information?"
                >Save</button>
                {% if action == 'u' and (userData.type == 'Super Admin' or 'Admin Purchsae Order Delete' in userData.accesses) %}
                    <button type="button" class="ask-continue button alert href-purchaseOrderBreakdown-action float-right" name="action" value="d"
                            data-message="Are you sure you want to delete this record?"
                    >Delete</button>
                {% endif %}
            </div>
        </div>
    </div>
    {{ form_widget(form.purchaseOrder_id) }}
    {{ form_widget(form.action) }}
    {{ form_widget(form.id) }}
    {{ form_widget(form._token) }}
</form>