@extends('admin.index')
@section('content')
    @php
        use App\Models\CompanyData;
        use App\Models\AcccountingManual;
        $DefC=CompanyData::orderBy('id','desc')->first();
        $title=trans('admin.Customer_Debts');
    @endphp



    <title>{{trans('admin.Customer_Debts')}}</title>

<style>
.labelss {
    margin-bottom: 5px;
    border: 1px solid #e9e9e9;
    padding: 6px;
    background-color: #fffaee;
    width: 100%;
}
.animated-btn{
     position: relative;
  animation-name: example;
  animation-duration: 4s;
  animation-iteration-count: infinite;
}
@keyframes example {
  0%   {background-color:#6abdbb; left:0px; top:0px;}
  50%  {background-color:#51dedb; left:5px; top:0px;}
  100% {background-color:#00ceca; left:0px; top:0px;}
}
    .over-flow{
        overflow:auto;
    }
    .table-width{
        width:140%;
    }
    @media print{
            .over-flow{
            overflow:visible;
        }
        .table-width{
            width:100%;
        }
        .panel-content{
            padding:0;
        }
        .form-group {
        margin-bottom:0;
        }
        @page{
            margin:0;
            padding:0;
        }
        input[type=date].form-control{
            font-weight: 700;
            color:black;
        }
    }
    @media (min-width: 768px) {
    .col-md-2 {
        -webkit-box-flex: 0;
        -ms-flex: 0 0 16.66667%;
        flex: -4 0 16.66667%;
        max-width: 10.66667% !important;
    }
}
@media print{

    .col-2-print {
        -webkit-box-flex: 0;
        -ms-flex: 0 0 16.66667%;
        flex: -4 0 16.66667%;
        max-width: 8.66667% !important;
}
.Headerrr2{
 display:flex;
     justify-content: flex-start;
}
}
</style>

   <main id="js-page-content" role="main" class="page-content">
                    <ol class="breadcrumb page-breadcrumb no-print">
                       <li class="breadcrumb-item"><a href="javascript:void(0);"> {{trans('admin.Reports')}}</a></li>
                        <li class="breadcrumb-item active"> {{trans('admin.Customer_Debts')}} </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>

                    <!-- Head Of Print -->
       @include('admin.layouts.PrintHeader')


                    <div class="row ">
                        <div class="col-lg-12">
                            <div id="panel-2" class="panel">
                                <div class="panel-hdr no-print">
                                    <h2>
                                        <span class="fw-300"><i>   {{trans('admin.Customer_Debts')}}  </i></span>
                                    </h2>
                                </div>
                                <div class="panel-container show ">
                                    <div class="panel-content">
                                            <div class="col-md-11 m-1" style="display: none" >
                                    <button type="button" class="btn btn-primary" onclick="Autoo()">Auto</button>
                                        </div>


                                               <div class="form-row Headerrr2 m-1">
                                            <div class="form-group col-md-2 col-2-print">
                                                <h4 class="form-label labelss" for="simpleinput">{{trans('admin.From')}}</h4>

                                                <h5 class="TableLabel">{{$from}}</h5>

                                            </div>
                                            <div class="form-group col-md-2 col-2-print">
                                                <h4 class="form-label labelss" for="simpleinput">{{trans('admin.To')}}</h4>
                                               <h5 class="TableLabel">{{$to}}</h5>
                                            </div>

                                                   <div class="form-group col-md-2 col-2-print">
                                                <h4 class="form-label labelss" for="simpleinput">{{trans('admin.Client')}}</h4>
                                               <h5 class="TableLabel">
                                               @if(!empty($Client))
                                           @php $NameAcc=AcccountingManual::find($Client);  @endphp
                                     {{app()->getLocale() == 'ar' ?$NameAcc->Name :$NameAcc->NameEn}}
                                                   @endif

                                            </h5>
                                            </div>



                                        </div>

                                             <form action="{{url('Customer_DebtsFilterTwo')}}" method="get" style="display: none">

                                        <div class="form-row">
                                            <div class="form-group col-md-2 col-4-print">
                                                <label class="form-label" for="simpleinput">{{trans('admin.From')}}</label>
                                                <input type="date" id="from" name="from" value="{{$from}}" class="form-control">
                                            </div>
                                            <div class="form-group col-md-2 col-4-print">
                                                <label class="form-label" for="simpleinput">{{trans('admin.To')}}</label>
                                                <input type="date" id="to" name="to" value="{{$to}}" class="form-control">
                                            </div>


                           <input type="hidden" id="Client" value="{{$Client}}" name="Client">
                           <input type="hidden" id="Store" value="{{$Store}}" name="Store">
                           <input type="hidden" id="Delegate" value="{{$Delegate}}" name="Delegate">
                           <input type="hidden" id="Safe" value="{{$Safe}}" name="Safe">
                           <input type="hidden" id="Branch" value="{{$Branch}}" name="Branch">
                           <input type="hidden" id="code" value="{{$code}}" name="code">

                                            <div class="form-group col-md-2 no-print">

                                                    <div class="buttons m-2">
                                            <button type="submit" class="btn btn-primary"><i class="fal fa-search"></i></button>
                                                </div>
                                            </div>
                                        </div>
                                                  </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row hide-table">
                        <div class="col-xl-12">
                            <div id="panel-1" class="panel">
                                <div class="panel-hdr no-print">
                                    <h2>
                                        {{trans('admin.Customer_Debts')}}
                                    </h2>

                                    <div class="panel-toolbar">
                                        <button class="btn btn-primary btn-sm" data-toggle="dropdown">Table
                                            Style</button>
                                       @include('admin.layouts.toolbar')
                                    </div>

                                </div>
                                <div class="panel-container show">
                                    <div class="panel-content">

                                        <!-- datatable start -->
                                        <div class="over-flow">
                                        <table id="X"
                                            class="table table-bordered table-hover table-striped">
                                            <thead class="bg-highlight">
                                                <tr>
                                                       <th>   {{trans('admin.Date')}}</th>
                                                    <th>   {{trans('admin.Code')}}</th>
                                                    <th>   {{trans('admin.Later_Due')}}</th>
                                                    <th>   {{trans('admin.Store')}}</th>
                                                    <th>   {{trans('admin.Safe')}}</th>
                                                    <th>   {{trans('admin.Client')}}</th>
                                                    <th>   {{trans('admin.Repayment_Period')}}</th>
                                                    <th>   {{trans('admin.Delegate')}}</th>
                                                    <th>   {{trans('admin.Total_Price')}}</th>
                                                    <th>   {{trans('admin.Pay')}}</th>
                                                    <th>   {{trans('admin.Residual')}}</th>
                                                    <th>   {{trans('admin.Total_Return')}}</th>
                                                    <th>   {{trans('admin.Total_Recipt_Voucher')}}</th>
                                                    <th>   {{trans('admin.Pay_Residual')}}</th>
                                                    <th>   {{trans('admin.Num_Of_Days')}}</th>
                                                </tr>
                                            </thead>
                                            <tbody class="Data" id="data-wrapper">

                                            </tbody>
                                            <tfoot>
                                                <tr>
                                                    <th>   {{trans('admin.Date')}}</th>
                                                    <th>   {{trans('admin.Code')}}</th>
                                                    <th>   {{trans('admin.Later_Due')}}</th>
                                                    <th>   {{trans('admin.Store')}}</th>
                                                    <th>   {{trans('admin.Safe')}}</th>
                                                    <th>   {{trans('admin.Client')}}</th>
                                                    <th>   {{trans('admin.Repayment_Period')}}</th>
                                                    <th>   {{trans('admin.Delegate')}}</th>
                                                    <th>   {{trans('admin.Total_Price')}}</th>
                                                    <th>   {{trans('admin.Pay')}}</th>
                                                    <th>   {{trans('admin.Residual')}}</th>
                                                    <th>   {{trans('admin.Total_Return')}}</th>
                                                    <th>   {{trans('admin.Total_Recipt_Voucher')}}</th>
                                                    <th>   {{trans('admin.Pay_Residual')}}</th>
                                                    <th>   {{trans('admin.Num_Of_Days')}}</th>
                                                </tr>
                                            </tfoot>

                                        </table>
                                        </div>
                       <button style="width: 100%" class="text-center btn btn-primary" id="btn-more"><i class="fal fa-plus">{{trans('admin.More')}}</i></button>

                                         <div class="auto-load text-center">
            <svg version="1.1" id="L9" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
                x="0px" y="0px" height="60" viewBox="0 0 100 100" enable-background="new 0 0 0 0" xml:space="preserve">
                <path fill="#000"
                    d="M73,50c0-12.7-10.3-23-23-23S27,37.3,27,50 M30.9,50c0-10.5,8.5-19.1,19.1-19.1S69.1,39.5,69.1,50">
                    <animateTransform attributeName="transform" attributeType="XML" type="rotate" dur="1s"
                        from="0 50 50" to="360 50 50" repeatCount="indefinite" />
                </path>
            </svg>
        </div>

                                        <!-- datatable end -->
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </main>



  <input type="hidden" id="COUNT" value="0">
@endsection

@push('js')

  <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/datagrid/datatables/datatables.bundle.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/summernote/summernote.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/select2/select2.bundle.css')}}">


 <script src="{{asset('Admin/js/datagrid/datatables/datatables.export.js')}}"></script>
    <script src="{{asset('Admin/js/datagrid/datatables/datatables.bundle.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/summernote/summernote.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/select2/select2.bundle.js')}}"></script>
    <script>
        //_fnFeatureHtmlLength();
        $(document).ready(function () {
            // Setup - add a text input to each footer cell
            $('#dt-basic-example thead tr').clone(true).appendTo('#dt-basic-example thead');
            $('#dt-basic-example thead tr:eq(1) th').each(function (i) {
                var title = $(this).text();
                $(this).html('<input type="text" class="form-control form-control-sm" placeholder="Search '  + '" />');

                $('input', this).on('keyup change', function () {
                    if (table.column(i).search() !== this.value) {
                        table
                            .column(i)
                            .search(this.value)
                            .draw();
                    }
                });
            });
            var table = $('#dt-basic-example').DataTable(
                {
                    // responsive: true,
                    orderCellsTop: true,
                    fixedHeader: true,
                    lengthChange: true,

                    dom: "<'row mb-3'<'col-sm-12 col-md-3 d-flex align-items-center justify-content-start'f><'col-sm-12 col-md-9 d-flex align-items-center justify-content-end'B>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",

                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'PDF',
                            titleAttr: 'Generate PDF',
                            className: 'btn-outline-danger btn-sm mr-1'
                        },
                        {
                            extend: 'excelHtml5',
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                            className: 'btn-outline-success btn-sm mr-1'
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'CSV',
                            titleAttr: 'Generate CSV',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'copyHtml5',
                            text: 'Copy',
                            titleAttr: 'Copy to clipboard',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });
            $('.js-thead-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example thead').removeClassPrefix('bg-').addClass(theadColor);
            });

            $('.js-tbody-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example').removeClassPrefix('bg-').addClass(theadColor);
            });

        });

    </script>


<script>
    var autoSave = $('#autoSave');
    var interval;
    var timer = function()
    {
        interval = setInterval(function()
        {
            //start slide...
            if (autoSave.prop('checked'))
                saveToLocal();

            clearInterval(interval);
        }, 3000);
    };

    //save
    var saveToLocal = function()
    {
        localStorage.setItem('summernoteData', $('#saveToLocal').summernote("code"));
        console.log("saved");
    }

    //delete
    var removeFromLocal = function()
    {
        localStorage.removeItem("summernoteData");
        $('#saveToLocal').summernote('reset');
    }

    $(document).ready(function()
    {
        //init default
        $('.js-summernote').summernote(
        {
            height: 200,
            tabsize: 2,
            placeholder: "Type here...",
            dialogsFade: true,
            toolbar: [
                ['style', ['style']],
                ['font', ['strikethrough', 'superscript', 'subscript']],
                ['font', ['bold', 'italic', 'underline', 'clear']],
                ['fontsize', ['fontsize']],
                ['fontname', ['fontname']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']]
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ],
            callbacks:
            {
                //restore from localStorage
                onInit: function(e)
                {
                    $('.js-summernote').summernote("code", localStorage.getItem("summernoteData"));
                },
                onChange: function(contents, $editable)
                {
                    clearInterval(interval);
                    timer();
                }
            }
        });

        //load emojis
        $.ajax(
        {
            url: 'https://api.github.com/emojis',
            async: false
        }).then(function(data)
        {
            window.emojis = Object.keys(data);
            window.emojiUrls = data;
        });

        //init emoji example
        $(".js-hint2emoji").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: 'type starting with : and any alphabet',
            hint:
            {
                match: /:([\-+\w]+)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(emojis, function(item)
                    {
                        return item.indexOf(keyword) === 0;
                    }));
                },
                template: function(item)
                {
                    var content = emojiUrls[item];
                    return '<img src="' + content + '" width="20" /> :' + item + ':';
                },
                content: function(item)
                {
                    var url = emojiUrls[item];
                    if (url)
                    {
                        return $('<img />').attr('src', url).css('width', 20)[0];
                    }
                    return '';
                }
            }
        });

        //init mentions example
        $(".js-hint2mention").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: "type starting with @",
            hint:
            {
                mentions: ['jayden', 'sam', 'alvin', 'david'],
                match: /\B@(\w*)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(this.mentions, function(item)
                    {
                        return item.indexOf(keyword) == 0;
                    }));
                },
                content: function(item)
                {
                    return '@' + item;
                }
            }
        });

    });

</script>
<script type="text/javascript">


    $(".show-table").click(function(){
        $(".hide-table").show();
    });

</script>


<!-- Search Selecet -->
 <script>
        $(document).ready(function()
        {
            $(function()
            {
                $('.select2').select2();

                $(".select2-placeholder-multiple").select2(
                {
                    placeholder: "Select State"
                });
                $(".js-hide-search").select2(
                {
                    minimumResultsForSearch: 1 / 0
                });
                $(".js-max-length").select2(
                {
                    maximumSelectionLength: 2,
                    placeholder: "Select maximum 2 items"
                });
                $(".select2-placeholder").select2(
                {
                    placeholder: "Select a state",
                    allowClear: true
                });

                $(".js-select2-icons").select2(
                {
                    minimumResultsForSearch: 1 / 0,
                    templateResult: icon,
                    templateSelection: icon,
                    escapeMarkup: function(elm)
                    {
                        return elm
                    }
                });

                function icon(elm)
                {
                    elm.element;
                    return elm.id ? "<i class='" + $(elm.element).data("icon") + " mr-2'></i>" + elm.text : elm.text
                }






            });
        });



    </script>

<!--  Filter Paginate -->
 <script>

      var from = $('#from').val();
     var to = $('#to').val();
     var Client = $('#Client').val();
     var Store = $('#Store').val();
     var Delegate = $('#Delegate').val();
     var Safe = $('#Safe').val();
     var Branch = $('#Branch').val();
     var code = $('#code').val();

        var page = 1;
        infinteLoadMore(page);
         $(document).on('click', '#btn-more', function(){
                page++;

                   var Auto =  $('.auto-load').text();
                  if(Auto !=  'No More'){
                infinteLoadMore(page);
                  }else{



                         if ($.fn.DataTable.isDataTable('#X')) {

    $('#X').dataTable().fnDestroy();

}

    var table = $('#X').DataTable(
                {
                    retrieve: true,
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: false,
                    lengthChange: false,
                     pageLength : 1000000,
                    dom: 'Bfrtip',

                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },

                        {
                            extend: 'excelHtml5',
                            exportOptions: {
                                format: {
                                    body: function ( inner, rowidx, colidx, node ) {
                                        if ($(node).children("select").length > 0) {
                                            // we are in a cell containing a "select" drop-down - so, get it:
                                            var selectNode = node.firstElementChild;
                                            var txt = selectNode.options[selectNode.selectedIndex].text;
                                            //var txt = selectNode.options[selectNode.selectedIndex].text;
                                            return txt;
                                        } else {

                                            if ($(node).children("input").length > 0) {
                                                return $(node).children("input").first().val();
                                            } else {
                                                return inner;
                                            }


                                        }
                                    }
                                }
                            },
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                            className: 'btn-outline-success btn-sm mr-1'
                        },

                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });
                 $('#btn-more').hide();
                  }

        });
        function infinteLoadMore(page) {
            $.ajax({
                    url: "Customer_DebtsFilterTwo?page=" + page,
                    datatype: "html",
                data:{
                       from:from,
                     to:to,
                     Client:Client,
                     Store:Store,
                     Delegate:Delegate,
                     Safe:Safe,
                     Branch:Branch,
                     code:code


                },
                    type: "get",
                    beforeSend: function () {
                        $('.auto-load').show();
                         $('#btn-more').show();
                    },
                     success:function(data)
                    {

                        if(data == ''){

                     $('.auto-load').html("No More");
                        return;

                           }else{
                     $('.auto-load').hide();
                    $("#data-wrapper").append(data);
                           }
                        }

                })

                .fail(function (jqXHR, ajaxOptions, thrownError) {
                    console.log('Server error occured');
                });


        }

    </script>

@endpush
