<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 colspan="32"> </tr> 
                   <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>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 = $gtotalbill5 = $gtotalbill7 = $gtotalbill10 = $gtotalSuits = $gtotalBottom = $gtotalacceess = 
                    $gtotaljewelery = $averaguabv = $averagasp = $averagupt = $gtotalSPS = 0.00; 
                    @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'];

                      $abv = $totalTotal / $order['totalBill']; 
                     
                      $averaguabv += $abv;  

                      $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']; 
                      $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['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/$order['totalstore']; 
                                       $aabv=$averaguabv/$order['totalstore']; 
                                       $aasp=$averagasp/$order['totalstore']; 
                                @endphp

                                <td>{{ number_format((float)$aupt, 3, '.', '') }}</td>
                                <td>{{  number_format((float)$aabv, 3, '.', '') }}</td>
                                <td>{{ number_format((float)$aasp, 3, '.', '') }}</td>
                                <td>0</td>
                                <td> {{$gtotalSPS}}</td>
                                <td> {{$gtotalmrp}} </td>
                                <td> {{$gtotalsps}} </td>
                                <td> {{$gtotalOffer}} </td>
                                <td> {{$gotherOffer}}</td>
                                <td> {{$gtotalvocher}} </td>
                                <td> {{$gtotalreward}} </td>
                                <td> {{$gtotal}} </td>
                                <td>0</td>
                                <td>0</td>
                                <td> {{$gtotalbill5}} </td>
                                <td> {{$gtotalbill7}} </td>
                                <td> {{$gtotalbill10}} </td>
                                <td>0</td>
                                <td>{{$gtotalSuits}}</td>
                                <td>{{$gtotalBottom}}</td>
                                <td>0</td>
                                <td>{{$gtotalacceess}}</td>
                                <td>{{$gtotaljewelery}}</td>
                                
                            </tr>                   
                </tfoot>
               
                @endif
            </table>
        </div>
    </div> 
</body>
</html>
