<?php $__env->startSection('content'); ?>
<?php
use App\Models\PurchasesDefaultData;
$Def=PurchasesDefaultData::orderBy('id','desc')->first();
use App\Models\DefaultDataShowHide;
$show=DefaultDataShowHide::orderBy('id','desc')->first();
?>
  <title><?php echo e(trans('admin.Shortcomings')); ?></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.Purchases')); ?> </a></li>
                        <li class="breadcrumb-item active"><?php echo e(trans('admin.Shortcomings')); ?> </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block"><span
                                class="js-get-date"></span></li>
                    </ol>
        
    <form id="form" action="<?php echo e(url('AddShortcomings')); ?>" method="post" enctype="multipart/form-data">
        <?php echo csrf_field(); ?>

               <?php echo view('honeypot::honeypotFormFields'); ?>
                    <div class="row">
                        <div class="col-lg-12">
                            <div id="panel-2" class="panel" style="background: #ccbed59e;">
                                <div class="panel-hdr">
                                    <h2>
                                        <span class="fw-300"><i>   <?php echo e(trans('admin.Shortcomings')); ?>  </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($Code); ?>" class="form-control " disabled>
                                            <input type="hidden" name="Code" value="<?php echo e($Code); ?>" class="form-control">
                                        </div>
                                  <?php if(auth()->guard('admin')->user()->emp == 0): ?>
                      <div class="form-group col-lg-3">
                                    <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                                    <input type="date" name="Date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required>
                                </div>
                                        <?php else: ?>
                                        
                                         <?php if(auth()->guard('admin')->user()->Date == 1): ?>
                                   <div class="form-group col-lg-3">
                                    <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                                    <input type="date" name="Date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control" required>
                                </div>
                                        <?php else: ?>
                                 <div class="form-group col-lg-3">
                                    <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Date')); ?></label>
                                    <input type="date" name="Date" value="<?php echo e(date('Y-m-d')); ?>" 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>
                                      
   
 


                                            <?php $__currentLoopData = $Stores; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $stor): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                                                <option value="<?php echo e($stor->id); ?>" <?php if($Def->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" id="SSAFE" name="Safe" required>
                                          
                                            <?php $__currentLoopData = $Safes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $safe): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                                                <option value="<?php echo e($safe->id); ?>" <?php if($Def->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>
                                        
                                     <?php if($show->Coin == 1): ?>
                                        <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($Def->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>
                                     <?php else: ?>
                                          <div class="form-group col-lg-2" style="display: none">
                                            <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($Def->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>
                                    <?php endif; ?>    
                                        
                                           <?php if($show->Draw == 1): ?>
                                        <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="1" class="form-control" required>
                                        </div>
                                        <?php else: ?>
                                          <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Draw')); ?></label>
                                            <input type="text" name="Draw" value="1" class="form-control" required>
                                        </div>
                                        <?php endif; ?>
                                        
                                        <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($Def->Payment_Method == 'Cash'): ?> selected <?php endif; ?>><?php echo e(trans('admin.Cash')); ?> </option>
                                                <option value="Later" <?php if($Def->Payment_Method == 'Later'): ?> selected <?php endif; ?>><?php echo e(trans('admin.Later')); ?></option> 
                                            </select>
                                        </div>
                                        
                                        
                                           <?php if($show->Status == 1): ?>    
                                        <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($Def->Status == 1): ?> selected <?php endif; ?>><?php echo e(trans('admin.Recived')); ?> </option>
                                                <option value="0" <?php if($Def->Status == 0): ?> selected <?php endif; ?>><?php echo e(trans('admin.Pending')); ?></option>
                                            </select>
                                        </div>
                                        <?php else: ?>
                                    <div class="form-group col-lg-2" style="display: none">
                                            <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($Def->Status == 1): ?> selected <?php endif; ?>><?php echo e(trans('admin.Recived')); ?> </option>
                                                <option value="0" <?php if($Def->Status == 0): ?> selected <?php endif; ?>><?php echo e(trans('admin.Pending')); ?></option>
                                            </select>
                                        </div>     
                                        <?php endif; ?>
                                        
                                        
                                               <?php if($show->Cost_Center == 1): ?>    
                                        <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 echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>  
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        <?php else: ?>
                                         <div class="form-group col-lg-2" style="display: none">
                                            <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 echo e(app()->getLocale() == 'ar' ?$cost->Arabic_Name :$cost->English_Name); ?>  
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        <?php endif; ?>
                                        
                                          <?php if($show->Delegate_Purchase == 1): ?>
                                        <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" 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($Def->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: ?>
                                         <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Delegate')); ?></label>
                                            <select class="select2 form-control w-100" 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($Def->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 if($show->Vendor_Date == 1): ?>
                                        <div class="form-group col-lg-2">
                                <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Vendor_Bill_Date')); ?></label>
                     <input type="date" name="Vendor_Bill_Date" value="<?php echo e(old('Vendor_Bill_Date')); ?>" class="form-control">
                                        </div>
                                        <?php else: ?>
                                         <div class="form-group col-lg-2" style="display: none">
                                <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Vendor_Bill_Date')); ?></label>
                     <input type="date" name="Vendor_Bill_Date" value="<?php echo e(old('Vendor_Bill_Date')); ?>" class="form-control">
                                        </div>
                                        <?php endif; ?>
                                        
                                        
                                          <?php if($show->Refrence_Number == 1): ?>
                                        <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(old('Refernce_Number')); ?>" class="form-control">
                                        </div>
                                        <?php else: ?>
                                          <div class="form-group col-lg-2" style="display: none">
                             <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Refrence_Number')); ?></label>
                   <input type="text" name="Refernce_Number" value="<?php echo e(old('Refernce_Number')); ?>" class="form-control">
                                        </div>
                                        <?php endif; ?>
                                        
                                        
                                        
                                        <div class="form-group col-lg-4">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Account')); ?></label>
                                      <select  class="select2 form-control w-100" id="vendor" name="Vendor" required>
                                          <option value="<?php echo e($Def->Vendor); ?>">
                                          
                                   <?php echo e(app()->getLocale() == 'ar' ?$Def->Vendor()->first()->Name :$Def->Vendor()->first()->NameEn); ?>             
                                          </option>
                                            </select> 
                                        </div>
                                        <div class="form-group col-lg-2">
                                 <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>
                                        
    
                                        
                                                <?php if($show->Note == 1): ?>  
                                        <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e(old('Note')); ?>" class="form-control">
                                        </div>
                                        <?php else: ?>
                                          <div class="form-group col-lg-2" style="display: none">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Notes')); ?>  </label>
                                            <input type="text" name="Note" value="<?php echo e(old('Note')); ?>" class="form-control">
                                        </div>
                                        <?php endif; ?>
                                        
                                        
                                                                                <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Purch_Date')); ?></label>
                           <input type="date" name="Purch_Date" value="<?php echo e(date('Y-m-d')); ?>" class="form-control">
                                        </div>
                                    
                                         <div class="form-group col-lg-2">
                                            <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Purch_Reason')); ?>  </label>
                                            <input type="text" name="Purch_Reason" value="<?php echo e(old('Purch_Reason')); ?>" class="form-control">
                                        </div>  
                                        
                                        <?php if($show->Manufacturing_Model_Shortcomings == 1): ?> 
                        <div class="form-group col-lg-12" >
                                            <label class="form-label" for=""><?php echo e(trans('admin.Manufacturing_Model')); ?></label>
                                            <select class="select2 form-control w-100" id="Manufacturing" onchange="ModelProd()">
                                          <option value=""> <?php echo e(trans('admin.Manufacturing_Model')); ?></option>
                                            <?php $__currentLoopData = $Models; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $mod): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                                                <option value="<?php echo e($mod->id); ?>">
                                             
                                                       <?php echo e(app()->getLocale() == 'ar' ?$mod->Name :$mod->NameEn); ?>    
                                                </option>
                                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>  
                                            </select>
                                        </div>
                                        
                                        <?php endif; ?>   
                                        
                                    </div>
                            </div>
                        </div>
                    </div>
                    </div>
                    <div class="col-xl-12">
                        <div id="panel-1" class="panel" > 
                           
                            <div class="panel-container show">
                                <div class="panel-content" style="background: #fad2f796;">
                                     <div class="row"> 
                            <div class="form-group col-lg-8">
                                <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 if($show->Group_Brand == 1): ?>
                                   <div class="form-group col-lg-2 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-2 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 id="mobile-overflow">
                                    <table 
                                    class="table table-bordered table-hover table-striped w-100 mobile-width-more table-color1 mt-2">
                                    <thead>
                                        <tr>
                                          <th><?php echo e(trans('admin.Name')); ?></th>
                                            <th style="padding:12px 20px;"><?php echo e(trans('admin.Unit')); ?></th>
                                            <th><?php echo e(trans('admin.Code')); ?></th>
                                          <th><?php echo e(trans('admin.AvQty')); ?></th>    
                                            <th><?php echo e(trans('admin.Qty')); ?></th>
                                            <th><?php echo e(trans('admin.Price')); ?></th>
                                            <th><?php echo e(trans('admin.Discount')); ?></th>
                                             <th><?php echo e(trans('admin.Tax')); ?></th>
                                            <th style="padding:12px 20px;"><?php echo e(trans('admin.Store')); ?></th>
                                            <?php if($show->Expire_Date == 1): ?> 
                                            <th><?php echo e(trans('admin.Exp_Date')); ?></th> 
                                            <?php endif; ?>
                                            <th><?php echo e(trans('admin.Actions')); ?></th>
                                        </tr>
                                    </thead>
                                    <tbody class="Data" id="Data">
                                       
                                    </tbody>
                                    </table>
                            <table 
                                    class="table table-bordered table-hover table-striped w-100 mobile-width-more" style="display: none">
                                    <thead>
                                        <tr>
                                        
                                        </tr>
                                    </thead>
                                    <tbody class="DataDD">
                                       
                                    </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>
                                            <th><?php echo e(trans('admin.AvQty')); ?></th>        
                                            <th><?php echo e(trans('admin.Qty')); ?></th>    
                                            <th><?php echo e(trans('admin.Price')); ?></th>
                                            <th><?php echo e(trans('admin.Discount')); ?></th>
                                            <th><?php echo e(trans('admin.Total_Bf_Taxes')); ?></th>
                                            <th><?php echo e(trans('admin.Tax')); ?></th>
                                            <th><?php echo e(trans('admin.Total')); ?></th>
                                            <th><?php echo e(trans('admin.Store')); ?></th>
                                             <?php if($show->Expire_Date == 1): ?> 
                                            <th><?php echo e(trans('admin.Exp_Date')); ?></th>
                                             <?php endif; ?>
                                            <th><?php echo e(trans('admin.Actions')); ?></th>
                                            </tr>
                                        </thead>
                                        <tbody id="data-dt">
                                         
                                           
                                        </tbody>

                                    </table>
                                    </div>
                                    <!-- datatable end -->
                                 <div class="form-row">
                                        <div class="form-group col-lg-4">
                                 <label class="form-label" for="simpleinput"> <?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">
                                                <input type="hidden" id="Total_Discount" disabled  class="form-control">
                                            <input type="hidden" id="Total_DiscountHide" name="Total_Discount">   
                                              <input type="hidden" id="Total_Bf_Taxes" disabled  class="form-control">
                                            <input type="hidden" id="Total_Bf_TaxesHide" name="Total_BF_Taxes">    
                                        </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">
                                        </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-4">
                           <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-4">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Total_Net')); ?> </label>
                       
         <input type="text" id="Total_PriceW" disabled  class="form-control">
                                        </div>  
                                             
                              
                                        <div class="form-group col-lg-4">
                           <label class="form-label" for="simpleinput"> <?php echo e(trans('admin.Paid')); ?> </label>
                                    <input type="text" name="Pay" id="paid"   class="form-control">

                                        </div>   
                                        
                                    </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>
                                        
          <button type="button"  class="btn btn-primary" onclick="SPP()"><i class="fal fa-save"></i>  <?php echo e(trans('admin.SaveandPrint')); ?> </button>
                                      </div>
                                </div>
                            </div>
                        </div>
                    </div>
 <div  id="CHECK" style="display: none">
                                         <div class="row">   
                                                  <div class="form-group col-lg-4">
                                            <label class="form-label" for=""><?php echo e(trans('admin.Check_Type')); ?></label>
                                            <select class="select2 form-control w-100"  name="Check_Type" >
                                                <option value=""> <?php echo e(trans('admin.Check_Type')); ?></option>
                                            <?php $__currentLoopData = $ChecksTypes; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $type): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>    
                                                <option value="<?php echo e($type->id); ?>">
                                           
                                          <?php echo e(app()->getLocale() == 'ar' ?$type->Arabic_Name :$type->Arabic_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.Due_Date')); ?>  </label>
                      <input type="date"  value="<?php echo e(old('Due_Date')); ?>" class="form-control" name="Due_Date">                    
                                        </div>
                                    
                                    
                                      <div class="form-group col-lg-4">
                                   <label class="form-label" for="simpleinput"><?php echo e(trans('admin.Check_Number')); ?>  </label>
             <input type="number" step="any"  value="<?php echo e(old('Check_Number')); ?>" class="form-control" name="Check_Number">                    
                                        </div>
                                                </div>

                                        </div>    


                    </div>

                </form> 
     <input type="hidden" id="ED" value="<?php echo e($show->Expire_Date); ?>">    
            <?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>


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

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

 
              $("#vendor").select2({
                placeholder: "select...",
                ajax: {
                    type: "GET",
                    dataType: "json",
                    url: "AllVendors",
                    processResults: function (data) {
                        return {
                            results: $.map(data, function (obj, index) {

                                return { id: index, text: obj };
                            }),
                        };

                        console.log(data);
                    },
                   data: function (params) {  
   
            
                   var query = {
                            search: params.term,
                        };
                                
            
              $.ajax({
                              url: 'AllVendorsJS/'+params.term,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                          $('#vendor').empty();  
                                  $.each(data, function(key, value){
   
                         $('#vendor').append('<option value="'+ key +'">' + value + '</option>');
                   
                                  });
                                      var countryId = $('#vendor').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");
                              }
                          });
            
            
            
        }
                },
            });

            $("#vendor").on("select2:select", function (e) {
                console.log("select done", e.params.data);
            });
            
            
                             $('#AccountCodeF').select2({
    placeholder: "select...",
    ajax: {
        type: "GET",
        dataType: 'json',
        url: 'AllVendors',
        processResults: function (data) {
          return {
            results: $.map(data, function(obj, index) {
              return { id: index, text: obj };
            })
          };
            
            	console.log(data);
            
        },
         data: function (params) {  
   
            
                   var query = {
                            search: params.term,
                        };
                                
            
              $.ajax({
                              url: 'AllVendorsJS/'+params.term,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                          $('#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: 'AllVendors',
        processResults: function (data) {
          return {
            results: $.map(data, function(obj, index) {
              return { id: index, text: obj };
            })
          };
            
            	console.log(data);
            
        },
         data: function (params) {  
   
            
                   var query = {
                            search: params.term,
                        };
                                
            
              $.ajax({
                              url: 'AllVendorsJS/'+params.term,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },

                              success:function(data) {
                                          $('#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);
});
      
                     
            
            
        });
    });
</script>

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

               var DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
        
           Discount=$("#Discount"+r).val();
         
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );  
      var BFF =  parseFloat(Qty) *  parseFloat(Price);  
       
       $("#TotalBFTax"+r).val(parseFloat(BFF));
           
       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) );  
        var BFF =  parseFloat(Qty) *  parseFloat(Price);  
         $("#TotalBFTax"+r).val(parseFloat(BFF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

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

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

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

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

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

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

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

<!-- Store Name -->
<script>
   function  StoreNamePurch(r){
   
   var countryId = $('#StorePurch'+r).val();
   var Pro = $('#Product'+r).val();
   var Un = $('#UnitPurch'+r).val();
   var CO = $('#CodePurch'+r).val();
                     if(countryId) {
                         $.ajax({
                             url: 'StoreNamePurchasesFilter/'+countryId,
                             type:"GET",
                             dataType:"json",
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                       $('#StorePurchName'+r).val(data.name); 
                   
                                     
                             $.ajax({
                             url: 'StorePricePurchasesFilter',
                             type:"GET",
                             data:{
                                Product:Pro,
                                Store:countryId,
                                Unit:Un,
                                Code:CO,
                             },
                            dataType:"json",         
                             beforeSend: function(){
                                 $('#loader').css("visibility", "visible");
                             },
   
                             success:function(data) {
                                 $.each(data, function(key, value){
                                     
                       $('#Price'+r).val(data.price); 
                   
                                     
   
                                 });
                                 
   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 DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
        
           Discount=$("#Discount"+r).val();
         
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );  
        var BFF =  parseFloat(Qty) *  parseFloat(Price);  
       
       $("#TotalBFTax"+r).val(parseFloat(BFF));
           
       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) );    
           var BFF =  parseFloat(Qty) *  parseFloat(Price);    
         $("#TotalBFTax"+r).val(parseFloat(BFF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

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

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

       if(TaxRate == ''  || TaxType == ''  ||  Qty == '' || Price == '' || Discount == '' || Total == '' || TotalBFTax == '' || Tax == '' || UnitID == '' || StorePurch == ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "none";           
     }
   
     
       if(TaxRate != ''  && TaxType != ''  &&  Qty != '' && Price != '' && Discount != '' && Total != '' && TotalBFTax != '' && Tax != '' && UnitID != '' && StorePurch != ''){
         
        document.getElementById("AddBtnPur"+r).style.display = "block";           
     }  
            
       
        
   
                             },
                             complete: function(){
                                 $('#loader').css("visibility", "hidden");
                             }
                         });             
                                     

   
                                 });
                                 
   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 DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
        
           Discount=$("#Discount"+r).val();
         
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );   
   var BFF =  parseFloat(Qty) *  (parseFloat(Price)  );   
       
       $("#TotalBFTax"+r).val(parseFloat(BFF));
           
       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) );    
      var BFF =  parseFloat(Qty) *  (parseFloat(Price)   );    
         $("#TotalBFTax"+r).val(parseFloat(BFF));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#Tax"+r).val(parseFloat(i));

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

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

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

<!-- Account Balance -->
<script>
   $(document).ready(function() {
   
                  $('#vendor').on('change', function(){
                      var countryId = $(this).val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceFilter/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {
                                  $.each(data, function(key, value){
   
        
                       $('#AccountCredit').val(parseFloat(key).toFixed(2)); 
                    $('#AccountCredit').val(parseFloat(value).toFixed(2)); 
                                  });
                              },
                              complete: function(){
                                  $('#loader').css("visibility", "hidden");
                              }
                          });
                      } else {
   
                          $('select[name="state"]').empty();
                      }
   
                  });
   
              });
    
    
     $(document).ready(function() { 
 
                      var countryId = $('#vendor').val();
                      if(countryId) {
                          $.ajax({
                              url: 'AccountBalanceFilter/'+countryId,
                              type:"GET",
                              dataType:"json",
                              beforeSend: function(){
                                  $('#loader').css("visibility", "visible");
                              },
   
                              success:function(data) {
                                  $.each(data, function(key, value){
   
        
               
                       $('#AccountCredit').val(parseFloat(key).toFixed(2)); 
                    $('#AccountCredit').val(parseFloat(value).toFixed(2)); 
                                  });
                              },
                              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='',vendor='',Brand='',Group='')
    {  
     $.ajax({
      url:'ShortcomingsFilter',
      method:'GET',
      data:{search:search,store:store,vendor:vendor,Brand:Brand,Group:Group},
      dataType:'json',
      success:function(data)
      {
       $('.Data').html(data.table_data);
             $("#Data").show();
      }
     })
    }
    
   $(document).on('keyup', '#search', function(){
     var search = $(this).val();     
     var store = $('#store').val();     
     var vendor = $('#vendor').val();     
     var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
       if(search == ''){
            $("#Data").hide();
          }
     fetch_customer_data(search,store,vendor,Brand,Group);
    });
       
       
    $(document).on('change', '#store', function(){
     var store = $(this).val();     
     var search = $('#search').val();     
        var vendor = $('#vendor').val();     
       var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,vendor,Brand,Group);
    });
       
       
        $(document).on('change', '#vendor', function(){
     var vendor = $(this).val();     
     var search = $('#search').val();  
      var store = $('#store').val();          
    var Brand = $('#Brandd').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,vendor,Brand,Group);
    });   
 
            $(document).on('change', '#Brandd', function(){
     var Brand = $(this).val();     
     var search = $('#search').val();  
      var store = $('#store').val();          
    var vendor = $('#vendor').val();     
     var Group = $('#Groupp').val();     
     fetch_customer_data(search,store,vendor,Brand,Group);
    });   
 
       
            $(document).on('change', '#Groupp', function(){
     var Group = $(this).val();     
     var search = $('#search').val();  
      var store = $('#store').val();          
    var Brand = $('#Brandd').val();     
     var vendor = $('#vendor').val();     
     fetch_customer_data(search,store,vendor,Brand,Group);
    });   
 
  
        
   });
</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 AvQty = $("#AvQty"+r).val();
             var Qty = $("#Qty"+r).val();
             var Barcode = $("#CodePurch"+r).val();
             var Price = $("#Price"+r).val();
             var Total = $("#Total"+r).val();
             var ExpDate = $("#ExpDate"+r).val();
             var PurchTax = $("#PurchTax"+r).val();
             var TotalTax = $("#Tax"+r).val();
             var Discount = $("#Discount"+r).val();
             var 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 Price_Sale = $("#Price_Sale"+r).val();
   var TaxRate = $("#TaxRate"+r).val();
             var TaxType = $("#TaxType"+r).val();
       var Exp='';
        var ED = $("#ED").val();
       

         if(ED == 1){
           
         Exp = "<td><input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>" + ExpDate + "</td>";
           
       }else{
           
           Exp = "<input type='hidden' name='Exp_Date[]' value='"+ExpDate+"'>";
       }
       
       
               var LANG = $("#LANG").val();
   if(LANG == 'ar' ){ 
          var Nemo = P_Ar_Name ;
          }else{
             var Nemo = P_En_Name ;   
          } 
       
             document.getElementById("AddBtnPur"+r).style.display = "none";
             document.getElementById("Row"+r).style.display = "none";
   
       
             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 + "</td><td><input type='hidden' name='Unit[]' value='"+UnitID+"'>" + UnitName + "</td><td><input type='hidden' name='P_Code[]' value='"+Barcode+"'>" + Barcode + "</td><td><input class='form-control'  type='hidden' name='AvQty[]' value='"+AvQty+"' >"+ AvQty +"<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><input type='number' id='PriD"+r+"' step='any' name='Price[]' value='"+Price+"' class='form-control' onkeyup='TotD("+r+")' onclick='TotD("+r+")' ></td><td><input class='Disc form-control' id='DiscD"+r+"' type='number' step='any' name='Discount[]' value='"+Discount+"' onkeyup='TotD("+r+")' onclick='TotD("+r+")' ></td><td><input class='TotalBFTax form-control' id='TotBFTaxD"+r+"' type='number' step='any' disabled  value='"+TotalBFTax+"'><input type='hidden'  id='TotBFTaxDHide"+r+"' name='TotalBFTax[]'  value='"+TotalBFTax+"'></td><td><input class='TotalTax form-control' id='TaxD"+r+"' disabled  type='number' step='any' value='"+TotalTax+"'><input type='hidden' id='TotalTaxVVHide"+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><input  type='hidden' name='StorePurch[]' value='"+StorePurch+"'>" + StorePurchName + "</td>"+Exp+"<td><button id='DelAssem' type='button' class='btn btn-default'><i class='fal fa-trash'></i></button><input type='hidden' name='Product[]' value='"+Product+"'><input type='hidden' name='VOne[]' value=''><input type='hidden' name='VTwo[]' value=''></td><input type='hidden' name='V_Name[]' value=''><input type='hidden' class='TDISCOOO' id='TDiscProEdit"+r+"' name='TDiscPro[]' value='"+TDiscPro+"'><input type='hidden' name='VV_Name[]' value=''><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' name='Price_Sale[]' value='"+Price_Sale+"'></tr>";
 

       
             $("#data-dt").append(markup);
       $("#Data").hide();
      $.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 sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
       
       
           var sumBF = 0;        
   $('.TotalBFTax').each(function(){
   sumBF += parseFloat($(this).val());
   }); 
       
           var sumTax = 0;        
   $('.TotalTax').each(function(){
   sumTax += parseFloat($(this).val());
   }); 
       
   
   $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
   $('#Total_Price').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
   $('#Total_PriceHide').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
   $('#Total_PriceW').val(parseFloat(sumT));
   $('#Total_Bill').val(parseFloat(sumT));
     
           $('#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));
       
          $('#Total_Bf_Taxes').val(parseFloat(sumBF)+parseFloat(sumTTD));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF)+parseFloat(sumTTD));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).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));
            
       
               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 sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
       
 $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
   $('#Total_Price').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
   $('#Total_PriceHide').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
    $('#Total_PriceW').val(parseFloat(sumT));
       $('#Total_Bill').val(parseFloat(sumT));
            
           $('#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));
       
          $('#Total_Bf_Taxes').val(parseFloat(sumBF)+parseFloat(sumTTD));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF)+parseFloat(sumTTD));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).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));
            
            
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
       
   
                    })  
       
       
     }    
</script> 


<!-- Total Products -->
<script>
   function PurchTotal(r) { 
   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 DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
        
           Discount=$("#Discount"+r).val();
         
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );  
     
            var BFF =  parseFloat(Qty) *  parseFloat(Price);  
    
         $("#TotalBFTax"+r).val(parseFloat(BFF).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) );  
       var BFF =  parseFloat(Qty) *  parseFloat(Price)  ;  
    
         $("#TotalBFTax"+r).val(parseFloat(BFF).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( Price == 0 ){
         
        document.getElementById("AddBtnPur"+r).style.display = "none";           
     }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 Price = $("#PriD"+r).val();
   var Discount = $("#DiscD"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       

               var DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
          
           Discount=$("#DiscD"+r).val();
               var BFG =  parseFloat(Qty) * parseFloat(Discount) ;
             $("#TDiscProEdit"+r).val(parseFloat(BFG));
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );  
     var BFF =  parseFloat(Qty) *  parseFloat(Price);  

       $("#TotBFTaxD"+r).val(parseFloat(BFF).toFixed(2));
       $("#TotBFTaxDHide"+r).val(parseFloat(BFF).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) ); 
 var BFF =  parseFloat(Qty) *  parseFloat(Price) ;  
         $("#TotBFTaxD"+r).val(parseFloat(BFF).toFixed(2));
         $("#TotBFTaxDHide"+r).val(parseFloat(BFF).toFixed(2));
          
            i =    parseFloat(TaxRate)   ; 
           
           $("#TaxD"+r).val(parseFloat(i).toFixed(2));
           $("#TaxDHide"+r).val(parseFloat(i).toFixed(2));

       iii =  parseFloat(BF) + parseFloat(i) ;
           
           $("#TotD"+r).val(parseFloat(iii).toFixed(2));
           $("#TotDHide"+r).val(parseFloat(iii).toFixed(2));
           
           
       }
       
 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 sumTTD = 0;        
   $('.TDISCOOO').each(function(){
   sumTTD += parseFloat($(this).val());
   }); 
       
 $('#Product_Numbers').val(parseFloat(rowctr));
   $('#Product_NumbersHide').val(parseFloat(rowctr));
       
   $('#Total_Qty').val(parseFloat(sumQ));
   $('#Total_QtyHide').val(parseFloat(sumQ));
       
    $('#Total_Price').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
   $('#Total_PriceHide').val(parseFloat(sumT) + parseFloat(sumTTD) -  parseFloat(sumTax));
   $('#Total_PriceW').val(parseFloat(sumT));
       $('#Total_Bill').val(parseFloat(sumT));
           $('#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));
       
          $('#Total_Bf_Taxes').val(parseFloat(sumBF)+parseFloat(sumTTD));
   $('#Total_Bf_TaxesHide').val(parseFloat(sumBF)+parseFloat(sumTTD));
       
          $('#Total_Taxes').val(parseFloat(sumTax).toFixed(2));
   $('#Total_TaxesHide').val(parseFloat(sumTax).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));
    
         
               var Pay =$('#Payment_Method').val();
      if(Pay == 'Later'){
         
        
                   $('#paid').val('');
           
       }
       
       
       
   }
    
</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 total =$('#Total_PriceHide').val();    
  $.fn.rowCount = function() {
     return $('tr', $(this).find('tbody')).length;
   };
   
   var rowctr = $('#dt').rowCount();     
     

        
       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{
           
           
           if(paid != 0  ||  paid == ''){
               
                document.getElementById("Submit").style.display = "block";    
           }else{
               
                     document.getElementById("Submit").style.display = "none";  
           }
           
       
       }
                 
                 
                 
             }
           
       }else{
           
       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
            if(paid != 0  ||  paid == ''){
               
                document.getElementById("Submit").style.display = "block";    
           }else{
               
                     document.getElementById("Submit").style.display = "none";  
           }
           
       }   
       }
 
        
       if(Pay == 'Check'){
         
           document.getElementById("CHECK").style.display = "block";  
           
       }else{
           
         document.getElementById("CHECK").style.display = "none";    
       }  
        
                          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));
         $('#Total_PriceW').val(parseFloat(RR));
                
        if(Pay == 'Later'){
         
           document.getElementById("LaterDate").style.display = "block";  
           
       }else{
           
         document.getElementById("LaterDate").style.display = "none";    
       }  
        
        
        
    }
    
    
    $(document).ready(function() {
          var Pay =$('#Payment_Method').val();
        var Stat =$('#Status').val();
        var paid =$('#paid').val();
                    var total =$('#Total_PriceHide').val();  
     

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

        
       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{
           
           
           if(paid != 0  ||  paid == ''){
               
                document.getElementById("Submit").style.display = "block";    
           }else{
               
                     document.getElementById("Submit").style.display = "none";  
           }
           
       
       }
                 
                 
                 
             }
           
       }else{
           
       if(rowctr == 0){
        document.getElementById("Submit").style.display = "none";    
           
       }else{
           
            if(paid != 0  ||  paid == ''){
               
                document.getElementById("Submit").style.display = "block";    
           }else{
               
                     document.getElementById("Submit").style.display = "none";  
           }
           
       }   
       }
 
            
        
        
        
        
       if(Pay == 'Check'){
         
           document.getElementById("CHECK").style.display = "block";  
           
       }else{
           
         document.getElementById("CHECK").style.display = "none";    
       }  
        
                              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));
         $('#Total_PriceW').val(parseFloat(RR));
       
              if(Pay == 'Later'){
         
           document.getElementById("LaterDate").style.display = "block";  
           
       }else{
           
         document.getElementById("LaterDate").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 vendor= $('#vendor').val();   
        
        if(store != '' && SSAFE != '' && vendor != null){
             if(x == 1){
              document.getElementById("Submit").style.display = "none"; 
      document.getElementById('form').submit();   
        } 
     }else{
                
                alert('تأكد من اختيار مخزن و خزنه وحساب');
                
            }
                
            
      
            
            
            
    }
    
    
       function SPS(){
           $('#sp').val(0);  
           var x= $('#sp').val();   
        
      
           
           
                          var store= $('#store').val();   
           var SSAFE= $('#SSAFE').val();   
           var vendor= $('#vendor').val();   
        
        if(store != '' && SSAFE != '' && vendor != null){
            if(x == 0){
              document.getElementById("Submit").style.display = "none"; 
      document.getElementById('form').submit();   
        }
     }else{
                
                alert('تأكد من اختيار مخزن و خزنه وحساب');
                
            }
              
           
           
    }

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

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


<!-- 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 Price = $("#Price"+r).val();
   var Discount = $("#Discount"+r).val();
   var i = 0;
   var ii=0;       
   var iii=0;       
        var DIS = $("#DIS").val();
        
       if(parseFloat(DIS) == 0){
        
           Discount=$("#Discount"+r).val();
         
       }else{
         
           var d= Discount / 100 ;
           var Multi= 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) );  
        var BFF =  parseFloat(Qty) *  parseFloat(Price)  ;  
       
       $("#TotalBFTax"+r).val(parseFloat(BFF).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) );    
          var BFF =  parseFloat(Qty) *  parseFloat(Price) ;    
         $("#TotalBFTax"+r).val(parseFloat(BFF).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( Price == 0 ){
         
        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();
                     }
   
   }   
</script>


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

<!-- Model Manfacturing -->
<script>
    
    
    function  ModelProd(){

        var model = $('#Manufacturing').val();
     $.ajax({
      url:'ManuProdsFilter',
      method:'GET',
      data:{model:model},
      dataType:'json',
      success:function(data)
      {
  $('.DataDD').html(data.t_data);

            $.each(data.ID, function(key, value){
                
            Fun(value);     
      });
         
      }
     })
     
 }     


</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/Purchases/Shortcomings.blade.php ENDPATH**/ ?>