@extends('admin.index')
@section('content')
@php
use App\Models\StoresDefaultData;
$Def=StoresDefaultData::orderBy('id','desc')->first();
use App\Models\DefaultDataShowHide;
$show=DefaultDataShowHide::orderBy('id','desc')->first();
@endphp
  <title>{{trans('admin.Return_Sale_Taransfer_Sure')}}</title>

   <main id="js-page-content" role="main" class="page-content">
                    <ol class="breadcrumb page-breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0);">{{trans('admin.Stores')}} </a></li>
                        <li class="breadcrumb-item active">{{trans('admin.Return_Sale_Taransfer_Sure')}}   </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>
    <form action="{{url('PostApproveReturnSaleStoresTransfers')}}" method="post">
        {!! csrf_field() !!}
         @honeypot
        <input type="hidden" value="{{$R->id}}" name="ID">
        <input type="hidden" value="{{$item->id}}" name="OriginalID">
                    <div class="row">
                        <div class="col-lg-12">
                            <div id="panel-2" class="panel">
                                <div class="panel-hdr">
                                    <h2>
                                        <span class="fw-300"><i> {{trans('admin.Taransfer_Sure')}}  </i></span>
                                    </h2>
                                </div>
                                <div class="panel-container show">
                                  <span id="ex"> @include('admin.layouts.messages')</span>       
                                    <div class="panel-content">
                                <form action="">
                                    <div class="form-row">
                                        <div class="form-group col-lg-3">
                                <label class="form-label" for="simpleinput"> {{trans('admin.Code')}}  </label>
                             <input type="text"  value="{{$item->Code}}" class="form-control " disabled>
                             <input type="hidden" name="Code"  value="{{$item->Code}}">
                                              <input type="hidden" name="Edit"  value="{{$item->Edit}}">
                                        </div>
                                            @if(auth()->guard('admin')->user()->emp == 0)
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                         <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required>
                                        </div>
                                        @else
                                        
                                         @if(auth()->guard('admin')->user()->Date == 1)
                                                     <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                         <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required>
                                        </div>
                                        @else
                                                     <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                         <input type="date" name="Date" value="{{$item->Date}}" class="form-control" required readonly>
                                        </div>
                                        @endif
                                        
                                        @endif
                                        <div class="form-group col-lg-3">
                        <label class="form-label" for="">{{trans('admin.From_Store')}}</label>
             <select class="select2 form-control w-100" id="store" disabled  required>
                                                <option value=""> {{trans('admin.From_Store')}}</option>
                                            @foreach($Stores as $store)    
        <option value="{{$store->id}}" @if($item->From_Store == $store->id) selected @endif>
                    {{app()->getLocale() == 'ar' ?$store->Name :$store->NameEn}}
                 </option>
                                            @endforeach    
                                            </select>
                    <input type="hidden" name="From_Store" value="{{$item->From_Store}}">                        
                                        </div>
                                           <div class="form-group col-lg-3">
                        <label class="form-label" for="">{{trans('admin.To_Store')}}</label>
             <select class="select2 form-control w-100" id="To" disabled required>
                                                <option value=""> {{trans('admin.To_Store')}}</option>
                                            @foreach($Stores as $store)    
            <option value="{{$store->id}}" @if($item->To_Store == $store->id) selected @endif>
                           {{app()->getLocale() == 'ar' ?$store->Name :$store->NameEn}}
                 </option>
                                            @endforeach    
                                            </select>
                                   <input type="hidden" name="To_Store" value="{{$item->To_Store}}">                     
                                        </div>            
                                                @if($Def->Show_Ship == 1)
                                                <div class="form-group col-lg-4">
                                            <label class="form-label" for="">{{trans('admin.Shipping_Compaines')}}</label>
                                            <select class="select2 form-control w-100" disabled>
                                                <option value=""> {{trans('admin.Shipping_Compaines')}}</option>
                                            @foreach($Shippings as $ship)    
                                                <option value="{{$ship->id}}" @if($item->Ship == $ship->id) selected @endif>
                                        {{app()->getLocale() == 'ar' ?$ship->Name :$ship->NameEn}}    
                                                </option>
                                            @endforeach    
                                            </select>
                                                  <input type="hidden" name="Ship" value="{{$item->Ship}}">  
                                        </div>
                                                    <div class="form-group col-lg-4">
                                            <label class="form-label" for="">{{trans('admin.CostShip')}}</label>
                                           <input class="form-control" type="number" step="any" name="CostShip" value="{{$item->CostShip}}" readonly>
                                        </div>
                                        @endif
                             <div class="form-group col-lg-4">
                                            <label class="form-label" for="">{{trans('admin.Coin')}}</label>
                                            <select class="select2 form-control w-100" disabled>
                                                 <option value=""> {{trans('admin.Coin')}}</option>
                                            @foreach($Coins as $coin)    
      <option value="{{$coin->id}}" @if($item->Coin == $coin->id) selected @endif> {{app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name}}</option>
                                            @endforeach 
                                            </select>
                                  <input type="hidden" name="Coin" value="{{$item->Coin}}">  
                                        </div>
                                        
                                                <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Delegate')}}</label>
                                            <select class="select2 form-control w-100" disabled>
                                        <option value="">{{trans('admin.Delegate')}}</option>        
                                            @foreach($Emps as $emp)
                                                <option value="{{$emp->id}}" @if($item->Delegate == $emp->id) selected @endif>
                                                         {{app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn}}         
                                                </option>
                                                @endforeach
                                            </select>
                                                     <input type="hidden" name="Delegate" value="{{$item->Delegate}}">  
                                        </div> 
                                        
                                                                     <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Branch')}}</label>
                                            <select class="select2 form-control w-100" disabled>
                                        <option value="">{{trans('admin.Branch')}}</option>        
                                            @foreach($Branches as $bran)
                                                <option value="{{$bran->id}}" @if($item->Branch == $bran->id) selected @endif>
                                                         {{app()->getLocale() == 'ar' ?$bran->Arabic_Name :$bran->English_Name}}      
                                                </option>
                                                @endforeach
                                            </select>
                                                                          <input type="hidden" name="Branch" value="{{$item->Branch}}">  
                                        </div> 
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Draw')}}</label>
                        <input type="number" step="any" value="{{$item->Draw}}" name="Draw" class="form-control" required readonly>
                                        </div>     
   
                                        <div class="form-group col-lg-12" style="display: none">
                                            <div class="input-items" style="position:relative;">
                   <input type="text" id="search" class="form-control" placeholder="{{trans('admin.Search_For_Products')}}">
                                             <i class="fal fa-barcode-alt" style="position:absolute;top:12px;left:3px;" ></i>
                                            </div>
                                         </div>
                                    
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="col-xl-12">
                        <div id="panel-1" class="panel">
                          
                            <div class="panel-container show">
                                <div class="panel-content">
                                 
                                    <!-- datatable start -->    
                                    <div id="mobile-overflow" style="display: none">
                    <table id="dt-basic-example" class="table table-bordered table-hover table-striped w-100 mobile-width">
                                        <thead>
                                            <tr>
                                                <th> {{trans('admin.Name')}}</th>
                                                <th> {{trans('admin.Unit')}}</th>
                                                <th> {{trans('admin.Code')}}</th>
                                                     @if(auth()->guard('admin')->user()->emp != 0)
                                                
                                                @if(auth()->guard('admin')->user()->cost_price  == 1)
                                                       <th> {{trans('admin.Price')}}</th>
                                                @endif
                                                
                                                @else
                                                       <th> {{trans('admin.Price')}}</th>
                                                @endif
                                         
                                                <th> {{trans('admin.Qty')}}</th>
                                                <th> {{trans('admin.Trans_Qty')}}</th>
                                                <th> {{trans('admin.Return_Qty')}}</th>
                                                <th> {{trans('admin.Actions')}}</th>
                                            </tr>
                                        </thead>
                                        <tbody class="Data">

                                        </tbody>
                                    </table>
                                    </div>
                                    <!-- datatable end -->
                                    <div class="row">
                                        <div class="col-md-12">
                                            <div id="mobile-overflow">
                              <table id="dt" class="table table-bordered table-hover table-striped w-100 mobile-width">
                                            <thead>
                                                <tr>
                                                <th> {{trans('admin.Name')}}</th>
                                                <th> {{trans('admin.Unit')}}</th>     
                                                <th> {{trans('admin.Code')}}</th>
                                                          @if(auth()->guard('admin')->user()->emp != 0)
                                                
                                                @if(auth()->guard('admin')->user()->cost_price  == 1)
                                                       <th> {{trans('admin.Price')}}</th>
                                                @endif
                                                
                                                @else
                                                       <th> {{trans('admin.Price')}}</th>
                                                @endif
                                                <th> {{trans('admin.Qty')}}</th>
                                                <th> {{trans('admin.Trans_Qty')}}</th>
                                                <th> {{trans('admin.Return_Qty')}}</th>
                                                <th> {{trans('admin.Actions')}}</th>
                                                </tr>
                                            </thead>
                                            <tbody id="data-dt">
                                              
                @foreach($Pros as $pro)                
                <tr>
                    <td>
   
                
         {{app()->getLocale() == 'ar' ?$pro->Product()->first()->P_Ar_Name :$pro->Product()->first()->P_En_Name}}        
                
     @if(!empty($pro->V1)) 
                ({{app()->getLocale() == 'ar' ?$pro->V1()->first()->Name :$pro->V1()->first()->NameEn}}) 
        <input type='hidden' name='V_Name[]' value="{{app()->getLocale() == 'ar' ?$pro->V1()->first()->Name :$pro->V1()->first()->NameEn}}">     
        @else
         <input type='hidden' name='V_Name[]' value=''>        
        @endif    
                @if(!empty($pro->V2)) 
              ({{app()->getLocale() == 'ar' ?$pro->V2()->first()->Name :$pro->V2()->first()->NameEn}}) 
            <input type='hidden' name='VV_Name[]' value="{{app()->getLocale() == 'ar' ?$pro->V2()->first()->Name :$pro->V2()->first()->NameEn}}">
                @else
            <input type='hidden' name='VV_Name[]' value=''>
                @endif      
            <input type='hidden' name='P_Ar_Name[]' value='{{$pro->Product()->first()->P_Ar_Name}}'>
            <input type='hidden' name='P_En_Name[]' value='{{$pro->Product()->first()->P_En_Name}}'>
            </td>
            <td>
            <input type='hidden' name='Unit[]' value='{{$pro->Unit}}'>       {{app()->getLocale() == 'ar' ?$pro->Unit()->first()->Name :$pro->Unit()->first()->NameEn}}    
            </td>
            <td>
            <input type='hidden' name='P_Code[]' value='{{$pro->P_Code}}'>{{$pro->P_Code}}
            </td>
             
                    
                                   @if(auth()->guard('admin')->user()->emp != 0)
                                                
                                                @if(auth()->guard('admin')->user()->cost_price  == 1)
                                                    <td>
                <input type='hidden' id="PRICE{{$pro->id}}" name='Price[]' value='{{$pro->Price}}'>
            <input type='hidden' name='OldPrice[]'  value='{{$pro->OldPrice}}'>
                 <input type='hidden' name='Original_Trans_Qty[]'  value='{{$pro->Original_Trans_Qty}}'>
                {{$pro->Price}}
                    
                    </td>
                    
                    @else
                    
                          <input type='hidden' id="PRICE{{$pro->id}}" name='Price[]' value='{{$pro->Price}}'>
            <input type='hidden' name='OldPrice[]'  value='{{$pro->OldPrice}}'>
                 <input type='hidden' name='Original_Trans_Qty[]'  value='{{$pro->Original_Trans_Qty}}'>
                                                @endif
                                                
                                                @else
                                                      <td>
                <input type='hidden' id="PRICE{{$pro->id}}" name='Price[]' value='{{$pro->Price}}'>
            <input type='hidden' name='OldPrice[]'  value='{{$pro->OldPrice}}'>
                 <input type='hidden' name='Original_Trans_Qty[]'  value='{{$pro->Original_Trans_Qty}}'>
                {{$pro->Price}}
                    
                    </td>
                                                @endif
        
                    
                    
            <td><input type='hidden' id="QTY{{$pro->id}}" name='Qty[]'  value='{{$pro->Av_Qty}}'>{{$pro->Av_Qty}}</td>
            <td>
            <input class='form-control' id="TransQTY{{$pro->id}}" type='number' step="any" name='Trans_Qty[]' value='{{$pro->Trans_Qty}}'   readonly>
            <input class='Tota' type='hidden' id="TOTT{{$pro->id}}" name='TotalP[]' value="0">
        <input  type='hidden' class="OLD" value='{{$pro->OldPrice * $pro->Trans_Qty}}'>        
            </td>
                    
           <td>
                <input type='number' step="any" id="ReturnQTY{{$pro->id}}" name='ReturnQty[]' class="form-control RetuQty" onclick="ChangeTRANSQTY({{$pro->id}})"
onkeyup="ChangeTRANSQTY({{$pro->id}})" value="0" >
              </td>    
                    
            <td>
          <input  type='hidden' name='Product[]' value='{{$pro->Product}}'>
            <input type='hidden' name='VOne[]' value='{{$pro->V1}}'>
            <input type='hidden' name='VTwo[]' value='{{$pro->V2}}'>
            <input type='hidden' id="CostQTY{{$pro->id}}" name='CostPrice[]' value='{{$pro->OldPrice}}'>
            <input type='hidden' id="TotCostQTY{{$pro->id}}" value='0' class="COSTA">
            <input type='hidden' id="wrong{{$pro->id}}" value='0' class="WRONG">
          
            </td>
                </tr>                              
                      @endforeach                          
                                                
                                            </tbody>
                                        </table>
                                        </div>
                                        </div>
                                    </div>
                                    <div class="form-row">
                                        
                                                 @if(auth()->guard('admin')->user()->emp != 0)
                                                
                                                @if(auth()->guard('admin')->user()->cost_price  == 1)
                                                               <div class="form-group col-lg-6">
                                  <label class="form-label" for="simpleinput">{{trans('admin.Total_Price_Return_Qty')}}</label>
                                            <input type="text" id="Total" value="{{$item->Total}}" disabled  class="form-control">
                  <input type="hidden" id="TotalHide"  name="Total"  class="form-control">
                  <input type="hidden" id="TotalOld"  name="TotalOld"  class="form-control">
                                        </div> 
                                        @else
                                         <input type="hidden" id="Total" value="{{$item->Total}}" disabled  class="form-control">
                  <input type="hidden" id="TotalHide"  name="Total"  class="form-control">
                  <input type="hidden" id="TotalOld"  name="TotalOld"  class="form-control">       
                                                @endif
                                                
                                                @else
                                                            <div class="form-group col-lg-6">
                                  <label class="form-label" for="simpleinput">{{trans('admin.Total_Price_Return_Qty')}}</label>
                                            <input type="text" id="Total"  disabled  class="form-control">
                  <input type="hidden" id="TotalHide"  name="Total"  class="form-control">
                  <input type="hidden" id="TotalOld"  name="TotalOld"  class="form-control">
                    <input type="hidden" id="Total_Cost" name="Total_Cost"   class="form-control">                                                
                                        </div> 
                                                @endif
                             
                                        
                                        
                                      <div class="form-group col-lg-6">
                                  <label class="form-label" for="simpleinput">{{trans('admin.Total_Return_Qty')}}</label>
                                            <input type="text" id="TotalQty" disabled   class="form-control">
                                    <input type="hidden" id="TotaQtylHide" name="TotalQty"   class="form-control">
                                        </div>              
                                        </div>
                                    
                                   <div class="row">
                                    <div class="form-group col-md-12">
                                        <label class="form-label" for="simpleinput"> {{trans('admin.Notes')}}  </label>

                            <textarea class="js-summernote" id="saveToLocal" name="Note">
                              {{$item->Note}}
                                        </textarea>            
                                    </div>
                                   </div>
                                    <div class="buttons mt-3" id="SUBMIT" style="display: none">
   <button type="submit" id="Submit" class="btn btn-primary"> <i class="fal fa-folder"></i> {{trans('admin.Save')}} </button>
                                      </div>
                                </div>
                            </div>
                        </div>
                    </div>



                    </div>
        </form> 
                </main>

<input type="hidden" id="Open" value="{{$Def->StoresTarnsferPrice}}">
@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.bundle.js')}}"></script>
    <script src="{{asset('Admin/js/datagrid/datatables/datatables.export.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/summernote/summernote.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/select2/select2.bundle.js')}}"></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>

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

<!-- Change QTY -->
<script>
 function ChangeTRANSQTY(r){
     
     var QTY= $('#TransQTY'+r).val();
     var TransQTY= $('#ReturnQTY'+r).val();
     var PRICE= $('#PRICE'+r).val();
     var CostQTY= $('#CostQTY'+r).val();
     

     
     if(parseFloat(TransQTY) > parseFloat(QTY)){
         
         document.getElementById('SUBMIT').style.display='none';
         $('#wrong'+r).val(1);
         
     }else{
         document.getElementById('SUBMIT').style.display='block';
          $('#wrong'+r).val(0);
         
     }
     
     var Result = parseFloat(PRICE) * parseFloat(TransQTY) ;
     var ResultCost = parseFloat(CostQTY) * parseFloat(TransQTY) ;
     
     $('#TOTT'+r).val(parseFloat(Result));
     
     $('#TotCostQTY'+r).val(parseFloat(ResultCost));
     
     
     
        $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
  var rowctr = $('#dt').rowCount();     
                
   
    var sumTE = 0;        
$('.Tota').each(function(){
  sumTE += parseFloat($(this).val());
});   
       
    var sumTQ = 0;        
$('.RetuQty').each(function(){
  sumTQ += parseFloat($(this).val());
});             
 
   
         var WRONGA = 0;        
$('.WRONG').each(function(){
  WRONGA += parseFloat($(this).val());
});  
     
         var sumCostQ = 0;        
$('.COSTA').each(function(){
  sumCostQ += parseFloat($(this).val());
});       
     
 $('#Total_Cost').val(parseFloat(sumCostQ));
 $('#Total').val(parseFloat(sumTE));
 $('#TotalHide').val(parseFloat(sumTE));
 $('#TotalQty').val(parseFloat(sumTQ));
 $('#TotaQtylHide').val(parseFloat(sumTQ));


 if(parseFloat(WRONGA) > 0){
         
         document.getElementById('SUBMIT').style.display='none';

         
     }else{
         document.getElementById('SUBMIT').style.display='block';

         
     }
     
     
 }
</script>


@endpush