<html>
<head>
    <style type="text/css" media="all">

       
        #design {
            font-family: Serif;
            border-collapse: collapse;
            width: 100%;
        }

        #design td,
        #design th,
        #design thead, 
        #design tbody {
            border: 1px solid #000;
            font-size: 12px;
        }

        * {
            margin: 2px;
            padding: 2px;
        }
    </style>
</head>
<body>
@php 
       $spcCustomer = \DB::table('oc_customer_ref')->select('customer_id')->whereIn('warehouse_id', $pos_id)->get();    

       foreach ($spcCustomer as $key => $value) { 
          $spsCustomersCollection[] = $value->customer_id;
        }
       $spscount = \DB::table('oc_plan_to_customer')->where('current',1)
       ->where('status',1)->whereBetween('start_date', [$startdate, $enddate])->whereIn('customer_id', $spsCustomersCollection)->count();

        
@endphp
       
    <div class="card-body">
             <h5> Total SPS : <?php echo $spscount; ?> </h5>
        <div class="card-body">
            <table class="table table-striped table-bordered table-responsive" id="design">
                <thead>
                    
                   <tr>
                        <th>Date</th>
                        @if($filterby != 'month') <th>Day</th> @endif
                        <th> Store Location</th>
                        <th>Foot fall</th>
                        <th>Repeat</th>
                        <th>New</th>
                        
                        <th>Total NOB</th>
                        <th>QTY</th>
                        <th>UPT</th>
                        <th>ABV</th>
                        <th>ASP</th>
                        <th>Target</th> 
                        <th> New SPS </th>   
                        <th> Old SPS </th>  
                                      
                        <th>MRP</th>
                        <th>SPS Discount</th>
                        <th>Clearence Discount</th>
                        <th>Other Offer Discount</th>
                        <th>Gift Vouchers</th>
                        <th>Reward Points</th>
                        <th>Realised sale</th> 
                        <th>ACH%</th>  
                        <th>CONV%</th>  
                        <th>0 - 1499</th>   
                        <th>1500 - 2499</th>  
                        <th>2500 - 4999</th> 
                        <th>4999 - 7499</th>   
                        <th>7500 - 9999</th>  
                        <th>10000  above</th> 
                        <th>Upper</th>
                        <th>Suit Sets</th>
                        <th>Bottom</th>
                        <th>Home</th>
                        <th>Accessory</th>
                        <th>Jewellery</th>
                    </tr>
                </thead>
                 @if(!empty($orders))
                <tbody>
                    @php    
                    $gtotalCash = $gtotalQty = $gtotalbill = $gtotalmrp = $gtotalsps = $gtotalOffer = $gtotalvocher = $gotherOffer = $gclearence =
                    $gtotalreward = $gtotal = $gtotalbill0 = $gtotalbill15 = $gtotalbill25 = $gtotalbill5 = $gtotalbill7 = $gtotalbill10 = $gtotalSuits = $gtotalBottom = $gtotalacceess = 
                    $gtotaljewelery = $averaguabv = $gtotalSPSNew = $gtotalSPSOld = $averagasp = $gtotalSPSOld = $averagupt = $gtotalSPS = $abv = $asp = 0.00; 
                    $totalCount = count($orders);
                    
                    @endphp
                    @foreach($orders as $key => $order)  
                      @php 
                             
                      $totalTotal = $otherOffer = $clearence = 0; 
                      //$totalTotal +=  $order['totalCash'] + $order['totalCard'] + $order['totalUpi'] + $order['totalWallet'] + $order['totalCn'] + $order['totalGv'] ; 
                      $totalTotal += $order['totalfinalamt'];
                      $gtotalQty += $order['totalQty'];

                      $gtotalSPS += $order['spscount']; 
                      $gtotalSPSOld += $order['oldspscount'];                      

                      $gtotalbill += $order['totalBill'];                     

                      $dismrp = ($order['totalMrp'] * 10/100);

                       $otherOffer = $order['otherOffer'];

                       $gotherOffer += $otherOffer;

                      $clearence = $order['clearence'];
                      $gclearence += $clearence;                     
                    

                      $averagupt += $order['upt'];
                       
                      if($order['totalBill'] > 0)
                      {
                          $abv= $totalTotal/  $order['totalBill']; 
                      }
                      
                      $averaguabv += $abv;  
                      
                      if($order['totalQty'] > 0)
                      {
                          $asp = $totalTotal/  $order['totalQty']; 
                      }
                      
                      $averagasp += $asp;

                      $gtotalmrp += $order['totalMrp'];
                      $gtotalsps += $order['totalSpsDiscount']; 
                     
                      $gtotalvocher += $order['voucher'];  
                      $gtotalreward += $order['totalreward']; 
                      $gtotal += $totalTotal; 

                      $gtotalbill5 += $order['bill5']; 
                      $gtotalbill7 += $order['bill7']; 
                      $gtotalbill10 += $order['bill10']; 

                      $gtotalbill0 += $order['bill0']; 
                      $gtotalbill15 += $order['bill15']; 
                      $gtotalbill25 += $order['bill25']; 

                      $gtotalSuits += $order['Suits']; 
                      $gtotalBottom += $order['Bottom']; 
                      $gtotalacceess += $order['acceess']; 
                      $gtotaljewelery += $order['jewelery']; 

                      @endphp         
                            <tr>
                                <td >{{$order['date']}}</td>
                               @if($filterby != 'month') <td >{{date('l', strtotime($order['date']))}}</td> @endif
                                <td >{{$order['store']}}</td>                                
                                <td >0</td>
                                <td >0</td>
                                <td >0</td>                                
                                <td >{{$order['totalBill']}}</td>
                                <td >{{$order['totalQty']}}</td>                                
                                <td >{{number_format($order['upt'],2)}}</td>
                                <td>{{ number_format((float)$abv, 2, '.', '')  }}</td>
                                <td>{{ number_format((float)$asp, 2, '.', '')  }}</td> 
                                
                                <td >0</td> 
                                <td >{{$order['spscount']}}</td>
                                <td >{{$order['oldspscount']}}</td>
                               
                                <td >{{$order['totalMrp']}}</td>
                                <td >{{$order['totalSpsDiscount']}}</td> 
                                <td >{{$clearence}}</td> 
                                <td>{{$otherOffer}}</td>
                                <td>{{$order['voucher']}}</td>
                                <td>{{$order['totalreward']}}</td>
                                <td >{{$totalTotal}}</td> 
                                <td >0</td> 
                                <td >0</td> 
                                <td >{{$order['bill0']}}</td> 
                                <td >{{$order['bill15']}}</td> 
                                <td >{{$order['bill25']}}</td> 
                                <td >{{$order['bill5']}}</td> 
                                <td >{{$order['bill7']}}</td> 
                                <td >{{$order['bill10']}}</td> 
                                <td >0</td> 
                                <td >{{!empty($order['Suits']) ? $order['Suits'] : 0 }}</td> 
                                <td >{{ !empty($order['Bottom']) ? $order['Bottom'] : 0 }}</td> 
                                <td >0</td> 
                                <td >{{!empty($order['acceess']) ? $order['acceess'] :0 }}</td>    
                                <td >{{ !empty($order['jewelery']) ? $order['jewelery'] : 0 }}</td>      
                            </tr>
                    @endforeach
                </tbody> 
                <tfoot>
                            <tr>
                                <td></td>
                              @if($filterby != 'month')  <td></td> @endif
                                <td></td>
                                <td>0</td>
                                <td>0</td>
                                <td>0</td>
                                <td> {{$gtotalbill}}</td>
                                <td> {{$gtotalQty}} </td>
                                
                                @php 
                                       $aupt=$averagupt/$totalCount; 
                                       $aabv=$averaguabv/$totalCount; 
                                       $aasp=$averagasp/$totalCount; 
                                @endphp

                                <td>{{ round ($aupt) }}</td>
                                <td>{{ round ($aabv) }}</td>
                                <td>{{ round ($aasp) }}</td>
                                <td>0</td>
                                <td> {{round($gtotalSPS)}}</td>
                                <td> {{round($gtotalSPSOld)}}</td> 
                                

                                <td> {{round($gtotalmrp)}} </td>
                                <td> {{round($gtotalsps)}} </td>
                                <td> {{round($gclearence)}} </td>
                                <td> {{round($gotherOffer)}}</td>
                                <td> {{round($gtotalvocher)}} </td>
                                <td> {{round($gtotalreward)}} </td>
                                <td> {{round($gtotal)}} </td>
                                <td>0</td>
                                <td>0</td>
                                <td> {{round($gtotalbill0) }} </td>
                                <td> {{round($gtotalbill15) }} </td>
                                <td> {{round($gtotalbill25) }} </td>
                                <td> {{round($gtotalbill5) }} </td>
                                <td> {{round($gtotalbill7) }} </td>
                                <td> {{round($gtotalbill10) }} </td>
                                <td>0</td>
                                <td>{{ round($gtotalSuits)}}</td>
                                <td>{{ round($gtotalBottom)}}</td>
                                <td>0</td>
                                <td>{{round($gtotalacceess)}}</td>
                                <td>{{round($gtotaljewelery)}}</td>
                                
                            </tr>                   
                </tfoot>
               
                @endif
            </table>
        </div>
    </div> 
</body>
</html>
