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

 

<label>Miesiąc:
    <select class="ui scrolling dropdown" id="month">
        {% for i in 1..12 %}
        <option value="{{i}}" {% if month == i %} selected {% endif %}>{{i}}</option>
        {%endfor%}
    </select></label>
<label>Rok: <select class="ui scrolling dropdown" id="year">
        {% for i in 2000..2025 %}
        <option value="{{i}}" {% if year == i %} selected {% endif %}>{{i}}</option>
        {%endfor%}
    </select></label>

<div style="margin-top: 5px; margin-bottom: 5px; border-top: 1px solid black;"></div>
<form class="ui form">
<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>
		{%endfor%}
		</tr>
		<tr>
		{% for dt in WMS %}
        {% if dt.ITEM_LINE_NO == d.ITEM_LINE_NO %}
		        <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 %}
			{%else%}
			  <td></td>
			  <td></td>
			  <td></td>
			  <td></td>
			  <td></td>
		  {%endfor%}
		{% 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%}		  
    </tr>

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

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

    $(document).on('click', '#bMissing', function () {

        $('#missingModal').modal('show');

    });

	$(document).on('click', '#bCritical', function () {

        $('#criticalModal').modal('show');

    });

	$(document).on('click', '#bErrors', function () {

        $('#errorsModal').modal('show');

    });

    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();



    $('#bSend').on('click', function () {

        var month = $('#month').val();
        var year = $('#year').val();
        var userId = $('#userId').val();

        $.ajax({ type: 'POST', url: 'index.php?action=sendMails', dataType: 'json', data: {
            termin: month + '' + year,
            month: month,
            year: year,
            userId: userId
        }	, success: function(data) {
            $.sticky('Wysłano e-maile.');
            //location.reload();
        } });



        //alert($(this).val());

    } );

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

        var month = $('#month').val();
        var year = $('#year').val();
        var userId = $('#userId').val();

        location.href = 'index.php?action=dra&month=' + month + '&year=' + year + '&userId=' + userId;

    } );



</script>
{%endblock%}
