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

<title> {{trans('admin.InstallmentCompaniesSales')}}</title>
<main id="js-page-content" role="main" class="page-content no-print">
   <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.InstallmentCompaniesSales')}} </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')
   <!-- Data -->
   <div class="row hide-table">
      <div class="col-xl-12">
         <div id="panel-1" class="panel second-color">
            <div class="panel-hdr">
               <h2>
                  {{trans('admin.InstallmentCompaniesSales')}}
               </h2>
               <div class="panel-toolbar">
                  <button class="btn btn-primary btn-sm" data-toggle="dropdown">Table
                  Style</button>

                         <form action="{{url('ExportInstallmentCompaniesSales')}}" method="get">
                 @honeypot
                  <div class="row" style="display: none">
                      @if(!empty($store))
                         @for($i=0 ; $i < count($store) ; $i++)
                           <input type="hidden" name="Store[]" value="{{$store[$i]}}">
                       @endfor

                  @else
                     <input type="hidden" name="Store" value="">
                  @endif

                       @if(!empty($safe))

                      @for($i=0 ; $i < count($safe) ; $i++)
                        <input type="hidden" name="Safe[]" value="{{$safe[$i]}}">
                      @endfor

                   @else
                     <input type="hidden" name="Safe" value="">
                @endif

                    @if(!empty($client))

                      @for($i=0 ; $i < count($client) ; $i++)
                       <input type="hidden" name="Client[]" value="{{$client[$i]}}">
                      @endfor

                @else
                     <input type="hidden" name="Client" value="">
             @endif
                 @if(!empty($payment_Method))

                      @for($i=0 ; $i < count($payment_Method) ; $i++)
                     <input type="hidden" name="Payment_Method[]" value="{{$payment_Method[$i]}}">
                      @endfor

             @else
                     <input type="hidden" name="Payment_Method" value="">
          @endif




                 @if(!empty($delegate))

                      @for($i=0 ; $i < count($delegate) ; $i++)
                     <input type="hidden" name="Delegate[]" value="{{$delegate[$i]}}">
                      @endfor

             @else
                     <input type="hidden" name="Delegate" value="">
          @endif

              @if(!empty($executor))

                      @for($i=0 ; $i < count($executor) ; $i++)
                       <input type="hidden" name="Executor[]" value="{{$executor[$i]}}">
                      @endfor

             @else
                     <input type="hidden" name="Executor" value="">
          @endif

          @if(!empty($shipping_Company))

                      @for($i=0 ; $i < count($shipping_Company) ; $i++)
                        <input type="hidden" name="Shipping_Company[]" value="{{$shipping_Company[$i]}}">
                      @endfor

             @else
                     <input type="hidden" name="Shipping_Company" value="">
          @endif

              @if(!empty($user))

                      @for($i=0 ; $i < count($user) ; $i++)
                     <input type="hidden" name="User[]" value="{{$user[$i]}}">
                      @endfor

          @else
                     <input type="hidden" name="User" value="">
                @endif


                           @if(!empty($installCompany))

                      @for($i=0 ; $i < count($installCompany) ; $i++)
                     <input type="hidden" name="InstallCompany[]" value="{{$installCompany[$i]}}">
                      @endfor

          @else
                     <input type="hidden" name="InstallCompany" value="">
                @endif


                  <input type="hidden" name="ContractNumber" value="{{$contractNumber}}">
                  <input type="hidden" name="PayFees" value="{{$payFees}}">
                  <input type="hidden" name="Branch" value="{{$branch}}">
                  <input type="hidden" name="Refrence_Number" value="{{$refrence_Number}}">
                  <input type="hidden" name="Code" value="{{$code}}">
                  <input type="hidden" name="From" value="{{$from}}">
                  <input type="hidden" name="To" value="{{$to}}">
                  <input type="hidden" name="Clients_Group" value="{{$clients_Group}}">
                  <input type="hidden" name="Cost_Center" value="{{$cost_Center}}">
                  <input type="hidden" name="Coin" value="{{$coin}}">
                  <input type="hidden" name="Shift_Code" value="{{$shift_Code}}">




         @if(!empty($types))

                      @for($i=0 ; $i < count($types) ; $i++)
                    <input type="hidden" name="Type[]" value="{{$types[$i]}}">
                      @endfor

                      @else
                     <input type="hidden" name="Type" value="">
                   @endif


                  </div>

                   <button type="submit" class="btn btn-success btn-sm" >
                                                    <i class="fal fa-excel">Excel All Data</i>
                                                    </button>
                </form>



                   @include('admin.layouts.toolbar')
               </div>
            </div>
            <div class="panel-container show">
               <span id="ex"> @include('admin.layouts.messages')</span>
               <div class="panel-content">
                  <!-- datatable start -->
                  <div style="overflow:auto;">
                     <table id="X" class="table table-bordered table-hover table-striped">
                        <thead class="bg-highlight">
                           <tr>
                               @if($colum->Date == 1)
                              <th>{{trans('admin.Date')}}</th>
                               @endif

                                   @if($colum->Time == 1)
                              <th>{{trans('admin.Time')}}</th>
                               @endif

                                 @if($colum->Code == 1)
                              <th>{{trans('admin.Code')}}</th>
                               @endif

                                   @if($colum->Refrence_Number == 1)
                              <th>{{trans('admin.Refernce_Number')}}</th>
                               @endif

                                   @if($colum->Branch == 1)
                              <th>{{trans('admin.Branch')}}</th>
                               @endif

                                      @if($colum->Client == 1)
                              <th>{{trans('admin.Client')}}</th>
                               @endif


                                   @if($colum->Store == 1)
                              <th>{{trans('admin.Store')}}</th>
                               @endif

                                   @if($colum->Safe == 1)
                              <th>{{trans('admin.Safe')}}</th>
                               @endif

                                   @if($colum->Type == 1)
                              <th>{{trans('admin.Type')}}</th>
                               @endif

                                   @if($colum->Total_Price == 1)
                              <th>{{trans('admin.Total_Price')}}</th>
                               @endif

                                   @if($colum->Total_Discount == 1)
                              <th>{{trans('admin.Total_Discount')}}</th>
                               @endif

                                   @if($colum->Total_Tax == 1)
                              <th>{{trans('admin.Total_Tax')}}</th>
                               @endif

                                   @if($colum->Total_Net == 1)
                              <th>{{trans('admin.Total_Net')}}</th>
                               @endif

                                   @if($colum->Paid == 1)
                              <th>{{trans('admin.Pay')}}</th>
                               @endif

                                   @if($colum->Residual == 1)
                              <th>{{trans('admin.Residual')}}</th>
                               @endif

                                   @if($colum->Due_Date == 1)
                              <th>{{trans('admin.Due_Date')}}</th>
                               @endif

                                   @if($colum->Coin == 1)
                              <th>{{trans('admin.Coin')}}</th>
                               @endif

                                   @if($colum->ShiftCode == 1)
                              <th>{{trans('admin.Shift_Code')}}</th>
                               @endif

                                   @if($colum->Delegate == 1)
                              <th>{{trans('admin.Delegate')}}</th>
                               @endif

                                   @if($colum->Executor == 1)
                              <th>{{trans('admin.Executor')}}</th>
                               @endif

                                   @if($colum->User == 1)
                              <th>{{trans('admin.User')}}</th>
                               @endif

                                   @if($colum->Shipping == 1)
                              <th>{{trans('admin.Shipping_Compaines')}}</th>
                               @endif

                                   @if($colum->Cost_Center == 1)
                              <th>{{trans('admin.Cost_Center')}}</th>
                               @endif

                                   @if($colum->Total_Return == 1)
                              <th>{{trans('admin.Total_Return')}}</th>
                               @endif

                                   @if($colum->Note == 1)
                              <th>{{trans('admin.Note')}}</th>
                               @endif

                                        @if($colum->InstallCompany == 1)
                              <th>{{trans('admin.InstallCompany')}}</th>
                               @endif
                                        @if($colum->ContractNumber == 1)
                              <th>{{trans('admin.ContractNumber')}}</th>
                               @endif
                                        @if($colum->PayFees == 1)
                              <th>{{trans('admin.PayFees')}}</th>
                               @endif
                                        @if($colum->ServiceFee == 1)
                              <th>{{trans('admin.ServiceFee')}}</th>
                               @endif
                                        @if($colum->CompanyPrecent == 1)
                              <th>{{trans('admin.CompanyPrecent')}}</th>
                               @endif





                              <th>{{trans('admin.Actions')}}</th>
                           </tr>
                        </thead>
                        <tbody>
                         @foreach($items as $item)
                            @php
                              $details=ProductSales::where('Sales',$item->id)->get();
                              $TotalReturn=ReturnSales::where('Sales',$item->id)->get()->sum('Total_Return_Value');
                            @endphp
                               <tr>
                                     @if($colum->Date == 1)
                                   <td>{{$item->Date}}</td>
                                   @endif

                                         @if($colum->Time == 1)
                                   <td>{{$item->Time}}</td>
                                   @endif

                                         @if($colum->Code == 1)
                                   <td>{{$item->Code}}</td>
                                   @endif

                                         @if($colum->Refrence_Number == 1)
                                   <td>{{$item->Refernce_Number}}</td>
                                   @endif

                                         @if($colum->Branch == 1)
                                   <td>@if(!empty($item->Branch))

                                     {{app()->getLocale() == 'ar' ?$item->Branch()->first()->Arabic_Name :$item->Branch()->first()->English_Name}}

                                       @endif</td>
                                   @endif

                                              @if($colum->Client == 1)
                                   <td>@if(!empty($item->Client))

                             {{app()->getLocale() == 'ar' ?$item->Client()->first()->Name :$item->Client()->first()->NameEn}}

                                       @endif</td>
                                   @endif

                                         @if($colum->Store == 1)
                                   <td>
                                       {{app()->getLocale() == 'ar' ?$item->Store()->first()->Name :$item->Store()->first()->NameEn}}
                                   </td>
                                   @endif

                                         @if($colum->Safe == 1)
                                   <td>
                                       {{app()->getLocale() == 'ar' ?$item->Safe()->first()->Name :$item->Safe()->first()->NameEn}}
                                   </td>
                                   @endif

                                         @if($colum->Type == 1)
                                   <td>
                                   @if($item->Status == 0)
                                       {{trans('admin.Pending')}}
                                    @elseif($item->Status == 1)
                                       {{trans('admin.Recived')}}
                                    @endif
                                   </td>
                                   @endif


                                     @if($colum->Total_Price == 1)
                                   <td>{{$item->Total_Price}}</td>
                                   @endif

                                         @if($colum->Total_Discount == 1)
                                   <td>{{$item->Total_Discount}}</td>
                                   @endif

                                         @if($colum->Total_Tax == 1)
                                   <td>{{$item->Total_Taxes + $item->ProfitTax}}</td>
                                   @endif

                                   @if($colum->Total_Net == 1)
                                   <td>{{($item->Total_Net}}</td>
                                   @endif

                                         @if($colum->Paid == 1)
                                   <td>{{$item->Pay}}</td>
                                   @endif

                                         @if($colum->Residual == 1)
                                   <td>{{(($item->Total_Price +  $item->Total_Taxes + $item->ProfitTax)  - $item->Total_Discount) - $item->Pay}}</td>
                                   @endif

                                   @if($colum->Due_Date == 1)
                                   <td>{{$item->Later_Due}}</td>
                                   @endif

                                         @if($colum->Coin == 1)
                                   <td>  {{app()->getLocale() == 'ar' ?$item->Coin()->first()->Arabic_Name :$item->Coin()->first()->English_Name}}   </td>
                                   @endif

                                         @if($colum->ShiftCode == 1)
                                   <td>{{$item->Shift_Code}}</td>
                                   @endif

                                   @if($colum->Delegate == 1)
                                   <td>@if(!empty($item->Delegate))

                                       {{app()->getLocale() == 'ar' ?$item->Delegate()->first()->Name :$item->Delegate()->first()->NameEn}}

                                       @endif</td>
                                   @endif

                                         @if($colum->Executor == 1)
                                   <td>@if(!empty($item->Executor))

                                     {{app()->getLocale() == 'ar' ?$item->Executor()->first()->Name :$item->Executor()->first()->NameEn}}

                                       @endif</td>
                                   @endif

                                         @if($colum->User == 1)
                                   <td>

                                {{app()->getLocale() == 'ar' ?$item->User()->first()->name :$item->User()->first()->nameEn}}
                                   </td>
                                   @endif

                                   @if($colum->Shipping == 1)
                                   <td>       @if(!empty($item->Ship))
                                           {{app()->getLocale() == 'ar' ?$item->Ship()->first()->Name :$item->Ship()->first()->NameEn}}
                                                    @endif
                                   </td>
                                   @endif

                                   @if($colum->Cost_Center == 1)
                                   <td>
                                       @if(!empty($item->Cost_Center))
                                             {{app()->getLocale() == 'ar' ?$item->Cost_Center()->first()->Arabic_Name :$item->Cost_Center()->first()->English_Name}}
                                                    @endif
                                   </td>
                                   @endif

                                         @if($colum->Total_Return == 1)
                                   <td>{{$TotalReturn}}</td>
                                   @endif

                                         @if($colum->Note == 1)
                                   <td>
                                       <button type="button" class="btn btn-default" data-toggle="modal" data-target="#Note{{$item->id}}">
                                                            {{trans('admin.Note')}}
                                                        </button>
                                   </td>
                                   @endif

                                         @if($colum->InstallCompany == 1)
                                   <td>
                                       @if(!empty($item->InstallCompany))


                                         {{app()->getLocale() == 'ar' ?$item->InstallCompany()->first()->Arabic_Name :$item->InstallCompany()->first()->English_Name}}
                                                    @endif
                                   </td>
                                   @endif
                                             @if($colum->ContractNumber == 1)
                                   <td>{{$item->ContractNumber}}</td>
                                   @endif
                                             @if($colum->PayFees == 1)
                                   <td>{{$item->PayFees}}</td>
                                   @endif
                                             @if($colum->ServiceFee == 1)
                                   <td>{{$item->ServiceFee}}</td>
                                   @endif
                                             @if($colum->CompanyPrecent == 1)
                                   <td>{{$item->CompanyPrecent}}</td>
                                   @endif





                                            <td>

                                  <a href="{{url('SalesPrint/'.$item->id)}}" class="btn btn-default" target="_blank" >
                                                    <i class="fal fa-print"></i>
                                                    </a>
  <a href="{{url('ESBill/'.$item->id)}}" class="btn btn-default" target="_blank" ><i class="fal fa-edit"></i></a>

                                    <button type="button" class="btn btn-default " data-toggle="collapse" data-target="#collapseExample{{$item->id}}" aria-expanded="true" aria-controls="collapseExample">
                                 <a data-toggle="tooltip" data-placement="top" title="  {{trans('admin.More')}}">
                            <i class="fal fa-arrow-circle-down"></i>
                                </a>
                         </button>
                               </td>
                            </tr>
                            <tr>
                              <td colspan="23">
                                 <div class="collapse " id="collapseExample{{$item->id}}" style="background:white">
                                       <table class="">

                                                            <tr>

                            @if($colum->Product_Code == 1)
                              <th>{{trans('admin.Product_Code')}}</th>
                               @endif

                                @if($colum->Product_Name == 1)
                              <th>{{trans('admin.Product_Name')}}</th>
                               @endif
                                @if($colum->Unit == 1)
                              <th>{{trans('admin.Unit')}}</th>
                               @endif

                                @if($colum->Av_Qty == 1)
                              <th>{{trans('admin.Av_Qty')}}</th>
                               @endif
                                @if($colum->Qty == 1)
                              <th>{{trans('admin.Qty')}}</th>
                               @endif

                                @if($colum->Price == 1)
                              <th>{{trans('admin.Price')}}</th>
                               @endif
                                @if($colum->Discount == 1)
                              <th>{{trans('admin.Discount')}}</th>
                               @endif

                                @if($colum->Total_BF_Tax == 1)
                              <th>{{trans('admin.Total_BF_Tax')}}</th>
                               @endif
                                @if($colum->Tax == 1)
                              <th>{{trans('admin.Tax')}}</th>
                               @endif

                                @if($colum->Total == 1)
                              <th>{{trans('admin.Total')}}</th>
                               @endif
                                @if($colum->Group == 1)
                              <th>{{trans('admin.Group')}}</th>
                               @endif

                                @if($colum->Brand == 1)
                              <th>{{trans('admin.Brand')}}</th>
                               @endif
                                @if($colum->Exp_Date == 1)
                              <th>{{trans('admin.Exp_Date')}}</th>
                               @endif

                                @if($colum->Product_Store == 1)
                              <th>{{trans('admin.Store')}}</th>
                               @endif

                                                            </tr>

                                                        <tbody>
                                                            @foreach($details as $detail)
                                                            <tr>

                            @if($colum->Product_Code == 1)
                                 <td>{{$detail->Product_Code}}</td>
                               @endif

                                @if($colum->Product_Name == 1)
                              <td>

                             {{app()->getLocale() == 'ar' ?$detail->Product()->first()->P_Ar_Name :$detail->Product()->first()->P_En_Name}}


                                @if(!empty($detail->V1))

                                 ({{app()->getLocale() == 'ar' ?$detail->V1()->first()->Name :$detail->V1()->first()->NameEn}})
                                  @endif
                                  @if(!empty($detail->V2))

                                       ({{app()->getLocale() == 'ar' ?$detail->V2()->first()->Name :$detail->V2()->first()->NameEn}})
                                  @endif
                                    </td>
                               @endif
                                @if($colum->Unit == 1)
                           <td>

                     {{app()->getLocale() == 'ar' ?$detail->Unit()->first()->Name :$detail->Unit()->first()->NameEn}}
                                </td>
                               @endif

                                @if($colum->Av_Qty == 1)
                            <td>{{$detail->AvQty}}</td>
                               @endif
                                @if($colum->Qty == 1)
                              <td>{{$detail->Qty}}</td>
                               @endif

                                @if($colum->Price == 1)
                            <td>{{$detail->Price}}</td>
                               @endif
                                @if($colum->Discount == 1)
                               <td>{{$detail->Discount}}</td>
                               @endif

                                @if($colum->Total_BF_Tax == 1)
                            <td>{{$detail->Total_Bf_Tax}}</td>
                               @endif
                                @if($colum->Tax == 1)
                           <td>{{$detail->Total_Tax}}</td>
                               @endif

                                @if($colum->Total == 1)
                           <td>{{$detail->Total}}</td>
                               @endif
                                @if($colum->Group == 1)
                                 <td>


                                 {{app()->getLocale() == 'ar' ?$detail->Group()->first()->Name :$detail->Group()->first()->NameEn}}
                                    </td>
                               @endif

                                @if($colum->Brand == 1)
                           <td>
                                            @if(!empty($detail->Product()->first()->Brand))


                                   {{app()->getLocale() == 'ar' ?$detail->Product()->first()->Brand()->first()->Name :$detail->Product()->first()->Brand()->first()->NameEn}}
                                            @endif
                                    </td>
                               @endif
                                @if($colum->Exp_Date == 1)
                            <td>{{$detail->Exp_Date}}</td>
                               @endif

                                @if($colum->Product_Store == 1)
                                <td>

                             {{app()->getLocale() == 'ar' ?$detail->Store()->first()->Name :$detail->Store()->first()->NameEn}}
                            </td>
                               @endif

                                                            </tr>
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                                </div>
                                   </td>
                           </tr>
                          @endforeach
                        </tbody>
                     </table>
                  </div>
                   {{$items->Links()}}
                  <!-- datatable end -->

                       <div style="overflow:auto;">
                     <table style="    background: linear-gradient(45deg, #1d1f83, #921b1bde);
color: white;" id="dt-basic-example" class="table table-bordered table-hover table-striped no-print">
                         <tr>
                         <th>{{trans('admin.Bills_Nums')}}</th>
                         <td>{{$Bills_Nums}}</td>

                           <th>{{trans('admin.Total_Qty')}}</th>
                         <td>{{$Total_Qty}}</td>

                            <th>{{trans('admin.Total_Discount')}}</th>
                         <td>{{$Total_Discount}}</td>

                            <th>{{trans('admin.Total_Taxes')}}</th>
                         <td>{{$TotalTax}}</td>

                        </tr>
                               <tr>
                         <th>{{trans('admin.Total_Bills')}}</th>
                         <td>{{$Total_Bills}}</td>

                           <th>{{trans('admin.Total_Net')}}</th>
                         <td>{{$Total_Net}}</td>


                        </tr>
                           </table>
                   </div>
               </div>
            </div>
         </div>
      </div>
   </div>

    @foreach($items as $item)
             <!-- Modal Note -->
    <div class="modal fade" id="Note{{$item->id}}" tabindex="-1" role="dialog" aria-hidden="true">
                        <div class="modal-dialog modal-dialog-centered" role="document">
                            <div class="modal-content">
                                <div class="modal-header">
                                    <h4 class="modal-title">

                                    <div class="row">


                                                {{$item->Note}}



                                                        </div>



                                    </h4>
                                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                        <span aria-hidden="true"><i class="fal fa-times"></i></span>
                                    </button>
                                </div>

                                <div class="modal-footer">
                         <button type="button" class="btn btn-secondary" data-dismiss="modal">{{trans('admin.Close')}}</button>
                                </div>
                            </div>
                        </div>
                    </div>


    @endforeach
</main>
@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',
                            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: '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>
<style>
   @media print {
   /*body * {*/
   /*	visibility: hidden;*/
   /*}*/
   .modal-content * {
   visibility: visible;
   overflow: visible;
   }
   .main-page  {
   display: none!important;
   }
   .modal {
   position: absolute;
   left: 0;
   top:-130px;
   right:0;
   margin: 0;
   padding: 0;
   /*min-height: 550px;*/
   /*visibility: visible;*/
   overflow: visible !important; /* Remove scrollbar for printing. */
   font-size:20px!important;
   }
   .modal-dialog {
   /*visibility: visible !important;*/
   overflow: visible !important; /* Remove scrollbar for printing. */
   }
   body{
   position:relative;
   }
   .no-print ,.page-content{
   display:none!important;
   }
   }
</style>
<!-- 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;
           }

           $("#Emp").select2({
               placeholder: "select...",
               ajax: {
                   type: "GET",
                   dataType: "json",
                   url: "AllEmps",
                   processResults: function (data) {
                       return {
                           results: $.map(data, function (obj, index) {
                               return { id: index, text: obj };
                           }),
                       };

                       console.log(data);
                   },
                   data: function (params) {
                       var query = {
                           search: params.term,
                       };
                       if (params.term == "*") query.items = [];
                       return { json: JSON.stringify(query) };
                   },
               },
           });

           $("#Emp").on("select2:select", function (e) {
               console.log("select done", e.params.data);
           });
       });
   });
</script>


<script>

   var table = $('#X').DataTable(
                {

                    retrieve: true,
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: false,
                    lengthChange: true,
                     pageLength : 10,
                    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',
                             exportOptions: {
                modifier: {
                  page: 'all',
                  search: 'none'
                }
                             },
                            className: 'btn-outline-success btn-sm mr-1'
                        },


                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                                       exportOptions: {
                modifier: {
                  page: 'all',
                  search: 'none'
                },
                             },
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });


</script>

@endpush
