<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>Article</th>
                        <th>Color</th>
                        <th>Subsection</th>
                        @foreach($sizes as $size)
                        <th>{{$size}}</th>
                        @endforeach
                        <th>Total</th>
                    </tr>
                </thead>
                 @php if(count($orders) > 0) { @endphp
                <tbody>

                 @php    
                    $gtotalTotal = $gtotalXS = $gtotalS = $gtotalL = $gtotalM = $gtotalXL = $gtotal2XL = $gtotal3XL = 
                    $gtotal4XL = $gtotal5XL = $gtotal6XL = $gtotal7XL = $gtotalFREE = 0.00; 
                 @endphp 
                
                 @foreach($orders as $key => $row)

                 @php $totalTotal = 0; @endphp
                  
                    <tr>                        
                        @php $article = \App\Article::select(['id','image','category_id','main_category_id'])->where('code',$row['article'])->first();
                            
                         @endphp
                        <td>{{  $row['article'] }}</td>
                        <td>{{  $row['color'] }}</td>                       
                        <td>{{ !empty($article->category) ? $article->category->name : '' }}</td>
                        <td> {{  $row['XS'] }} </td>
                        <td> {{  $row['S'] }} </td>
                        <td> {{  $row['M'] }} </td>
                        <td> {{  $row['L'] }} </td>
                        <td> {{  $row['XL'] }} </td>
                        <td> {{  $row['2XL'] }} </td>
                        <td> {{  $row['3XL'] }} </td>
                        <td> {{  $row['4XL'] }} </td>
                        <td> {{  $row['5XL'] }} </td>
                        <td> {{  $row['6XL'] }} </td>
                        <td> {{  $row['7XL'] }} </td>
                        <td> {{  $row['FREE'] }} </td>
                         @php 
                                $totalTotal +=  $row['XS'] + $row['S'] + $row['L'] + $row['M'] + $row['XL'] + $row['2XL'] + $row['3XL'] + 
                                 $row['4XL'] + $row['5XL'] + $row['6XL'] + $row['7XL'] + $row['FREE'];
                                
                                $gtotalTotal += $totalTotal;
                                $gtotalXS += $row['XS'];
                                $gtotalS += $row['S'];
                                $gtotalL += $row['L']; 
                                $gtotalM += $row['M'];
                                $gtotalXL += $row['XL'];
                                $gtotal2XL += $row['2XL'];
                                $gtotal3XL += $row['3XL'];
                                $gtotal4XL += $row['4XL'];
                                $gtotal5XL += $row['5XL'];
                                $gtotal6XL += $row['6XL'];
                                $gtotal7XL += $row['7XL'];
                                $gtotalFREE += $row['FREE'];
                                
                         @endphp
                        <td>{{$totalTotal}}</td>
                    </tr>
                @endforeach
                </tbody>
                <tfoot>
                            <tr>
                                <td colspan='3'></td>                             
                                <td> {{$gtotalXS}}</td>
                                <td> {{$gtotalS}} </td>
                                <td> {{$gtotalM}} </td>
                                <td> {{$gtotalL}} </td>
                                
                                <td> {{$gtotalXL}} </td>
                                <td> {{$gtotal2XL}} </td>
                                <td> {{$gtotal3XL}} </td>
                                <td> {{$gtotal4XL}} </td>
                                <td> {{$gtotal5XL}} </td>
                                <td> {{$gtotal6XL}} </td>
                                <td> {{$gtotal7XL}} </td>
                                <td> {{$gtotalFREE}} </td>
                                <td> {{$gtotalTotal}} </td>
                            </tr>                   
                </tfoot>
                @php } @endphp
            </table>
        </div>
    </div> 
</body>
</html>
