<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>
       
    <div class="card-body">
            
        <div class="card-body">
            <table class="table table-striped table-bordered table-responsive" id="design">
                <thead>
                    
                   <tr>
                        <th>Date</th>
                        <th>Day</th>
                        <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>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 =
                    $gtotalreward = $gtotal = $gtotalbill0 = $gtotalbill15 = $gtotalbill25 = $gtotalbill5 = $gtotalbill7 = $gtotalbill10 = $gtotalSuits = $gtotalBottom = $gtotalacceess = 
                    $gtotaljewelery = $averaguabv = $averagasp = $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'] ; 
                      
                      $gtotalQty += $order['totalQty'];
                      $gtotalSPS += $order['spscount'];
                      $gtotalbill += $order['totalBill'];

                      $gotherOffer += $order['otherOffer'];
                      $gtotalOffer += $order['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>
                                <td >{{date('l', strtotime($order['date']))}}</td>
                                <td >{{$order['store']}}</td>                                
                                <td >0</td>
                                <td >0</td>
                                <td >0</td>                                
                                <td >{{$order['totalBill']}}</td>
                                <td >{{$order['totalQty']}}</td>                                
                                <td >{{ number_format((float)$order['upt'], 3, '.', '') }}</td>
                                <td >{{ number_format((float)$abv, 3, '.', '') }}</td>
                                <td >{{ number_format((float)$asp, 3, '.', '') }}</td> 
                                
                                <td >0</td> 
                                <td >{{$order['spscount']}}</td>
                                <td >{{$order['totalMrp']}}</td>
                                <td >{{$order['totalSpsDiscount']}}</td> 
                                <td >{{$order['clearence']}}</td> 
                                <td>{{$order['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>
                                <td></td>
                                <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($gtotalmrp) }} </td>
                                <td> {{ round($gtotalsps) }} </td>
                                <td> {{ round($gtotalOffer) }} </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>
