

<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">التقارير</a></li>
            <li><a href="savedailyController.php?do=show">تقرير  المخزون</a></li>
            <li class="active">عرض التقرير</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير  المخزون
                <a href="{$youtubes[162]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
            </div>
            <div class="panel-body">

                <form class="form-inline hidden-print " action="savedailyController.php?do=show" method="post">


                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" id="fromdate"   data-date-format="yyyy-mm-dd"  >
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata"  id="todate"   data-date-format="yyyy-mm-dd"  >
                    </div>
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">التصنيفات</label>
                        <input type="text" class="searchdata wdt100" id="select2categories" data-placeholder="اختر " />

                    </div>
                    <div class="form-group" style="min-width: 219px;">
                        <label class="sr-only">المنتجات</label>
                        <input type="text" class="searchdata wdt100" id="select2products" data-placeholder="اختر " />
                    </div>
                </form>

            </div>

            <div class="clearfix"></div>
            <hr/>
            <table class="table table-bordered border-primary" id="getajaxdata">
                <thead>
                    <tr>
				      	<th scope="col">تاريخ الشراء</th>
                        <th scope="col">المنتج</th>
                        <th scope="col">السيريل</th>
                        <th scope="col">العدد</th>
                        <th scope="col">الشاسيه</th>
                        <th scope="col">الموتور</th>
                        <th scope="col">اللون</th>
                        <th scope="col">سعر الشراء</th>
                        <th scope="col">الضريبه</th>
                        <th scope="col">شامل الضريبه</th>
                        <th scope="col"> حذف  </th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>

        </div>
    </div>
</div>
{literal}
<script type="text/javascript">


    $(document).ready(function () {
        var formatResult;
        formatResult = function (data) {
            return  data.text;
        }


        $("#select2products").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "stockReportsController.php?do=select2products",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                        categoryid: $('#select2categories').val(),
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });

        $("#select2categories").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "stockReportsController.php?do=select2categories",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                    return {
                        searchTerm: term,
                    };
                },
                results: function (data) {
                    return {results: data};
                }
            },
            formatResult: formatResult,
            initSelection: function (element, callback) {
                var item = element.val().split(':');
                var data = {id: item[0], text: item[1]};
                callback(data);
            }
        });




        fetch_data();
        function fetch_data(fromdate = '', todate = '', data1 = '', data2 = '')
        {

            var dataTable = $('#getajaxdata').DataTable({
                "lengthMenu": [[200, 400, 600, 800, 1000, -1], [200, 400, 600, 800, 1000, "All"]],
                dom: 'Bfrtip',
                buttons: [
                    {
                        extend: 'copyHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'csvHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'print',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'excelHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    {
                        extend: 'pdfHtml5',
                        exportOptions: {
                            columns: [0, 1, 2, 3, 4, 5, 6, 7]
                        }
                    },
                    'colvis'
                ],
                "dom": "<'row' <'col-md-12'B>><'row'<'col-md-6 col-sm-12'l><'col-md-6 col-sm-12'f>r><'table-scrollable't><'row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>>",
                "order": [[7, "asc"]],
                "displayLength": 200,
                "ajax": {
                    url: 'stockReportsController.php?do=showajax',
                    type: "POST",
                    data: {
                        fromdate: fromdate,
                        todate: todate,
                        data1: data1,
                        data2: data2,
                    }
                },
                "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                    if (aData[1] == "الكميه")
                    {
                        $('td', nRow).css('background-color', '#c4f378');
                    }
                },

            });

        }


        $('.searchdata').change(function () {
            var fromdate = $('#fromdate').val();
            var todate = $('#todate').val();
            var data1 = $('#select2categories').val();
            var data2 = $('#select2products').val();


            $('#getajaxdata').DataTable().destroy();
            fetch_data(fromdate, todate, data1, data2);

        });


        $(document).on('click', '.productserailid', function () {
            var productserailid = Number($(this).attr('data-id'));
            if (confirm('هل أنت متأكد من الحذف ؟ ')) {
                $.post('stockReportsController.php?do=deleteproductserial', {productserailid: productserailid}, function (reslut) {
                    if (reslut == 1) {
                        $('#select2products').trigger("change");

                    }

                });
            }
        });


    });







</script>
{/literal}
