@extends('admin.index')
@section('content')
   @php
use App\Models\DefaultDataShowHide;
$show=DefaultDataShowHide::orderBy('id','desc')->first();
@endphp
  <title>{{trans('admin.Manufacturing_Request')}}</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.Manufacturing')}} </a></li>
                        <li class="breadcrumb-item active">{{trans('admin.Manufacturing_Request')}} </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>
        
    <form id="form" action="{{url('AddManufacturingRequest')}}" method="post" enctype="multipart/form-data">
        {!! csrf_field() !!}
               @honeypot
                    <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.Manufacturing_Request')}}  </i></span>
                                    </h2>
                                </div>
                                <div class="panel-container show">
                                      <span id="ex"> @include('admin.layouts.messages')</span> 
                                    <div class="panel-content">
                                    <div class="form-row">
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Code')}} </label>
                                            <input type="text" value="{{$Code}}" class="form-control " disabled>
                                            <input type="hidden" name="Code" value="{{$Code}}" class="form-control">
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Date')}}</label>
                           <input type="date" name="Date" value="{{date('Y-m-d')}}" class="form-control" required>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> {{trans('admin.Payment_Method')}}</label>
         <select class="select2 form-control w-100" name="Payment_Method" id="Payment_Method" onchange="Statuss()" required>
                         <option value="Cash">{{trans('admin.Cash')}} </option>
                         <option value="Later">{{trans('admin.Later')}}</option>
                         <option value="Check">{{trans('admin.Check')}}</option>
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Store')}}</label>
                                            <select class="select2 form-control w-100" id="store" name="Store" required>
                                       <option value="">{{trans('admin.Store')}}</option>
                                            @foreach($Stores as $stor)    
                                                <option value="{{$stor->id}}">
                                      
                                     {{app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn}}                
                                                </option>
                                            @endforeach    
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="">{{trans('admin.Delegate')}}</label>
                                            <select class="select2 form-control w-100" name="Delegate" id="Delegate">
                                          <option value=""> {{trans('admin.Delegate')}}</option>
                                            @foreach($Employess as $emp)    
                                                <option value="{{$emp->id}}">
              
                                               {{app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn}}                    
                                                </option>
                                            @endforeach  
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Delegate_Phone')}}</label>
                           <input type="number"  id="Delegate_Phone" class="form-control" disabled>
                           <input type="hidden" name="Delegate_Phone" id="Delegate_PhoneHide">
                                        </div>
                                        <div class="form-group col-lg-2">
                                <label class="form-label" for="simpleinput">{{trans('admin.Recived_Date')}}</label>
                     <input type="date" name="Recived_Date" value="{{old('Recived_Date')}}" class="form-control">
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="">{{trans('admin.Client')}}</label>
                                            <select  class="select2 form-control w-100" id="Client" name="Client" required>
                                <option value="">{{trans('admin.Client')}}</option>                
                                        @foreach($Clients as $client)
                                        <option value="{{$client->id}}">
                                    {{app()->getLocale() == 'ar' ?$client->Name :$client->NameEn}}              
                                                </option>                     
                                        @endforeach                                        
                                            </select>          
                                        </div>
                    <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Client_Phone')}}</label>
                           <input type="number" name="Client_Phone"  id="Client_Phone" class="form-control">
                       <!--   <input type="hidden" name="Client_Phone" id="Client_PhoneHide"> -->
                                        </div>
                 <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Client_Address')}}</label>
                           <input type="text" name="Client_Address"   id="Client_Address" class="form-control">
                          <!--     <input type="hidden" name="Client_Address" id="Client_AddressHide">  -->
                                        </div>    
                                        <div class="form-group col-lg-2">
                                 <label class="form-label" for="simpleinput"> {{trans('admin.Account_Credit')}} </label>
                             <input type="text" id="AccountCredit" value="0" class="form-control " disabled>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Notes')}}  </label>
                                            <input type="text" name="Note" value="{{old('Note')}}" class="form-control">
                                        </div>
                                    </div>
                                        
                                            <div  id="LATER" style="display: none">
                                             <div class="form-group col-lg-12">
                                            <label class="form-label" for="simpleinput">{{trans('admin.Later_Due')}}</label>
                           <input type="date" name="Later_Due" class="form-control" value="{{old('Later_Due')}}">
                                        </div>         

                                        </div>    
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="col-xl-12">
                        <div id="panel-1" class="panel">
                            
                            <div class="form-group col-lg-12">
                                <label class="form-label" for="simpleinput">  </label>
                                <div class="input-items" style="position:relative;">
                 <input type="text" id="search" class="form-control" placeholder="{{trans('admin.Search_For_Products')}}">
                             
                                      @if(app()->getLocale() == 'ar' )
                     <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;left:3px;"></i>
                      @else
                            <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;right: 0;left:auto;"></i>
                      @endif
                                </div>
                             </div>
                           
                            <div class="panel-container show">
                                <div class="panel-content">
                                    <div id="mobile-overflow">
                                    <table 
                                    class="table table-bordered table-hover table-striped w-100 mobile-width-more table-color1">
                                    <thead>
                                        <tr>
                                            <th>{{trans('admin.Name')}}</th>
                                            <th style="padding:12px 20px;">{{trans('admin.Unit')}}</th>
                                            <th>{{trans('admin.Code')}}</th>
                                            <th>{{trans('admin.Qty')}}</th>
                                            
                                        @if(auth()->guard('admin')->user()->emp == 0)  
                                                   <th>{{trans('admin.Price')}}</th>
                                            <th>{{trans('admin.Discount')}}</th>
                                                        @else    
                                     @if(auth()->guard('admin')->user()->cost_price_purch == 1) 
                                                   <th>{{trans('admin.Price')}}</th>
                                            <th>{{trans('admin.Discount')}}</th>
                                            @endif
                                            @endif          
                                            <th style="padding:12px 20px;">{{trans('admin.Store')}}</th>
                                                   @if($show->Expire_Date == 1) 
                                            <th>{{trans('admin.Exp_Date')}}</th> 
                                            @endif
                                            <th>{{trans('admin.Actions')}}</th>
                                        </tr>
                                    </thead>
                                    <tbody class="Data" id="Data">
                                       
                                    </tbody>
                                    </table>
                                    </div>
                                    <!-- datatable start -->
                                     <div id="mobile-overflow">
                                    <table id="dt"
                                        class="table table-bordered table-hover table-striped w-100 mobile-width table-color2">
                                        <thead>
                                            <tr>
                                            <th>{{trans('admin.Name')}}</th>
                                            <th>{{trans('admin.Unit')}}</th>
                                            <th>{{trans('admin.Code')}}</th>
                                            <th>{{trans('admin.Qty')}}</th>    
                                                
                                              @if(auth()->guard('admin')->user()->emp == 0)    
                                                <th>{{trans('admin.Price')}}</th>
                                            <th>{{trans('admin.Discount')}}</th>
                                            <th>{{trans('admin.Total_Bf_Taxes')}}</th>
                                            <th>{{trans('admin.Tax')}}</th>
                                            <th>{{trans('admin.Total')}}</th>
                                                @else    
                                     @if(auth()->guard('admin')->user()->cost_price_purch == 1) 
                                                <th>{{trans('admin.Price')}}</th>
                                            <th>{{trans('admin.Discount')}}</th>
                                            <th>{{trans('admin.Total_Bf_Taxes')}}</th>
                                            <th>{{trans('admin.Tax')}}</th>
                                            <th>{{trans('admin.Total')}}</th>
                                                @endif
                                @endif          
      
                                                
                                            <th>{{trans('admin.Store')}}</th>
                                            @if($show->Expire_Date == 1) 
                                            <th>{{trans('admin.Exp_Date')}}</th> 
                                            @endif
                                            <th>{{trans('admin.Actions')}}</th>
                                            </tr>
                                        </thead>
                                        <tbody id="data-dt">
                                         
                                           
                                        </tbody>
                                    </table>
                                    </div>
                                    <!-- datatable end -->
                                    <div class="form-row">
                                        <div class="form-group col-lg-4">
                                 <label class="form-label" for="simpleinput"> {{trans('admin.Product_Numbers')}} </label>
                      <input type="text" id="Product_Numbers" disabled  class="form-control">
                      <input type="hidden" id="Product_NumbersHide" name="Product_Numbers">
                                        </div>
                                        <div class="form-group col-lg-4">
                         <label class="form-label" for="simpleinput"> {{trans('admin.Total_Qty')}} </label>
                                           <input type="text" id="Total_Qty" disabled  class="form-control">
                                            <input type="hidden" id="Total_QtyHide" name="Total_Qty">
                                        </div>
                                        
                                        
                                                   @if(auth()->guard('admin')->user()->emp == 0)   
                                              <div class="form-group col-lg-4">
                                  <label class="form-label" for="simpleinput"> {{trans('admin.Total_Discount')}}  </label>
                                         <input type="text" id="Total_Discount" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHide" name="Total_Discount">
                                        </div>
                                        <div class="form-group col-lg-3">
                        <label class="form-label" for="simpleinput">   {{trans('admin.Total_Bf_Taxes')}} </label>
                                          <input type="text" id="Total_Bf_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_Bf_TaxesHide" name="Total_BF_Taxes">
                                        </div>
                                        <div class="form-group col-lg-3">
                          <label class="form-label" for="simpleinput">   {{trans('admin.Total_Taxes')}}</label>
                                         <input type="text" id="Total_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_TaxesHide" name="Total_Taxes">
                                        </div>
                                        <div class="form-group col-lg-3">
                       <label class="form-label" for="simpleinput">  {{trans('admin.Total_Price')}}</label>
                                   <input type="text" id="Total_Price" disabled  class="form-control">
                                            <input type="hidden" id="Total_PriceHide" name="Total_Price">
                                        </div>

                                            @else    
                                     @if(auth()->guard('admin')->user()->cost_price_purch == 1) 
                                           <div class="form-group col-lg-4">
                                  <label class="form-label" for="simpleinput"> {{trans('admin.Total_Discount')}}  </label>
                                         <input type="text" id="Total_Discount" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHide" name="Total_Discount">
                                        </div>
                                        <div class="form-group col-lg-3">
                        <label class="form-label" for="simpleinput">   {{trans('admin.Total_Bf_Taxes')}} </label>
                                          <input type="text" id="Total_Bf_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_Bf_TaxesHide" name="Total_BF_Taxes">
                                        </div>
                                        <div class="form-group col-lg-3">
                          <label class="form-label" for="simpleinput">   {{trans('admin.Total_Taxes')}}</label>
                                         <input type="text" id="Total_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_TaxesHide" name="Total_Taxes">
                                        </div>
                                        <div class="form-group col-lg-3">
                       <label class="form-label" for="simpleinput">  {{trans('admin.Total_Price')}}</label>
                                   <input type="text" id="Total_Price" disabled  class="form-control">
                                            <input type="hidden" id="Total_PriceHide" name="Total_Price">
                                        </div>
   
                                        @else
                                        
                            <input type="hidden" id="Total_Discount" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHide" name="Total_Discount">
      <input type="hidden" id="Total_Bf_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_Bf_TaxesHide" name="Total_BF_Taxes">
          <input type="hidden" id="Total_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_TaxesHide" name="Total_Taxes">
       <input type="hidden" id="Total_Price" disabled  class="form-control">
                                            <input type="hidden" id="Total_PriceHide" name="Total_Price">                

                                            @endif
                                            @endif          
                                  
                                    </div>
                                    <div class="buttons mt-3" id="Submit" style="display: none">
                          <input type="hidden" id="sp" name="SP">                 
            <button type="button"  class="btn btn-primary" onclick="SPS()"> <i class="fal fa-folder"></i> {{trans('admin.Save')}} </button>
                                        
          <button type="button"  class="btn btn-primary" onclick="SPP()"><i class="fal fa-save"></i>  {{trans('admin.SaveandPrint')}} </button>
                                      </div>
                                </div>
                            </div>
                        </div>
                    </div>

                    </div>

                </form> 
<input type="hidden" id="ED" value="{{$show->Expire_Date}}">
        
          @if(auth()->guard('admin')->user()->emp == 0)    
        <input type="hidden" id="CLOSE" value="1">
        
          @else    
            @if(auth()->guard('admin')->user()->cost_price_purch == 1) 
                <input type="hidden" id="CLOSE" value="1">
             @else
                <input type="hidden" id="CLOSE" value="0">
            @endif
                                @endif         
        
        
        
        
        
                </main>

@if(app()->getLocale() == 'ar' ) 
<input type="hidden" id="LANG" value="ar">
@else
<input type="hidden" id="LANG" value="en">
@endif



@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;
            }

 
              $("#vendor").select2({
                placeholder: "select...",
                ajax: {
                    type: "GET",
                    dataType: "json",
                    url: "AllVendors",
                    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,
                        };
                                
            
              $.ajax({
                              url: 'AllVendorsJS/'+params.term,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                          $('#vendor').empty();  
                                  $.each(data, function(key, value){
   
                         $('#vendor').append('<option value="'+ key +'">' + value + '</option>');
                   
                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
            
            
            
        }
                },
            });

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

<!-- Unit Code and Name -->
<script>
   function  UnitCodePurchh(r){
   
   var countryId = $('#UnitPurch'+r).val();
   var Pro = $('#Product'+r).val();
   var store = $('#StorePurch'+r).val();
   var code = $('#CodePurch'+r).val();
                     if(countryId) {
                         $.ajax({
                             url: 'UnitPurchasesFilter/'+countryId+'/'+Pro+'/'+store+'/'+code,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                       $('#CodePurch'+r).val(data.code); 
                       $('#UnitPurchName'+r).val(data.name); 
                       $('#TaxRate'+r).val(data.rate); 
                       $('#TaxType'+r).val(data.type); 
                       $('#Price'+r).val(data.price); 
                       $('#PurchTax'+r).val(data.tax); 
                                         $('#UnitPriceOne'+r).val(data.priceOne); 
                       $('#UnitPriceTwo'+r).val(data.priceTwo); 
                       $('#UnitPriceThree'+r).val(data.priceThree);                   
   
                                 });
                                 
                                var TaxRate = $("#TaxRate"+r).val();
   var TaxType = $("#TaxType"+r).val();
   var Qty = $("#Qty"+r).val();
   var Price = $("#Price"+r).val();
   var Discount = $("#Discount"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       

       
       if(TaxType == 1){
           //Precent
          
      var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);  
       
       $("#TotalBFTax"+r).val(parseFloat(BF));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#Tax"+r).val(parseFloat(ii));

       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
       }else if(TaxType == 2){
          //Number 
        var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);   
         $("#TotalBFTax"+r).val(parseFloat(BF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
           
       }
       

        var Total = $("#Total"+r).val();
        var TotalBFTax = $("#TotalBFTax"+r).val();
        var Tax = $("#Tax"+r).val();
        var UnitID = $("#UnitPurch"+r).val();
        var StorePurch = $("#StorePurch"+r).val();

       if(TaxRate == ''  || TaxType == ''  ||  Qty == '' || Price == '' || Discount == '' || Total == '' || TotalBFTax == '' || Tax == '' || UnitID == '' || StorePurch == ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "none";           
     }
   
     
       if(TaxRate != ''  && TaxType != ''  &&  Qty != '' && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "block";           
     }  
            
       
        
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
   
   }   
</script>  

<!-- Unit Code and Name V -->
<script>
   function  UnitCodePurch(r){
   
   var countryId = $('#UnitPurch'+r).val();
   var Pro = $('#Product'+r).val();
   var store = $('#StorePurch'+r).val();
       var code = $('#CodePurch'+r).val();
                     if(countryId) {
                         $.ajax({
                             url: 'UnitPurchasesFilter/'+countryId+'/'+Pro+'/'+store+'/'+code,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
             $('#CodePurch'+r).val(data.code); 
                       $('#UnitPurchName'+r).val(data.name); 
                       $('#TaxRate'+r).val(data.rate); 
                       $('#TaxType'+r).val(data.type); 
                       $('#Price'+r).val(data.price); 
                       $('#PurchTax'+r).val(data.tax); 
                       $('#UnitPriceOne'+r).val(data.priceOne); 
                       $('#UnitPriceTwo'+r).val(data.priceTwo); 
                       $('#UnitPriceThree'+r).val(data.priceThree);                   
   
                                 });
                                 
                                var TaxRate = $("#TaxRate"+r).val();
   var TaxType = $("#TaxType"+r).val();
   var Qty = $("#Qty"+r).val();
   var Price = $("#Price"+r).val();
   var Discount = $("#Discount"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       

       
       if(TaxType == 1){
           //Precent
          
      var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);  
       
       $("#TotalBFTax"+r).val(parseFloat(BF));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#Tax"+r).val(parseFloat(ii));

       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
       }else if(TaxType == 2){
          //Number 
        var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);   
         $("#TotalBFTax"+r).val(parseFloat(BF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
           
       }
       

        var Total = $("#Total"+r).val();
        var TotalBFTax = $("#TotalBFTax"+r).val();
        var Tax = $("#Tax"+r).val();
        var UnitID = $("#UnitPurch"+r).val();
        var StorePurch = $("#StorePurch"+r).val();

       if(TaxRate == ''  || TaxType == ''  ||  Qty == '' || Price == '' || Discount == '' || Total == '' || TotalBFTax == '' || Tax == '' || UnitID == '' || StorePurch == ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "none";           
     }
   
     
       if(TaxRate != ''  && TaxType != ''  &&  Qty != '' && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "block";           
     }  
            
       
        
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
   
   }   
</script>  

<!-- Store Name -->
<script>
   function  StoreNamePurch(r){
   
   var countryId = $('#StorePurch'+r).val();
                     if(countryId) {
                         $.ajax({
                             url: 'StoreNamePurchasesFilter/'+countryId,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                       $('#StorePurchName'+r).val(data.name); 

                                     
   
                                 });
                                 
   var TaxRate = $("#TaxRate"+r).val();
   var TaxType = $("#TaxType"+r).val();
   var Qty = $("#Qty"+r).val();
   var Price = $("#Price"+r).val();
   var Discount = $("#Discount"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       

       
       if(TaxType == 1){
           //Precent
          
      var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);  
       
       $("#TotalBFTax"+r).val(parseFloat(BF));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#Tax"+r).val(parseFloat(ii));

       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
       }else if(TaxType == 2){
          //Number 
        var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);   
         $("#TotalBFTax"+r).val(parseFloat(BF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
           
       }
       

        var Total = $("#Total"+r).val();
        var TotalBFTax = $("#TotalBFTax"+r).val();
        var Tax = $("#Tax"+r).val();
        var UnitID = $("#UnitPurch"+r).val();
        var StorePurch = $("#StorePurch"+r).val();

       if(TaxRate == ''  || TaxType == ''  ||  Qty == '' || Price == '' || Discount == '' || Total == '' || TotalBFTax == '' || Tax == '' || UnitID == '' || StorePurch == ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "none";           
     }
   
     
       if(TaxRate != ''  && TaxType != ''  &&  Qty != '' && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "block";           
     }  
            
       
        
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
   
   }   
</script>  

<!--  Filter Products -->
<script>
    
   $(document).ready(function(){
   
    fetch_customer_data();
   
    function fetch_customer_data(search = '',store='',Client='')
    {  
     $.ajax({
      url:'ManufacturingRequestFilter',
      method:'GET',
      data:{search:search,store:store,Client:Client},
      dataType:'json',
      success:function(data)
      {
        
          
       $('.Data').html(data.table_data);
               $("#Data").show();
          
      }
     })
    }
    
   $(document).on('keyup', '#search', function(event){
     var search = $(this).val();     
     var store = $('#store').val();     
     var Client = $('#Client').val();     

 fetch_customer_data(search,store,Client);

    });
       
       
    $(document).on('change', '#store', function(){
     var store = $(this).val();     
     var search = $('#search').val();      
     var Client = $('#Client').val();     
 fetch_customer_data(search,store,Client);
    });
       
    $(document).on('change', '#Client', function(){
     var Client = $(this).val();     
     var search = $('#search').val();     
     var store = $('#store').val();     
 fetch_customer_data(search,store,Client);
    });  
       
     
          
   });
</script>

<!-- Add Products -->
<script>
   function Fun(r) { 
       
             var P_Ar_Name = $("#P_Ar_Name"+r).val();
             var P_En_Name= $("#P_En_Name"+r).val();
             var Product = $("#Product"+r).val();
             var UnitID = $("#UnitPurch"+r).val();
             var UnitName = $("#UnitPurchName"+r).val();
             var Qty = $("#Qty"+r).val();
             var AvQty = $("#AvQty"+r).val();
             var Barcode = $("#CodePurch"+r).val();
             var Price = $("#Price"+r).val();
             var Total = $("#Total"+r).val();
             var ExpDate = $("#ExpDate"+r).val();
             var PurchTax = $("#PurchTax"+r).val();
             var TotalTax = $("#Tax"+r).val();
             var Discount = $("#Discount"+r).val();
             var TotalBFTax = $("#TotalBFTax"+r).val();
             var StorePurch = $("#StorePurch"+r).val();
             var StorePurchName = $("#StorePurchName"+r).val();
             var PurchTax = $("#PurchTax"+r).val();
             var VOne = $("#VOne"+r).val();
             var VTwo = $("#VTwo"+r).val();
             var V_Name = $("#V_Name"+r).val();
             var VV_Name = $("#VV_Name"+r).val();
            var TaxRate = $("#TaxRate"+r).val();
             var TaxType = $("#TaxType"+r).val();  
             var PatchNum = $("#PatchNum"+r).val();  
                var HighDisc = $("#HighDisc"+r).val();
             var Viro = '';
             var VViro = '';
         var serial =$("#serial"+r).val();
       if( V_Name != ''){
           
          Viro= '(' + V_Name +')';
       }
  
       if( VV_Name != ''){
           
         VViro= '(' + VV_Name +')'; 
       }

          var PO='';
          var DO='';
          var TBT='';
          var TO='';
          var TOTT='';

        var CLOSE = $("#CLOSE").val();
      
          if(parseFloat(CLOSE) == 0){
            PO="<input type='hidden' name='Price[]' id='PriD"+r+"'  value='"+Price+"'>";  
              DO="<input type='hidden' name='Discount[]' class='Disc' id='DiscD"+r+"'  value='"+Discount+"'>";  
              
             TBT="<input class='TotalBFTax form-control' id='TotBFTaxD"+r+"' type='hidden' step='any' disabled  value='"+TotalBFTax+"'><input type='hidden'  id='TotBFTaxDHide"+r+"' name='TotalBFTax[]'  value='"+TotalBFTax+"'>";
         
              TO="<input class='TotalTax form-control' id='TaxD"+r+"' type='hidden' step='any' disabled  value='"+TotalTax+"'><input type='hidden' id='TaxDHide"+r+"' name='TotalTax[]'  value='"+TotalTax+"'>";
         
              TOTT="<input class='Tot form-control' type='hidden' step='any' id='TotD"+r+"' disabled   name='Total[]' value='"+Total+"'><input type='hidden' id='TotDHide"+r+"' name='Total[]'  value='"+Total+"'>";
              
     }else{

            PO="<td><input type='number' id='PriD"+r+"' step='any' name='Price[]' value='"+Price+"' class='form-control' onkeyup='TotD("+r+")' onclick='TotD("+r+")'></td>";  
         
           DO="<td><input class='Disc form-control' id='DiscD"+r+"' type='number' step='any' name='Discount[]' value='"+Discount+"' onkeyup='TotD("+r+")' onclick='TotD("+r+")' ></td>";  
         
            TBT="<td><input class='TotalBFTax form-control' id='TotBFTaxD"+r+"' type='number' step='any' disabled  value='"+TotalBFTax+"'><input type='hidden'  id='TotBFTaxDHide"+r+"' name='TotalBFTax[]'  value='"+TotalBFTax+"'></td>";
         
              TO="<td><input class='TotalTax form-control' id='TaxD"+r+"' type='number' step='any' disabled  value='"+TotalTax+"'><input type='hidden' id='TaxDHide"+r+"' name='TotalTax[]'  value='"+TotalTax+"'></td>";
         
              TOTT="<td><input class='Tot form-control' type='number' step='any' id='TotD"+r+"' disabled   name='Total[]' value='"+Total+"'><input type='hidden' id='TotDHide"+r+"' name='Total[]'  value='"+Total+"'></td>";
     
     }
       
   

            var Exp='';
        var ED = $("#ED").val();
         if(ED == 1){
           
         Exp = "<td><input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>" + ExpDate + "</td>";
           
       }else{
           
           Exp = "<input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>";
       }
  

             document.getElementById("AddBtnPur"+r).style.display = "none";
             document.getElementById("Row"+r).style.display = "none";
                    $("#Data").hide();
       
       
               var LANG = $("#LANG").val();
   if(LANG == 'ar' ){ 
          var Nemo = P_Ar_Name ;
          }else{
             var Nemo = P_En_Name ;   
          } 
       
             var markup = "<tr><td><input type='hidden' name='P_Ar_Name[]' value='"+P_Ar_Name+"'><input type='hidden' name='P_En_Name[]' value='"+P_En_Name+"'>" + Nemo + ""+ Viro +" "+ VViro +"</td><td><input type='hidden' name='Unit[]' value='"+UnitID+"'>" + UnitName + "</td><td><input type='hidden' name='P_Code[]' value='"+Barcode+"'>" + Barcode + "</td><td><input class='Qun form-control' id='QuntD"+r+"' type='number' step='any' name='Qty[]' value='"+Qty+"' onkeyup='TotD("+r+")' onclick='TotD("+r+")' ></td>"+PO+""+DO+""+TBT+""+TO+""+TOTT+"<td><input  type='hidden' name='StorePurch[]' value='"+StorePurch+"'>" + StorePurchName + "</td>"+Exp+"<td><button id='DelAssem' type='button' class='btn btn-default'><i class='fal fa-trash'></i></button><input id='PRO"+r+"' type='hidden' name='Product[]' value='"+Product+"'><input type='hidden' name='VOne[]' value='"+VOne+"'><input type='hidden' name='VTwo[]' value='"+VTwo+"'></td><input type='hidden' name='V_Name[]' value='"+Viro+"'><input type='hidden' name='VV_Name[]' value='"+VViro+"'><input type='hidden' name='PurchTax[]' value='"+PurchTax+"'><input id='TaxRateD"+r+"' type='hidden'  value='"+TaxRate+"'><input type='hidden' id='TaxTypeD"+r+"'  value='"+TaxType+"'><input type='hidden' id='HighDiscD"+r+"'  value='"+HighDisc+"'></tr>";
   
            
           var P = $("#PRO"+r).val();
             if(Product == P){
              if(parseFloat(serial) == 0){        
             $("#data-dt").append(markup);
              }
             }else{
                 
                $("#data-dt").append(markup);  
             }
    
      $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
                
    var sumQ = 0;        
   $('.Qun').each(function(){
   sumQ += parseFloat($(this).val());
   });   
            
    var sumT = 0;        
   $('.Tot').each(function(){
   sumT += parseFloat($(this).val());
   });       
       
        var sumD = 0;        
   $('.Disc').each(function(){
   sumD += parseFloat($(this).val());
   }); 
       
       
           var sumBF = 0;        
   $('.TotalBFTax').each(function(){
   sumBF += parseFloat($(this).val());
   }); 
       
           var sumTax = 0;        
   $('.TotalTax').each(function(){
   sumTax += parseFloat($(this).val());
   }); 
       
   
   $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
   $('#Total_Price').val(parseFloat(sumT));
   $('#Total_PriceHide').val(parseFloat(sumT));
     
    
   $('#Total_Discount').val(parseFloat(sumD));
   $('#Total_DiscountHide').val(parseFloat(sumD));
       
   $('#Total_Bf_Taxes').val(parseFloat(sumBF));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF));
       
   $('#Total_Taxes').val(parseFloat(sumTax));
   $('#Total_TaxesHide').val(parseFloat(sumTax));
       

       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }
       
            var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        
      if(Pay == 'Later' &&  Stat == 0 ){
               
             if(paid == 0 || paid < 0){   
        document.getElementById("Submit").style.display = "none";  
             }else{
                 
           if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }
                 
                 
                 
             }
           
       }else{
           
       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }   
       }
 
        $('#data-dt').on('click', '#DelAssem', function(e){
                $(this).closest('tr').remove(); 
            
   
      $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
                
    var sumQ = 0;        
   $('.Qun').each(function(){
   sumQ += parseFloat($(this).val());
   });   
            
    var sumT = 0;        
   $('.Tot').each(function(){
   sumT += parseFloat($(this).val());
   });       
       
        var sumD = 0;        
   $('.Disc').each(function(){
   sumD += parseFloat($(this).val());
   }); 
       
       
           var sumBF = 0;        
   $('.TotalBFTax').each(function(){
   sumBF += parseFloat($(this).val());
   }); 
       
           var sumTax = 0;        
   $('.TotalTax').each(function(){
   sumTax += parseFloat($(this).val());
   }); 
       
   
   $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
   $('#Total_Price').val(parseFloat(sumT));
   $('#Total_PriceHide').val(parseFloat(sumT));
     
    
       $('#Total_Discount').val(parseFloat(sumD));
   $('#Total_DiscountHide').val(parseFloat(sumD));
       
          $('#Total_Bf_Taxes').val(parseFloat(sumBF));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF));
       
          $('#Total_Taxes').val(parseFloat(sumTax));
   $('#Total_TaxesHide').val(parseFloat(sumTax));
       

       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }
            
                  var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        
      if(Pay == 'Later' &&  Stat == 0 ){
               
             if(paid == 0 || paid < 0){   
        document.getElementById("Submit").style.display = "none";  
             }else{
                 
           if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }
                 
                 
                 
             }
           
       }else{
           
       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
        document.getElementById("Submit").style.display = "block";    
       }   
       }
 
     
      
       
       
   
                    })  
       
       
     }    
</script> 

<!-- Total Products -->
<script>
   function PurchTotal(r) {
       
   var TaxRate = $("#TaxRate"+r).val();
   var TaxType = $("#TaxType"+r).val();
   var Qty = $("#Qty"+r).val();
   var AvQty = $("#AvQty"+r).val();
   var Price = $("#Price"+r).val();
   var Discount = $("#Discount"+r).val();
   var HighDisc = $("#HighDisc"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       
     var x=  0 ;
   
          var DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
          
           Discount=$("#Discount"+r).val();
       }else{
         
           var d= Discount / 100 ;
           var Multi= parseFloat(Qty) * parseFloat(Price) ;
          var dd= Multi * d;
           
        Discount=  dd; 
       }
       if(TaxType == 1){
           //Precent
          
      var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);  
       
       $("#TotalBFTax"+r).val(parseFloat(BF));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#Tax"+r).val(parseFloat(ii));

       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
       }else if(TaxType == 2){
          //Number 
        var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);   
         $("#TotalBFTax"+r).val(parseFloat(BF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#Total"+r).val(parseFloat(iii));
           
           
       }
       

        var Total = $("#Total"+r).val();
        var TotalBFTax = $("#TotalBFTax"+r).val();
        var Tax = $("#Tax"+r).val();
        var UnitID = $("#UnitPurch"+r).val();
        var StorePurch = $("#StorePurch"+r).val();

 
        document.getElementById("AddBtnPur"+r).style.display = "block";           

  
       
   }
    
    
     function TotD(r) { 
   var TaxRate = $("#TaxRateD"+r).val();
   var TaxType = $("#TaxTypeD"+r).val();
   var Qty = $("#QuntD"+r).val();
   var AvQty = $("#AvQuntD"+r).val();
   var Price = $("#PriD"+r).val();
   var Discount = $("#DiscD"+r).val();
            var HighDisc = $("#HighDiscD"+r).val();
   var show = $("#SHW").val();
   var i = 0;
   var ii=0;       
   var iii=0;       
     var x=0 ;
       
                 var DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
          
           Discount=$("#DiscD"+r).val();
       }else{
         
           var d= Discount / 100 ;
           var Multi= parseFloat(Qty) * parseFloat(Price) ;
          var dd= Multi * d;
           
        Discount=  dd; 
       }
       
       
       
         
       if(TaxType == 1){
           //Precent
          
      var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);  
       
       $("#TotBFTaxD"+r).val(parseFloat(BF));
       $("#TotBFTaxDHide"+r).val(parseFloat(BF));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#TaxD"+r).val(parseFloat(ii));
           $("#TaxDHide"+r).val(parseFloat(ii));

       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#TotD"+r).val(parseFloat(iii));
           $("#TotDHide"+r).val(parseFloat(iii));
           
       }else if(TaxType == 2){
          //Number 
        var BF = ( parseFloat(Qty) *  parseFloat(Price) ) -  parseFloat(Discount);   
         $("#TotBFTaxD"+r).val(parseFloat(BF));
         $("#TotBFTaxDHide"+r).val(parseFloat(BF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#TaxD"+r).val(parseFloat(i));
           $("#TaxDHide"+r).val(parseFloat(i));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#TotD"+r).val(parseFloat(iii));
           $("#TotDHide"+r).val(parseFloat(iii));
           
           
       }
       

      
   
        $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
                
    var sumQ = 0;        
   $('.Qun').each(function(){
   sumQ += parseFloat($(this).val());
   });   
            
    var sumT = 0;        
   $('.Tot').each(function(){
   sumT += parseFloat($(this).val());
   });       
       
        var sumD = 0;        
   $('.Disc').each(function(){
   sumD += parseFloat($(this).val());
   }); 
       
       
           var sumBF = 0;        
   $('.TotalBFTax').each(function(){
   sumBF += parseFloat($(this).val());
   }); 
       
           var sumTax = 0;        
   $('.TotalTax').each(function(){
   sumTax += parseFloat($(this).val());
   }); 
       
   
   $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
   $('#Total_Price').val(parseFloat(sumT));
   $('#Total_PriceHide').val(parseFloat(sumT));
     
    
   $('#Total_Discount').val(parseFloat(sumD));
   $('#Total_DiscountHide').val(parseFloat(sumD));
       
   $('#Total_Bf_Taxes').val(parseFloat(sumBF));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF));
       
   $('#Total_Taxes').val(parseFloat(sumTax));
   $('#Total_TaxesHide').val(parseFloat(sumTax));
       

   }
    
</script>

<!-- Scanner  problem -->         
<script>
   $(".form-control").keypress(function(event){
   if (event.which == '10' || event.which == '13') {
   event.preventDefault();
   }
   });             
   
   
</script>

<!-- Status -->
<script>
    function Statuss(){
        
        var Pay =$('#Payment_Method').val();
        var paid =$('#paid').val();
            
  $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
     

        
       if(Pay == 'Later'){
            
                     document.getElementById("LATER").style.display = "block";  
            if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           

                document.getElementById("Submit").style.display = "block";    
       
           
       }   
           
       }else{
                     document.getElementById("LATER").style.display = "none";  
        if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           

                document.getElementById("Submit").style.display = "block";    
       
           
       }   
       }
 
    }
    
    $(document).ready(function() {
            var Pay =$('#Payment_Method').val();
        var paid =$('#paid').val();
            
  $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
     

        
       if(Pay == 'Later'){
            
                     document.getElementById("LATER").style.display = "block";  
            if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           

                document.getElementById("Submit").style.display = "block";    
       
           
       }   
           
       }else{
                     document.getElementById("LATER").style.display = "none";  
        if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           

                document.getElementById("Submit").style.display = "block";    
       
           
       }   
       }
     
        
    });
</script> 

<!-- Submit Script -->
<script>

        function SPP(){
           $('#sp').val(1);  
           var x= $('#sp').val();   
        
                  var store= 1;   
           var SSAFE= 1;   
           var vendor= 1;   
        
        if(store != '' && SSAFE != '' && vendor != null){
             if(x == 1){
              document.getElementById("Submit").style.display = "none"; 
      document.getElementById('form').submit();   
        } 
     }else{
                
                alert('تأكد من اختيار مخزن و خزنه وحساب');
                
            }
                
            
      
            
            
            
    }
    
    
       function SPS(){
           $('#sp').val(0);  
           var x= $('#sp').val();   
        
      
           
           
                          var store= 1;   
           var SSAFE= 1;   
           var vendor= 1;   
        
        if(store != '' && SSAFE != '' && vendor != null){
            if(x == 0){
              document.getElementById("Submit").style.display = "none"; 
      document.getElementById('form').submit();   
        }
     }else{
                
                alert('تأكد من اختيار مخزن و خزنه وحساب');
                
            }
              
           
           
    }

    
 
</script>
   
<!-- Change Price Unit -->
<script>
    function ChangePriceUnit(r){
        
    var POne = $('#UnitPriceOne'+r).val();    
    var PTwo = $('#UnitPriceTwo'+r).val();    
    var PThree = $('#UnitPriceThree'+r).val();    
    var ID = $('#UnitPriceID'+r).val();    

        if(PTwo == ''){
            
            PTwo  = 0 ;
        }else{
            
          PTwo = $('#UnitPriceTwo'+r).val();   
        }
        
           if(PThree == ''){
            
            PThree  = 0 ;
        }else{
            
          PThree = $('#UnitPriceThree'+r).val();   
        }
        
          if(POne) {
                         $.ajax({
                             url: 'ChangePriceUnit/'+POne+'/'+PTwo+'/'+PThree+'/'+ID,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                     alert('تم التحديث بنجاح');
                                     
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     }else{
                         
                        alert('حقل السعر الاول مطلوب'); 
                         
                     }
        
        
        
    }
</script>



<!-- Account Balance and Phone Delegate and Client -->
<script>
   $(document).ready(function() {
   
                  $('#Client').on('change', function(){
                      var countryId = $(this).val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceFilter/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {
                                  $.each(data, function(key, value){
   
        
                    $('#AccountCredit').val(key); 
                    $('#AccountCredit').val(value); 
                                      
                                  $.ajax({
                              url: 'ClientPhoneAndAddress/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {

                    $('#Client_Phone').val(data.phone); 
                    $('#Client_Address').val(data.address); 

                          
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });      
                                      
                                      
                                      
                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {
   
                          $('select[name="state"]').empty();
                      }
   
                  });
   
              });
    
     $(document).ready(function() { 
 
                      var countryId = $('#Client').val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceFilter/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {
                                  $.each(data, function(key, value){
   
        
                    $('#AccountCredit').val(key); 
                    $('#AccountCredit').val(value); 
                                      
                             $.ajax({
                              url: 'ClientPhoneAndAddress/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {

                    $('#Client_Phone').val(data.phone); 
                    $('#Client_Address').val(data.address); 

                          
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });                
                                      
                                      
                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {
   
                          $('select[name="state"]').empty();
                      }
     
     });

     $(document).ready(function() {
   


                  $('#Delegate').on('change', function(){
                      var countryId = $(this).val();
                      if(countryId) {
                          $.ajax({
                              url: 'DelegatePhone/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {

                    $('#Delegate_Phone').val(data.phone); 
                    $('#Delegate_PhoneHide').val(data.phone); 


                          
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {
   
                          $('select[name="state"]').empty();
                      }
   
                  });
   
              });
    
</script>  


<script>
       $(document).ready(function(){
             $( "#Barcode" ).val(Math.floor(Math.random() * 1000000));
   });
</script>
@endpush