@extends('admin.index')
@section('content')
@php
use App\Models\ProductsPurchases;
use App\Models\ReturnPurchProducts;
use App\Models\ReturnPurch;
use App\Models\CompanyData;
use App\Models\ProductUnits;
use App\Models\DefaultDataShowHide;
$Def=CompanyData::orderBy('id','desc')->first();
$show=DefaultDataShowHide::orderBy('id','desc')->first();
@endphp
 <title>{{trans('admin.PurchasesBills')}}</title>
           <style>
       @media print{
            .table{
               font-size:17px;
               color:black !important;
               border:2px solid black;
               
           }
         .table-bordered {
    border: 2px solid black!important;
}
.table-bordered th, .table-bordered td {
    border: 1px solid black !important;
}
     .table-bordered th, .table-bordered td {
    border: 1px solid black !important;
}  
     
       }
          </style>
          
               
     <main id="js-page-content" role="main" class="page-content">
                    <ol class="breadcrumb page-breadcrumb">
                        <li class="breadcrumb-item"><a href="javascript:void(0);">{{trans('admin.Report')}}</a></li>
                        <li class="breadcrumb-item active"> {{trans('admin.PurchasesBills')}} </li>
                        <li class="position-absolute pos-top pos-right d-none d-sm-block">
                        <span class="js-get-date"></span></li>
                    </ol>
                    
                    <!-- data entry -->
          
                    <div class="row hide-table">
                        <div class="col-xl-12">
                            <div id="panel-1" class="panel">
                                 <div class="modal-body">
                                    <div data-size="A4">
                                       <div class="row invoive-info">
                                            <div style="text-align: center;" class="col-md-4 col-sm-4 col-4 invoice-client-info">
                                                <div class="style-info">
                                                    <h1 style="text-align: center;" class="m-0">
                                               @if(!empty($Def->Name))
                       {{app()->getLocale() == 'ar' ?$Def->Name :$Def->NameEn}}
                      @else
                       {{trans('admin.Klar')}}
                      @endif         
                                                    </h1>
                              <h3 style="text-align: center;" class="m-10">
                         @if(!empty($Def->Print_Text))
                        {{app()->getLocale() == 'ar' ?$Def->Print_Text :$Def->Print_Text_En}}     
                      @endif                
                                                    </h3>
                                                </div>
                                            </div>
                                            <div style="text-align: center;" class="col-md-4 col-sm-4 col-4 invoice-client-info">
             
              <h1>{{trans('admin.PurchasesBills')}}</h1>
                   
                                            </div>
                                   <div style="text-align: center;" class="col-md-4 col-sm-4 col-4 invoice-client-info">
                         <div class="style-info">
                       @if(!empty($Def->Logo))         
    <img style="height: 50px; " class="img-fluid" src="{{URL::to($Def->Logo)}}" alt="Logo" />
                                       
                    @else  
 <img style="height: 50px;" class="img-fluid" src="https://klarerp.com/site/img/theme/logo.png" alt="Logo" />
                      @endif
               
                             
            <input type="checkbox" id="CHANGE" class="form-control m-2 m2 no-print" onclick="ChangeClass()"><span class="no-print">{{trans('admin.PrintDetails')}}  </span>              
                                       </div>
                                            </div>
                                        </div>
                                        <hr />
                                        <div class="row"></div>
                                      
                                        <div class="row">
                                            <div class="col-sm-12">
                                                <div class="table-responsive-lg">
                                
                        <div style="overflow:auto;">
                     <table id="" class="table table-bordered table-hover table-striped">
                        <thead class="bg-highlight">
                           <tr>
                               @if($colum->Date == 1)
                              <th>{{trans('admin.Date')}}</th>
                               @endif

                                   @if($colum->Time == 1)
                              <th>{{trans('admin.Time')}}</th>
                               @endif
                               
                                 @if($colum->Code == 1)
                              <th>{{trans('admin.Code')}}</th>
                               @endif
                               
                                   @if($colum->Refrence_Number == 1)
                              <th>{{trans('admin.Refernce_Number')}}</th>
                               @endif
                               
                                   @if($colum->Branch == 1)
                              <th>{{trans('admin.Branch')}}</th>
                               @endif
                               
                                      @if($colum->Vendor == 1)
                              <th>{{trans('admin.Vendor')}}</th>
                               @endif
                               
                               
                                   @if($colum->Store == 1)
                              <th>{{trans('admin.Store')}}</th>
                               @endif
                               
                                   @if($colum->Safe == 1)
                              <th>{{trans('admin.Safe')}}</th>
                               @endif
                               
                                   @if($colum->Type == 1)
                              <th>{{trans('admin.Type')}}</th>
                               @endif
                               
                                   @if($colum->Total_Price == 1)
                              <th>{{trans('admin.Total_Price')}}</th>
                               @endif
                               
                                   @if($colum->Total_Discount == 1)
                              <th>{{trans('admin.Total_Discount')}}</th>
                               @endif
                               
                                   @if($colum->Total_Tax == 1)
                              <th>{{trans('admin.Total_Tax')}}</th>
                               @endif
                               
                                   @if($colum->Total_Net == 1)
                              <th>{{trans('admin.Total_Net')}}</th>
                               @endif
                               
                                   @if($colum->Paid == 1)
                              <th>{{trans('admin.Pay')}}</th>
                               @endif
                               
                                   @if($colum->Residual == 1)
                              <th>{{trans('admin.Residual')}}</th>
                               @endif
                               
                                   @if($colum->Due_Date == 1)
                              <th>{{trans('admin.Due_Date')}}</th>
                               @endif
                               
                                   @if($colum->Coin == 1)
                              <th>{{trans('admin.Coin')}}</th>
                               @endif
                               
                    
                                   @if($colum->Delegate == 1)
                              <th>{{trans('admin.Delegate')}}</th>
                               @endif
                               
                                   @if($colum->User == 1)
                              <th>{{trans('admin.User')}}</th>
                               @endif
                               
                                   @if($colum->Shipping == 1)
                              <th>{{trans('admin.Shipping_Compaines')}}</th>
                               @endif
                               
                                   @if($colum->Cost_Center == 1)
                              <th>{{trans('admin.Cost_Center')}}</th>
                               @endif
                               
                                   @if($colum->Total_Return == 1)
                              <th>{{trans('admin.Total_Return')}}</th>
                               @endif
                               
                                   @if($colum->Note == 1)
                              <th>{{trans('admin.Note')}}</th>
                               @endif

                    
                           </tr>
                        </thead>
                        <tbody>
                         @foreach($items as $item)
                            @php
                              $details=ProductsPurchases::where('Purchase',$item->id)->get(); 
                              $TotalReturn=ReturnPurch::where('Purchase',$item->id)->get()->sum('Total_Return_Value'); 
                            @endphp
                               <tr>
                                     @if($colum->Date == 1)
                                   <td>{{$item->Date}}</td>
                                   @endif
                                   
                                         @if($colum->Time == 1)
                                   <td>{{$item->Time}}</td>
                                   @endif
                                   
                                         @if($colum->Code == 1)
                                   <td>{{$item->Code}}</td>
                                   @endif
                                   
                                         @if($colum->Refrence_Number == 1)
                                   <td>{{$item->Refernce_Number}}</td>
                                   @endif
                                   
                                         @if($colum->Branch == 1)
                                   <td>@if(!empty($item->Branch))     {{app()->getLocale() == 'ar' ?$item->Branch()->first()->Arabic_Name :$item->Branch()->first()->English_Name}}         @endif</td>
                                   @endif
                                   
                                              @if($colum->Vendor == 1)
                                   <td>@if(!empty($item->Vendor))      {{app()->getLocale() == 'ar' ?$item->Vendor()->first()->Name :$item->Vendor()->first()->NameEn}}       @endif</td>
                                   @endif
                                   
                                         @if($colum->Store == 1)
                                   <td>          {{app()->getLocale() == 'ar' ?$item->Store()->first()->Name :$item->Store()->first()->NameEn}}     </td>
                                   @endif
                                   
                                         @if($colum->Safe == 1)
                                   <td>       {{app()->getLocale() == 'ar' ?$item->Safe()->first()->Name :$item->Safe()->first()->NameEn}}    </td>
                                   @endif
                                   
                                         @if($colum->Type == 1)
                                   <td>
                                   @if($item->Status == 0)
                                       {{trans('admin.Pending')}}
                                    @elseif($item->Status == 1)
                                       {{trans('admin.Recived')}}
                                    @endif   
                                   </td>
                                   @endif
                                   
                                   
                                     @if($colum->Total_Price == 1)
                                   <td>{{number_format((float)$item->Total_Price, 2, '.', '')}}</td>
                                   @endif
                                   
                                         @if($colum->Total_Discount == 1)
                                   <td>{{$item->Total_Discount}}</td>
                                   @endif
                                   
                                         @if($colum->Total_Tax == 1)
                                   <td>{{$item->Total_Taxes}}</td>
                                   @endif 
                                   
                                   @if($colum->Total_Net == 1)
                                   <td>{{($item->Total_Price + $item->Total_Taxes) - $item->Total_Discount}}</td>
                                   @endif
                                   
                                         @if($colum->Paid == 1)
                                   <td>{{$item->Pay}}</td>
                                   @endif
                                   
                                         @if($colum->Residual == 1)
                                   <td>           @php  $resd=(($item->Total_Price +  $item->Total_Taxes + $item->ProfitTax)  - $item->Total_Discount) - $item->Pay; @endphp
                                       
                                   {{number_format((float)$resd, 2, '.', '')}}</td>
                                   @endif 
                                   
                                   @if($colum->Due_Date == 1)
                                   <td>{{$item->Later_Due}}</td>
                                   @endif
                                   
                                         @if($colum->Coin == 1)
                                   <td>       {{app()->getLocale() == 'ar' ?$item->Coin()->first()->Arabic_Name :$item->Coin()->first()->English_Name}}  </td>
                                   @endif
                        
                                   
                                   @if($colum->Delegate == 1)
                                   <td>@if(!empty($item->Delegate))            {{app()->getLocale() == 'ar' ?$item->Delegate()->first()->Name :$item->Delegate()->first()->NameEn}}      @endif</td>
                                   @endif
                           
                                   
                                         @if($colum->User == 1)
                                   <td>         {{app()->getLocale() == 'ar' ?$item->User()->first()->name :$item->User()->first()->nameEn}}       </td>
                                   @endif 
                                   
                                   @if($colum->Shipping == 1)
                                   <td>       @if(!empty($item->Ship))        
                                                  {{app()->getLocale() == 'ar' ?$item->Ship()->first()->Name :$item->Ship()->first()->NameEn}}     
                                                    @endif
                                   </td>
                                   @endif  
                                   
                                   @if($colum->Cost_Center == 1)
                                   <td>
                                       @if(!empty($item->Cost_Center))        
                                                            {{app()->getLocale() == 'ar' ?$item->Cost_Center()->first()->Arabic_Name :$item->Cost_Center()->first()->English_Name}}       
                                                    @endif
                                   </td>
                                   @endif
                                   
                                         @if($colum->Total_Return == 1)
                                   <td>{{$TotalReturn}}</td>
                                   @endif
                                   
                                         @if($colum->Note == 1)
                                   <td>  
                                    {{$item->Note}}
                                   </td>
                                   @endif
                  
                            </tr>  
                            <tr class="X no-print">  
                              <td colspan="23"> 
                         
                                       <table class="" style="background: grey">
                                                        
                                                            <tr>
                                                   
                            @if($colum->Product_Code == 1)
                              <th>{{trans('admin.Product_Code')}}</th>
                               @endif
                                                                
                                      @if(!empty($colum->Name_Width))
                                @if($colum->Product_Name == 1)
                              <th style="width: {{$colum->Name_Width}}px">{{trans('admin.Product_Name')}}</th>
                               @endif 
                                @else
                                       @if($colum->Product_Name == 1)                            
                                  <th>{{trans('admin.Product_Name')}}</th>
                               @endif                                
                                                                
                               @endif 
       
                                @if($colum->Unit == 1)
                              <th>{{trans('admin.Unit')}}</th>
                               @endif
                                                                
                            @if($colum->Rate == 1)
                              <th>{{trans('admin.Rate')}}</th>
                               @endif  
                                                                
                                @if($colum->Qty == 1)
                              <th>{{trans('admin.Qty')}}</th>
                               @endif
                                                                
                                @if($colum->Price == 1)
                              <th>{{trans('admin.Price')}}</th>
                               @endif 
                                @if($colum->Discount == 1)
                              <th>{{trans('admin.Discount')}}</th>
                               @endif
                                                                
                                @if($colum->Total_BF_Tax == 1)
                              <th>{{trans('admin.Total_BF_Tax')}}</th>
                               @endif
                                @if($colum->Tax == 1)
                              <th>{{trans('admin.Tax')}}</th>
                               @endif
                                                                
                                @if($colum->Total == 1)
                              <th>{{trans('admin.Total')}}</th>
                               @endif 
                                @if($colum->Group == 1)
                              <th>{{trans('admin.Group')}}</th>
                               @endif
                                                                
                                @if($colum->Brand == 1)
                              <th>{{trans('admin.Brand')}}</th>
                               @endif 
                                @if($colum->Exp_Date == 1)
                              <th>{{trans('admin.Exp_Date')}}</th>
                               @endif
                                                                
                                @if($colum->Product_Store == 1)
                              <th>{{trans('admin.Store')}}</th>
                               @endif 
                                      
                                                            </tr>
                                                       
                                                        <tbody>
                                                            @foreach($details as $detail)
                                                            <tr>
                               
                            @if($colum->Product_Code == 1)
                                 <td>{{$detail->Product_Code}}</td>
                               @endif
                                                                
                            @if(!empty($colum->Name_Width))
                                       
                                @if($colum->Product_Name == 1)
                              <td style="width: {{$colum->Name_Width}}px" >
                        {{app()->getLocale() == 'ar' ?$detail->Product()->first()->P_Ar_Name :$detail->Product()->first()->P_En_Name}}   
                                  
                                    
                                @if(!empty($detail->V1))    
                                  
                                       {{app()->getLocale() == 'ar' ?$detail->V1()->first()->Name :$detail->V1()->first()->NameEn}} 
                                  @endif 
                                  @if(!empty($detail->V2))    
                                  
                                      {{app()->getLocale() == 'ar' ?$detail->V2()->first()->Name :$detail->V2()->first()->NameEn}} 
                                  @endif     
                                    </td>
                               @endif 
                            @else
                                         @if($colum->Product_Name == 1)
                              <td>
                               {{app()->getLocale() == 'ar' ?$detail->Product()->first()->P_Ar_Name :$detail->Product()->first()->P_En_Name}}   
                                  
                                    
                                @if(!empty($detail->V1))    
                                  
                                       {{app()->getLocale() == 'ar' ?$detail->V1()->first()->Name :$detail->V1()->first()->NameEn}} 
                                  @endif 
                                  @if(!empty($detail->V2))    
                                  
                                      {{app()->getLocale() == 'ar' ?$detail->V2()->first()->Name :$detail->V2()->first()->NameEn}} 
                                  @endif      
                                    </td>
                               @endif                                  
                                                                
                            @endif                              
                             
                                                                
                                                                
                                @if($colum->Unit == 1)
                           <td>           {{app()->getLocale() == 'ar' ?$detail->Unit()->first()->Name :$detail->Unit()->first()->NameEn}}    </td>
                               @endif
                                                                
              @if($colum->Rate == 1)                            
                                        <td>
                                                            
                                @php
     $Raty=ProductUnits::where('Product',$detail->Product)->where('Unit',$detail->Unit)->first();                         
                @endphp  
     {{$Raty->Rate}}                                   
                                        </td>  
                                      @endif 
                                @if($colum->Qty == 1)
                              <td>{{$detail->Qty}}</td>
                               @endif
                                                                
                                @if($colum->Price == 1)
                            <td>{{$detail->Price}}</td>
                               @endif 
                                @if($colum->Discount == 1)
                               <td>{{$detail->Discount}}</td>
                               @endif
                                                                
                                @if($colum->Total_BF_Tax == 1)
                            <td>{{$detail->Total_Bf_Tax}}</td>
                               @endif
                                @if($colum->Tax == 1)
                           <td>{{$detail->Total_Tax}}</td>
                               @endif
                                                                
                                @if($colum->Total == 1)
                           <td>{{$detail->Total}}</td>
                               @endif 
                                @if($colum->Group == 1)
                                 <td>
                                            {{app()->getLocale() == 'ar' ?$detail->Product()->first()->Group()->first()->Name :$detail->Product()->first()->Group()->first()->NameEn}}  
                                    </td>
                               @endif
                                                                
                                @if($colum->Brand == 1)
                           <td>
                                            @if(!empty($detail->Product()->first()->Brand)) 
                                       {{app()->getLocale() == 'ar' ?$detail->Product()->first()->Brand()->first()->Name :$detail->Product()->first()->Brand()->first()->NameEn}} 
                                            @endif 
                                    </td>
                               @endif 
                                @if($colum->Exp_Date == 1)
                            <td>{{$detail->Exp_Date}}</td>
                               @endif
                                                                
                                @if($colum->Product_Store == 1)
                                <td>       {{app()->getLocale() == 'ar' ?$detail->Store()->first()->Name :$detail->Store()->first()->NameEn}}       </td>
                               @endif 
  
                                                            </tr>
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                            
                                   </td>
                           </tr> 
                          @endforeach
                            
                            
                            @if($type == 1)
                            @foreach($Returns as $item)
                                  @php
                             $details=ReturnPurchProducts::where('Return',$item->id)->get();  
                            @endphp
                               <tr>
                                     @if($colum->Date == 1)
                                   <td>{{$item->Date}}</td>
                                   @endif
                                   
                                         @if($colum->Time == 1)
                                   <td>{{$item->Time}}</td>
                                   @endif
                                   
                                         @if($colum->Code == 1)
                                   <td>{{$item->Code}}</td>
                                   @endif
                                   
                                         @if($colum->Refrence_Number == 1)
                                   <td>{{$item->Refrence_Number}}</td>
                                   @endif
                                   
                                         @if($colum->Branch == 1)
                                   <td>@if(!empty($item->Branch))     {{app()->getLocale() == 'ar' ?$item->Branch()->first()->Arabic_Name :$item->Branch()->first()->English_Name}}         @endif</td>
                                   @endif
                                   
                                              @if($colum->Vendor == 1)
                                   <td>@if(!empty($item->Vendor))      {{app()->getLocale() == 'ar' ?$item->Vendor()->first()->Name :$item->Vendor()->first()->NameEn}}       @endif</td>
                                   @endif
                                   
                                         @if($colum->Store == 1)
                                   <td>          {{app()->getLocale() == 'ar' ?$item->Store()->first()->Name :$item->Store()->first()->NameEn}}     </td>
                                   @endif
                                   
                                         @if($colum->Safe == 1)
                                   <td>       {{app()->getLocale() == 'ar' ?$item->Safe()->first()->Name :$item->Safe()->first()->NameEn}}    </td>
                                   @endif
                                   
                                         @if($colum->Type == 1)
                                   <td>
                             
                                       {{trans('admin.Return_Sales')}}
                    
                                   </td>
                                   @endif
                                   
                                   
                                     @if($colum->Total_Price == 1)
                                   <td>{{$item->Total_Return_Value}}</td>
                                   @endif
                                   
                                         @if($colum->Total_Discount == 1)
                                   <td>{{$item->Total_Discount}}</td>
                                   @endif
                                   
                                         @if($colum->Total_Tax == 1)
                                   <td>{{$item->Total_Taxes}}</td>
                                   @endif 
                                   
                                   @if($colum->Total_Net == 1)
                                   <td>{{$item->Total_Return_Value}}</td>
                                   @endif
                                   
                                         @if($colum->Paid == 1)
                                   <td>{{$item->Pay}}</td>
                                   @endif
                                   
                                         @if($colum->Residual == 1)
                                   <td>0</td>
                                   @endif 
                                   
                                   @if($colum->Due_Date == 1)
                                   <td>{{$item->Later_Due}}</td>
                                   @endif
                                   
                                         @if($colum->Coin == 1)
                                   <td>       {{app()->getLocale() == 'ar' ?$item->Coin()->first()->Arabic_Name :$item->Coin()->first()->English_Name}}  </td>
                                   @endif
                                   
                           
                                   
                                   @if($colum->Delegate == 1)
                                   <td>@if(!empty($item->Delegate))            {{app()->getLocale() == 'ar' ?$item->Delegate()->first()->Name :$item->Delegate()->first()->NameEn}}      @endif</td>
                                   @endif
                                   
                         
                                   
                                         @if($colum->User == 1)
                                   <td>         {{app()->getLocale() == 'ar' ?$item->User()->first()->name :$item->User()->first()->nameEn}}       </td>
                                   @endif 
                                   
                                   @if($colum->Shipping == 1)
                                   <td>       @if(!empty($item->Ship))        
                                                      {{app()->getLocale() == 'ar' ?$item->Ship()->first()->Name :$item->Ship()->first()->NameEn}}     
                                                    @endif
                                   </td>
                                   @endif  
                                   
                                   @if($colum->Cost_Center == 1)
                                   <td>
                                       @if(!empty($item->Cost_Center))        
                                                         {{app()->getLocale() == 'ar' ?$item->Cost_Center()->first()->Arabic_Name :$item->Cost_Center()->first()->English_Name}}       
                                                    @endif
                                   </td>
                                   @endif
                                   
                                         @if($colum->Total_Return == 1)
                                   <td>{{$item->Total_Return_Value}}</td>
                                   @endif
                                   
                                         @if($colum->Note == 1)
                                   <td></td>
                                   @endif
                         
                            </tr>  
                            <tr class="X no-print">  
                              <td colspan="23"> 
             
                                       <table class="table table-bordered table-hover w-100 table-striped mobile-width" style="background: grey">
                                                        
                                                            <tr>
                                                   
                            @if($colum->Product_Code == 1)
                              <th>{{trans('admin.Product_Code')}}</th>
                               @endif
                                                                
                                @if($colum->Product_Name == 1)
                              <th>{{trans('admin.Product_Name')}}</th>
                               @endif 
                                @if($colum->Unit == 1)
                              <th>{{trans('admin.Unit')}}</th>
                               @endif
                                                                
                       
                                @if($colum->Qty == 1)
                              <th>{{trans('admin.Return_Qty')}}</th>
                               @endif
                                                                
                                @if($colum->Price == 1)
                              <th>{{trans('admin.Price')}}</th>
                               @endif 
                                @if($colum->Discount == 1)
                              <th>{{trans('admin.Discount')}}</th>
                               @endif
                                                                
                                @if($colum->Total_BF_Tax == 1)
                              <th>{{trans('admin.Total_BF_Tax')}}</th>
                               @endif
                                @if($colum->Tax == 1)
                              <th>{{trans('admin.Tax')}}</th>
                               @endif
                                                                
                                @if($colum->Total == 1)
                              <th>{{trans('admin.Total')}}</th>
                               @endif 
                                @if($colum->Group == 1)
                              <th>{{trans('admin.Group')}}</th>
                               @endif
                                                                
                                @if($colum->Brand == 1)
                              <th>{{trans('admin.Brand')}}</th>
                               @endif 
                                @if($colum->Exp_Date == 1)
                              <th>{{trans('admin.Exp_Date')}}</th>
                               @endif
                                                                
                                @if($colum->Product_Store == 1)
                              <th>{{trans('admin.Store')}}</th>
                               @endif 
                                      
                                                            </tr>
                                                       
                                                        <tbody>
                                                            @foreach($details as $detail)
                                                            <tr>
                               
                            @if($colum->Product_Code == 1)
                                 <td>{{$detail->Product_Code}}</td>
                               @endif
                                                                
                                @if($colum->Product_Name == 1)
                              <td>
                            {{app()->getLocale() == 'ar' ?$detail->Product()->first()->P_Ar_Name :$detail->Product()->first()->P_En_Name}}   
                                  
                                    
                                @if(!empty($detail->V1))    
                                  
                                       {{app()->getLocale() == 'ar' ?$detail->V1()->first()->Name :$detail->V1()->first()->NameEn}} 
                                  @endif 
                                  @if(!empty($detail->V2))    
                                  
                                      {{app()->getLocale() == 'ar' ?$detail->V2()->first()->Name :$detail->V2()->first()->NameEn}} 
                                  @endif  
                                    </td>
                               @endif 
                                @if($colum->Unit == 1)
                           <td>           {{app()->getLocale() == 'ar' ?$detail->Unit()->first()->Name :$detail->Unit()->first()->NameEn}}    </td>
                               @endif
                                                                
                          
                                @if($colum->Qty == 1)
                              <td>{{$detail->Return_Qty}}</td>
                               @endif
                                                                
                                @if($colum->Price == 1)
                            <td>{{$detail->Price}}</td>
                               @endif 
                                @if($colum->Discount == 1)
                               <td>{{$detail->Discount}}</td>
                               @endif
                                                                
                                @if($colum->Total_BF_Tax == 1)
                            <td>{{$detail->Total_Bf_Tax}}</td>
                               @endif
                                @if($colum->Tax == 1)
                           <td>{{$detail->Total_Tax}}</td>
                               @endif
                                                                
                                @if($colum->Total == 1)
                           <td>{{$detail->Total}}</td>
                               @endif 
                                @if($colum->Group == 1)
                                 <td>
                                           {{app()->getLocale() == 'ar' ?$detail->Product()->first()->Group()->first()->Name :$detail->Product()->first()->Group()->first()->NameEn}}  
                                    </td>
                               @endif
                                                                
                                @if($colum->Brand == 1)
                           <td>
                                            @if(!empty($detail->Product()->first()->Brand)) 
                                   {{app()->getLocale() == 'ar' ?$detail->Product()->first()->Brand()->first()->Name :$detail->Product()->first()->Brand()->first()->NameEn}} 
                                            @endif 
                                    </td>
                               @endif 
                                @if($colum->Exp_Date == 1)
                            <td>{{$detail->Exp_Date}}</td>
                               @endif
                                                                
                                @if($colum->Product_Store == 1)
                                <td>       {{app()->getLocale() == 'ar' ?$detail->Store()->first()->Name :$detail->Store()->first()->NameEn}}       </td>
                               @endif 
  
                                                            </tr>
                                                            @endforeach
                                                        </tbody>
                                                    </table>
                                 
                                   </td>
                           </tr> 
                            
                            @endforeach
                            @endif
                        </tbody>
                        
                     </table>
                  </div>
                                                    
                                                                      {{$items->Links()}}
              
                  <!-- datatable end -->
                   
                       <div style="overflow:auto;">
                     <table style="    background: linear-gradient(45deg, #1d1f83, #921b1bde);
color: white;" id="dt-basic-example" class="table table-bordered table-hover table-striped">
                         <tr>
                         <th>{{trans('admin.Bills_Nums')}}</th>
                         <td>{{$Bills_Nums}}</td>
                         
                           <th>{{trans('admin.Total_Qty')}}</th>
                         <td>{{$Total_Qty}}</td>
                             
                            <th>{{trans('admin.Total_Discount')}}</th>
                         <td>{{$Total_Discount}}</td>  
                             
                            <th>{{trans('admin.Total_Taxes')}}</th>
                         <td>{{$TotalTax}}</td> 
               
                        </tr> 
                               <tr>
                         <th>{{trans('admin.Total_Bills')}}</th>
                         <td>{{$Total_Bills}}</td>
                         
                           <th>{{trans('admin.Total_Net')}}</th>
                         <td>{{$Total_Net}}</td>
                             
                            <th>{{trans('admin.Total_Return')}}</th>
                         <td>{{$Total_Return}}</td>  
                             
                    
                        </tr> 
                           </table>                 
                   </div>           
                                                    
                                                </div>
                                            </div>
                                        </div>
                                        
                         
                                    </div>
                                </div>
                                
                                  @if($show->Text == 1)  
                                                   <div class="row">
                                       
                                             @if(!empty($Def->Print_Text_Footer))
              {!! app()->getLocale() == 'ar' ?$Def->Print_Text_Footer :$Def->Print_Text_Footer_En !!}
                      @endif          
                                        </div>  
                                @endif
                                
                       
                                
                                
                     
                                <div class="modal-footer">
                <a href="{{url('KlarAdmin')}}" class="btn btn-secondary" data-dismiss="modal">{{trans('admin.Back')}}</a>
             <button type="button" class="btn btn-default" onclick="window.print()"><i class="fal fa-print"></i></button>  
                                </div>
                                
                            </div>
                        </div>
         </div>
</main>

       


@endsection
@push('js')
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/datagrid/datatables/datatables.bundle.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/summernote/summernote.css')}}">
    <link rel="stylesheet" media="screen, print" href="{{asset('Admin/css/formplugins/select2/select2.bundle.css')}}">


    <style>
        th{
            width:135px!important;
        }
    </style>

 <script src="{{asset('Admin/js/datagrid/datatables/datatables.export.js')}}"></script>
    <script src="{{asset('Admin/js/datagrid/datatables/datatables.bundle.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/summernote/summernote.js')}}"></script>
    <script src="{{asset('Admin/js/formplugins/select2/select2.bundle.js')}}"></script>
    <script>
        //_fnFeatureHtmlLength();
        $(document).ready(function () {
            // Setup - add a text input to each footer cell
            $('#dt-basic-example thead tr').clone(true).appendTo('#dt-basic-example thead');
            $('#dt-basic-example thead tr:eq(1) th').each(function (i) {
                var title = $(this).text();
                $(this).html('<input type="text" class="form-control form-control-sm" placeholder="Search ' + title + '" />');

                $('input', this).on('keyup change', function () {
                    if (table.column(i).search() !== this.value) {
                        table
                            .column(i)
                            .search(this.value)
                            .draw();
                    }
                });
            });
            var table = $('#dt-basic-example').DataTable(
                {
                    responsive: true,
                    orderCellsTop: true,
                    fixedHeader: true,
                    lengthChange: true,

                    dom: "<'row mb-3'<'col-sm-12 col-md-3 d-flex align-items-center justify-content-start'f><'col-sm-12 col-md-9 d-flex align-items-center justify-content-end'B>>" +
                        "<'row'<'col-sm-12'tr>>" +
                        "<'row'<'col-sm-12 col-md-5'i><'col-sm-12 col-md-7'p>>",

                    buttons: [
                        {
                            extend: 'pageLength',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'colvis',
                            text: 'Column Visibility',
                            titleAttr: 'Col visibility',
                            className: 'btn-outline-default'
                        },
                        {
                            extend: 'pdfHtml5',
                            text: 'PDF',
                            titleAttr: 'Generate PDF',
                            className: 'btn-outline-danger btn-sm mr-1'
                        },
                        {
                            extend: 'excelHtml5',
                            text: 'Excel',
                            titleAttr: 'Generate Excel',
                            className: 'btn-outline-success btn-sm mr-1'
                        },
                        {
                            extend: 'csvHtml5',
                            text: 'CSV',
                            titleAttr: 'Generate CSV',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'copyHtml5',
                            text: 'Copy',
                            titleAttr: 'Copy to clipboard',
                            className: 'btn-outline-primary btn-sm mr-1'
                        },
                        {
                            extend: 'print',
                            text: 'Print',
                            titleAttr: 'Print Table',
                            className: 'btn-outline-primary btn-sm'
                        }
                    ],
                });
            $('.js-thead-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example thead').removeClassPrefix('bg-').addClass(theadColor);
            });

            $('.js-tbody-colors a').on('click', function () {
                var theadColor = $(this).attr("data-bg");
                console.log(theadColor);
                $('#dt-basic-example').removeClassPrefix('bg-').addClass(theadColor);
            });

        });

    </script>
  
  <script>
    $(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
            }

            $(".js-data-example-ajax").select2(
            {
                ajax:
                {
                    url: "https://api.github.com/search/repositories",
                    dataType: 'json',
                    delay: 250,
                    data: function(params)
                    {
                        return {
                            q: params.term, // search term
                            page: params.page
                        };
                    },
                    processResults: function(data, params)
                    {
                        // parse the results into the format expected by Select2
                        // since we are using custom formatting functions we do not need to
                        // alter the remote JSON data, except to indicate that infinite
                        // scrolling can be used
                        params.page = params.page || 1;

                        return {
                            results: data.items,
                            pagination:
                            {
                                more: (params.page * 30) < data.total_count
                            }
                        };
                    },
                    cache: true
                },
                placeholder: 'Search for a repository',
                escapeMarkup: function(markup)
                {
                    return markup;
                }, // let our custom formatter work
                minimumInputLength: 1,
                templateResult: formatRepo,
                templateSelection: formatRepoSelection
            });

            function formatRepo(repo)
            {
                if (repo.loading)
                {
                    return repo.text;
                }

                var markup = "<div class='select2-result-repository clearfix d-flex'>" +
                    "<div class='select2-result-repository__avatar mr-2'><img src='" + repo.owner.avatar_url + "' class='width-2 height-2 mt-1 rounded' /></div>" +
                    "<div class='select2-result-repository__meta'>" +
                    "<div class='select2-result-repository__title fs-lg fw-500'>" + repo.full_name + "</div>";

                if (repo.description)
                {
                    markup += "<div class='select2-result-repository__description fs-xs opacity-80 mb-1'>" + repo.description + "</div>";
                }

                markup += "<div class='select2-result-repository__statistics d-flex fs-sm'>" +
                    "<div class='select2-result-repository__forks mr-2'><i class='fal fa-lightbulb'></i> " + repo.forks_count + " Forks</div>" +
                    "<div class='select2-result-repository__stargazers mr-2'><i class='fal fa-star'></i> " + repo.stargazers_count + " Stars</div>" +
                    "<div class='select2-result-repository__watchers mr-2'><i class='fal fa-eye'></i> " + repo.watchers_count + " Watchers</div>" +
                    "</div>" +
                    "</div></div>";

                return markup;
            }

            function formatRepoSelection(repo)
            {
                return repo.full_name || repo.text;
            }
        });
    });

</script>
<script>
    var autoSave = $('#autoSave');
    var interval;
    var timer = function()
    {
        interval = setInterval(function()
        {
            //start slide...
            if (autoSave.prop('checked'))
                saveToLocal();

            clearInterval(interval);
        }, 3000);
    };

    //save
    var saveToLocal = function()
    {
        localStorage.setItem('summernoteData', $('#saveToLocal').summernote("code"));
        console.log("saved");
    }

    //delete 
    var removeFromLocal = function()
    {
        localStorage.removeItem("summernoteData");
        $('#saveToLocal').summernote('reset');
    }

    $(document).ready(function()
    {
        //init default
        $('.js-summernote').summernote(
        {
            height: 200,
            tabsize: 2,
            placeholder: "Type here...",
            dialogsFade: true,
            toolbar: [
                ['style', ['style']],
                ['font', ['strikethrough', 'superscript', 'subscript']],
                ['font', ['bold', 'italic', 'underline', 'clear']],
                ['fontsize', ['fontsize']],
                ['fontname', ['fontname']],
                ['color', ['color']],
                ['para', ['ul', 'ol', 'paragraph']],
                ['height', ['height']]
                ['table', ['table']],
                ['insert', ['link', 'picture', 'video']],
                ['view', ['fullscreen', 'codeview', 'help']]
            ],
            callbacks:
            {
                //restore from localStorage
                onInit: function(e)
                {
                    $('.js-summernote').summernote("code", localStorage.getItem("summernoteData"));
                },
                onChange: function(contents, $editable)
                {
                    clearInterval(interval);
                    timer();
                }
            }
        });

        //load emojis
        $.ajax(
        {
            url: 'https://api.github.com/emojis',
            async: false
        }).then(function(data)
        {
            window.emojis = Object.keys(data);
            window.emojiUrls = data;
        });

        //init emoji example
        $(".js-hint2emoji").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: 'type starting with : and any alphabet',
            hint:
            {
                match: /:([\-+\w]+)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(emojis, function(item)
                    {
                        return item.indexOf(keyword) === 0;
                    }));
                },
                template: function(item)
                {
                    var content = emojiUrls[item];
                    return '<img src="' + content + '" width="20" /> :' + item + ':';
                },
                content: function(item)
                {
                    var url = emojiUrls[item];
                    if (url)
                    {
                        return $('<img />').attr('src', url).css('width', 20)[0];
                    }
                    return '';
                }
            }
        });

        //init mentions example
        $(".js-hint2mention").summernote(
        {
            height: 100,
            toolbar: false,
            placeholder: "type starting with @",
            hint:
            {
                mentions: ['jayden', 'sam', 'alvin', 'david'],
                match: /\B@(\w*)$/,
                search: function(keyword, callback)
                {
                    callback($.grep(this.mentions, function(item)
                    {
                        return item.indexOf(keyword) == 0;
                    }));
                },
                content: function(item)
                {
                    return '@' + item;
                }
            }
        });

    });

</script>
<script type="text/javascript">


    $(".show-table").click(function(){
        $(".hide-table").show();
    });
    
</script>

	<style>
	@media print {
		body * {
			visibility: hidden;
		}
		.modal-body * {
			visibility: visible;
			overflow: visible;
		}
		
        

	}
	</style>

<script>
function ChangeClass(){
    
   var $a1Check  = $('#CHANGE').is(':checked');

   
    if($a1Check){

  $(".X").removeClass("no-print");
 
        
    }
    else{
     
 $(".X").addClass("no-print");
     
        
        
    }    
    
    
    

    
}
</script>

@endpush