{% set userData = app.session.get('userData') %}
<form id="form-canvassItemSupplierSelect" method="POST">
    <h5>Select Supplier(s) for Item: {{ item.description }}</h5>
    <div id="flash-messages-content-modal-large"></div>
    <div class="content-detail-container">
        <div class="row max-width-initial">
            <div class="large-4 columns">
                <div class="page-detail">Item: <span>{{ canvassItem.materialrequisitionitem.item.description }}</span></div>
                <div class="page-detail">Required Qty.: <span>{{ canvassItem.quantity|number_format(0, '.', ',') }}</span></div>
                <div class="page-detail">Voided Qty.: <span>{{ canvassItem.quantityvoided|number_format(0, '.', ',') }}</span></div>
            </div>
            <div class="large-4 columns end">
                <div class="page-detail">Canvassed Qty.: <span>{{ canvassItem.quantitycanvassed|number_format(0, '.', ',') }}</span></div>
                <div class="page-detail">Qty. for Canvassing: <span>{{ canvassItem.quantityforcanvassing|number_format(0, '.', ',') }}</span></div>
            </div>
        </div>
    </div>
    <p class="form-hint-text">Select supplier(s) below</p>
    <input type="hidden" name="canvassItem_id" value="{{ canvassItem.idencoded }}" />
    <table class="display response" id="canvassItemSupplier-datalist-select" width="100%">
        <thead>
        <tr>
            {#<th>&nbsp;</th>#}
            <th>Supplier</th>
            <th>Mobile No.</th>
            <th>Phone No.</th>
            <th>Email</th>
            <th>Currency</th>
            <th>Payment Mode</th>
            <th>Term</th>
            <th>W/Tax Rate</th>
            <th>Price</th>
            <th>Quantity</th>
            {#<th>UOM</th>#}
            <th style="display: none;">Down Payment</th>
            <th>Notes</th>
            {#<th>Last Price</th>
            <th>Last Date</th>#}
            <td>Action</td>
        </tr>
        </thead>
        <tbody>
        {% set pmCod = constant('RxConnexionBundle\\Entity\\CanvassItemSupplierEntity::PAYMENT_MODE_COD') %}
        {% set pmTerm = constant('RxConnexionBundle\\Entity\\CanvassItemSupplierEntity::PAYMENT_MODE_TERM') %}
        {% for key,canvassItemSupplier in canvassItem.canvassitemsuppliers %}
            {% set supplier = canvassItemSupplier.supplier %}
            {#{% set currency = canvassItemSupplier.currency %}#}
            {#{% set wTaxRate = canvassItemSupplier.withholdingTaxRate %}#}
            {#{% set itemLastSupplier = canvassItemSupplier.supplier.itemSupplierLastOrder(canvassItemSupplier.canvassitem.materialrequisitionitem.item.id) %}#}
            <tr>
                {#<td>
                    <input type="checkbox" name="canvassItemSuppliers[{{ key }}][isSelected]" {{ canvassItemSupplier.isselected ? 'checked' : '' }} />
                </td>#}
                <td>{{ supplier.description }}</td>
                <td>{{ supplier.mobileNo }}</td>
                <td>{{ supplier.phoneNo }}</td>
                <td>{{ supplier.email }}</td>
                <td>
                    {#<select name="canvassItemSuppliers[{{ key }}][currency]" style="width: 50px;">#}
                        {#{% for c in currencies %}#}
                            {#<option {{ currency == c ? 'selected' : '' }} value="{{ c.id }}">{{ c.code }}</option>#}
                        {#{% endfor %}#}
                    {#</select>#}
                </td>
                <td>
                    <select name="canvassItemSuppliers[{{ key }}][paymentMode]" style="width: 50px;">
                        <option {{ pmCod == canvassItemSupplier.paymentMode ? 'selected' : '' }} value="{{ pmCod }}">COD</option>
                        <option {{ pmTerm == canvassItemSupplier.paymentMode ? 'selected' : '' }} value="{{ pmTerm }}">Term</option>
                    </select>
                </td>
                <td><input type="text" name="canvassItemSuppliers[{{ key }}][term]" value="{{ canvassItemSupplier.term }}" style="width: 75px;" /></td>
                <td>
                    {#<select name="canvassItemSuppliers[{{ key }}][wTaxRate]" style="width: 75px;">#}
                        {#<option></option>#}
                        {#{% for wtr in wTaxRates %}#}
                            {#<option {{ wTaxRate == wtr ? 'selected' : '' }} value="{{ wtr.id }}">{{ wtr.descriptionAndRate }}</option>#}
                        {#{% endfor %}#}
                    {#</select>#}
                </td>
                <td><input type="text" class="amount" name="canvassItemSuppliers[{{ key }}][price]" value="{{ canvassItemSupplier.price }}" /></td>
                <td>
                    <input type="hidden" name="canvassItemSuppliers[{{ key }}][id]" value="{{ canvassItemSupplier.id }}" />
                    <input type="text" class="large-8 columns" name="canvassItemSuppliers[{{ key }}][quantity]" value="{{ canvassItemSupplier.quantity|number_format(0, '.', ',') }}" style="width: 75px;" />
                    {#<label style="padding:5px; ">{{ canvassItemSupplier.canvassitem.materialrequisitionitem.item.receivingunitmeasurement }}</label></input>#}
                </td>
                {#<td>
                    <select name="canvassItemSuppliers[{{ key }}][unitOfMeasurement]" class="large-8 columns" style="padding:0px!important;margin-bottom:0px!important;">
                        {% for itemunitmeasurement in canvassItem.materialrequisitionitem.item.itemunitmeasurements %}
                            <option value="{{ itemunitmeasurement.id }}" {% if itemunitmeasurement.id == canvassItemSupplier.canvassitem.itemunitmeasurement.id %}{{ 'selected' }}{% endif %}>{{ itemunitmeasurement.description }}</option>
                        {% endfor %}
                    </select>
                </td>#}
                <td style="display: none;"><input type="text" class="amount" name="canvassItemSuppliers[{{ key }}][downPayment]" value="{{ canvassItemSupplier.downpayment }}" /></td>
                <td>{{ canvassItemSupplier.note }}</td>
                {#<td>{{ itemLastSupplier ? itemLastSupplier.price : '' }}</td>
                <td>{{ itemLastSupplier ? itemLastSupplier.date : '' }}</td>#}
                <td><a href="javascript:void(0)" class="href-canvassItemSupplier-remove" data-id="{{ canvassItemSupplier.idencoded }}" data-ref-id="{{ canvassItemSupplier.canvassitem.idencoded }}">Remove</a></td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    {% if canvassItem.canvassitemsuppliers|length > 0 %}
        <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 no-margin-right no-margin-bottom href-canvassItemSupplierSelect-action float-right"
                            data-message="Are you sure you want to save this information?"
                    >Save</button>
                </div>
            </div>
        </div>
    {% endif %}
</form>
<br/>
<p class="form-hint-text">Supplier History</p>
<table class="display responsive" id="supplierFormSelect-history-datalist" width="100%">
    <thead>
    <tr>
        <th>Supplier Name</th>
        <th>Mobile No.</th>
        <th>Phone No.</th>
        <th>Email</th>
        <th>Canvassed Date</th>
        <th class="text-right">Price</th>
    </tr>
    </thead>
    <tbody>
    {% for sh in supplierHistories %}
        <tr>
            <td>{{ sh.supplierDesc }}</td>
            <td>{{ sh.supplierMobileNo }}</td>
            <td>{{ sh.supplierPhoneNo }}</td>
            <td>{{ sh.supplierEmail }}</td>
            <td>{{ sh.canvassDate }}</td>
            <td class="text-right">{{ sh.price|number_format(2, '.', ',') }}</td>
        </tr>
    {% endfor %}
    </tbody>
</table>