<style>
    .nodata {
        background-color: #72B4EC;
        color: white;
        border-radius: 13px;
        margin: 14px;
        font-size: 24px;
        text-align: center;
        padding: 5px;
    }
</style>
<script>
    /* $(document).ready(function(e) {
     var id= document.getElementById("sellbillid").value;

     window.open("clientReportsController.php?do=showDetail2&id="+id);
     });*/
</script>
<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">{$smarty.const.PAYED_DEPT_GENERAL_FEATURES}</a></li>
            <li><a href="clientPayedDeptController.php?do=show">{$smarty.const.PAYED_DEPT_CLIENTS}</a></li>
            <li class="active">{$smarty.const.PAYED_DEPT_RECEIPT_RECEIPT_CLIENT}</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;">
                    {$smarty.const.PAYED_DEPT_SHOW_RECEIPT_RECEIPT_CLIENT}<br />
                    {if $message != ""}
                    {$message}
                    {/if}</h3>
                <a href="{$youtubes[264]->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="clientPayedDeptController.php" class="hidden-print"><input type="button" id="submit"
                        style="margin-left: 12px" class="btn btn-primary pull-left "
                        value="{$smarty.const.PAYED_DEPT_ADD_NEW}" /></a>
            </div>
            <div class="panel-body">
                <form class="form-inline  hidden-print" action="clientPayedDeptController.php?do=show" method="post">
                    <input type="hidden" id="todaydDateOnly" value="{$todaydDateOnly}" />
                    <div class="form-group">

                        <label class="sr-only"> {$smarty.const.PAYED_DEPT_CLIENT_NAME} </label>
                        <input type="hidden" name="clientid" id="clientid"
                            class="select2Supp2 search_ajax select2-offscreen" tabindex="-1">
                        <input type="hidden" id="select2Supp2id" value="{$client->clientid}">
                        <input type="hidden" id="select2Supp2text" value="{$client->clientname}">
                        <!--                        <select class="select2 wdt100 search_ajax" name="clientid" id="clientid" >
                                                    <option value="-1">اختر عميل </option>
                                                    <option value="-2"> كل العملاء</option>
                                                    {foreach $clientsData as $data }



                                                    <option value="{$data->clientid}">{$data->clientname}</option>


                                                    {/foreach}


                                                </select>-->
                    </div>
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_RECEIPT} </label>
                        <input type="hidden" name="clientdebtchangemodelid" id="clientdebtchangemodelid"
                            class="select2Recits search_ajax select2-offscreen" tabindex="-1">
                        <!--                        <select name="clientdebtchangemodelid" id="clientdebtchangemodelid"  class="select2 wdt100 search_ajax" >

                                                    <option value="-1">اختر الايصال</option>
                                                    {foreach $allmydata as $myallmydata}
                                                    <option value="{$myallmydata->clientdebtchangemodelid}">{$myallmydata->clientdebtchangemodelid}</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>
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_CLEAR} </label>
                        <input type="checkbox" class="search_ajax" name="bure" id="bure" value="1" />
                    </div>
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_ONLY} </label>
                        <input type="checkbox" checked class="search_ajax" name="onlyReceipt" id="onlyReceipt" value="1" />
                    </div>
                    <div class="form-group" {if $Programsettingdata->costcenter eq 0} {else} style="display:none" {/if}
                        >
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_COST_CENTER}</label>
                        <select class="select2 wdt100" name="costcenterid" id="costcenterid">
                            <option value="-1">{$smarty.const.PAYED_DEPT_SELECT_COST_CENTER}</option>
                            {foreach $allCostcenter as $myallCostcenter}
                            <option value="{$myallCostcenter->id}" {if $myallCostcenter->id eq
                                $projectid}selected=""{/if}>{$myallCostcenter->name}</option>
                            {/foreach}
                        </select>
                    </div>
                    <br />
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_FROM_DATE}</label>
                        <input type="text" class="form-control awdatepicker search_ajax" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="from" id="from">
                    </div>
                    <div class="form-group">
                        <label class="sr-only">{$smarty.const.PAYED_DEPT_TO_DATE}</label>
                        <input type="text" class="form-control awdatepicker search_ajax" autocomplete="off"
                            data-date-format="yyyy-mm-dd" name="to" id="to">
                    </div>

                    <br />
                    <div class="clearfix"></div>
                    <!-- <button type="submit" class="btn btn-primary">بحث</button>-->
                    <button type="button" class="btn btn-primary"
                        id="todayPayments">{$smarty.const.PAYED_DEPT_SEARCH_TOADY}</button>
                    <button type="button" class="btn btn-primary"
                        id="refreshResultsBtn">{$smarty.const.PAYED_DEPT_SEARCH_UPDATE}</button>
            </div>
            <!--{*if count($shownData) > 0*}-->
            <div class="col-lg-offset-8 col-lg-4">
                <div class="well well-sm hidden-print">
                    <h4 class="text-center">{$smarty.const.PAYED_DEPT_TOTAL_VALUE_RECEIPTS} <br />
                        <span class="sumRecit"></span> {$currency}
                    </h4>
                </div>
            </div>
            <div class="clearfix"></div>
            <hr />

            <table class="table table-black " id="receipts"><!-- dataTableClass -->
                <thead>
                    <tr>
                        <th>#</th>
                        <th>{$smarty.const.PAYED_DEPT_RECEIPT_NUMBER}</th>
                        <th>الرقم التسلسلى</th>
                        <th>{$smarty.const.PAYED_DEPT_CLIENT_NAME}</th>
                        <th>{$smarty.const.PAYED_DEPT_DATE}</th>
                        <th> {$smarty.const.PAYED_DEPT_DEBT_BEFORE}</th>
                        <th>{$smarty.const.PAYED_DEPT_AMOUNT}</th>
                        <th> {$smarty.const.PAYED_DEPT_DEBT_AFTER}</th>
                        <th> {$smarty.const.PAYED_DEPT_COMMENT}</th>
                        <th>{$smarty.const.PAYED_DEPT_USER_NAME} </th>
                        <th>{$smarty.const.PAYED_DEPT_SAVE}</th>
                        <th>النوع</th>
                        <th class="hidden-print"> {$smarty.const.PAYED_DEPT_EDIT}</th>
                        <th class="hidden-print"> {$smarty.const.PAYED_DEPT_DELETE}</th>
                        <!--<th class="hidden-print">طباعه </th>-->
                        <th class="hidden-print">{$smarty.const.PAYED_DEPT_PRINT_RECEIPT} </th>
                        <th class="hidden-print">قيد اليومية</th>
                    </tr>
                </thead>
                <tbody>
                    {*assign var=i value=1*}
                    {*foreach $shownData as $data*}
                    <!--                    <tr>
                                            <td>{$i}</td>{$data->clientdebtchangeid}
                                            <td>{$data->clientdebtchangemodelid}</td>
                                            <td>{$data->clientname}</td>
                                            <td>{$data->clientdebtchangedate}</td>
                                            <td>{$data->clientdebtchangebefore}</td>
                                            <td>{$data->clientdebtchangeamount}</td>
                                            <td>{$data->clientdebtchangeafter}</td>
                                            <td>{$data->employeename}</td>
                                            <td>{$data->savename}</td>
                                            <th class="hidden-print">
                                                {if ($data->del == 0)}
                                                <a data-go="clientPayedDeptController.php?do=remove&id={$data->clientdebtchangemodelid}&action={$data->dailyentryid}" class="removethis"><input  type="button"  class="btn btn-danger pull-right" value="حذف" /> </a>
                                                {else}
                                                محذوف
                                                {/if}
                                            </th>
                                            <th class="hidden-print"><a target="_blank" href="clientPayedDeptController.php?do=editprint&id={$data->clientdebtchangeid}" ><input  type="button"  class="btn btn-success pull-right" value="طباعه" /> </a></th>
                                            <th class="hidden-print"><a target="_blank" href="clientPayedDeptController.php?do=editprint2&id={$data->clientdebtchangeid}" ><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">{$smarty.const.PAYED_DEPT_TOTAL_VALUE_RECEIPTS} <br />
                        <span class="sumRecit"></span> {$currency}
                    </h4>
                </div>
            </div>
            <div class="clearfix"></div>
            <!-- Modal -->
            <div class="hidden-print">
                <div class="modal fade " id="myModal1" 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" data-dismiss="modal"
                                    aria-hidden="true">&times;</button>
                                <div class="modal-title">تأكيد حذف عميل</div>
                            </div>
                            <div class="modal-body"> هل تريد حذف هذا العميل؟ </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">لا</button>
                                <button type="button" class="btn btn-primary savemodel1">نعم</button>
                            </div>
                        </div>
                        <!-- /.modal-content -->
                    </div>
                    <!-- /.modal-dialog -->
                </div>
            </div>
            <!-- /.modal -->
            <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">{$smarty.const.PAYED_DEPT_PRINT}</button>
                        </div>
                    </div>
                </div>
                <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>
            <!--            {*else*}
                        <div class="nodata">عفوا لا توجد نتائج</div>
                        {*/if*}-->
        </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: 'clientPayedDeptController.php?do=showallajax', type: 'POST',
                "data": {
                    "from": function () {
                        return $('#from').val()
                    },
                    "to": function () {
                        return $('#to').val()
                    },
                    "clientdebtchangemodelid": function () {
                        return $('#clientdebtchangemodelid').val()
                    },
                    "paySerialNo": function () {
                        return $('#paySerialNu').val()
                    },
                    "clientid": function () {
                        return $('#clientid').val()
                    },
                    "costcenterid": function () {
                        return $('#costcenterid').val()
                    },
                    "bure": function () {
                        if ($('#bure').is(':checked')) {
                            return 1;
                        } else {
                            return 0;
                        }

                    },
                    "onlyReceipt": function () {
                        if ($('#onlyReceipt').is(':checked')) {
                            return 1;
                        } else {
                            return 0;
                        }

                    },
                    //                    "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": [
                { "className": "hidden-print", "targets": [9, 10,11,12,13,14] }

                //            {// 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();
            //otablesell.draw();//both work fine
        });
        $('body').on('click', '#refreshResultsBtn', function () {
            $('.search_ajax:first').trigger('change');
        });
        $('body').on('click', '#todayPayments', function () {
            $('#from').val($('#todaydDateOnly').val());
            $('#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);
        });




        //search with clientdebtchangemodelid get
        $('#clientdebtchangemodelid').select2('data', { id: $('#idsearch').val(), text: $('#idsearch').val() });
        $('#refreshResultsBtn').click();
    });
    $(".removethis").live("click", function () {
        $(".removethis").unbind("click");
        window.location.href = $(this).attr('data-go');
        $('.removethis').removeAttr('data-go');
    });
    $('.delPayment').live('click', function () {
        var btn = $(this);
        if (!btn.hasClass('processing...')) {
            btn.addClass('processing...');


            var id = btn.data('id');
            var type = btn.data('type');
            type = type.split('-');
            if (type[0].trim() == "خزنة")
                type = "save";
            else if (type[0].trim() == "بنك")
                type = "bank";

            $.post('sellbillAjaxController.php?do=delMakeSellBillPayment', { clientdebtchangeId: id, paytype: type }, function (data) {
                btn.removeClass('processing...');
                if (Number(data) == 1) {
                    //btn.parent().parent().remove();
                    window.location.reload();
                } else {
                    alert('عفوا حدث خطأ.حاول مرة اخرى')
                }
            });
        }
    });
</script>
{/literal}