<?php $__env->startSection('content'); ?>
   <?php
use App\Models\ExpireDateQty;
use App\Models\SalesDefaultData;
$Def=SalesDefaultData::orderBy('id','desc')->first();
use App\Models\DefaultDataShowHide;
$show=DefaultDataShowHide::orderBy('id','desc')->first();
$Style='none';
$credStyle="none";
    use App\Models\StoresDefaultData;
       $FCOST=StoresDefaultData::orderBy('id','desc')->first();

?>
  <title><?php echo e(trans('admin.EditSalesOrder')); ?></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);"><?php echo e(trans('admin.Sales')); ?> </a></li>
                        <li class="breadcrumb-item active"><?php echo e(trans('admin.EditSalesOrder')); ?> </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>
          <input type="hidden" id="CHECK">
    <form id="form" action="<?php echo e(url('PostEditSalesOrder/'.$item->id)); ?>" method="post" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>

              <?php echo view('honeypot::honeypotFormFields'); ?>
         <input type="hidden" name="Quote" value="<?php echo e($item->Quote); ?>">
                    <div class="row">
                        <div class="col-lg-12">
                            <div id="panel-2" class="panel">
                                <div class="panel-hdr">
                                    <h2>
                                        <span class="fw-300"><i>   <?php echo e(trans('admin.EditSalesOrder')); ?>  </i></span>
                                    </h2>
                                </div>
                                <div class="panel-container show">
                                      <span id="ex"> <?php echo $__env->make('admin.layouts.messages', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?></span> 
                                    <div class="panel-content">
                                    <div class="form-row">
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Code')); ?> </label>
                                            <input type="text" value="<?php echo e($item->Code); ?>" class="form-control " disabled>
                                            <input type="hidden" name="Code" value="<?php echo e($item->Code); ?>" class="form-control">
                                        </div>
                                          <?php if(auth()->guard('admin')->user()->emp == 0): ?>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                         <input type="date" name="Date" value="<?php echo e($item->Date); ?>" class="form-control" required>
                                        </div>
                                        <?php else: ?>
                                        
                                         <?php if(auth()->guard('admin')->user()->Date == 1): ?>
                                                     <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                         <input type="date" name="Date" value="<?php echo e($item->Date); ?>" class="form-control" required>
                                        </div>
                                        <?php else: ?>
                                                     <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                         <input type="date" name="Date" value="<?php echo e($item->Date); ?>" class="form-control" required readonly>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <?php endif; ?>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Store')); ?></label>
                                            <select class="select2 form-control w-100" id="store" name="Store" required>
                                                <option value=""> <?php echo e(trans('admin.Store')); ?></option>
                                            <?php $__currentLoopData = $Stores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
    <option value="<?php echo e($stor->id); ?>" <?php if($item->Store == $stor->id): ?>  selected  <?php endif; ?>>
                                                    <?php echo e(app()->getLocale() == 'ar' ?$stor->Name :$stor->NameEn); ?>  
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>    
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Safe')); ?></label>
                                            <select class="select2 form-control w-100" name="Safe" required>
                                                 <option value=""> <?php echo e(trans('admin.Safe')); ?></option>
                                            <?php $__currentLoopData = $Safes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $safe): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
        <option value="<?php echo e($safe->id); ?>" <?php if($item->Safe == $safe->id): ?>  selected  <?php endif; ?>>
                                        <?php echo e(app()->getLocale() == 'ar' ?$safe->Name :$safe->NameEn); ?>  
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>    
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Coin')); ?></label>
                                            <select class="select2 form-control w-100" name="Coin" required>
                                                 <option value=""> <?php echo e(trans('admin.Coin')); ?></option>
                                            <?php $__currentLoopData = $Coins; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $coin): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                 <option value="<?php echo e($coin->id); ?>" <?php if($item->Coin == $coin->id): ?>  selected  <?php endif; ?>>
                                                 <?php echo e(app()->getLocale() == 'ar' ?$coin->Arabic_Name :$coin->English_Name); ?>   
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                              <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Draw')); ?></label>
                              <input type="text" name="Draw" value="<?php echo e($item->Draw); ?>" class="form-control" required>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> <?php echo e(trans('admin.Payment_Method')); ?></label>
         <select class="select2 form-control w-100" name="Payment_Method" id="Payment_Method" onchange="Statuss()" required>
          <option value="Cash" <?php if($item->Payment_Method == 'Cash'): ?>  selected  <?php endif; ?> ><?php echo e(trans('admin.Cash')); ?> </option>
        <option value="Later"  <?php if($item->Payment_Method == 'Later'): ?>  selected  <?php endif; ?>><?php echo e(trans('admin.Later')); ?></option>
<option value="Installment"  <?php if($item->Payment_Method == 'Installment'): ?>  selected  <?php endif; ?>><?php echo e(trans('admin.Installment')); ?></option>
                 <option value="Check" <?php if($item->Payment_Method == 'Check'): ?> selected <?php endif; ?>><?php echo e(trans('admin.Check')); ?></option>
                  <option value="InstallmentCompanies"><?php echo e(trans('admin.InstallmentCompanies')); ?></option>
                                            </select>
                                        </div>
                                        
                                                                       <div class="form-group col-lg-2" style="display: none" id="Later_Due">
                                              <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Later_Due')); ?></label>
                           <input type="date" name="Later_Due" value="<?php echo e($item->Later_Due); ?>"  class="form-control" >       
                                        </div>            
                                        
                                        <div class="form-group col-lg-2">
                                              <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Sale_Date')); ?></label>
                           <input type="date" name="Sale_Date" value="<?php echo e($item->Sale_Date); ?>"  class="form-control" >       
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Status')); ?></label>
         <select class="select2 form-control w-100" name="Status" onchange="Statuss()" id="Status"  required>
          <option value="1" <?php if($item->Status == 1): ?>  selected  <?php endif; ?> ><?php echo e(trans('admin.Recived')); ?> </option>
          <option value="0" <?php if($item->Status == 0): ?>  selected  <?php endif; ?> ><?php echo e(trans('admin.Pending')); ?></option>
                                            </select>
                                        </div>
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for=""> <?php echo e(trans('admin.Cost_Center')); ?> </label>
                                            <select class="select2 form-control w-100" name="Cost_Center">
                                            <option value=""> <?php echo e(trans('admin.Cost_Center')); ?></option>
                                            <?php $__currentLoopData = $CostCenters; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cost): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
         <option value="<?php echo e($cost->id); ?>" <?php if($item->Cost_Center == $cost->id): ?>  selected  <?php endif; ?>>
                                                 <?php echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>   
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        
                                        
                      
                                        
                                            <?php if(auth()->guard('admin')->user()->emp == 0): ?>   
                                        
                                                          <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Delegate')); ?></label>
                                            <select class="select2 form-control w-100 EmpDele" name="Delegate">
                                          <option value=""> <?php echo e(trans('admin.Delegate')); ?></option>
                                            <?php $__currentLoopData = $Employess; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $emp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                  <option value="<?php echo e($emp->id); ?>" <?php if($item->Delegate == $emp->id): ?>  selected  <?php endif; ?>>
                                                 <?php echo e(app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn); ?>     
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        
                                        
                                        
                                        <?php else: ?>
                                        
                                 <?php if($Def->DelegateEmp == 0): ?>
                        <input type="hidden" name="Delegate" value="<?php echo e(auth()->guard('admin')->user()->emp); ?>"> 
                         <?php else: ?>
                                   <div class="form-group col-lg-2">
                           <label class="form-label" for=""><?php echo e(trans('admin.Delegate')); ?></label>
                           <select class="select2 form-control w-100 EmpDele" name="Delegate">
                              <option value=""> <?php echo e(trans('admin.Delegate')); ?></option>
                              <?php $__currentLoopData = $Employess; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $emp): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                              <option value="<?php echo e($emp->id); ?>" <?php if($item->Delegate == $emp->id): ?> selected <?php endif; ?>>
                             <?php echo e(app()->getLocale() == 'ar' ?$emp->Name :$emp->NameEn); ?>   
                              </option>
                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                           </select>
                        </div>
                         
                         <?php endif; ?>
                                        <?php endif; ?>
                                   
                                        
                           <?php if(auth()->guard()->user()->emp == 0): ?>    

                                                <?php if($show->Executor_Sale == 1): ?>
                                  <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Executor')); ?></label>
                                  <select  class="js-data-example-ajax form-control w-100" id="Emp" name="Executor" >
                            <?php if(!empty($item->Executor)): ?>          
                         <option value="<?php echo e($item->Executor); ?>">
                                      
                                 <?php echo e(app()->getLocale() == 'ar' ?$item->Executor()->first()->Name :$item->Executor()->first()->NameEn); ?>      
                                      </option>
                            <?php endif; ?>            
                                            </select>  
                                        </div>
                                        <?php else: ?>
                                        <input type="hidden" name="Executor">   
                                        <?php endif; ?>

                                    <?php else: ?>   
                                        
                                        
                                  
                                        
                                                <?php if($Def->ExecuteEmp == 0): ?>
                         
                           <input type="hidden" name="Executor" value="<?php echo e(auth()->guard()->user()->executor); ?>">  
                         
                            <?php else: ?>
                         
                         
                              <?php if($show->Executor_Sale == 1): ?>
                                         
                      <div class="form-group col-lg-2">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Executor')); ?></label>
                                  <select  class="js-data-example-ajax form-control w-100" id="Emp" name="Executor" >
                            <?php if(!empty($item->Executor)): ?>          
                         <option value="<?php echo e($item->Executor); ?>">
                                      
                                 <?php echo e(app()->getLocale() == 'ar' ?$item->Executor()->first()->Name :$item->Executor()->first()->NameEn); ?>      
                                      </option>
                            <?php endif; ?>            
                                            </select>  
                                        </div>
                        <?php else: ?>
                         
                       <input type="hidden" name="Executor" value="<?php echo e(auth()->guard()->user()->executor); ?>">  
                        <?php endif; ?> 
                         
                         
                         
                         
                         <?php endif; ?>
                                        
                                    <?php endif; ?>       
                                        
                                        
                                        
                                        <div class="form-group col-lg-2">
                             <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Refrence_Number')); ?></label>
                   <input type="text" name="Refernce_Number" value="<?php echo e($item->Refernce_Number); ?>" class="form-control">
                                        </div>
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Account')); ?> (<?php echo e(trans('admin.Client')); ?>)</label>
                            <select  class="select2 form-control w-100" id="client" name="Client" required>
                                <option value="<?php echo e($item->Client); ?>">    <?php echo e(app()->getLocale() == 'ar' ?$item->Client()->first()->Name :$item->Client()->first()->NameEn); ?>      </option>
                                            </select>       
                                        </div>
                                        
                                           <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('ايقونه اضافه عميل')): ?>
                                                           <div class="form-group col-lg-1">
                  <button style="margin: 22px" type="button" class="btn btn-default" data-toggle="modal" data-target="#NewClient">
                                            <i class="fal fa-user"></i>          
                                     </button> 
                                             
         <!-- Modal New Client -->
                           <div class="modal fade" id="NewClient" tabindex="-1" role="dialog" aria-hidden="true">
                              <div class="modal-dialog modal-dialog-centered modal-xl" role="document">
                                 <div class="modal-content">
                                    <div class="modal-header">
                                       <h4 class="modal-body row">
                                          <div class="form-group col-md-2">
                                             <label class="form-label" for="simpleinput">   <?php echo e(trans('admin.Code')); ?></label>
                                             <input type="text" id="CODE"  value="<?php echo e($CodeUser); ?>" disabled class="form-control">
                                          </div>
                                          <div class="form-group col-md-2">
                                             <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Arabic_Name')); ?>  </label><span class="strick">*</span>
                                             <input type="text" id="Name" value="<?php echo e(old('Name')); ?>" class="form-control">
                                          </div>
                                               <div class="form-group col-md-2">
                                             <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.English_Name')); ?>  </label><span class="strick">*</span>
                                             <input type="text" id="NameEn" value="<?php echo e(old('NameEn')); ?>" class="form-control">
                                          </div>
                                          <div class="form-group col-md-3">
                                             <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Phone')); ?>  </label><span class="strick">*</span>
                                             <input type="number" id="Phone" value="<?php echo e(old('Phone')); ?>" class="form-control">
                                          </div>
                                          <div class="form-group col-md-3">
                                             <label class="form-label" for="">   <?php echo e(trans('admin.Price_Level')); ?> </label><span class="strick">*</span>
                                             <select class="select2 form-control w-100" id="PriceLevel">
                                                <option value="1"> <?php echo e(trans('admin.Level1')); ?> </option>
                                                <option value="2"> <?php echo e(trans('admin.Level2')); ?> </option>
                                                <option value="3"> <?php echo e(trans('admin.Level3')); ?> </option>
                                             </select>
                                          </div>
                                       </h4>
                                       <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                                       <span aria-hidden="true"><i class="fal fa-times"></i></span>
                                       </button>
                                    </div>
                                    <div class="modal-footer">
                                       <button type="button" class="btn btn-secondary" data-dismiss="modal"> <?php echo e(trans('admin.No')); ?></button>
                                       <button type="button" onclick="NewClients()"  class="btn btn-primary"> <?php echo e(trans('admin.AddNew')); ?></button>
                                    </div>
                                 </div>
                              </div>
                           </div>      
                                             
                                        </div>
                                        <?php endif; ?>
 <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('خانه رصيد حساب العميل')): ?>   <?php $credStyle="block"; ?> <?php endif; ?>

                                        
                                        <div class="form-group col-lg-3" style="display: <?php echo e($credStyle); ?>">
                                 <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Account_Credit')); ?> </label>
                             <input type="text" id="AccountCredit" value="0" class="form-control " disabled>
                                        </div>
                                        
                                        
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e($item->Note); ?>" class="form-control">
                                        </div>
                                    </div>
                                        
                               <div id="Install" style="display: none">
                                 
                                <div class="row">   
                                <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Presenter')); ?></label>
           <input type="number" step="any"  value="<?php echo e($item->presenter); ?>" class="form-control" name="presenter" >
                  
                                        </div>   
                                  <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.annual_interest')); ?></label>
           <input type="number" step="any"  value="<?php echo e($item->annual_interest); ?>" class="form-control" name="annual_interest">
                        
                                        </div>   
                                    
                                    <div class="form-group col-lg-3">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.monthly_installment')); ?></label>
     <input type="number" step="any"  value="<?php echo e($item->monthly_installment); ?>" class="form-control" name="monthly_installment">
                               
                                        </div>  
                                    
                                         <div class="form-group col-lg-3">
                               <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Years_Number')); ?></label>
     <input type="number" step="any"  value="<?php echo e($item->Years_Number); ?>" class="form-control" name="Years_Number">
                               
                                        </div>  
                                    
                                     <div class="form-group col-lg-4">
                               <label class="form-label" for="simpleinput"><?php echo e(trans('admin.total')); ?></label>
     <input type="number" step="any"  value="<?php echo e($item->total); ?>" class="form-control" name="total" readonly>
                                
                                        </div>  
                                    
                                      <div class="form-group col-lg-4">
                               <label class="form-label" for="simpleinput"><?php echo e(trans('admin.installment_Num')); ?></label>
     <input type="number" step="any"  value="<?php echo e($item->installment_Num); ?>" class="form-control" name="installment_Num">
                           
                                        </div>  
                                    
                                         <div class="form-group col-lg-4">
                               <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date_First_installment')); ?></label>
     <input type="date"   value="<?php echo e($item->Date_First_installment); ?>" class="form-control" name="Date_First_installment">
                             
                                        </div>  
                                    </div> 
                                        </div>   
                                        <div id="CompInstall" style="display: none">
                                 <div class="row">
                                     
                           <div class="form-group col-lg-4">
                              <label class="form-label" for=""><?php echo e(trans('admin.InstallCompany')); ?></label>
                              <select class="select2 form-control w-100"  name="InstallCompany" id="InstallCompany" onchange="InstaallComp()" >
                                 <option value=""> <?php echo e(trans('admin.InstallCompany')); ?></option>
                                 <?php $__currentLoopData = $InstallmentCompanies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $inst): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                                 <option value="<?php echo e($inst->id); ?>">
                                   
 <?php echo e(app()->getLocale() == 'ar' ?$inst->Arabic_Name :$inst->English_Name); ?>                                     
                                 </option>
                                 <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>    
                              </select>
                           </div>
                           
                                     
                                        <div class="form-group col-lg-4">
                           <label class="form-label" for="simpleinput"><?php echo e(trans('admin.ContractNumber')); ?>  </label>
                           <input type="text" name="ContractNumber" value="<?php echo e(old('ContractNumber')); ?>" class="form-control">
                        </div>
                                     
                                     

                                         <div class="form-group col-lg-4">
                              <label class="form-label" for=""><?php echo e(trans('admin.PayFees')); ?></label>
                              <select class="select2 form-control w-100"  name="PayFees"  >
                                 <option value="No"> <?php echo e(trans('admin.No')); ?></option>
                                 <option value="Yes"> <?php echo e(trans('admin.Yes')); ?></option>
                              </select>
                           </div>
                                         <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('رسوم خدمات شركات التقسيط')): ?>  <?php $Style='block';  ?>   <?php endif; ?>          
                                     
                                                        <div class="form-group col-lg-4" style="display: <?php echo e($Style); ?>">
                           <label class="form-label" for="simpleinput"><?php echo e(trans('admin.ServiceFee')); ?>  </label>
                           <input type="text" name="ServiceFee" id="ServiceFee" value="<?php echo e(old('ServiceFee')); ?>" class="form-control" readonly>
                        </div>
                                  
                                     
                                                                           <div class="form-group col-lg-4" style="display: <?php echo e($Style); ?>">
                           <label class="form-label" for="simpleinput"><?php echo e(trans('admin.CompanyPrecent')); ?>  </label>
                           <input type="text" name="CompanyPrecent" id="CompanyPrecent" value="<?php echo e(old('CompanyPrecent')); ?>" class="form-control" readonly>
                        </div>
                
                                                      <div class="form-group col-lg-4" style="display: <?php echo e($Style); ?>">
                           <label class="form-label" for="simpleinput"><?php echo e(trans('admin.TotalServiceFee')); ?>  </label>
                           <input type="text"  id="TotalServiceFee"  class="form-control" readonly>
                        </div>



                                     
                           </div>
                      </div>
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="col-xl-12">
                        <div id="panel-1" class="panel">
                     <div class="row">
                        <?php if($show->SearchCode == 1): ?>
                        <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput">  </label>
                           <div class="input-items" style="position:relative;">
                              <input type="text" id="search" class="form-control" placeholder="<?php echo e(trans('admin.Search_For_Products')); ?>">
                         
                                      <?php if(app()->getLocale() == 'ar' ): ?>
                     <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;left:3px;"></i>
                      <?php else: ?>
                            <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;right: 0;left:auto;"></i>
                      <?php endif; ?>
                           </div>
                        </div>
                             <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput">  </label>
                           <div class="input-items" style="position:relative;">
                              <input type="text" id="SearchCode" class="form-control" placeholder="<?php echo e(trans('admin.SearchCode')); ?>">
                          
                                      <?php if(app()->getLocale() == 'ar' ): ?>
                     <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;left:3px;"></i>
                      <?php else: ?>
                            <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;right: 0;left:auto;"></i>
                      <?php endif; ?>
                           </div>
                        </div>
                         <?php else: ?>
                              <div class="form-group col-lg-6">
                           <label class="form-label" for="simpleinput">  </label>
                           <div class="input-items" style="position:relative;">
                              <input type="text" id="search" class="form-control" placeholder="<?php echo e(trans('admin.Search_For_Products')); ?>">
                          
                                      <?php if(app()->getLocale() == 'ar' ): ?>
                     <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;left:3px;"></i>
                      <?php else: ?>
                            <i class="fal fa-barcode-alt" style="position:absolute ;top:5px;right: 0;left:auto;"></i>
                      <?php endif; ?>
                           </div>
                        </div>
                         <?php endif; ?>
      
                        <?php if($show->Group_Brand == 1): ?>
                        <div class="form-group col-lg-3 mt-3">
                           <select class="select2 form-control w-100" id="Brandd">
                              <option value=""><?php echo e(trans('admin.Brand')); ?></option>
                              <?php $__currentLoopData = $Brands; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $brand): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="<?php echo e($brand->id); ?>"> <?php echo e(app()->getLocale() == 'ar' ?$brand->Name :$brand->NameEn); ?></option>
                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                           </select>
                        </div>
                        <div class="form-group col-lg-3 mt-3">
                           <select class="select2 form-control w-100" id="Groupp">
                              <option value=""><?php echo e(trans('admin.Group')); ?></option>
                              <?php $__currentLoopData = $ItemsGroups; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $group): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                              <option value="<?php echo e($group->id); ?>"><?php echo e(app()->getLocale() == 'ar' ?$group->Name :$group->NameEn); ?></option>
                              <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                           </select>
                        </div>
                        <?php endif; ?>
                     
                     </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><?php echo e(trans('admin.Name')); ?></th>
                                 <th><?php echo e(trans('admin.Unit')); ?></th>
                                 <th><?php echo e(trans('admin.Code')); ?></th>
                                 <?php if($show->Patch_Number == 1): ?>  
                                 <th><?php echo e(trans('admin.Patch_Number')); ?></th>
                                 <?php endif; ?>   
                                  <?php if($show->AvQty == 1): ?>
                                <th><?php echo e(trans('admin.AvQty')); ?></th>
                                  <?php endif; ?>  
                                 <th><?php echo e(trans('admin.Qty')); ?></th>
                                 <th><?php echo e(trans('admin.Price')); ?></th>
                                  <?php if($show->Disc == 1): ?>
                                 <th><?php echo e(trans('admin.Discount')); ?></th>
                                  <?php endif; ?>
                                     <?php if($show->Tax == 1): ?>
                                 <th><?php echo e(trans('admin.Tax')); ?></th>
                                  <?php endif; ?>
                                     <?php if($show->Store == 1): ?>
                                 <th style="padding:12px 20px;"><?php echo e(trans('admin.Store')); ?></th>
                                  <?php endif; ?>
                                 <?php if($show->Expire_Date == 1): ?>  
                                 <th><?php echo e(trans('admin.Exp_Date')); ?></th>
                                 <?php endif; ?>
                                                     <?php if($show->Sales_Pro_Desc == 1): ?>  
                                 <th><?php echo e(trans('admin.Desc')); ?></th>
                                 <?php endif; ?>
                                 <th><?php echo e(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-more table-color2">
                                        <thead>
                                         <tr>
                                 <th><?php echo e(trans('admin.Name')); ?></th>
                                 <th><?php echo e(trans('admin.Unit')); ?></th>
                                 <th><?php echo e(trans('admin.Code')); ?></th>
                                 <?php if($show->Patch_Number == 1): ?>  
                                 <th><?php echo e(trans('admin.Patch_Number')); ?></th>
                                 <?php endif; ?>    
                                    <?php if($show->AvQty == 1): ?>
                                <th><?php echo e(trans('admin.AvQty')); ?></th>
                                  <?php endif; ?>  
                                 <th><?php echo e(trans('admin.Qty')); ?></th>
                                 <th><?php echo e(trans('admin.Price')); ?></th>
                                <?php if($show->Disc == 1): ?>
                                 <th><?php echo e(trans('admin.Discount')); ?></th>
                                  <?php endif; ?>
                                    <?php if($show->TotalBfTax == 1): ?>
                                 <th><?php echo e(trans('admin.Total_Bf_Taxes')); ?></th>
                                         <?php endif; ?>
                                        <?php if($show->Tax == 1): ?>
                                 <th><?php echo e(trans('admin.Tax')); ?></th>
                                  <?php endif; ?>
                                 <th><?php echo e(trans('admin.Total')); ?></th>
                                  
                                        <?php if($show->Store == 1): ?>
                                 <th><?php echo e(trans('admin.Store')); ?></th>
                                  <?php endif; ?>
                                 <?php if($show->Expire_Date == 1): ?>  
                                 <th><?php echo e(trans('admin.Exp_Date')); ?></th>
                                 <?php endif; ?>
                                                    <?php if($show->Sales_Pro_Desc == 1): ?>  
                                 <th><?php echo e(trans('admin.Desc')); ?></th>
                                 <?php endif; ?>
                                 <th><?php echo e(trans('admin.Actions')); ?></th>
                              </tr>
                                        </thead>
                                        <tbody id="data-dt">
                                             <?php if($show->Disc == 1): ?>
                                <?php  $disshow='';   ?>
                                    <?php else: ?>        
                                       <?php  $disshow='none';   ?>      
                                  <?php endif; ?>
                                    
                                            
                                        <?php if($show->TotalBfTax == 1): ?>
                                <?php  $totbfhow='';   ?>
                                    <?php else: ?>        
                                       <?php  $totbfhow='none';   ?>      
                                  <?php endif; ?>
                                            
                                            
                                     <?php if($show->Tax == 1): ?>
                                <?php  $taxshow='';   ?>
                                    <?php else: ?>        
                                       <?php  $taxshow='none';   ?>      
                                  <?php endif; ?>
                                            
                                            
                                        <?php if($show->Store == 1): ?>
                                <?php  $storeshow='';   ?>
                                    <?php else: ?>        
                                       <?php  $storeshow='none';   ?>      
                                  <?php endif; ?>
                                            
                                            
                                             <?php if($show->AvQty == 1): ?>
                                <?php  $avqtyshow='';   ?>
                                    <?php else: ?>        
                                       <?php  $avqtyshow='none';   ?>      
                                  <?php endif; ?>            
                                            
                                    <?php $__currentLoopData = $details; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $pro): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>        
                                            
                                            <tr>
                          <td>
                            
                                  <?php echo e(app()->getLocale() == 'ar' ?$pro->Product()->first()->P_Ar_Name :$pro->Product()->first()->P_En_Name); ?>  
                        <input type='hidden' name='P_Ar_Name[]' value='<?php echo e($pro->Product()->first()->P_Ar_Name); ?>'>
                    <input type='hidden' name='P_En_Name[]' value='<?php echo e($pro->Product()->first()->P_En_Name); ?>'>

                    <?php if(!empty($pro->V1)): ?>  
                             ( <?php echo e(app()->getLocale() == 'ar' ?$pro->V1()->first()->Name :$pro->V1()->first()->NameEn); ?> )
                            
                        <input type='hidden' name='VOne[]' value='<?php echo e($pro->V1); ?>'>
                        <input type='hidden' name='V_Name[]' value='<?php echo e($pro->V_Name); ?>'>          
                            
                    <?php else: ?>
                       <input type='hidden' name='VOne[]' value=''>
                        <input type='hidden' name='V_Name[]' value=''>      
                    <?php endif; ?> 
                            
                      <?php if(!empty($pro->V2)): ?>  
                        ( <?php echo e(app()->getLocale() == 'ar' ?$pro->V2()->first()->Name :$pro->V2()->first()->NameEn); ?> )
                        <input type='hidden' name='VTwo[]' value='<?php echo e($pro->V2); ?>'>
                        <input type='hidden' name='VV_Name[]' value='<?php echo e($pro->VV_Name); ?>'>       
                    <?php else: ?>
                         <input type='hidden' name='VTwo[]' value=''>
                      <input type='hidden' name='VV_Name[]' value=''>     
                    <?php endif; ?>            
     
                    </td>
                  <td><input type='hidden' name='Unit[]' value='<?php echo e($pro->Unit); ?>'> <?php echo e(app()->getLocale() == 'ar' ?$pro->Unit()->first()->Name :$pro->Unit()->first()->NameEn); ?> </td>
                  <td><input type='hidden' name='P_Code[]' value='<?php echo e($pro->Product_Code); ?>'><?php echo e($pro->Product_Code); ?></td>
                                                
                                 <input type='hidden' name='Patch_Number[]' value='<?php echo e($pro->Patch_Number); ?>'> 
                                                <input type='hidden' class='COSTPRICES'  name='CostPrice[]' value='<?php echo e($pro->CostPrice); ?>'>
    <?php if($show->Patch_Number == 1): ?>  
                                     <td><?php echo e($pro->Patch_Number); ?>

                                              
                                                </td>
                                            <?php endif; ?>                      
                                                
                      <td style="display: <?php echo e($avqtyshow); ?>" ><input type='hidden' name='AvQty[]' value='<?php echo e($pro->AvQty); ?>'><?php echo e($pro->AvQty); ?></td>
                      <td><input class='Qun' type='hidden' name='Qty[]' value='<?php echo e($pro->Qty); ?>'><?php echo e($pro->Qty); ?></td>
                      <td><input type='hidden' name='Price[]' value='<?php echo e($pro->Price); ?>'><?php echo e($pro->Price); ?></td>
              <td style="display: <?php echo e($disshow); ?>"><input class='Disc' type='hidden' name='Discount[]' value='<?php echo e($pro->Discount); ?>'>  <input type='hidden' class='TDISCOOO' id='TDiscProEdit<?php echo e($pro->id); ?>' name='TDiscPro[]' value='<?php echo e($pro->TDiscount); ?>'><?php echo e($pro->Discount); ?></td>
 <td style="display: <?php echo e($totbfhow); ?>"><input class='TotalBFTax' type='hidden' name='TotalBFTax[]' value='<?php echo e($pro->Total_Bf_Tax); ?>'><?php echo e($pro->Total_Bf_Tax); ?></td>
        <td style="display: <?php echo e($taxshow); ?>"><input class='TotalTax' type='hidden' name='TotalTax[]' value='<?php echo e($pro->Total_Tax); ?>'><?php echo e($pro->Total_Tax); ?></td>
        <td><input class='Tot' type='hidden' name='Total[]' value='<?php echo e($pro->Total); ?>'><?php echo e($pro->Total); ?></td>
        <td style="display: <?php echo e($storeshow); ?>"><input  type='hidden' name='StorePurch[]' value='<?php echo e($pro->Store); ?>'>
            <input type='hidden' name='Exp_Date[]' value='<?php echo e($pro->Exp_Date); ?>'>
                <input type='hidden'    name='weight[]' value='<?php echo e($pro->weight); ?>'>
                    <input type='hidden'    name='UnitRate[]' value='<?php echo e($pro->UnitRate); ?>'>
                    <input type='hidden'  class='W'  name='Total_Wight[]' value='<?php echo e($pro->Total_Wight); ?>'>
            <?php echo e(app()->getLocale() == 'ar' ?$pro->Store()->first()->Name :$pro->Store()->first()->NameEn); ?></td>
                                                
             <?php if($show->Expire_Date == 1): ?>  
                                     
        <td>
                                                
             <?php  $qqq=ExpireDateQty::find($pro->Exp_Date); ?>               
                        <?php if(!empty($qqq)): ?>                 
                        <?php echo e($qqq->Exp_Date); ?>

                          <?php endif; ?>                                                       
                                                
        </td>
                                  
        <?php endif; ?>           
                                                
                                                
                                     <input type='hidden' name='SalesProDesc[]' value='<?php echo e($pro->SalesProDesc); ?>'>          
                                                                            <input type='hidden'   name='CostPrice[]' value='<?php echo e($pro->CostPrice); ?>'>       
    <input type='hidden' class='COSTPRICES' id='TotCostNew<?php echo e($pro->id); ?>' name='TotCostNew[]' value='<?php echo e($pro->TotCostNew); ?>'>                   
                                        <?php if($show->Sales_Pro_Desc == 1): ?>           
                                <td><?php echo e($pro->SalesProDesc); ?></td> 
                                                <?php endif; ?>                        

                      <td>
                        <button id='DelAssem' type='button' class='btn btn-default'><i class='fal fa-trash'></i></button>   <input type='hidden' name='Product[]' value='<?php echo e($pro->Product); ?>'>
                        <input type='hidden' name='PurchTax[]' value='<?php echo e($pro->Tax); ?>'>  
                          <input type='hidden' id='Enough<?php echo e($pro->id); ?>' name='AllEnough[]' class='ENO'  value='0'> 
                      </td>
                   </tr>
                                            
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>           
                                        </tbody>

                                    </table>
                                    </div>
                                    <!-- datatable end -->
                                       <div class="form-row">
                                        <div class="form-group col-lg-4">
                                 <label class="form-label" for="simpleinput"> <?php echo e(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"> <?php echo e(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>
                                                     <div class="form-group col-lg-4">
                       <label class="form-label" for="simpleinput">  <?php echo e(trans('admin.Total_Price')); ?></label>
                                   <input type="text" id="Total_Price" disabled  class="form-control">
                                            <input type="hidden" id="Total_PriceHide" name="Total_Price">
                                               <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_Discount" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHide" name="Total_Discount"> 
                                                   <input type="hidden" id="TotalCost" name="Total_Cost"> 
                                        </div>

                                        <div class="form-group col-lg-3">
                        <label class="form-label" for="simpleinput">   <?php echo e(trans('admin.Total_Discount')); ?> </label>
                                                       <input type="text" id="Total_DiscountTT" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHideTT" name="Total_Discount">           
                                        </div>
                                                            <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Total_af_Discount')); ?> </label>
                                    <input type="text" class="form-control" id="TAFterD"  disabled>

                                        </div>
                                        <div class="form-group col-lg-3">
                          <label class="form-label" for="simpleinput">   <?php echo e(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"> <?php echo e(trans('admin.Total_Bill')); ?> </label>
                       
         <input type="text" id="Total_Bill" disabled  class="form-control">
                                        </div>  
                                        <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Discount_Bill')); ?> </label>
                           <input type="text" class="form-control" id="resdiual" name="DiscountBill" value="0" onkeyup="Statuss()">

                                        </div>
                                        <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Total_Net')); ?> </label>
                                    <input type="text" class="form-control" id="Total_PriceW"  disabled>

                                        </div>
                                        <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Paid')); ?> </label>
                                    <input type="text" name="Pay" id="paid"   class="form-control">

                                        </div>
                                              <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('نسبه الربح')): ?>
      
                                <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.ProfitPrecent')); ?> </label>
                           <input type="number" step="any" name="ProfitPrecent" id="ProfitPrecent"   class="form-control" value="<?php echo e($item->ProfitPrecent); ?>" readonly>
                                        <span style="color: red" id="proPrecent"></span>
                        </div>
                                             <?php endif; ?>  
                                           
                                                              <?php if($Def->Total_Wight_Bill == 1): ?>
                              <div class="form-group col-lg-3">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Total_Wight_Bill')); ?> </label>
                           <input type="number" step="any" name="Total_Wight_Bill" id="Total_Wight_Bill"   class="form-control" value="0" readonly>
                          
                        </div>
                         <?php 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> <?php echo e(trans('admin.Save')); ?> </button>

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



                    </div>

                </form> 
        <input type="hidden" id="ED" value="<?php echo e($show->Expire_Date); ?>">   
       <input type="hidden" id="DISCSHOW" value="<?php echo e($show->Disc); ?>">
   <input type="hidden" id="TOTBFSHOW" value="<?php echo e($show->TotalBfTax); ?>">
   <input type="hidden" id="TAXSHOW" value="<?php echo e($show->Tax); ?>">
   <input type="hidden" id="STORESHOW" value="<?php echo e($show->Store); ?>">
   <input type="hidden" id="AVQTYSHOW" value="<?php echo e($show->AvQty); ?>">   
       <input type="hidden" id="Sales_Pro_Desc" value="<?php echo e($show->Sales_Pro_Desc); ?>">      
          <input type="hidden" id="SHW"  value="0"> 
        
             <?php if($Def->Price_Sale == 0): ?>
              
              <?php if(auth()->guard('admin')->user()->emp != 0): ?>
                  
                  <?php if(auth()->guard('admin')->user()->price_sale == 1): ?>
                     
                    <input type="hidden" id="PRICEOPEN" value="1">  
                  <?php else: ?>
                      
                     <input type="hidden" id="PRICEOPEN" value="0">    
                  <?php endif; ?>
                  
              <?php else: ?>
                 
         <input type="hidden" id="PRICEOPEN" value="0">    
              <?php endif; ?>
            
              
          <?php else: ?>
        
           <?php if(auth()->guard('admin')->user()->emp != 0): ?>
                  
                  <?php if(auth()->guard('admin')->user()->price_sale == 1): ?>
                     
                      <input type="hidden" id="PRICEOPEN" value="1">  
                  <?php else: ?>
                      
                  <input type="hidden" id="PRICEOPEN" value="0">    
                  <?php endif; ?>
                  
              <?php else: ?>
                 
                <input type="hidden" id="PRICEOPEN" value="1">    
              <?php endif; ?>
        
        
        
              
            <?php endif; ?>
        
        
        
        
         <?php if(auth()->guard('admin')->user()->emp != 0): ?>
                  
                  <?php if(auth()->guard('admin')->user()->discount == 1): ?>
                     
                    <input type="hidden" id="DISCOPEN" value="1">  
                  <?php else: ?>
                      
                     <input type="hidden" id="DISCOPEN" value="0">    
                  <?php endif; ?>
                  
              <?php else: ?>
                 
         <input type="hidden" id="DISCOPEN" value="1">    
              <?php endif; ?>
            
        
              <?php if($show->Patch_Number == 1): ?>
    <input type="hidden" id="Patch" value="1">
    <?php else: ?>
     <input type="hidden" id="Patch" value="0">
     <?php endif; ?>
        
                   <?php if($Def->Discount == 0): ?>
            <input type="hidden" id="DIS" value="0">  <!-- Number -->
        <?php else: ?>
            <input type="hidden" id="DIS" value="1">  <!-- Precent -->
        
        <?php endif; ?>
                </main>

    <input type="hidden" id="Brandd" value="">  
            <input type="hidden" id="Groupp" value="">  

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

<input type="hidden" id="LOWCOSTPRICE" value="<?php echo e($Def->SalesLowCostPrice); ?>">
<input type="hidden" id="LimitSalesQty" value="<?php echo e($Def->LimitSalesQty); ?>">
<input type="hidden" id="Duplicate_Items" value="<?php echo e($Def->Duplicate_Items); ?>">
<input type="hidden" id="RATOO" value="0">
<input type="hidden" id="DEFAULTCOSTPRICE" value="<?php echo e($FCOST->Cost_Price); ?>">
 <input type="hidden" id="SHOWHIDEPRO" value="<?php echo e($Def->Hide_Product); ?>">
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>

    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/datagrid/datatables/datatables.bundle.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/summernote/summernote.css')); ?>">
    <link rel="stylesheet" media="screen, print" href="<?php echo e(asset('Admin/css/formplugins/select2/select2.bundle.css')); ?>">

    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.bundle.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/datagrid/datatables/datatables.export.js')); ?>"></script>
    <script src="<?php echo e(asset('Admin/js/formplugins/summernote/summernote.js')); ?>"></script>
    <script src="<?php echo e(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;
           }
   
           $("#Emp").select2({
               placeholder: "select...",
               ajax: {
                   type: "GET",
                   dataType: "json",
                   url: "AllEmps",
                   processResults: function (data) {
                       return {
                           results: $.map(data, function (obj, index) {
                               return { id: index, text: obj };
                           }),
                       };
   
                       console.log(data);
                   },
                  data: function (params) {  
   
           
                  var query = {
                           search: params.term,
                       };
                               
           
             $.ajax({
                             url: 'AllEmpsJ/'+params.term,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                         $('#Emp').empty();  
                                 $.each(data, function(key, value){
   
                        $('#Emp').append('<option value="'+ key +'">' + value + '</option>');
                  
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
           
           
       }
               },
           });
   
           $("#Emp").on("select2:select", function (e) {
               console.log("select done", e.params.data);
           });
           
             $("#client").select2({
               placeholder: "select...",
               ajax: {
                   type: "GET",
                   dataType: "json",
                   url: "AllClientsFilter",
                   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: 'AllClientsFilterJS/'+params.term,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                         $('#client').empty();  
                                 $.each(data, function(key, value){
   
                        $('#client').append('<option value="'+ key +'">' + value + '</option>');
                  
                                 });
                                 
                               var countryId = $('#client').val();
                     if(countryId) {
                         $.ajax({
                             url: 'AccountBalanceSOFilter/'+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); 
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }          
                                
                                 
                                 
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
           
           
       }
               },
           });
   
           $("#client").on("select2:select", function (e) {
               console.log("select done", e.params.data);
           });
    
           
                         $('#AccountCodeF').select2({
   placeholder: "select...",
   ajax: {
       type: "GET",
       dataType: 'json',
       url: 'AllClientsFilter',
       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: 'AllClientsFilterJS/'+params.term,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                         $('#AccountCodeF').empty();  
                                 $.each(data, function(key, value){
   
                        $('#AccountCodeF').append('<option value="'+ key +'">' + value + '</option>');
                  
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
           
           
       }
   }
   });
   
   
   $('#AccountCodeF').on('select2:select', function (e) {
   console.log("select done", e.params.data);
   });
     
           
           
           
                         $('#AccountCodee').select2({
   placeholder: "select...",
   ajax: {
       type: "GET",
       dataType: 'json',
       url: 'AllClientsFilter',
       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: 'AllClientsFilterJS/'+params.term,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                         $('#AccountCodee').empty();  
                                 $.each(data, function(key, value){
   
                        $('#AccountCodee').append('<option value="'+ key +'">' + value + '</option>');
                  
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
           
           
       }
   }
   });
   
   
   $('#AccountCodee').on('select2:select', function (e) {
   console.log("select done", e.params.data);
   });
     
           
           
           
             $(".EmpDele").select2({
               placeholder: "select...",
               ajax: {
                   type: "GET",
                   dataType: "json",
                   url: "AllEmps",
                   processResults: function (data) {
                       return {
                           results: $.map(data, function (obj, index) {
                               return { id: index, text: obj };
                           }),
                       };
   
                       console.log(data);
                   },
                  data: function (params) {  
   
           
                  var query = {
                           search: params.term,
                       };
                               
           
             $.ajax({
                             url: 'AllEmpsJ/'+params.term,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                         $('.EmpDele').empty();  
                                 $.each(data, function(key, value){
   
                        $('.EmpDele').append('<option value="'+ key +'">' + value + '</option>');
                  
                                 });
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
           
           
       }
               },
           });
   
           $(".EmpDele").on("select2:select", function (e) {
               console.log("select done", e.params.data);
           });
                
                 
           
           
       });
   });
</script>

<!-- Account Balance -->
<script>
   $(document).ready(function() {
   
                  $('#client').on('change', function(){
                      var countryId = $(this).val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceSOFilter/'+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); 
                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {
   
                          $('select[name="state"]').empty();
                      }
   
                  });
   
              });
    
     $(document).ready(function() { 
   
                      var countryId = $('#client').val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceSFilter/'+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); 
                                  });
                              },
                              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='',Brand='',Group='')
    {  
     $.ajax({
      url:'1/SalesProductsFilter',
      method:'GET',
      data:{search:search,store:store,client:client,Brand:Brand,Group:Group},
      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();     
     var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
          if (event.which != '13') {
       
   fetch_customer_data(search,store,client,Brand,Group);
       
   }
   
    });
       
       
    $(document).on('change', '#store', function(){
     var store = $(this).val();     
     var search = $('#search').val();     
     var client = $('#client').val();     
     var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,client,Brand,Group);
    });
       
    $(document).on('change', '#client', function(){
     var client = $(this).val();     
     var search = $('#search').val();     
     var store = $('#store').val();     
     var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,client,Brand,Group);
    });  
       
     $(document).on('change', '#Brandd', function(){
     var Brand = $(this).val();     
     var search = $('#search').val();     
     var store = $('#store').val();     
     var client = $('#client').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,client,Brand,Group);
    });   
       
     $(document).on('change', '#Groupp', function(){
     var Group = $(this).val();     
     var search = $('#search').val();     
     var store = $('#store').val();     
     var Brand = $('#Brandd').val();     
     var client = $('#client').val();     
     fetch_customer_data(search,store,client,Brand,Group);
    });      
          
   });
</script>
<!-- Filter Search Code -->
<script>
    
   $(document).ready(function(){
   
    fetch_customer_data();
   
    function fetch_customer_data(search = '',store='',client='',Brand='',Group='')
    {  
     $.ajax({
      url:'1/SalesProductsSearchCodeFilter',
      method:'GET',
      data:{search:search,store:store,client:client,Brand:Brand,Group:Group},
      dataType:'json',
      success:function(data)
      {
        
          
       $('.Data').html(data.table_data);
               $("#Data").show();
          
      }
     })
    }
    
   $(document).on('keyup', '#SearchCode', function(event){
     var search = $(this).val();     
     var store = $('#store').val();     
     var client = $('#client').val();     
     var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
          if (event.which != '13') {
       
   fetch_customer_data(search,store,client,Brand,Group);
       
   }
   
    });
       
       
   
          
   });
</script>

<!-- Unit Code and Name V-->
<script>
   function  UnitCodePurch(r){
   
   var countryId = $('#UnitPurch'+r).val();
   var Pro = $('#Product'+r).val();
   var client = $('#client').val();
   var code = $('#CodePurch'+r).val();
   var Store = $('#StorePurch'+r).val();
       
                     if(countryId) {
                         $.ajax({
                             url: 'UnitSalesFilter/'+countryId+'/'+Pro+'/'+client+'/'+code+'/'+Store,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                     
                       $('#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); 
                       $('#AvQty'+r).val(parseFloat(data.qty).toFixed(2)); 
                            
         
                       $('#UnitPriceOne'+r).val(data.priceOne); 
                       $('#UnitPriceTwo'+r).val(data.priceTwo); 
                       $('#UnitPriceThree'+r).val(data.priceThree); 
                           $("#CostPrice"+r).val(data.cost);       
   
       
   
                                 });
                                 
   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;       
    var HighDisc = $("#HighDiscD"+r).val();
                                 
          var Product = $("#Product"+r).val();
             var UnitID = $("#UnitPurch"+r).val();       
            $.ajax({
                             url: 'UnitSalesRateFilter',
                             type:"GET",
                            data:{
                              Product:Product,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                     $('#RATOO').val(data.rate); 

                                 
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
       
                             
                                 
   
                                        
                 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; 
       }
       
                var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscPro"+r).val(parseFloat(BFG));
   
   
       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();
        var AvQty = $("#AvQty"+r).val();
        var x=  <?php echo $Def->Mainus; ?> ;
   
       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 = "inline-block";           
     }  
            
                 // x de elly hya lw byshtghl bsalb 
              if(x == 0){
    
       if(AvQty != 0){
           
           
       if(parseFloat(AvQty) >= parseFloat(Qty)){
            
    document.getElementById("AddBtnPur"+r).style.display = "inline-block";
            
        }else{
            
            
   document.getElementById("AddBtnPur"+r).style.display = "none";     
            
        }   
       
   
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";         
           }    
        
        
    }else{
        
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
        
    }   
   
        
                                   if(HighDisc != 0){
           
         
           if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                     document.getElementById("Submit").style.display="none";   
           }else{
                  document.getElementById("Submit").style.display="inline-block";    
               
           }
           
           
       }
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
       
       
           
   
   }   
</script>  
<!-- Unit Code and Name -->
<script>
   function  UnitCodePurchh(r){
   
   var countryId = $('#UnitPurch'+r).val();
   var Pro = $('#Product'+r).val();
   var client = $('#client').val();
   var code = $('#CodePurch'+r).val();
       var Store = $('#StorePurch'+r).val();   
                     if(countryId) {
                         $.ajax({
                             url: 'UnitSalesFilter/'+countryId+'/'+Pro+'/'+client+'/'+code+'/'+Store,
                             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); 
                       $('#AvQty'+r).val(parseFloat(data.qty).toFixed(2)); 
                                     
                       $('#UnitPriceOne'+r).val(data.priceOne); 
                       $('#UnitPriceTwo'+r).val(data.priceTwo); 
                       $('#UnitPriceThree'+r).val(data.priceThree); 
                       $("#CostPrice"+r).val(data.cost);
                                 });
                                 
                                 
                                 
                                 
                                 
   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;       
    var HighDisc = $("#HighDiscD"+r).val();
   
                                 
                                 
                                       var Product = $("#Product"+r).val();
             var UnitID = $("#UnitPurch"+r).val();       
            $.ajax({
                             url: 'UnitSalesRateFilter',
                             type:"GET",
                            data:{
                              Product:Product,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                     $('#RATOO').val(data.rate); 

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

                                        
                 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; 
       }
                  var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscPro"+r).val(parseFloat(BFG));
       
       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();
        var AvQty = $("#AvQty"+r).val();
       var x=  <?php echo $Def->Mainus; ?> ;
   
       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 = "inline-block";           
     }  
            
                 // x de elly hya lw byshtghl bsalb 
              if(x == 0){
    
       if(AvQty != 0){
           
           
       if(parseFloat(AvQty) >= parseFloat(Qty)){
            
    document.getElementById("AddBtnPur"+r).style.display = "inline-block";
            
        }else{
            
            
   document.getElementById("AddBtnPur"+r).style.display = "none";     
            
        }   
       
   
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";         
           }    
        
        
    }else{
        
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
        
    }   
   
                    if(HighDisc != 0){
           
         
           if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                     document.getElementById("Submit").style.display="none";   
           }else{
                  document.getElementById("Submit").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();
   var Product = $('#Product'+r).val();
   var Code = $('#CodePurch'+r).val();
   var Unit = $('#UnitPurch'+r).val();
    var UnitDefault = $("#UnitDefault"+r).val();   
    var CodeDefault = $("#CodeDefault"+r).val();   
    var StoreDefault = $("#StoreDefault"+r).val();   
                     if(countryId) {
                         $.ajax({
        url: 'StoreNameSalesFilter/'+countryId+'/'+Product+'/'+Code+'/'+Unit+'/'+UnitDefault+'/'+CodeDefault+'/'+StoreDefault,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                       $('#StorePurchName'+r).val(data.name); 
                       $('#AvQty'+r).val(data.AvQty); 
   
                                     
   
                                 });
                                 
   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;       
    var HighDisc = $("#HighDiscD"+r).val();
   
                                       var Product = $("#Product"+r).val();
             var UnitID = $("#UnitPurch"+r).val();       
            $.ajax({
                             url: 'UnitSalesRateFilter',
                             type:"GET",
                            data:{
                              Product:Product,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                     $('#RATOO').val(data.rate); 

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

                                             
                 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; 
       }
                  var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscPro"+r).val(parseFloat(BFG));
       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();
   var AvQty = $("#AvQty"+r).val();
   var x=  <?php echo $Def->Mainus; ?> ;
                      
       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 = "inline-block";           
     }  
            
          // x de elly hya lw byshtghl bsalb 
      if(x == 0){
    
       if(AvQty != 0){
           
           
       if(parseFloat(AvQty) >= parseFloat(Qty)){
            
    document.getElementById("AddBtnPur"+r).style.display = "inline-block";
            
        }else{
            
   document.getElementById("AddBtnPur"+r).style.display = "none";     
            
        }   
       
   
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";         
           }    
        
        
    }else{
        
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
        
    }   
   
     
                    if(HighDisc != 0){
           
         
           if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                     document.getElementById("Submit").style.display="none";   
           }else{
                  document.getElementById("Submit").style.display="block";    
               
           }
           
           
       }
   
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
   
   }   
</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 ExpDateName = $("#ExpDate"+r).find(":selected").text();
             var PurchTax = $("#PurchTax"+r).val();
             var TotalTax = $("#Tax"+r).val();
             var Discount = $("#Discount"+r).val();
         var TDiscPro = $("#TDiscPro"+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 CostPrice = $("#CostPrice"+r).val();
                var SalesProDesc = $("#SalesProDesc"+r).val();
                var weight = $("#weight"+r).val();
                var maxSales = $("#maxSales"+r).val();
                var LimitSalesQty = $("#LimitSalesQty").val();
   var DEFAULTCOSTPRICE = $("#DEFAULTCOSTPRICE").val();    
   var Sales_Pro_Desc = $("#Sales_Pro_Desc").val();    


   

           var RATOO = $("#RATOO").val();
 
       var TWeight=parseFloat(Qty) * (parseFloat(weight) * parseFloat(RATOO)) ;
        
       
       

             var ShowDesc = '';
             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 PRICEOPEN = $("#PRICEOPEN").val();
        var DISCOPEN = $("#DISCOPEN").val();
       
          if(parseFloat(PRICEOPEN) == 0){
            PO="<input type='number' id='PriD"+r+"' step='any'  value='"+Price+"' class='form-control' disabled ><input type='hidden' name='Price[]'  value='"+Price+"'>";  
     }else{
   
            PO="<input type='number' id='PriD"+r+"' step='any' name='Price[]' value='"+Price+"' class='form-control' onkeyup='TotD("+r+")' onclick='TotD("+r+")'>";  
     
     }
       
       
               if(parseFloat(DISCOPEN) == 0){
    DO="<input class='Disc form-control' id='DiscD"+r+"' type='number' step='any' value='"+Discount+"'  disabled ><input type='hidden' name='Discount[]'  value='"+Discount+"'>";  
     }else{
       DO="<input class='Disc form-control' id='DiscD"+r+"' type='number' step='any' name='Discount[]' value='"+Discount+"' onkeyup='TotD("+r+")' onclick='TotD("+r+")' >";  
     
     }
              
            var Exp='';
        var ED = $("#ED").val();
       
        var DIS = $("#DIS").val();
   
         if(ED == 1){
           
         Exp = "<td><input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>" + ExpDateName + "</td>";
           
       }else{
           
           Exp = "<input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>";
       }
                   if(Sales_Pro_Desc == 1){
           
         ShowDesc = "<td><input type='hidden' name='SalesProDesc[]' value='"+SalesProDesc+"'>" + SalesProDesc + "</td>";
           
       }else{
           
           ShowDesc = "<input type='hidden' name='SalesProDesc[]' value='"+SalesProDesc+"'>";
       }
           
       
       
       

       
        var Patch = $("#Patch").val();
       if(parseFloat(Patch) == 1){
           
   var pn="<td><input type='hidden' step='any' class='form-control' name='Patch_Number[]' value="+PatchNum+">"+PatchNum+"</td>";
       }else{
           var pn="<input type='hidden'  name='Patch_Number[]' value="+PatchNum+">";
           
       }
       
             document.getElementById("AddBtnPur"+r).style.display = "none";
             document.getElementById("Row"+r).style.display = "none";
                         var SHOWHIDEPRO = $("#SHOWHIDEPRO").val();
       
       if(parseFloat(SHOWHIDEPRO) == 0){
                 $("#Data").hide();
          }
       
       
       var RFF= parseFloat(Qty) * parseFloat(Price);
       var RFFResult= parseFloat(RFF) - parseFloat(Total);
       
            var DISCSHOW = $("#DISCSHOW").val();
        var TOTBFSHOW = $("#TOTBFSHOW").val();
        var TAXSHOW = $("#TAXSHOW").val();
        var STORESHOW = $("#STORESHOW").val();
        var AVQTYSHOW = $("#AVQTYSHOW").val();
       
       
           if(AVQTYSHOW == 1){
           
       var  AVQTYSHOWW = "";
           
       }else{
           
             var  AVQTYSHOWW = "none";
       }
       
        if(DISCSHOW == 1){
           
       var  DISCSHOWW = "";
           
       }else{
           
             var  DISCSHOWW = "none";
       }
       
       
          if(TOTBFSHOW == 1){
           
        var TOTBFSHOWW = "";
           
       }else{
           
            var TOTBFSHOWW  = "none";
       }
       
       
       
          if(TAXSHOW == 1){
           
      var   TAXSHOWW = "";
           
       }else{
           
            var   TAXSHOWW = "none";
       }
       
       
       
          if(STORESHOW == 1){
           
        var STORESHOWW = "";
           
       }else{
           
             var STORESHOWW  = "none";
       }
       
               var LANG = $("#LANG").val();
   if(LANG == 'ar' ){ 
          var Nemo = P_Ar_Name ;
          }else{
             var Nemo = P_En_Name ;   
          } 
       
       
       var TotCostNew=parseFloat(Qty) * parseFloat(CostPrice) ;

       
       
        
       
             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' id='BAR"+r+"' name='P_Code[]' value='"+Barcode+"'>" + Barcode + "</td>"+pn+"<td style='display:"+AVQTYSHOWW+"'><input type='hidden' id='AvQuntD"+r+"' name='AvQty[]' value='"+AvQty+"'>" + AvQty + "</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><td>"+PO+"</td><td style='display:"+DISCSHOWW+"'>"+DO+"</td><td style='display:"+TOTBFSHOWW+"'><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><td style='display:"+TAXSHOWW+"'><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><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><td style='display:"+STORESHOWW+"'><input  type='hidden' name='StorePurch[]' value='"+StorePurch+"'>" + StorePurchName + "</td>"+Exp+""+ShowDesc+"<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+"'><input type='hidden' id='Enough"+r+"' name='AllEnough[]' class='ENO'  value='0'><input type='hidden' class='DiscoPrecent' id='disssccoount"+r+"' value='"+RFFResult+"'><input type='hidden' class='TDISCOOO' id='TDiscProEdit"+r+"' name='TDiscPro[]' value='"+TDiscPro+"'><input type='hidden' id='costPric"+r+"'   name='CostPrice[]' value='"+CostPrice+"'><input type='hidden' id='weightT"+r+"'   name='weight[]' value='"+weight+"'><input type='hidden' id='UnitRate"+r+"'   name='UnitRate[]' value='"+RATOO+"'><input type='hidden' id='Total_Wight"+r+"' class='W'  name='Total_Wight[]' value='"+TWeight+"'><input type='hidden' id='maxSa"+r+"' value='"+maxSales+"'><input type='hidden' class='COSTPRICES' id='TotCostNew"+r+"' name='TotCostNew[]' value='"+TotCostNew+"'></tr>";
   
       
       
       
       var Duplicate_Items=$('#Duplicate_Items').val();
       
       
   if(LimitSalesQty == 1){
       
       if(maxSales >= Qty){
         
                  var P = $("#PRO"+r).val();
           var Bar = $("#BAR"+r).val();
           
           if(Duplicate_Items == 0){
             if(Product != P &&  Barcode != Bar){
                  $("#data-dt").append(markup); 
             }
       }else{
          $("#data-dt").append(markup);   
           
       }
           
          }else{
              
      if(LANG == 'ar' ){           
    alert('تجاوزت الحد المسموح  لبيع كمية هذا المنتج');     
      }else{
          
    alert('You have exceeded the selling limit for this product');            
      }
              
          }
       
       
       
       
   }else{
           var P = $("#PRO"+r).val();
           var Bar = $("#BAR"+r).val();
               if(Duplicate_Items == 0){
             if(Product != P &&  Barcode != Bar){
                  $("#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());
   }); 
       
               var prec = 0;        
   $('.DiscoPrecent').each(function(){
   prec += parseFloat($(this).val());
   }); 
       
          var sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
   
       
                 var COPRI = 0;        
   $('.COSTPRICES').each(function(){
   COPRI += parseFloat($(this).val());
   });       
       
       
       var COWeight = 0;        
   $('.W').each(function(){
   COWeight += parseFloat($(this).val());
   }); 
       
       
   
       $('#Total_Wight_Bill').val(parseFloat(COWeight));
       $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
       var TootPriice=parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax);
     $('#Total_Price').val(parseFloat(TootPriice).toFixed(2));
   $('#Total_PriceHide').val(parseFloat(TootPriice).toFixed(2));
       
   $('#Total_PriceW').val(parseFloat(sumT).toFixed(2));
       
       var PROFIIIT=parseFloat(sumT) - parseFloat(COPRI);
   $('#ProfitPrecent').val(parseFloat(PROFIIIT).toFixed(2));
       
       var nfd=((parseFloat(sumT) - parseFloat(COPRI)) * 100) / parseFloat(COPRI);
   $('#proPrecent').text(parseFloat(nfd).toFixed(2));
       $('#Total_Bill').val(parseFloat(sumT).toFixed(2));
   
           $('#Total_DiscountTT').val(parseFloat(sumTTD).toFixed(2));
   $('#Total_DiscountHideTT').val(parseFloat(sumTTD).toFixed(2));
    
       $('#Total_Discount').val(parseFloat(sumD).toFixed(2));
   $('#Total_DiscountHide').val(parseFloat(sumD).toFixed(2));
       
       
       var BEFO=parseFloat(sumBF)+parseFloat(sumTTD);
       
          $('#Total_Bf_Taxes').val(parseFloat(BEFO).toFixed(2));
   $('#Total_Bf_TaxesHide').val(parseFloat(BEFO).toFixed(2));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).toFixed(2));
   $('#TotalCost').val(parseFloat(COPRI).toFixed(2));
   
       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";    
       }   
       }
   
       
      
       
        var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        var resdiual =$('#resdiual').val();
        var total =$('#Total_PriceHide').val();
        var totalDisc =$('#Total_DiscountHideTT').val();
   
          var totalTax =$('#Total_TaxesHide').val();
   
   
         var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
             var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
          $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
         $('#paid').val(parseFloat(RR).toFixed(2));
       
         $('#presenter').val(parseFloat(RR).toFixed(2));
         $('#total').val(parseFloat(sumT).toFixed(2));
    
       
       
       
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
       
        $('#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());
   }); 
       
                           var prec = 0;        
   $('.DiscoPrecent').each(function(){
   prec += parseFloat($(this).val());
   }); 
            
                      var sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
                    var COPRI = 0;        
   $('.COSTPRICES').each(function(){
   COPRI += parseFloat($(this).val());
   }); 
            
                   var COWeight = 0;        
   $('.W').each(function(){
   COWeight += parseFloat($(this).val());
   }); 
       
      $('#Total_Wight_Bill').val(parseFloat(COWeight));

    $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
       var TootPriice=parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax);
     $('#Total_Price').val(parseFloat(TootPriice).toFixed(2));
   $('#Total_PriceHide').val(parseFloat(TootPriice).toFixed(2));
       
   $('#Total_PriceW').val(parseFloat(sumT).toFixed(2));
       
       var PROFIIIT=parseFloat(sumT) - parseFloat(COPRI);
   $('#ProfitPrecent').val(parseFloat(PROFIIIT).toFixed(2));
       
       var nfd=((parseFloat(sumT) - parseFloat(COPRI)) * 100) / parseFloat(COPRI);
   $('#proPrecent').text(parseFloat(nfd).toFixed(2));
       $('#Total_Bill').val(parseFloat(sumT).toFixed(2));
   
           $('#Total_DiscountTT').val(parseFloat(sumTTD).toFixed(2));
   $('#Total_DiscountHideTT').val(parseFloat(sumTTD).toFixed(2));
    
       $('#Total_Discount').val(parseFloat(sumD).toFixed(2));
   $('#Total_DiscountHide').val(parseFloat(sumD).toFixed(2));
       
       
       var BEFO=parseFloat(sumBF)+parseFloat(sumTTD);
       
          $('#Total_Bf_Taxes').val(parseFloat(BEFO).toFixed(2));
   $('#Total_Bf_TaxesHide').val(parseFloat(BEFO).toFixed(2));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).toFixed(2));
   $('#TotalCost').val(parseFloat(COPRI).toFixed(2));
   
       
            
                  var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        var resdiual =$('#resdiual').val();
        var total =$('#Total_PriceHide').val();
        var totalDisc =$('#Total_DiscountHideTT').val();
   
          var totalTax =$('#Total_TaxesHide').val();
   
   
         var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
             var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
          $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
         $('#paid').val(parseFloat(RR).toFixed(2));
    
             $('#presenter').val(parseFloat(RR).toFixed(2));
         $('#total').val(parseFloat(sumT).toFixed(2));
            
   
       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";    
       }   
       }
   
     
      
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
                 var EN = 0;   
 $('.ENO').each(function(){
   EN += parseFloat($(this).val());
   }); 
    
                        var Total_PriceW =$('#Total_PriceW').val();

             if(EN == 0){
        
             if(Total_PriceW == 'NaN'){
                   document.getElementById("Submit").style.display = "none";   
                    }else{
        document.getElementById("Submit").style.display = "block";    
             }
             
       }else{
           
        document.getElementById("Submit").style.display = "none";    
       } 
   
                    })  
       
       
     }    
</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 CostPrice = $("#CostPrice"+r).val();
   var LOWCOSTPRICE = $("#LOWCOSTPRICE").val();
         var Product = $("#Product"+r).val();
         var store = $("#StorePurch"+r).val();
         var pro_code = $("#CodePurch"+r).val();
             var UnitID = $("#UnitPurch"+r).val();       
             var DEFAULTCOSTPRICE = $("#DEFAULTCOSTPRICE").val();       
   var i = 0;
   var ii=0;       
   var iii=0;       
       
      
                   $.ajax({
                             url: 'UnitSalesRateFilter',
                             type:"GET",
                            data:{
                              Product:Product,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                     $('#RATOO').val(data.rate); 

                                 
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
       
       
       if(DEFAULTCOSTPRICE == 2){
          
            $.ajax({
                             url: 'NewCostProductFilter',
                             type:"GET",
                            data:{
                              store:store,  
                              pro_code:pro_code, 
                              Product:Product,  
                              Qty:Qty,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                                 $("#CostPrice"+r).val(data.total_cost);
                                 
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
          
          }
       
       


      
     var x=  <?php echo $Def->Mainus; ?> ;
   
          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; 
       }
       
                  var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscPro"+r).val(parseFloat(BFG));
       
       
       if(TaxType == 1){
           //Precent
          
        var BF =  parseFloat(Qty) *  (parseFloat(Price)  -  parseFloat(Discount) );  
       
       $("#TotalBFTax"+r).val(parseFloat(BF).toFixed(2));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#Tax"+r).val(parseFloat(ii).toFixed(2));
   
       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#Total"+r).val(parseFloat(iii).toFixed(2));
           
       }else if(TaxType == 2){
          //Number 
          var BF =  parseFloat(Qty) *  (parseFloat(Price)  -  parseFloat(Discount) );  
         $("#TotalBFTax"+r).val(parseFloat(BF).toFixed(2));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i).toFixed(2));
   
       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#Total"+r).val(parseFloat(iii).toFixed(2));
           
           
       }
       
   
        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 != ''  && Qty != 0 && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
         
                if(Qty < 0 || Price < 0 || Discount < 0 || Total < 0){
               document.getElementById("AddBtnPur"+r).style.display = "none";  
           
           }else{
               
            
               if(parseFloat(LOWCOSTPRICE) == 0){
                  
                   
                     if(DEFAULTCOSTPRICE == 2){
                   
                            if(parseFloat(Price)*parseFloat(Qty) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                         
                     }else{
                            if(parseFloat(Price) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                      
                     }
                   
                   
                  }else{
                   document.getElementById("AddBtnPur"+r).style.display = "inline-block"; 
                  }
               
           }
             
     }  
            
      // x de elly hya lw byshtghl bsalb 
    if(x == 0){
    
       if(parseFloat(AvQty) != 0){
           
           
        if(parseFloat(AvQty) >= parseFloat(Qty)){
          
            if(Qty < 0 || Price < 0 || Discount < 0 || Total < 0){
               document.getElementById("AddBtnPur"+r).style.display = "none";  
           
           }else{
               
               
               if(parseFloat(LOWCOSTPRICE) == 0){
                  
                   
                     if(DEFAULTCOSTPRICE == 2){
                   
                            if(parseFloat(Price)*parseFloat(Qty) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                         
                     }else{
                            if(parseFloat(Price) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                      
                     }
                   
                   
                  }else{
                   document.getElementById("AddBtnPur"+r).style.display = "inline-block"; 
                  }
               
             
           }
            
        }else{
            
   document.getElementById("AddBtnPur"+r).style.display = "none";     
            
        }   
       
   
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";         
           }    
        
        
    }else{
        
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
        
    }   
   
   
       if(HighDisc != 0){
           
         
           if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                     document.getElementById("AddBtnPur"+r).style.display = "none";    
           }else{
                          if(Qty < 0 || Price < 0 || Discount < 0 || Total < 0){
               document.getElementById("AddBtnPur"+r).style.display = "none";  
           
           }else{
               
               
                 if(parseFloat(LOWCOSTPRICE) == 0){
                  
                   
                     if(DEFAULTCOSTPRICE == 2){
                   
                            if(parseFloat(Price)*parseFloat(Qty) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                         
                     }else{
                            if(parseFloat(Price) < parseFloat(CostPrice)){
                         
        document.getElementById("AddBtnPur"+r).style.display = "none"; 

                         }else{
                document.getElementById("AddBtnPur"+r).style.display = "inline-block";   
                         }
                      
                     }
                   
                   
                  }else{
                   document.getElementById("AddBtnPur"+r).style.display = "inline-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 CostPrice = $("#costPric"+r).val();
    var weight = $("#weightT"+r).val();
    var RATOO = $("#UnitRate"+r).val();
    var maxSales = $("#maxSa"+r).val();
    var LimitSalesQty = $("#LimitSalesQty").val();
       var DEFAULTCOSTPRICE = $("#DEFAULTCOSTPRICE").val();      
            var Product = $("#Product"+r).val();
         var store = $("#StorePurch"+r).val();
         var pro_code = $("#CodePurch"+r).val();
             var UnitID = $("#UnitPurch"+r).val();      
          
    var LANG = $("#LANG").val();
       var EN = 0;   
   var i = 0;
   var ii=0;       
   var iii=0;    
        
        var TWeight=parseFloat(Qty) * (parseFloat(weight) * parseFloat(RATOO)) ;

                $("#Total_Wight"+r).val(parseFloat(TWeight));
     
         
 
       if(DEFAULTCOSTPRICE == 2){
          
            $.ajax({
                             url: 'NewCostProductFilter',
                             type:"GET",
                            data:{
                              store:store,  
                              pro_code:pro_code, 
                              Product:Product,  
                              Qty:Qty,  
                              UnitID:UnitID  
                            },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                            
                                     
                                 $("#costPric"+r).val(data.total_cost);
                                 
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
           
          
          }
       
       

         
    
 var LOWCOSTPRICE = $("#LOWCOSTPRICE").val();     
     var x=  <?php echo $Def->Mainus; ?> ;
       
                 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; 
       }
                     var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscProEdit"+r).val(parseFloat(BFG));
       if(TaxType == 1){
           //Precent
          
    var BF =  parseFloat(Qty) *  (parseFloat(Price)  -  parseFloat(Discount) );  
       
       $("#TotBFTaxD"+r).val(parseFloat(BF).toFixed(2));
       $("#TotBFTaxDHide"+r).val(parseFloat(BF).toFixed(2));
           
       i =    parseFloat(TaxRate)  / 100 ;  
           
        ii=  parseFloat(BF) * parseFloat(i) ;
              
           $("#TaxD"+r).val(parseFloat(ii).toFixed(2));
           $("#TaxDHide"+r).val(parseFloat(ii).toFixed(2));
   
       iii =  parseFloat(BF) + parseFloat(ii) ;
           
           $("#TotD"+r).val(parseFloat(iii).toFixed(2));
           $("#TotDHide"+r).val(parseFloat(iii).toFixed(2));
           
       }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));
           
           
       }
    
            
         if(parseFloat(Qty) > parseFloat(AvQty)){
             
         
         document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);
       
             
         }else{
           
               if(parseFloat(Qty) < 0 || parseFloat(Price) < 0 || parseFloat(Discount) < 0)
           {
               document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);
              
              }else{  
                  
                  
                  if(parseFloat(LOWCOSTPRICE) == 0){
                     
                      
                        if(DEFAULTCOSTPRICE == 2){
                      
                            
                 if(parseFloat(Price)* parseFloat(Qty) < parseFloat(CostPrice)){
                         
                             document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);  

                         }else{
                             
                             
                                   
   if(LimitSalesQty == 1){
       
       if(maxSales >= Qty){
         
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);     
       
           
          }else{
 document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);         
      if(LANG == 'ar' ){           
    alert('تجاوزت الحد المسموح  لبيع كمية هذا المنتج');     
      }else{
          
    alert('You have exceeded the selling limit for this product');            
      }
              
          }
       
   }else{
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);       
       
   }
          
                             
                             
                             
                
                         }            
                            
                     
                        }else{
                            
                      if(parseFloat(Price) < parseFloat(CostPrice)){
                         
                             document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);  

                         }else{
                             
                             
                                   
   if(LimitSalesQty == 1){
       
       if(maxSales >= Qty){
         
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);     
       
           
          }else{
 document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);         
      if(LANG == 'ar' ){           
    alert('تجاوزت الحد المسموح  لبيع كمية هذا المنتج');     
      }else{
          
    alert('You have exceeded the selling limit for this product');            
      }
              
          }
       
   }else{
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);       
       
   }
          
                             
                             
                             
                
                         }
                     
                        }
                      
                     }else{
                     
            if(LimitSalesQty == 1){
       
       if(maxSales >= Qty){
         
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);     
       
           
          }else{
 document.getElementById("QuntD"+r).style.border="1px solid darkred";     
             $("#Enough"+r).val(1);         
      if(LANG == 'ar' ){           
    alert('تجاوزت الحد المسموح  لبيع كمية هذا المنتج');     
      }else{
          
    alert('You have exceeded the selling limit for this product');            
      }
              
          }
       
   }else{
                          document.getElementById("QuntD"+r).style.border="none"; 
             $("#Enough"+r).val(0);       
       
   }
                     }
                  
                  
            
                        }

         }
         
         
         
         
         
       var Total = $("#TotD"+r).val();
       var RFF= parseFloat(Qty) * parseFloat(Price);
       var RFFResult= parseFloat(RFF) - parseFloat(Total);
         $("#disssccoount"+r).val(parseFloat(RFFResult).toFixed(2));
         
          var TotCostNew=parseFloat(Qty) * parseFloat(CostPrice) ;
         
          $("#TotCostNew"+r).val(parseFloat(TotCostNew).toFixed(2));
         

         
   
       $.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());
   }); 
       
               var prec = 0;        
   $('.DiscoPrecent').each(function(){
   prec += parseFloat($(this).val());
   }); 
       
          var sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
   
                          var COPRI = 0;        
   $('.COSTPRICES').each(function(){
   COPRI += parseFloat($(this).val());
   }); 
         
         
           var COWeight = 0;        
   $('.W').each(function(){
   COWeight += parseFloat($(this).val());
   }); 
       
      $('#Total_Wight_Bill').val(parseFloat(COWeight));

     
  
  
    $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
       var TootPriice=parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax);
     $('#Total_Price').val(parseFloat(TootPriice).toFixed(2));
   $('#Total_PriceHide').val(parseFloat(TootPriice).toFixed(2));
       
   $('#Total_PriceW').val(parseFloat(sumT).toFixed(2));
       
       var PROFIIIT=parseFloat(sumT) - parseFloat(COPRI);
   $('#ProfitPrecent').val(parseFloat(PROFIIIT).toFixed(2));
       
       var nfd=((parseFloat(sumT) - parseFloat(COPRI)) * 100) / parseFloat(COPRI);
   $('#proPrecent').text(parseFloat(nfd).toFixed(2));
       $('#Total_Bill').val(parseFloat(sumT).toFixed(2));
   
           $('#Total_DiscountTT').val(parseFloat(sumTTD).toFixed(2));
   $('#Total_DiscountHideTT').val(parseFloat(sumTTD).toFixed(2));
    
       $('#Total_Discount').val(parseFloat(sumD).toFixed(2));
   $('#Total_DiscountHide').val(parseFloat(sumD).toFixed(2));
       
       
       var BEFO=parseFloat(sumBF)+parseFloat(sumTTD);
       
          $('#Total_Bf_Taxes').val(parseFloat(BEFO).toFixed(2));
   $('#Total_Bf_TaxesHide').val(parseFloat(BEFO).toFixed(2));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).toFixed(2));
   $('#TotalCost').val(parseFloat(COPRI).toFixed(2));
   
   
       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";    
       }   
       }
   
       
           var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        var resdiual =$('#resdiual').val();
        var total =$('#Total_PriceHide').val();
        var totalDisc =$('#Total_DiscountHideTT').val();
          var totalTax =$('#Total_TaxesHide').val();
   
   
         var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
             var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
          $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
         $('#paid').val(parseFloat(RR).toFixed(2));
    
          $('#presenter').val(parseFloat(RR).toFixed(2));
         $('#total').val(parseFloat(sumT).toFixed(2));
               var Pay =$('#Payment_Method').val();

      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
                   
   $('.ENO').each(function(){
   EN += parseFloat($(this).val());
   }); 
    
                        var Total_PriceW =$('#Total_PriceW').val();

             if(EN == 0){
        
             if(Total_PriceW == 'NaN'){
                   document.getElementById("Submit").style.display = "none";   
                    }else{
        document.getElementById("Submit").style.display = "block";    
             }
             
       }else{
           
        document.getElementById("Submit").style.display = "none";    
       } 
       
         
           
         
   }
    
</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 Stat =$('#Status').val();
       var paid =$('#paid').val();
       var resdiual =$('#resdiual').val();
       var total =$('#Total_PriceHide').val();
       var totalDisc =$('#Total_DiscountHideTT').val();
   
         var totalTax =$('#Total_TaxesHide').val();
   
   
        var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
            var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
         $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
        $('#paid').val(parseFloat(RR).toFixed(2));
   $('#Total_PriceW').val(parseFloat(RR));
        $('#presenter').val(parseFloat(RR).toFixed(2));
        $('#total').val(parseFloat(RR).toFixed(2));
   $.fn.rowCount = function() {
    return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
    
   if(rowctr == 0){
       document.getElementById("Submit").style.display = "none";    
          
      }else{
          
   
              
               document.getElementById("Submit").style.display = "block";    
      
      }
    if(Pay == 'Installment'){
      
           document.getElementById("Install").style.display = "block";  
        
    }else{
        
         document.getElementById("Install").style.display = "none"; 
        
    }
       
       
              if(Pay == 'Check'){
        
          document.getElementById("CHECK").style.display = "block";  
          
      }else{
          
        document.getElementById("CHECK").style.display = "none";    
      }  
       
              if(Pay == 'Later'){
        
          document.getElementById("Later_Due").style.display = "block";  
                  $('#paid').val('');
          
      }else{
          
        document.getElementById("Later_Due").style.display = "none";    
      }     
       
               if(Pay == 'InstallmentCompanies'){
        
          document.getElementById("CompInstall").style.display = "block";  
          
      }else{
          
        document.getElementById("CompInstall").style.display = "none";    
      }  
       
       
       
   }
    
</script> 
<!-- Submit Script -->
<script>
   function SPP(){
      $('#sp').val(1);  
      var x= $('#sp').val();   
      var store= $('#store').val();   
      var SSAFE= $('#SSAFE').val();   
      var client= $('#client').val();   
   
   
       if(store != '' && SSAFE != '' && client != 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= $('#store').val();   
      var SSAFE= $('#SSAFE').val();   
      var client= $('#client').val();   
   
   if(store != '' && SSAFE != '' && client != null){
       
    if(x == 0){
        document.getElementById("Submit").style.display = "none"; 
   document.getElementById('form').submit();   
   }
   }else{
           
           alert('تأكد من اختيار مخزن و خزنه وحساب');
           
       }
      
      
   
   }
   
   function SPP8(){
      $('#sp').val(2);  
      var x= $('#sp').val();   
   
   
     
     
                   var store= $('#store').val();   
      var SSAFE= $('#SSAFE').val();   
      var client= $('#client').val();   
   
   if(store != '' && SSAFE != '' && client != null){
     if(x == 2){
        document.getElementById("Submit").style.display = "none"; 
   document.getElementById('form').submit();   
   }
   }else{
           
           alert('تأكد من اختيار مخزن و خزنه وحساب');
           
       }
     
   }
   
   function SPP5(){
      $('#sp').val(3);  
      var x= $('#sp').val();   
   
   
      
                    var store= $('#store').val();   
      var SSAFE= $('#SSAFE').val();   
      var client= $('#client').val();   
   
   if(store != '' && SSAFE != '' && client != null){
     if(x == 3){
        document.getElementById("Submit").style.display = "none"; 
   document.getElementById('form').submit();   
   }
   }else{
           
           alert('تأكد من اختيار مخزن و خزنه وحساب');
           
       }
      
      
   }
   
   
   
</script>
<!-- Installment Total -->
<script>
   function Install(){
       
     var presenter =$('#presenter').val();  
     var annual_interest =$('#annual_interest').val();  
     var Years_Number =$('#Years_Number').val();  
     var total =$('#total').val();  
   
       
       var dif = parseFloat(total) - parseFloat(presenter) ; 
       
       var Percent = parseFloat(annual_interest) / parseFloat(100) ;
       
       var Tp = parseFloat(dif) * parseFloat(Percent) ;
       
       var years = parseFloat(Tp) * parseFloat(Years_Number) ;
       
       var tot = parseFloat(dif) + parseFloat(years) ; 
       
       var monthly = parseFloat(Years_Number) * parseFloat(12) ; 
       
       var t = parseFloat(tot) / parseFloat(monthly) ;
       
       
              $('#monthly_installment').val(parseFloat(t)); 
              $('#monthly_installmentHide').val(parseFloat(t)); 
              $('#installment_Num').val(parseFloat(monthly));  
              $('#installment_NumHide').val(parseFloat(monthly));      
   
   }
</script>

<!-- Add New Client -->
<script>
   function NewClients(){
       
   var co = $('#CODE').val();    
   var Name = $('#Name').val();  
   var PriceLevel = $('#PriceLevel').val();  
   var Phone = $('#Phone').val();  
   var NameEn = $('#NameEn').val();  
   var LANG = $('#LANG').val();  
       if(NameEn == ''){
          
               NameEn = Name ;
          }       
         if(Name) {
                        $.ajax({
                            url: 'AddNewClient/'+co+'/'+Name+'/'+PriceLevel+'/'+Phone,
                            type:"GET",
                            data:{
                                NameEn:NameEn
                            }
                            dataType:"json",
                            beforeSend: function(){
                                $('#loader').css("visibility", "visible");
                            },
   
                            success:function(data) {
                                $.each(data, function(key, value){
                                    
                             if(LANG == 'ar'){
                            alert('تم الاضافه بنجاح');
                       }else{
                           alert('Added Successfully'); 
                       }        
                         
    $('#Name').val('');  
    $('#Phone').val('');               
                                    
                                    
                                });
                            },
                            complete: function(){
                                $('#loader').css("visibility", "hidden");
                            }
                        });
                    }else{
                        
                                  if(LANG == 'ar'){        
                       alert('حقل الاسم مطلوب'); 
                      }else{
                          
                       alert('Name Input is Required');        
                      }
                        
                    }
       
       
       
   }
</script>

<!-- Change Price -->
<script>
   function ChangePriceU(r){
       
     var PriceOne = $("#UnitPriceOne"+r).val();
          $("#Price"+r).val(parseFloat(PriceOne).toFixed(2));
       
    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 i = 0;
      var ii=0;       
      var iii=0;       
    var x=  <?php echo $Def->Mainus; ?> ;
            var HighDisc = $("#HighDisc"+r).val(); 
                                                
                    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; 
          }
                     var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
                $("#TDiscProEdit"+r).val(parseFloat(BFG));
          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 != ''  && Qty != 0 && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
            
           document.getElementById("AddBtnPur"+r).style.display = "inline-block";           
        }  
               
         // x de elly hya lw byshtghl bsalb 
       if(x == 0){
       
          if(parseFloat(AvQty) != 0){
              
              
           if(parseFloat(AvQty) >= parseFloat(Qty)){
             
             
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";
               
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";     
               
           }   
          
   
              }else{
                  
         document.getElementById("AddBtnPur"+r).style.display = "none";         
              }    
           
           
       }else{
           
          document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
           
       }   
          
          if(HighDisc != 0){
              
            
              if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                        document.getElementById("AddBtnPur"+r).style.display = "none";    
              }else{
                      document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
                  
              }
              
              
          }
          
       
   }
       
   function ChangePriceUU(r){
       
     var PriceTwo = $("#UnitPriceTwo"+r).val();
          $("#Price"+r).val(parseFloat(PriceTwo).toFixed(2));
       
    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 i = 0;
      var ii=0;       
      var iii=0;       
    var x=  <?php echo $Def->Mainus; ?> ;
        var HighDisc = $("#HighDisc"+r).val();                                           
                    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; 
          }
          
                      var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
                $("#TDiscProEdit"+r).val(parseFloat(BFG));
          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 != ''  && Qty != 0 && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
            
           document.getElementById("AddBtnPur"+r).style.display = "inline-block";           
        }  
               
         // x de elly hya lw byshtghl bsalb 
       if(x == 0){
       
          if(parseFloat(AvQty) != 0){
              
              
           if(parseFloat(AvQty) >= parseFloat(Qty)){
             
             
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";
               
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";     
               
           }   
          
   
              }else{
                  
         document.getElementById("AddBtnPur"+r).style.display = "none";         
              }    
           
           
       }else{
           
          document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
           
       }   
       
          if(HighDisc != 0){
              
            
              if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                        document.getElementById("AddBtnPur"+r).style.display = "none";    
              }else{
                      document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
                  
              }
              
              
          }
             
       
   }
           
   function ChangePriceUUU(r){
       
     var PriceThree = $("#UnitPriceThree"+r).val();
          $("#Price"+r).val(parseFloat(PriceThree).toFixed(2));
       
    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 i = 0;
      var ii=0;       
      var iii=0;       
    var x=  <?php echo $Def->Mainus; ?> ;
            var HighDisc = $("#HighDisc"+r).val();                                       
                    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; 
          }
                     var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
                $("#TDiscProEdit"+r).val(parseFloat(BFG));
          
          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 != ''  && Qty != 0 && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
            
           document.getElementById("AddBtnPur"+r).style.display = "inline-block";           
        }  
               
         // x de elly hya lw byshtghl bsalb 
       if(x == 0){
       
          if(parseFloat(AvQty) != 0){
              
              
           if(parseFloat(AvQty) >= parseFloat(Qty)){
             
             
       document.getElementById("AddBtnPur"+r).style.display = "inline-block";
               
           }else{
               
      document.getElementById("AddBtnPur"+r).style.display = "none";     
               
           }   
          
   
              }else{
                  
         document.getElementById("AddBtnPur"+r).style.display = "none";         
              }    
           
           
       }else{
           
          document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
           
       }   
       
          if(HighDisc != 0){
              
            
              if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                        document.getElementById("AddBtnPur"+r).style.display = "none";    
              }else{
                      document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
                  
              }
              
              
          }
             
       
   }
   
</script>
<!-- Recipy Voucher Add Ajax -->       
<script>
   $(document).ready(function(){
   
   fetch_customer_data();
   
   function fetch_customer_data(Creditor = '',AccountCode='',Shift='',Safe='',Coin='',Draw='',STORE='')
   {  
    $.ajax({
     url:'AddReciptVoucherAjax',
     method:'GET',
     data:{Creditor:Creditor,AccountCode:AccountCode,Shift:Shift,Safe:Safe,Coin:Coin,Draw:Draw,STORE:STORE},
     dataType:'json',
     success:function(data)
     {
         
         alert('تم الاضافه بنجاح');
   
         $('#Creditor').val(''); 
   $('#AccountCodeF').empty();     
         
     }
    })
   }
   
   $(document).on('click', '#ReciptVoucher', function(){
   
    var Creditor = $('#Creditor').val();     
    var AccountCode = $('#AccountCodeF').val();       
    var Shift = null;       
    var Safe = $('#SafeF').val();       
    var Coin = $('#CoinF').val();       
    var Draw = $('#DrawF').val();       
    var STORE = $('#STOREF').val();    
      
      if(Creditor != '' && AccountCode != ''){
       fetch_customer_data(Creditor,AccountCode,Shift,Safe,Coin,Draw,STORE);    
      }
      
   });
   
      
   
                
   });
   
</script>  
<!-- Payment Voucher Add Ajax -->       
<script>
   $(document).ready(function(){
   
   fetch_customer_data();
   
   function fetch_customer_data(Debitor = '',AccountCodee='',Shift='',Safe='',Coin='',Draw='',STORE='')
   {  
    $.ajax({
     url:'AddPaymentVoucherAjax',
     method:'GET',
     data:{Debitor:Debitor,AccountCodee:AccountCodee,Shift:Shift,Safe:Safe,Coin:Coin,Draw:Draw,STORE:STORE},
     dataType:'json',
     success:function(data)
     {
         
         alert('تم الاضافه بنجاح');
   
         $('#Debitor').val(''); 
   $('#AccountCodee').empty();     
         
     }
    })
   }
   
   $(document).on('click', '#PaymentVoucher', function(){
   
    var Debitor = $('#Debitor').val();     
    var AccountCodee = $('#AccountCodee').val();       
    var Shift = null;       
    var Safe = $('#SafeP').val();       
    var Coin = $('#CoinP').val();       
    var Draw = $('#DrawP').val();       
    var STORE = $('#STOREP').val();    
   
      if(Debitor != '' && AccountCodee != ''){
       fetch_customer_data(Debitor,AccountCodee,Shift,Safe,Coin,Draw,STORE);    
      }
      
   });
   
      
   
   
                
   });
   
</script>  
<!-- Change Tax -->
<script>
   function  TAXPurch(r){
   
   var countryId = $('#OLDTAX'+r).val();
   var Pro = $('#Product'+r).val();
   var Un = $('#UnitPurch'+r).val();
   var CO = $('#CodePurch'+r).val();
                   if(countryId) {
                       $.ajax({
                           url: 'TaxNamePurchasesFilter/'+countryId,
                           type:"GET",
                           dataType:"json",
                           beforeSend: function(){
                               $('#loader').css("visibility", "visible");
                           },
   
                           success:function(data) {
                        
                                   
                     $('#TaxRate'+r).val(data.rate); 
                     $('#TaxType'+r).val(data.type); 
                     $('#PurchTax'+r).val(data.tax); 
         
   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=  <?php echo $Def->Mainus; ?> ;
   
        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; 
     }
     
                var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
           $("#TDiscPro"+r).val(parseFloat(BFG));
     
     
     if(TaxType == 1){
         //Precent
        
      var BF =  parseFloat(Qty) *  (parseFloat(Price)  -  parseFloat(Discount) );  
     
     $("#TotalBFTax"+r).val(parseFloat(BF).toFixed(2));
         
     i =    parseFloat(TaxRate)  / 100 ;  
         
      ii=  parseFloat(BF) * parseFloat(i) ;
            
         $("#Tax"+r).val(parseFloat(ii).toFixed(2));
   
     iii =  parseFloat(BF) + parseFloat(ii) ;
         
         $("#Total"+r).val(parseFloat(iii).toFixed(2));
         
     }else if(TaxType == 2){
        //Number 
        var BF =  parseFloat(Qty) *  (parseFloat(Price)  -  parseFloat(Discount) );  
       $("#TotalBFTax"+r).val(parseFloat(BF).toFixed(2));
        
          i =    parseFloat(TaxRate)   ; 
         
         $("#Tax"+r).val(parseFloat(i).toFixed(2));
   
     iii =  parseFloat(BF) + parseFloat(i) ;
         
         $("#Total"+r).val(parseFloat(iii).toFixed(2));
         
         
     }
     
   
      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 != ''  && Qty != 0 && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
       
      document.getElementById("AddBtnPur"+r).style.display = "inline-block";           
   }  
          
    // x de elly hya lw byshtghl bsalb 
   if(x == 0){
   
     if(parseFloat(AvQty) != 0){
         
         
      if(parseFloat(AvQty) >= parseFloat(Qty)){
        
        
   document.getElementById("AddBtnPur"+r).style.display = "inline-block";
          
      }else{
          
   document.getElementById("AddBtnPur"+r).style.display = "none";     
          
      }   
     
   
         }else{
             
    document.getElementById("AddBtnPur"+r).style.display = "none";         
         }    
      
      
   }else{
      
     document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
      
   }   
   
   
     if(HighDisc != 0){
         
       
         if(parseFloat(Discount)  >  parseFloat(HighDisc)){
                   document.getElementById("AddBtnPur"+r).style.display = "none";    
         }else{
                 document.getElementById("AddBtnPur"+r).style.display = "inline-block";      
             
         }
         
         
     }
     
     
      
   
                           },
                           complete: function(){
                               $('#loader').css("visibility", "hidden");
                           }
                       });
                   } else {
   
                       $('select[name="state"]').empty();
                   }
   
   }   
   
   function PayInstall(){
      
         var Pay= $('#paid').val();
   
        $('#presenter').val(parseFloat(Pay).toFixed(2));
      
   }
</script>


<!-- installment Compamies -->
<script>
      function  InstaallComp(){
   
   var InstallCompany = $('#InstallCompany').val();
   var TotalNet = $('#Total_PriceW').val();

       
                     if(InstallCompany) {
                         $.ajax({
                             url: 'InstallCompanyFilter',
                             type:"GET",
                             data:{
                               InstallCompany:InstallCompany,  
                               TotalNet:TotalNet  
                             },
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
       
                               $('#ServiceFee').val(data.Fee);  
                               $('#CompanyPrecent').val(data.Prec);  
                               $('#TotalServiceFee').val(data.Tot);  
      
   
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });
                     } else {
   
                         $('select[name="state"]').empty();
                     }
       
       
           
   
   }   
</script>



<!--- Sum Totaals -->
<script>
    $(document).ready(function () {
     
  
      $.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());
   }); 
       
               var prec = 0;        
   $('.DiscoPrecent').each(function(){
   prec += parseFloat($(this).val());
   }); 
       
          var sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
   
       
                 var COPRI = 0;        
   $('.COSTPRICES').each(function(){
   COPRI += parseFloat($(this).val());
   });       
       
       
       var COWeight = 0;        
   $('.W').each(function(){
   COWeight += parseFloat($(this).val());
   }); 
       
       
   
       $('#Total_Wight_Bill').val(parseFloat(COWeight));
       $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
       var TootPriice=parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax);
     $('#Total_Price').val(parseFloat(TootPriice).toFixed(2));
   $('#Total_PriceHide').val(parseFloat(TootPriice).toFixed(2));
       
   $('#Total_PriceW').val(parseFloat(sumT).toFixed(2));
       
       var PROFIIIT=parseFloat(sumT) - parseFloat(COPRI);
   $('#ProfitPrecent').val(parseFloat(PROFIIIT).toFixed(2));
       
       var nfd=((parseFloat(sumT) - parseFloat(COPRI)) * 100) / parseFloat(COPRI);
   $('#proPrecent').text(parseFloat(nfd).toFixed(2));
       $('#Total_Bill').val(parseFloat(sumT).toFixed(2));
   
           $('#Total_DiscountTT').val(parseFloat(sumTTD).toFixed(2));
   $('#Total_DiscountHideTT').val(parseFloat(sumTTD).toFixed(2));
    
       $('#Total_Discount').val(parseFloat(sumD).toFixed(2));
   $('#Total_DiscountHide').val(parseFloat(sumD).toFixed(2));
       
       
       var BEFO=parseFloat(sumBF)+parseFloat(sumTTD);
       
          $('#Total_Bf_Taxes').val(parseFloat(BEFO).toFixed(2));
   $('#Total_Bf_TaxesHide').val(parseFloat(BEFO).toFixed(2));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).toFixed(2));
   $('#TotalCost').val(parseFloat(COPRI).toFixed(2));
   
       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";    
       }   
       }
   
       
      
       
        var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        var resdiual =$('#resdiual').val();
        var total =$('#Total_PriceHide').val();
        var totalDisc =$('#Total_DiscountHideTT').val();
   
          var totalTax =$('#Total_TaxesHide').val();
   
   
         var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
             var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
          $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
         $('#paid').val(parseFloat(RR).toFixed(2));
       
         $('#presenter').val(parseFloat(RR).toFixed(2));
         $('#total').val(parseFloat(sumT).toFixed(2));
    
       
       
       
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
       
        
    });
          
          
       $('#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());
   }); 
       
                           var prec = 0;        
   $('.DiscoPrecent').each(function(){
   prec += parseFloat($(this).val());
   }); 
            
                      var sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
                    var COPRI = 0;        
   $('.COSTPRICES').each(function(){
   COPRI += parseFloat($(this).val());
   }); 
            
                   var COWeight = 0;        
   $('.W').each(function(){
   COWeight += parseFloat($(this).val());
   }); 
       
      $('#Total_Wight_Bill').val(parseFloat(COWeight));

    $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
       var TootPriice=parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax);
     $('#Total_Price').val(parseFloat(TootPriice).toFixed(2));
   $('#Total_PriceHide').val(parseFloat(TootPriice).toFixed(2));
       
   $('#Total_PriceW').val(parseFloat(sumT).toFixed(2));
       
       var PROFIIIT=parseFloat(sumT) - parseFloat(COPRI);
   $('#ProfitPrecent').val(parseFloat(PROFIIIT).toFixed(2));
       
       var nfd=((parseFloat(sumT) - parseFloat(COPRI)) * 100) / parseFloat(COPRI);
   $('#proPrecent').text(parseFloat(nfd).toFixed(2));
       $('#Total_Bill').val(parseFloat(sumT).toFixed(2));
   
           $('#Total_DiscountTT').val(parseFloat(sumTTD).toFixed(2));
   $('#Total_DiscountHideTT').val(parseFloat(sumTTD).toFixed(2));
    
       $('#Total_Discount').val(parseFloat(sumD).toFixed(2));
   $('#Total_DiscountHide').val(parseFloat(sumD).toFixed(2));
       
       
       var BEFO=parseFloat(sumBF)+parseFloat(sumTTD);
       
          $('#Total_Bf_Taxes').val(parseFloat(BEFO).toFixed(2));
   $('#Total_Bf_TaxesHide').val(parseFloat(BEFO).toFixed(2));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).toFixed(2));
   $('#TotalCost').val(parseFloat(COPRI).toFixed(2));
   
       
            
                  var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
        var resdiual =$('#resdiual').val();
        var total =$('#Total_PriceHide').val();
        var totalDisc =$('#Total_DiscountHideTT').val();
   
          var totalTax =$('#Total_TaxesHide').val();
   
   
         var RR= (parseFloat(total) + parseFloat(totalTax) ) - (parseFloat(resdiual) + parseFloat(totalDisc));
             var RRR= parseFloat(total) - (parseFloat(resdiual) + parseFloat(totalDisc));
          $('#TAFterD').val(parseFloat(RRR).toFixed(2));        
         $('#paid').val(parseFloat(RR).toFixed(2));
    
             $('#presenter').val(parseFloat(RR).toFixed(2));
         $('#total').val(parseFloat(sumT).toFixed(2));
            
   
       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";    
       }   
       }
   
     
      
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
                 var EN = 0;   
 $('.ENO').each(function(){
   EN += parseFloat($(this).val());
   }); 
    
                        var Total_PriceW =$('#Total_PriceW').val();

             if(EN == 0){
        
             if(Total_PriceW == 'NaN'){
                   document.getElementById("Submit").style.display = "none";   
                    }else{
        document.getElementById("Submit").style.display = "block";    
             }
             
       }else{
           
        document.getElementById("Submit").style.display = "none";    
       } 
   
                    })    
</script>


<?php $__env->stopPush(); ?>
<?php echo $__env->make('admin.index', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /Applications/MAMP/htdocs/laravel/ERP/resources/views/admin/Sales/EditSalesOrder.blade.php ENDPATH**/ ?>