<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="#">الموردين</a></li>
            <li class="active">تقرير دفعات</li>
        </ol>
        <div class="panel panel-default panel-m">
            <!-- Default panel contents -->
            <div class="panel-heading">تقرير دفعات
                {if $message != ""}
                {$message}
                {/if}
                <a href="{$youtubes[123]->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="supplierReportsController.php" method="post">
                    <input type="hidden" id="todaydDateOnly" value="{$todaydDateOnly}" />
                    <div class="form-group">
                        <label class="sr-only">اختر مورد</label>
                        <select data-placeholder="اختر مورد" class="select2 wdt300 search_ajax" name="supplierId"
                            id="supplierId">
                            <option value="-1"> اختر مورد</option>
                            <option value="-2"> كل الموردين</option>
                            {foreach $supplierData as $supplier}
                            <option value="{$supplier->supplierid}">{$supplier->suppliername}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">اختر خزنة</label>
                        <select data-placeholder="اختر خزنة" class="select2 wdt300 search_ajax" name="saveId"
                            id="saveId">
                            <option value="-1"> اختر خزنة</option>
                            {foreach $saveData as $save}
                            <option value="{$save->saveid}">{$save->savename}</option>
                            {/foreach}
                        </select>
                    </div>


                    <div class="form-group" {if $Programsettingdata->costcenter neq 0 &&
                        $Programsettingdata->realestatedev neq 0 } style="display:none" {/if}>
                        <label class="sr-only">مركز التكلفه</label>
                        <select class="select2 wdt100" name="Costcenterid" id="Costcenterid">
                            <option value="-1">اختر مركز التكلفه</option>
                            {foreach $allCostcenter as $myallCostcenter}
                            <option value="{$myallCostcenter->id}" {if $myallCostcenter->id eq
                                $projectid}selected=""{/if}>{$myallCostcenter->name}</option>
                            {/foreach}
                        </select>
                    </div>

                    <div class="form-group">
                        <label class="sr-only">الرقم التسلسلى </label>
                        <input type="hidden" name="paySerialNo" id="paySerialNu" class="search_ajax select2-offscreen"
                            tabindex="-1">
                    </div>
                    <br />
                    <div class="form-group">
                        <label class="sr-only">من التاريخ</label>
                        <input type="text" class="form-control awdatepicker search_ajax" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="from" id="datepicker_from">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">إلى التاريخ</label>
                        <input type="text" class="form-control awdatepicker search_ajax" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="to" id="datepicker_to"><!--  onChange="getResult();"-->
                    </div>

                    <button type="button" class="btn btn-primary  hidden-print" id="todayPayments">دفعات اليوم</button>
                    <button type="button" class="btn btn-primary  hidden-print" id="refreshResultsBtn">بحث / تحديث
                        النتائج</button>
                </form>
            </div>
            <div>
                <!-- Nav tabs -->
                <ul class="nav nav-tabs">
                    <li class="active"><a href="#cashTab" data-toggle="tab">النقدى</a></li>
                    <li><a href="#chequesTab" data-toggle="tab">المسحوبات</a></li>
                </ul>
                <div class="tab-content">
                    <div class="tab-pane active" id="cashTab"><!-- start the 1st tab -->
                        <div class="col-lg-offset-8 col-lg-4">
                            <div class="well well-sm">
                                <h4 class="text-center">الإجمالي: <span class="sumRecit">{$sum}</span> {$currency}</h4>
                            </div>
                        </div>
                        <hr />
                        <div id="resultDiv"><!------ Start result --------->

                            <hr />

                            <table class="table table-black" id="receipts">
                                <thead>
                                    <tr>
                                        <th>#</th>
                                        <th>رقم الايصال</th>
                                        <th>الرقم التسلسلى</th>
                                        <th>اسم المورد</th>
                                        <th>التاريخ</th>
                                        <th>الدين قبل </th>
                                        <th>المبلغ</th>
                                        <th>الدين بعد </th>
                                        <th style="width:30%; max-width: 30%;"> التعليق </th>
                                        <th>اسم المستخدم</th>
                                        <th>اسم الخزنة</th>
                                        <th class="hidden-print">تعديل</th>
                                        <th class="hidden-print">حذف</th>
                                        <th class="hidden-print">طباعه </th>
                                        <th class="hidden-print">قيد اليومية</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {*assign var=i value=1*}
                                    {*foreach $shownData as $data*}
                                    <!--

                                                            {if $data->del eq 1}
                                                            <tr class="danger">
                                                                {else}
                                                            <tr class="gradeA">
                                                                {/if}
                                                                <td>{$data@iteration}</td>
                                                                <td>{$data->supplierdebtchangeid}</td>
                                                                <td>{$data->suppliername}</td>
                                                                <td>{$data->supplierdebtchangedate}</td>
                                                                <td>{$data->supplierdebtchangebefore}</td>
                                                                <td>{$data->supplierdebtchangeamount}</td>
                                                                <td>{$data->supplierdebtchangeafter}</td>
                                                                <td>{$data->comment}</td>
                                                                <td>{$data->username}</td>
                                                                <td>{$data->savename}</td>
                                                                <td class="hidden-print">
                                                                    {if $data->del eq 1}
                                                                    لقد تم حذفه
                                                                    {else}

                                                                    <a href="#" ><input id="delbtn{$i}" data-itr="{$i}" data-action="supplierReportsController.php?do=remove&id={$data->supplierdebtchangeid}&dailyentry={$data->dailyentryid}" type="button"  class="btn btn-danger pull-right" value="حذف" /> </a>
                                                                    {/if}
                                                                </td>
                                                                <th  class="hidden-print"><a target="_blank" href="supplierReportsController.php?do=editprint&id={$data->supplierdebtchangeid}" ><input  type="button"  class="btn btn-success pull-right" value="طباعه" /> </a></th>
                                                            </tr>-->
                                    {*assign var=i value=$i+1*}
                                    {*/foreach*}
                                </tbody>

                            </table>
                            <div class="col-lg-offset-8 col-lg-4">
                                <div class="well well-sm">
                                    <h4 class="text-center">الإجمالي: <span class="sumRecit">{$sum}</span> {$currency}
                                    </h4>
                                </div>
                            </div>
                        </div> <!------ End result --------->
                    </div>

                    <div class="tab-pane" id="chequesTab"><!-- start the 2nd tab -->

                        <div class="col-lg-offset-8 col-lg-4">
                            <div class="well well-sm">
                                <h4 class="text-center">الإجمالي: <span class="sumRecit_cheques">{$sum}</span>
                                    {$currency}</h4>
                            </div>
                        </div>
                        <hr>
                        <table class="table table-black" id="receipts_cheques">
                            <thead>
                                <tr>
                                    <th>رقم الشيك</th>
                                    <th>اسم البنك</th>
                                    <th>اسم الحساب</th>
                                    <th>اسم المورد</th>
                                    <th>التاريخ</th>
                                    <th>المبلغ المدفوع</th>
                                    <th class="hidden-print">الحذف</th>
                                    <th class="hidden-print">التعديل</th>
                                    <th class="hidden-print">طباعه</th>
                                </tr>
                            </thead>
                            <tbody>



                            </tbody>

                        </table>
                        <div class="col-lg-offset-8 col-lg-4">
                            <div class="well well-sm">
                                <h4 class="text-center">الإجمالي: <span class="sumRecit_cheques">{$sum}</span>
                                    {$currency}</h4>
                            </div>
                        </div>
                    </div>
                </div>


            </div>

            <!-- Modal -->
            <div class="modal fade hidden-print" id="myModal155" tabindex="-1" role="dialog"
                aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close pull-left savemodel2" data-dismiss="modal"
                                aria-hidden="true">&times;</button>
                        </div>
                        <div class="modal-body">
                            <span class="modal-title">

                                هل تريد حذف هذا العنصر؟
                            </span>

                            <form id="supDel" action="" method="post" class="form-horizontal">
                            </form>
                            <input type="hidden" name="currentItr" id="currentItr" value="0" />
                        </div>
                        <div class="modal-footer">
                            <button type="button" id="ddbtn" class="btn btn-default">حذف </button>

                            <button type="button" class="btn btn-default" data-dismiss="modal">اغلاق </button>
                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
                <!-- /.modal-dialog -->
            </div>

            <div class="clearfix"></div>
            <hr />
            <div class=" hidden-print">
                <div class="col-lg-12">
                    <div class="form-group">
                        <div class="col-lg-4">
                            <button type="button" onclick="print_Custom('mycustomheader');"
                                class="btn btn-success pull-right">طباعة</button>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
        </div>

    </div>
</div>
<input type="hidden" id="idsearch" value="{$idsearch}">
{literal}
<script>
    $(function () {
        var receipts = $('#receipts');
        var otablereceipts = receipts.DataTable({
            "processing": true,
            "stateSave": true,
            "serverSide": true,
            "ajax": {
                url: 'supplierReportsController.php?do=showallajax', type: 'POST',
                "data": {
                    "from": function () {
                        return $('#datepicker_from').val()
                    },
                    "to": function () {
                        return $('#datepicker_to').val()
                    },
                    "saveId": function () {
                        return $('#saveId').val()
                    },
                    "supplierId": function () {
                        return $('#supplierId').val()
                    },
                    "debtchangeid": function () {
                        return $('#idsearch').val()//$('#supplierId').val()
                    },
                    "paySerialNo": function () {
                        return $('#paySerialNu').val()
                    },
                    "Costcenterid": function () {
                        return $('#Costcenterid').val()
                    },
                    //                    "searchDate": function () {
                    //                        return localStorage.getItem("search")
                    //                    },
                    // etc..
                }
            }, //  server side processing
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                if (aData[0].includes("danger")) {//not deleted
                    $('td', nRow).css('background-color', '#F2DEDE');
                } else if (aData[0].includes("dark")) {
                    $('td', nRow).css('background-color', '#9E9E9E');
                } else {
                    //$('td', nRow).css('background-color', 'white');
                }
            },
            dom: 'Bfrtip',
            buttons: [//'csv', 'pdf'
                {
                    extend: "print",
                    className: "btn dark btn-outline",
                    text: "طباعه<i class='fa fa-print'></i>",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    },
                    customize: function (win) {
                        $(win.document.body).find('table')
                            //.addClass('compact')
                            .css('direction', 'rtl');
                    }
                }, {
                    extend: "copy",
                    className: "btn red btn-outline",
                    text: "نسخ",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    }
                }, {
                    extend: "excel",
                    className: "btn yellow btn-outline ",
                    text: "اكسل",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    }
                }, {
                    extend: "colvis",
                    className: "btn dark btn-outline",
                    text: "المكونات"
                }
            ], "bStateSave": true,
            "language": {
                "aria": {
                    "sortAscending": ": Used to order Ascending",
                    "sortDescending": ": Used to order Descending"
                },
                "emptyTable": "لا يوجد بيانات",
                "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                "infoEmpty": "لا يوجد بيانات",
                "infoFiltered": "(تنقيه  من عدد فواتير كلى _MAX_)",
                "lengthMenu": " _MENU_ عنصر",
                "search": "البحث:",
                "zeroRecords": "لا يوجد بيانات تشابه البحث"
            },
            responsive: !0,
            "columnDefs": [//            {// set default column settings //                "orderable": false,
                //                "searchable": false,
                //                "targets": [lstone],
                //                "className": 'hide-print'
                //            },
                //            {// set default column settings
                //                "orderable": false,
                //                "searchable": false,
                //                "targets": [belastone],
                //                "className": 'hide-print'
                //            },
                //            {// set default column settings
                //                "orderable": false,
                //                "searchable": false, //                "targets": [thrdone],
                //                "className": 'hide-print'
                //            },
                //                {targets: '_all', "className": 'show-print'}
            ],
            order: [
                [0, "asc"]
            ],
            paging: true,
            lengthMenu: [
                [5, 10, 15, 20, 50, -1],
                [5, 10, 15, 20, 50, "All"]
            ],
            pageLength: 10,
            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>>"
        });
        var receipts_cheques = $('#receipts_cheques');
        var otablereceipts_cheques = receipts_cheques.DataTable({
            "processing": true,
            "stateSave": true,
            "serverSide": true,
            "ajax": {
                url: 'supplierReportsController.php?do=showallajaxCheques', type: 'POST',
                "data": {
                    "from": function () {
                        return $('#datepicker_from').val()
                    },
                    "to": function () {
                        return $('#datepicker_to').val()
                    },
                    "supplierId": function () {
                        return $('#supplierId').val()
                    },
                    "Costcenterid": function () {
                        return $('#Costcenterid').val()
                    },
                    //                    "searchDate": function () {
                    //                        return localStorage.getItem("search")
                    //                    },
                    // etc..
                }
            }, //  server side processing
            "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
                if (aData[0].includes("danger")) {//not deleted
                    $('td', nRow).css('background-color', '#F2DEDE');
                } else if (aData[0].includes("dark")) {
                    $('td', nRow).css('background-color', '#9E9E9E');
                } else {
                    //$('td', nRow).css('background-color', 'white');
                }
            },
            dom: 'Bfrtip',
            buttons: [//'csv', 'pdf'
                {
                    extend: "print",
                    className: "btn dark btn-outline",
                    text: "طباعه<i class='fa fa-print'></i>",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    },
                    customize: function (win) {
                        $(win.document.body).find('table')
                            //.addClass('compact')
                            .css('direction', 'rtl');
                    }
                }, {
                    extend: "copy",
                    className: "btn red btn-outline",
                    text: "نسخ",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    }
                }, {
                    extend: "excel",
                    className: "btn yellow btn-outline ",
                    text: "اكسل",
                    exportOptions: {
                        //columns: '.show-print'
                        columns: ':visible'
                    }
                }, {
                    extend: "colvis",
                    className: "btn dark btn-outline",
                    text: "المكونات"
                }
            ], "bStateSave": true,
            "language": {
                "aria": {
                    "sortAscending": ": Used to order Ascending",
                    "sortDescending": ": Used to order Descending"
                },
                "emptyTable": "لا يوجد بيانات",
                "info": "عرض من  _START_ إلى  _END_  - عدد فواتير البحث _TOTAL_",
                "infoEmpty": "لا يوجد بيانات",
                "infoFiltered": "(تنقيه  من عدد فواتير كلى _MAX_)",
                "lengthMenu": " _MENU_ عنصر",
                "search": "البحث:",
                "zeroRecords": "لا يوجد بيانات تشابه البحث"
            },
            responsive: !0,
            "columnDefs": [//            {// set default column settings //                "orderable": false,
                //                "searchable": false,
                //                "targets": [lstone],
                //                "className": 'hide-print'
                //            },
                //            {// set default column settings
                //                "orderable": false,
                //                "searchable": false,
                //                "targets": [belastone],
                //                "className": 'hide-print'
                //            },
                //            {// set default column settings
                //                "orderable": false,
                //                "searchable": false, //                "targets": [thrdone],
                //                "className": 'hide-print'
                //            },
                //                {targets: '_all', "className": 'show-print'}
            ],
            order: [
                [0, "asc"]
            ],
            paging: true,
            lengthMenu: [
                [5, 10, 15, 20, 50, -1],
                [5, 10, 15, 20, 50, "All"]
            ],
            pageLength: 10,
            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>>"
        });
        $('body').on('change', '.search_ajax', function () {
            otablereceipts.ajax.reload();
            otablereceipts_cheques.ajax.reload();
            //otablesell.draw();//both work fine
        });
        $('body').on('click', '#refreshResultsBtn', function () {
            $('.search_ajax:first').trigger('change');
        });
        $('body').on('click', '#todayPayments', function () {
            $('#datepicker_from').val($('#todaydDateOnly').val());
            $('#datepicker_to').val($('#todaydDateOnly').val());
            $('.search_ajax:first').trigger('change');
        });
        //when draw is comlete cal total of column using datatable api sum func
        otablereceipts.on('draw', function (e, ajaxdata) {
            //var sum = otablesell.column(3).data().sum();
            $('.sumRecit').html(ajaxdata.json.totals.totalRecitsAll);
        });
        otablereceipts_cheques.on('draw', function (e, ajaxdata) {
            //var sum = otablesell.column(3).data().sum();
            $('.sumRecit_cheques').html(ajaxdata.json.totals.totalRecitsAll);
        });



        //search with debtchangeid get
        //        $('#debtchangeid').select2('data', {id: $('#idsearch').val(), text: $('#idsearch').val()});
        //        $('#refreshResultsBtn').click();
    });
</script>
{/literal}