{% extends 'index.html' %}
{% block body %}

 
		
			<form class="ui form">
ZD/MM: <input type="text" id="ZD"/>
</form>
<p><button style="margin-top: 20px;" id="zSend" type="button" class="ui primary button buttonzSend">
    <i class="send icon"></i> Filtruj
</button></p>

<div style="margin-top: 5px; margin-bottom: 5px; border-top: 1px solid black;"></div>

<table class="ui celled table" id="dataTable">
    <thead>
    <tr>
        <th style="text-align: center;" colspan="22">
            Deliveries
        </th>
    </tr>
    <tr>
        <th style="text-align: center;">Lp.</th>
        <th style="text-align: center;">SN</th>
        <th style="text-align: center;">LineNo</th>
        <th style="text-align: center;">SKU</th>
        <th style="text-align: center;">QUANTITY</th>
        <th style="text-align: center;">QUALITY</th>
		        <th style="text-align: center;">WMS SN</th>
        <th style="text-align: center;">WMS LineNo</th>
        <th style="text-align: center;">WMS SKU</th>
        <th style="text-align: center;">WMS QUANTITY</th>
        <th style="text-align: center;">WMS QUALITY</th>
		        <th style="text-align: center;">Su Dok_number</th>
		        <th style="text-align: center;">Su Pz_dok_number</th>
        <th style="text-align: center;">Su LineNo</th>
        <th style="text-align: center;">Su SKU</th>
        <th style="text-align: center;">Su QUANTITY</th>

    </tr>
    </thead>
    <tbody>
		{% for d in Send_to_WMS %}
		<tr>
        <td>d</td>
        <td>{{d.SN}}</td>
        <td>{{d.ITEM_LINE_NO}}</td>
        <td>{{d.ITEM_PRODUCT_SKU}}</td>
        <td>{{d.ITEM_PRODUCT_QUANTITY}}</td>
		<td>{{d.ITEM_QUALITY}}</td>

		{% set foo = '1' %}

		{% for dt in WMS %}

        {% if dt.ITEM_LINE_NO == d.ITEM_LINE_NO %}
		{% set foo = '2' %}
		
		<td>{{dt.SN}}</td>
        <td>{{dt.ITEM_LINE_NO}}</td>
        <td>{{dt.ITEM_PRODUCT_SKU}}</td>
        <td>{{dt.ITEM_PRODUCT_QUANTITY}}</td>
		<td>{{dt.ITEM_QUALITY}}</td>
		
		    {% endif %}
		  {%endfor%}
		  {% if foo == '1' %}
		  <td></td>
		  <td></td>
		  <td></td>
		  <td></td>
		  <td></td>
		  {% endif %}

		{% for ds in Subiekt %}
        {% if ds.ob_DokMagLp == d.ITEM_LINE_NO %}  
		        <td>{{ds.dok_NrPelny}}</td>
		        <td>{{ds.dok_NrPelnyPZ}}</td>
        <td>{{ds.ob_DokMagLp}}</td>
        <td>{{ds.tw_Symbol}}</td>
        <td>{{ds.ob_Ilosc|number_format(0, '.', ',')}} </td>
		
		    {% endif %}
		  {%endfor%}
{%endfor%}		  
    </tr>

    </tbody>
</table>
</form>

{%endblock%}
{% block javascript %}
<script>

	 $('#zSend').on('click', function () {
	//$(document).on( 'click', '.buttonzSend', function () {
				var ZD =  $('#ZD').val();
//alert(ZD);
            $.ajax({ type: 'POST', url: 'compare.php?action=index', dataType: 'json', data: {
                ZD: ZD
                 
            }	, success: function(data) {
                //$.sticky('Zmieniono: rekordów.');
				
            }
, error: function(data) {
        //$.sticky('Wysłałem maila err.');
		location.href = 'compare.php?action=index&ZD=' + ZD ;}
		});


       

    } );
    var t = $('#dataTable').DataTable({
        "language": {
            "url": "js/Polish.json"
        },
        "bPaginate": true,
        "bLengthChange": true,
        "bFilter": true,
        "bInfo": true,
        "bAutoWidth": false,
        "columnDefs": [{
            "type": 'polish-string',
            "targets": [1,3,4]
        }],
        "aLengthMenu": [[-1, 10, 50, 100], ["Wszystkie", 10, 50, 100]],
        "order": [[0, 'asc']]
    });

    t.on('order.dt search.dt', function () {
        t.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
            cell.innerHTML = i + 1 + ".";
        });
    }).draw();





    $('select').on('change', function () {

		var ZD =  $('#ZD').val();

        location.href = 'compare.php?action=index&month=' + month + '&year=' + year + '&ZD=' + ZD ;

    } );
	


</script>
{%endblock%}
