

<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">المخازن</a></li>
            <li><a href="mechandiseReturnRequest.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="mechandiseReturnRequest.php" class="hidden-print"><input type="button"  id="submit" style="margin-left: 12px" class="btn btn-primary pull-left " value="إضافة جديد"/></a>
            </div>
            
            <hr/>
            <form class="form-inline hidden-print" id="searchdata"  method="post" action="mechandiseReturnRequest.php?do=show">
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" autocomplete="off"  
                         data-date-format="yyyy-mm-dd"  id="start_date" name="start_date" value="{$date}">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker searchdata" autocomplete="off"   
                        data-date-format="yyyy-mm-dd"  id="end_date" name="end_date" value="{$date}">
                    </div>
                     <div class="form-group"  >
                        <label class="sr-only">العملاء</label>
                        <div style="width: 250px;">
                            <input type="text" name="clientid" class="wdt100 searchdata" 
                            id="select2client" data-placeholder="اختر " />
                        </div> 
                    </div>
                    <div class="form-group"  >
                        <label class="sr-only">المنتجات</label>
                        <div style="width: 250px;">
                            <input type="text" name="productid" class=" wdt100 select2product searchdata" 
                            id="select2product1" data-placeholder="اختر " />
                        </div> 
                    </div>
                    <div class="form-group">
                        <div class="radio-inline">
                            <label> <input value="0" class="searchdata"  name="damagedintact"   type="radio" checked="checked"  />
                                تالف </label>
                        </div>
                        <div class="radio-inline">
                            <label> <input value="1" class="searchdata"  name="damagedintact"   type="radio"  />
                                سليم   </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="sr-only">المحذوف</label>
                        <div style="text-align: center;">
                          <input type="checkbox" class="form-control searchdata" name="conditions" id="conditions"  value="1" style="    width: 23px;">  
                        </div>
                    </div>

                    
                        
                 
                </form>
            <hr/>
            <table class="table table-black" id="getajaxdata" 
            data-controll="mechandiseReturnRequest.php?do=showajax">
                <thead>
                    <tr>
                        <th style="width:50px;">م</th>
                        <th>العميل</th>
                        <th>تالف او سليم   </th>
                        <th>المنتجات</th>
                      
                        <th>الحاله</th>
                        <th>التاريخ</th>
                        <th>المستخدم</th>
                        <th class="noprint">تعديل</th>
                        <th class="noprint">حذف</th>
                    </tr>
                </thead>
                <tbody>

                </tbody>
            </table>
            <div class="clearfix"></div>
        </div>
    </div>
</div>

{literal}
<script type="text/javascript">
$(document).ready(function () {
        var formatResult;
        formatResult = function (data) {return  data.text;}
        fetch_data();
function fetch_data()
{

    var myformData = new FormData($('form#searchdata')[0]);
    var showajaxlink = $("#getajaxdata").attr('data-controll');
    var dataTable = $('#getajaxdata').DataTable({
        "processing": true,
        "serverSide": true,
        "lengthMenu" : [[100, 200, 300, 400, 500, -1],[100, 200, 300, 400, 500, "All"] ],
            dom: 'Bfrtip',
            buttons: [
                {
                    extend: 'copyHtml5',
                    exportOptions: {
                         columns: [ 1, 2, 3, 4, 5, 6 , 7 ]
                    }
                },
                {
                    extend: 'csvHtml5',
                    exportOptions: {
                         columns: [ 1, 2, 3, 4, 5, 6 , 7 ]
                    }
                },
                {
                    extend: 'print',
                    exportOptions: {
                         columns: [ 1, 2, 3, 4, 5, 6 , 7 ]
                    }
                },
                {
                    extend: 'excelHtml5',
                    exportOptions: {
                         columns: [ 1, 2, 3, 4, 5, 6 , 7 ]
                    }
                },
                {
                    extend: 'pdfHtml5',
                    exportOptions: {
                        columns: [ 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": [[0, "desc"]],
        "displayLength": 100,
        "columnDefs": [
            {"className": "dt-center", "targets": "_all"}
          ],
        "ajax" : {url: showajaxlink,
            type: 'POST',
            data: function(data){
                myformData.append('ordercol', data.order[0].column);
                myformData.append('orderdir', data.order[0].dir);
                myformData.append('searchval', data.search.value);
                return Object.fromEntries(myformData);
            }    
        }
    });
    $('.group-checkable', "#getajaxdata").change(function () {
        var set = $("#getajaxdata").find('tbody > tr > td:nth-child(1) input[type="checkbox"]');
        var checked = $(this).prop("checked");
        $(set).each(function () {
            $(this).prop("checked", checked);
        });
    });
}

$('body').on('change', '.searchdata', function () {
    $('#getajaxdata').DataTable().destroy();
    fetch_data();
});



$('body').on('click', '.csearchdata', function () {
    $('#getajaxdata').DataTable().destroy();
    fetch_data();
});

            $('body').on('click', '.addappend', function () {
                var itr = Number($("#productsitr").val()) + 1;
                $("#productsitr").val(itr);
              $.post('mechandiseReturnRequest.php?do=appendproduct', {itr: itr}, function (result) {
                $("#products").append(result);
                products(itr);
                

              });
            });

            $('body').on('change', '.agrees', function () {
                var agrees = $(this).val();
                var id = Number($(this).attr('data-id'));
              $.post('mechandiseReturnRequest.php?do=agrees', {agrees: agrees, id: id}, function (result) {
                if(agrees != 2){
                    window.location = 'mechandiseReturnRequest.php?do=edit&id='+id;
                }
              });
            });

            $('body').on('click', '.removeappend', function () {
                var id = Number($(this).attr('data-id'));
                var edit = Number($(this).attr('data-edit'));
                if(edit == 1){
                    $.post('mechandiseReturnRequest.php?do=removeappend', {id: id}, function (result) {
                        $("#products"+id).remove();
                    });
                }else{
                    $("#products"+edit+id).remove();

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


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




    
});  
</script>
{/literal}

