

<div class="row">
    <div class="container">
      <ol class="breadcrumb">
            <li><a href="#">مشاريع خارجيه</a></li>
            <li><a href="executorsreport.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>
            </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="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>
                        <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);
            }
        });

       


        

         fetch_data($('#fromdate').val(), $('#todate').val(), $('#select2client').val(), $('#select2sellbill').val());
        function fetch_data(fromdate = '', todate = '', data1 = '', data2 = '')
        {

            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: 'executorsreport.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 = $('#select2client').val();
            var data2 = $('#select2sellbill').val();

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

        });

       






      

    });







</script>
{/literal}
