<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <h1><?php echo $heading_title; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
        <div class="pull-right">
            <button  id="report"   onclick="report();"  class="btn btn-primary pull-right"><i class="fa fa-print"></i></button>
        </div>
    </div>
  </div>
  <div class="container-fluid">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-bar-chart"></i> <?php echo $text_list; ?></h3>
      </div>
      <div class="panel-body">
        <div class="well">
          <div class="row">
            <div class="col-sm-6">
              <div class="form-group">
                <label class="control-label" for="input-date-start"><?php echo $entry_date_start; ?></label>
                <div class="input-group date">
                  <input type="text" name="filter_date_start" value="<?php echo $filter_date_start; ?>" placeholder="<?php echo $entry_date_start; ?>" data-date-format="YYYY-MM-DD" id="input-date-start" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span>
                </div>
              </div>
             <div class="form-group">
                <label class="control-label" for="input-date-end"><?php echo $entry_date_end; ?></label>
                <div class="input-group date">
                  <input type="text" name="filter_date_end" value="<?php echo $filter_date_end; ?>" placeholder="<?php echo $entry_date_end; ?>" data-date-format="YYYY-MM-DD" id="input-date-end" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
              </div>
            </div>
            <div class="col-sm-6">

              <button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa fa-filter"></i> <?php echo $button_filter; ?></button>
              </div>
          </div>
        </div>
          <div class="container container-width">

              <h3>Отчет о предоставленых услугах за период с <?php echo $date_start;?> по <?php echo $date_end; ?></h3>
            <div style="overflow-x: auto">
                 <table border="1" class="table-padding">
                  <tr>
                      <td class="text-bold text-head">Категория</td>
                      <td class="text-bold text-head">Продукт</td>

                      <?php foreach($products_day as $day) { ?>
                          <td class="text-bold"><?php echo $day['col_day']; ?> </td>
                      <?php }?>
                      <td class="text-bold text-head">Итого</td>
                  </tr>
                  <?php $allsum=0; $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-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>
                  <?php }
                  $old=$product['category_name'];
                  } ?>

                     <tr>
                      <tr>
                          <td class="text-bold text-left"> <?php echo $product['category_name'] ;?> </td>
                          <td class="text-bold text-left"> <?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>
          </div>

        <div class="row">
          <div class="col-sm-6 text-left"><?php echo $pagination; ?></div>
          <div class="col-sm-6 text-right"><?php echo $results; ?></div>
        </div>
      </div>
    </div>
  </div>
  <script type="text/javascript"><!--
      function report() {
          var filter_date_start = $('input[name=\'filter_date_start\']').val();
          var filter_date_end = $('input[name=\'filter_date_end\']').val();
          var url='<?php echo $catalog; ?>index.php?route=report/sale_tax/invoice&token=<?php echo $token; ?>&date_start='+filter_date_start+'&date_end='+filter_date_end;

          window.open(url, '_blank');

      }

$('#button-filter').on('click', function() {
	url = 'index.php?route=report/sale_tax&token=<?php echo $token; ?>';

	var filter_date_start = $('input[name=\'filter_date_start\']').val();

	if (filter_date_start) {
		url += '&filter_date_start=' + encodeURIComponent(filter_date_start);
	}

	var filter_date_end = $('input[name=\'filter_date_end\']').val();

	if (filter_date_end) {
		url += '&filter_date_end=' + encodeURIComponent(filter_date_end);
	}

	var filter_group = $('select[name=\'filter_group\']').val();

	if (filter_group) {
		url += '&filter_group=' + encodeURIComponent(filter_group);
	}

	var filter_order_status_id = $('select[name=\'filter_order_status_id\']').val();

	if (filter_order_status_id != 0) {
		url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
	}

	location = url;
});
//--></script>
  <script type="text/javascript"><!--
$('.date').datetimepicker({
	pickTime: false
});
//--></script></div>
<?php echo $footer; ?>