<!DOCTYPE html>
<html >
<head>
<meta charset="UTF-8" />
<title><?php echo $title; ?></title>
    <base href="<?php echo $base; ?>" />
<link href="view/javascript/bootstrap/css/bootstrap.css" rel="stylesheet" media="all" />
<script type="text/javascript" src="view/javascript/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="view/javascript/bootstrap/js/bootstrap.min.js"></script>
<link href="view/javascript/font-awesome/css/font-awesome.min.css" type="text/css" rel="stylesheet" />
<link type="text/css" href="view/stylesheet/stylesheet.css" rel="stylesheet" media="all" />
</head>
<body>
<div class="container">
    <h3>Отчет о предоставленых услугах за период с <?php echo $date_start;?> по <?php echo $date_end; ?></h3>
    <table border="1" class="table-padding">
        <tr>
            <td class="min-td text-bold">Категория</td>
            <td class="min-td text-bold">Продукт</td>

        <?php foreach($products_day as $day) { ?>
            <td class="text-bold"><?php echo $day['col_day']; ?> </td>
        <?php }?>
        <td class="text-bold">Итого</td>
        </tr>
        <?php   $allsum=0;
                $catg=0;
                $summ_catg=array();
                $col_summ;
                $old='';
                foreach($products as $product) {
                    if($old!=$product['category_name']){
                        if($old!=''){?>
                            <tr><td colspan="2">Итого по <?php echo $old; $oldsum=0;?></td>
                                <?php foreach($products_day as $day) { ?>
                                    <td class="text-bold"><?php echo $day['summa_catg'];
                                        $oldsum+=$day['summa_catg'];
                                        $day['summa_catg']=0;?> </td>
                                <?php }?>
                                <td class="text-bold"><?php echo $oldsum; ?></td>
                            </tr>
                     <?php }
                        $old=$product['category_name'];
                    } ?>

            <tr>
                <td> <?php echo $product['category_name'] ;?> </td>
                <td> <?php echo $product['product_name'] ;?> </td>
                <?php
                $summ=0;
                foreach ($products_day as  $i=>$day)
                {
                    if(isset($product['booking'][$day['id']])){
                        $summ+=(int)$product['booking'][$day['id']];
                        $products_day[$i]['summa']+=(int)$product['booking'][$day['id']];
                        $products_day[$i]['summa_catg']+=(int)$product['booking'][$day['id']];
                    echo '<td class="text-center">'.(int)$product['booking'][$day['id']].'</td>  ';
                    $summ+=$product['booking'][$day['id']];
                    }else{
                    echo '<td></td>';
                }
                }
                $allsum+=$summ;
                ?>
                <td class="text-center"><?php echo $summ; ?></td>

            </tr>
        <?php } ?>
        <tr><td colspan="2">Итого по <?php echo $old; $oldsum=0;?></td>
            <?php foreach($products_day as $day) { ?>
                <td class="text-center"><?php echo $day['summa_catg'];
                    $oldsum+=$day['summa_catg'];
                    $day['summa_catg']=0;?> </td>
            <?php }?>
            <td class="text-center"><?php echo $oldsum; ?></td>
        </tr>
        <tr><td colspan="2">Всего:</td>
        <?php foreach ($products_day as $day) {?>

            <td class="text-center"><?php echo $day['summa']; ?></td>
        <?php }?>
            <td class="text-center"><?php echo $allsum; ?></td>
        </tr>

    </table>

</div>
</body>
</html>
<style>
    @import url('https://fonts.googleapis.com/css?family=Open+Sans');

    table tr td{
        padding: 5px 10px;
        font-family: 'Open Sans', sans-serif;
    }
    h3{
        font-family: 'Open Sans', sans-serif;
    }
    .text-center{
        text-align: center;
    }
    .min-td{
        min-width: 140px;
    }
    .text-bold{
        font-weight: bold;
    }
</style>