

<div class="row">
    <div class="container">
      <ol class="breadcrumb">
            <li><a href="#">مشاريع خارجيه</a></li>
            <li><a href="executors.php?do=show">  منفذين للمشروع </a></li>
            <li class="active">اضافة  </li>
        </ol>


        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading" style="padding:5px 15px 15px">
                <h3 class="panel-title" style="display: inline-block;"> عرض       </h3>
                <a href="{$youtubes[198]->url}" target="_blank" class="hidden-print"><img src="../views/default/assets/img/youtube.png" class="pull-left" alt="Youtube" style="width: 2%;"></a>
                <a href="executors.php" class="hidden-print"><input type="button"  id="submit" style="margin-left: 12px" class="btn btn-primary pull-left " value="إضافة جديد"/></a>
            </div>
            
            <hr/>
            <div class="panel-body">

                <form class="form-inline hidden-print " action="savedailyController.php?do=show" method="post">
                    <div class="form-group" style="min-width: 170px;">
                        <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" style="min-width: 170px;">
                        <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: 170px;">
                        <label class="sr-only">العملاء</label>
                        <input type="text" class="searchdata wdt100" id="select2client" data-placeholder="اختر " />
                    </div>
                    <div class="form-group" style="min-width: 170px;">
                        <label class="sr-only">المستخدمين</label>
                        <input type="text" class="searchdata wdt100" id="select2user" data-placeholder="اختر " />
                    </div>
                    <div class="form-group" style="min-width: 170px;">
                        <label class="sr-only">المنفذين</label>
                        <input type="text" class="searchdata wdt100" id="select2user2" data-placeholder="اختر " />
                    </div>
                    <div class="form-group" style="min-width: 170px;">
                        <label class="sr-only">الفواتير</label>
                        <input type="text" class="searchdata wdt100" id="select2sellbill" data-placeholder="اختر " />
                    </div>
                </form>

            </div>

            <div class="clearfix"></div>
            <hr/>
            <table class="table table-bordered border-primary" id="getajaxdata">
                <thead>
                    <tr>
                        <th >رقم</th>
                        <th >العميل</th>
                        <th >الموظف</th>
                        <th >الفاتوره</th>
                        <th >تاريخ التنفيذ</th>
                        <th >تاريخ الاضافه</th>
                        <th >المستخدم</th>
                        <th >تعديل</th>
                        <th >حذف</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;
        }


          $("#select2sellbill").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "executors.php?do=select2sellbill",
                type: "post",
                dataType: 'json',
                data: function (term, page) {
                     var select2client = Number($('#select2client').val());
                     if (!select2client) {
                        alert('يجب اختيار عيل اولا');
                        return false;
                     }
                    return {
                        searchTerm: term,
                        clientid: select2client,
                    };
                },
                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);
            }
        });


        $("#select2client").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2client",
                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);
            }
        });

        $("#select2user").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2user",
                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);
            }
        });


        $("#select2user2").select2({
            placeholder: "إسم  المشروع",
            multiple: false,
            quietMillis: 100,
            ajax: {
                url: "tasksController.php?do=select2user",
                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($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2user').val(), $('#select2user2').val(), $('#select2sellbill').val());
        function fetch_data(fromdate = '', todate = '', data1 = '', data2 = '', data3 = '', data4 = '')
        {

            var dataTable = $('#getajaxdata').DataTable({
                "lengthMenu": [[20, 40, 60, 80, 100, -1], [20, 40, 60, 80, 100, "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": 20,
                "ajax": {
                    url: 'executors.php?do=showajax',
                    type: "POST",
                    data: {
                        fromdate: fromdate,
                        todate: todate,
                        data1: data1,
                        data2: data2,
                        data3: data3,
                        data4: data4,
                    }
                },
                "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 = $('#select2client').val();
            var data2 = $('#select2user').val();
            var data3 = $('#select2user2').val();
            var data4 = $('#select2sellbill').val();

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

        });

       


       

      

        $('body').on('click', '.removetask', function () {
            var id = $(this).attr('data-id');
            if (confirm('هل انت متاكد من الحذف ؟')) {
                var thisis = $(this);
                $.post('executors.php?do=del', {id: id}, function (data) {
                    if (data == 1) {
                        thisis.parent().parent().remove();
                    }else{
                       alert('حدث خطأ أثناء التنفيذ');
                    }
                    $('#getajaxdata').DataTable().destroy();
                    fetch_data($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2user').val(), $('#select2user2').val(), $('#select2sellbill').val());
                });
            } else {
                 alert('لماذا ضغطت إلغاء؟ يجب أن تكون قد أكدت');
            }
        });






      

    });







</script>
{/literal}
