@extends('admin.index')
@section('content')
@php
use App\Models\ProductUnits;
use App\Models\ProductsPurchases;
use App\Models\ProductsStoresTransfers;
use App\Models\ProductsStartPeriods;
use App\Models\OutcomManufacturingModel;
use App\Models\Measuerments;
use App\Models\StoresDefaultData;
use App\Models\FifoQty;
use App\Services\Average;
$average=new Average();
@endphp

<title> {{trans('admin.StoresCost')}}</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.StoresCost')}} </li>
      <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
         class="js-get-date"></span></li>
   </ol>
   <!-- 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.StoresCost')}}
               </h2>
               <div class="panel-toolbar">
                  <button class="btn btn-primary btn-sm" data-toggle="dropdown">Table
                  Style</button>

              <form action="{{url('StoresCostNewPrint')}}" 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($group))

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

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

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

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



                  <input type="hidden" name="Branch" value="{{$branch}}">
                  <input type="hidden" name="Product_Name" value="{{$product_Name}}">
                  <input type="hidden" name="Product_Code" value="{{$product_Code}}">


                  </div>

                     <button type="submit" class="btn btn-primary btn-sm" >
                                                    <i class="fal fa-print">{{trans('admin.Print')}}</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 class="over-flow">
                                        <table id="X"
                                            class="table table-bordered table-hover table-striped table-width">
                                            <thead class="bg-highlight">
                                                       <tr>
                                                     <th>{{trans('admin.Code')}} </th>
                                                    <th>{{trans('admin.Name')}} </th>
                                                    <th>{{trans('admin.Unit')}} </th>
                                                    <th>{{trans('admin.Qty')}} </th>
                                                    <th>{{trans('admin.Avg_Purch')}} </th>
                                                    <th>{{trans('admin.Cost')}} </th>
                                                </tr>
                                            </thead>

                                            <tbody>
                                                @foreach($items as $rows)
                                             @php
                                              $units=ProductUnits::where('Product',$rows->Product)->get();
            $rr=ProductUnits::where('Product',$rows->Product)->where('Def',1)->first();
  $plow=ProductUnits::where('Product',$rows->Product)->where('Rate',1)->first();


$Average=$average->AverageCostGetUnit($rows->Product,$plow->Barcode,$store,$plow->Unit);
$Cost=$Average;
$SMallAverage=$Average;

                                            @endphp


             @if($rows->Product()->first()->P_Type == 'Completed' or $rows->Product()->first()->P_Type == 'Raw' or $rows->Product()->first()->P_Type == 'Industrial')
       <tr>

       <td>
      <input type="text" id="CodeStart{{$rows->id}}" class="form-control" value="{{$rr->Barcode}}"  disabled>
      <input type="hidden" id="Product{{$rows->id}}"  value="{{$rows->Product}}" >
      <input type="hidden" id="Store{{$rows->id}}"  value="{{$rows->Store}}" >
       </td>

        <td>


             {{app()->getLocale() == 'ar' ?$rows->P_Ar_Name :$rows->P_En_Name}}
            @if(!empty($rows->Product()->first()->Space))  ({{$rows->Product()->first()->Space}}) @endif
            @if(!empty($rows->Product()->first()->Storage))  ({{$rows->Product()->first()->Storage}}) @endif
            @if(!empty($rows->Product()->first()->Processor))  ({{$rows->Product()->first()->Processor}}) @endif
            @if(!empty($rows->Product()->first()->Camera))  ({{$rows->Product()->first()->Camera}}) @endif
            @if(!empty($rows->Product()->first()->Screen))  ({{$rows->Product()->first()->Screen}}) @endif
            @if(!empty($rows->Product()->first()->OS))  ({{$rows->Product()->first()->OS}}) @endif
            @if(!empty($rows->Product()->first()->Battery))  ({{$rows->Product()->first()->Battery}}) @endif
            @if(!empty($rows->Product()->first()->Warranty))  ({{$rows->Product()->first()->Warranty}}) @endif
            @if(!empty($rows->Product()->first()->Color))  ({{$rows->Product()->first()->Color}}) @endif
            @if(!empty($rows->Product()->first()->Category))  ({{$rows->Product()->first()->Category}}) @endif
            @if(!empty($rows->Product()->first()->Model))  ({{$rows->Product()->first()->Model}}) @endif
        </td>

        <td>
             <select class="select2 form-control w-100"   id="UnitStart{{$rows->id}}" onchange="UnitCodeStartt({{$rows->id}})">
                <option value="">{{trans('admin.Choice_Unit')}}</option>

            @foreach($units as $uni)
              @php  $nam=Measuerments::find($uni->Unit); @endphp

                 @if(app()->getLocale() == 'ar')
                 $naame=$nam->Name;
                 @else
                  $naame=$nam->NameEn;
                 @endif

            <option value="{{$uni->Unit}}";  @if($uni->Def == 1)   selected  @endif > {{$naame}}</option>
                        @endforeach
                        </select>
        </td>


         <td>
      <input type="text" id="Qty{{$rows->id}}" class="form-control Qun" value="{{$rows->Qty / $rr->Rate}}"  disabled>
       </td>


       <td>
       <input type="text" disabled id="AVG{{$rows->id}}" class="form-control" value="{{number_format((float)abs($Average), 2, '.', '')}}" >
<input type="hidden" disabled id="SMALLAVG{{$rows->id}}" value="{{number_format((float)abs($SMallAverage), 2, '.', '')}}" >
       </td>


           <td>
    <input type="text" id="COST{{$rows->id}}" disabled  class="form-control Tot" value="{{number_format((float)abs($Cost), 2, '.', '')}}" >
       </td>


        </tr>



        @elseif($rows->Product()->first()->P_Type == 'Serial')



       <tr>

       <td>
           <input type="text" id="CodeStart{{$rows->id}}" class="form-control" value="{{$rows->P_Code}}"  disabled>
      <input type="hidden" id="Product{{$rows->id}}"  value="{{$rows->Product}}" >
              <input type="hidden" id="Store{{$rows->id}}"  value="{{$rows->Store}}" >
       </td>

          <td>
     {{app()->getLocale() == 'ar' ?$rows->P_Ar_Name :$rows->P_En_Name}}
            @if(!empty($rows->Product()->first()->Space))  ({{$rows->Product()->first()->Space}}) @endif
            @if(!empty($rows->Product()->first()->Storage))  ({{$rows->Product()->first()->Storage}}) @endif
            @if(!empty($rows->Product()->first()->Processor))  ({{$rows->Product()->first()->Processor}}) @endif
            @if(!empty($rows->Product()->first()->Camera))  ({{$rows->Product()->first()->Camera}}) @endif
            @if(!empty($rows->Product()->first()->Screen))  ({{$rows->Product()->first()->Screen}}) @endif
            @if(!empty($rows->Product()->first()->OS))  ({{$rows->Product()->first()->OS}}) @endif
            @if(!empty($rows->Product()->first()->Battery))  ({{$rows->Product()->first()->Battery}}) @endif
            @if(!empty($rows->Product()->first()->Warranty))  ({{$rows->Product()->first()->Warranty}}) @endif
            @if(!empty($rows->Product()->first()->Color))  ({{$rows->Product()->first()->Color}}) @endif
            @if(!empty($rows->Product()->first()->Category))  ({{$rows->Product()->first()->Category}}) @endif
            @if(!empty($rows->Product()->first()->Model))  ({{$rows->Product()->first()->Model}}) @endif
        </td>

        <td>
             <select class="select2 form-control w-100"   id="UnitStart{{$rows->id}}" onchange="UnitCodeStartt({{$rows->id}})">
                <option value="">  {{trans('admin.Choice_Unit')}}</option>

            @foreach($units as $uni)
                @php  $nam=Measuerments::find($uni->Unit); @endphp




     @if(app()->getLocale() == 'ar')
                 $naame=$nam->Name;
                 @else
                  $naame=$nam->NameEn;
                 @endif

            <option value="{{$uni->Unit}}";  @if($uni->Def == 1)   selected  @endif > {{$naame}}</option>
                        @endforeach
                        </select>
        </td>


         <td>
      <input type="text" id="Qty{{$rows->id}}" class="form-control Qun" value="{{$rows->Qty / $rr->Rate}}"  disabled>
       </td>


       <td>
       <input type="text" disabled id="AVG{{$rows->id}}" class="form-control" value="{{number_format((float)abs($Average), 2, '.', '')}}" >
<input type="hidden" disabled id="SMALLAVG{{$rows->id}}" value="{{number_format((float)abs($SMallAverage), 2, '.', '')}}" >
       </td>


           <td>
    <input type="text" id="COST{{$rows->id}}" disabled  class="form-control Tot" value="{{number_format((float)abs($Cost), 2, '.', '')}}" >
       </td>
        </tr>


        @elseif($rows->Product()->first()->P_Type == 'Single_Variable')



       <tr>

       <td>

                  <input type="text" id="CodeStart{{$rows->id}}" class="form-control" value="{{$rows->P_Code}}"  disabled>
      <input type="hidden" id="Product{{$rows->id}}"  value="{{$rows->Product}}" >
              <input type="hidden" id="Store{{$rows->id}}"  value="{{$rows->Store}}" >
       </td>


         <td>

             {{app()->getLocale() == 'ar' ?$rows->P_Ar_Name :$rows->P_En_Name}}      {{app()->getLocale() == 'ar' ?$rows->V1()->first()->Name :$rows->V1()->first()->NameEn}}
            @if(!empty($rows->Product()->first()->Space))  ({{$rows->Product()->first()->Space}}) @endif
            @if(!empty($rows->Product()->first()->Storage))  ({{$rows->Product()->first()->Storage}}) @endif
            @if(!empty($rows->Product()->first()->Processor))  ({{$rows->Product()->first()->Processor}}) @endif
            @if(!empty($rows->Product()->first()->Camera))  ({{$rows->Product()->first()->Camera}}) @endif
            @if(!empty($rows->Product()->first()->Screen))  ({{$rows->Product()->first()->Screen}}) @endif
            @if(!empty($rows->Product()->first()->OS))  ({{$rows->Product()->first()->OS}}) @endif
            @if(!empty($rows->Product()->first()->Battery))  ({{$rows->Product()->first()->Battery}}) @endif
            @if(!empty($rows->Product()->first()->Warranty))  ({{$rows->Product()->first()->Warranty}}) @endif
            @if(!empty($rows->Product()->first()->Color))  ({{$rows->Product()->first()->Color}}) @endif
            @if(!empty($rows->Product()->first()->Category))  ({{$rows->Product()->first()->Category}}) @endif
            @if(!empty($rows->Product()->first()->Model))  ({{$rows->Product()->first()->Model}}) @endif
        </td>

        <td>
             <select class="select2 form-control w-100"   id="UnitStart{{$rows->id}}" onchange="UnitCodeStart({{$rows->id}})">
                <option value="">  {{trans('admin.Choice_Unit')}}</option>
            @foreach($units as $uni)
              @php  $nam=Measuerments::find($uni->Unit); @endphp

                   @if(app()->getLocale() == 'ar')
                 $naame=$nam->Name;
                 @else
                  $naame=$nam->NameEn;
                 @endif
            <option value="{{$uni->Unit}}";  @if($uni->Def == 1)   selected  @endif > {{$naame}}</option>
                        @endforeach
                        </select>
        </td>



        <td>
      <input type="text" id="Qty{{$rows->id}}" class="form-control Qun" value="{{$rows->Qty / $rr->Rate}}"  disabled>
       </td>


       <td>
       <input type="text" disabled id="AVG{{$rows->id}}" class="form-control" value="{{number_format((float)abs($Average), 2, '.', '')}}" >
<input type="hidden" disabled id="SMALLAVG{{$rows->id}}" value="{{number_format((float)abs($SMallAverage), 2, '.', '')}}" >
       </td>


           <td>
    <input type="text" id="COST{{$rows->id}}" disabled  class="form-control Tot" value="{{number_format((float)abs($Cost), 2, '.', '')}}" >
       </td>

        </tr>


        @elseif($rows->Product()->first()->P_Type == 'Duble_Variable')



       <tr>

       <td>

                  <input type="text" id="CodeStart{{$rows->id}}" class="form-control" value="{{$rows->P_Code}}"  disabled>
      <input type="hidden" id="Product{{$rows->id}}"  value="{{$rows->Product}}" >
              <input type="hidden" id="Store{{$rows->id}}"  value="{{$rows->Store}}" >
       </td>


     <td>
     {{app()->getLocale() == 'ar' ?$rows->P_Ar_Name :$rows->P_En_Name}}      {{app()->getLocale() == 'ar' ?$rows->V1()->first()->Name :$rows->V1()->first()->NameEn}}
 {{app()->getLocale() == 'ar' ?$rows->V2()->first()->Name :$rows->V2()->first()->NameEn}}
            @if(!empty($rows->Product()->first()->Space))  ({{$rows->Product()->first()->Space}}) @endif
            @if(!empty($rows->Product()->first()->Storage))  ({{$rows->Product()->first()->Storage}}) @endif
            @if(!empty($rows->Product()->first()->Processor))  ({{$rows->Product()->first()->Processor}}) @endif
            @if(!empty($rows->Product()->first()->Camera))  ({{$rows->Product()->first()->Camera}}) @endif
            @if(!empty($rows->Product()->first()->Screen))  ({{$rows->Product()->first()->Screen}}) @endif
            @if(!empty($rows->Product()->first()->OS))  ({{$rows->Product()->first()->OS}}) @endif
            @if(!empty($rows->Product()->first()->Battery))  ({{$rows->Product()->first()->Battery}}) @endif
            @if(!empty($rows->Product()->first()->Warranty))  ({{$rows->Product()->first()->Warranty}}) @endif
            @if(!empty($rows->Product()->first()->Color))  ({{$rows->Product()->first()->Color}}) @endif
            @if(!empty($rows->Product()->first()->Category))  ({{$rows->Product()->first()->Category}}) @endif
            @if(!empty($rows->Product()->first()->Model))  ({{$rows->Product()->first()->Model}}) @endif
        </td>

        <td>
             <select class="select2 form-control w-100"   id="UnitStart{{$rows->id}}" onchange="UnitCodeStart({{$rows->id}})">
                <option value="">    {{trans('admin.Choice_Unit')}}</option>
            @foreach($units as $uni)
              @php  $nam=Measuerments::find($uni->Unit); @endphp

         @if(app()->getLocale() == 'ar')
                 $naame=$nam->Name;
                 @else
                  $naame=$nam->NameEn;
                 @endif

            <option value="{{$uni->Unit}}";  @if($uni->Def == 1)   selected  @endif > {{$naame}}</option>
                        @endforeach
                        </select>
        </td>



        <td>
      <input type="text" id="Qty{{$rows->id}}" class="form-control Qun" value="{{$rows->Qty / $rr->Rate}}"  disabled>
       </td>


       <td>
       <input type="text" disabled id="AVG{{$rows->id}}" class="form-control" value="{{number_format((float)abs($Average), 2, '.', '')}}" >
<input type="hidden" disabled id="SMALLAVG{{$rows->id}}" value="{{number_format((float)abs($SMallAverage), 2, '.', '')}}" >
       </td>


           <td>
    <input type="text" id="COST{{$rows->id}}" disabled  class="form-control Tot" value="{{number_format((float)abs($Cost), 2, '.', '')}}" >
       </td>

        </tr>


              @endif








                                                @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">
                         <tr>
                                                    <td> {{trans('admin.Products_Num')}} </td>
                                                    <td>{{$Products_Num}}</td>
                                                    <td> {{trans('admin.Total_Qty')}}</td>
                                                    <td>{{$Total_Qty}}</td>

                                                </tr>
                                                <tr>
                  <td style="text-align: center; font-size: 200%; " colspan="2">{{trans('admin.Total_Cost')}}  </td>
                  <td style="text-align: center; font-size: 200%;" colspan="2" id="TOTALCOST">{{$Total_Cost}}</td>


                                                </tr>

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


</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>


   <!-- Unit Code and Name V -->
   <script>
       function  UnitCodeStart(x){

           var countryId = $('#UnitStart'+x).val();
           var Pro = $('#Product'+x).val();
           var code = $('#CodeStart'+x).val();
           var Small = $('#SMALLAVG'+x).val();
           var store = $('#Store').val();
           if(countryId) {
               $.ajax({
                   url: 'UnitNameCodeInventoryFilterTWO',
                   type:"GET",
                   data:{
                       id:countryId,
                       Pro:Pro,
                       code:code,
                       store:store,
                       small:Small,
                   },
                   dataType:"json",
                   beforeSend: function(){
                       $('#loader').css("visibility", "visible");
                   },

                   success:function(data) {
                       $.each(data, function(key, value){

                           $('#Qty'+x).val(data.qty);
                           $('#AVG'+x).val(parseFloat(data.price));
                           var AVG=  $('#AVG'+x).val();
                           var Qty=  $('#Qty'+x).val();

                           var Rsu = parseFloat(Qty) * parseFloat(AVG) ;

                           $('#COST'+x).val(parseFloat(Rsu));



                           $.fn.rowCount = function() {
                               return $('tr', $(this).find('tbody')).length;
                           };

                           var rowctr = $('#X').rowCount();

                           var sumQ = 0;
                           $('.Qun').each(function(){
                               sumQ += parseFloat($(this).val());
                           });

                           var sumT = 0;
                           $('.Tot').each(function(){
                               sumT += parseFloat($(this).val());
                           });

                           $('#PRONUMS').text(parseFloat(rowctr));
                           $('#TOTALQTY').text(parseFloat(sumQ));
                           $('#TOTALCOST').text(parseFloat(sumT));

                       });

                   },
                   complete: function(){
                       $('#loader').css("visibility", "hidden");
                   }
               });
           } else {

               $('select[name="state"]').empty();
           }

       }
   </script>

   <!-- Unit Code and Name -->
   <script>
       function  UnitCodeStartt(x){

           var countryId = $('#UnitStart'+x).val();
           var Pro = $('#Product'+x).val();
           var code = $('#CodeStart'+x).val();
           var store = $('#Store').val();
           var Small = $('#SMALLAVG'+x).val();
           if(countryId) {
               $.ajax({
                   url: 'UnitNameCodeInventoryFilterTWO',
                   type:"GET",
                   data:{
                       id:countryId,
                       Pro:Pro,
                       code:code,
                       store:store,
                       small:Small,
                   },
                   dataType:"json",
                   beforeSend: function(){
                       $('#loader').css("visibility", "visible");
                   },

                   success:function(data) {
                       $.each(data, function(key, value){

                           $('#Qty'+x).val(data.qty);
                           $('#CodeStart'+x).val(data.code);
                           $('#AVG'+x).val(parseFloat(data.price));
                           var AVG=  $('#AVG'+x).val();
                           var Qty=  $('#Qty'+x).val();

                           var Rsu = parseFloat(Qty) * parseFloat(AVG) ;

                           $('#COST'+x).val(parseFloat(Rsu));

                           $.fn.rowCount = function() {
                               return $('tr', $(this).find('tbody')).length;
                           };

                           var rowctr = $('#X').rowCount();

                           var sumQ = 0;
                           $('.Qun').each(function(){
                               sumQ += parseFloat($(this).val());
                           });

                           var sumT = 0;
                           $('.Tot').each(function(){
                               sumT += parseFloat($(this).val());
                           });

                           $('#PRONUMS').text(parseFloat(rowctr));
                           $('#TOTALQTY').text(parseFloat(sumQ));
                           $('#TOTALCOST').text(parseFloat(sumT));


                       });

                   },
                   complete: function(){
                       $('#loader').css("visibility", "hidden");
                   }
               });
           } else {

               $('select[name="state"]').empty();
           }

       }
   </script>


@endpush
