<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  colspan='19'  style="background-color:#909090; text-align:center; font-size:15px;">Article Size Wise </th>
                    </tr>
                   <tr>                        
                        <th>#</th>
                        <th>store</th>
                        <th>Section</th>
                        <th>Subsection</th>
                        <th>Article</th>
                        <th>Color</th>
                        @foreach($sizes as $size)
                        <th>{{$size}}</th>
                        @endforeach
                        <th>Total</th>
                        <th>MRP</th>
                           
                    </tr>
                </thead>
                <tbody>
                       @php $totalcountallsize  = $grandTotal = 0 ;  @endphp   

                        @foreach($rows as $key => $row)
                           @php $totalrow = 0 ; @endphp
                             <tr>
                                    <td>{{ $key + 1 }}</td>
                                    <td>{{ $productRows[$row]['store'] }}</td>
                                    <td>{{ $productRows[$row]['section'] }}</td>
                                    <td>{{ $productRows[$row]['subsection'] }}</td>
                                    <td>{{ $productRows[$row]['article'] }}</td>
                                    <td>{{ $productRows[$row]['color'] }}</td>

                                    @foreach($sizes as $size)
                                    <td>
                                        {{ empty($articleProductCombinations[$row][$size]) ? 0 : $articleProductCombinations[$row][$size] }}
                                        @php
                                            
                                        if(empty($productCountSize[$size])) {
                                            $productCountSize[$size] = 0;
                                        }
                                        if(empty($articleProductCombinations[$row][$size])) {
                                            $articleProductCombinations[$row][$size] = 0;
                                        } 
                                         $totalrow +=    (int)$articleProductCombinations[$row][$size] ;
                                        $productCountSize[$size]+= (int)$articleProductCombinations[$row][$size];
                                        @endphp
                                    </td>
                                    @endforeach
                                    <?php   
                                         $totalcountallsize = $totalcountallsize + $totalrow ;  
                                         $grandTotal = $totalcountallsize;
                                         $colorcode = $productRows[$row]['color'];
                                         $articlescode = $productRows[$row]['article'];
                                         $wproductmin = \DB::table('oc_warehouse_product')->where('article',$articlescode)->where('color',$colorcode)->whereIn('warehouse_id',$posids)->orderBy('warehouse_id')->min('mrp');
                                         $wproductmax = \DB::table('oc_warehouse_product')->where('article',$articlescode)->where('color',$colorcode)->whereIn('warehouse_id',$posids)->orderBy('warehouse_id')->max('mrp');
                        
                                    ?>
                                    <td>{{$totalrow}}</td>
                                    <td>{{$wproductmin}} - {{$wproductmax}}</td>
                          </tr>

                        @endforeach
                </tbody> 
               <tfoot>
                <tr>
                         <td colspan="6"></td> 
                        @foreach($sizes as $size)
                         
                         <td> {{ empty($productCountSize[$size]) ? 0 : $productCountSize[$size] }} </td> 
                      
                        @endforeach
                        <td> {{$grandTotal}}</td>
                        <td></td>
                        
                </tr>
                </tfoot>
            </table>
        </div>
    </div> 
</body>
</html>
