<?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>
  </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">
              <div class="form-group">
                <label class="control-label" for="input-status"><?php echo $entry_status; ?></label>
                <select name="filter_order_status_id" id="input-status" class="form-control">
                  <option value="0"><?php echo $text_all_status; ?></option>
                  <?php foreach ($order_statuses as $order_status) { ?>
                  <?php if ($order_status['order_status_id'] == $filter_order_status_id) { ?>
                  <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>


              </div>

                <div class="form-group">
                    <label class="control-label" for="product-status">Статус продукта</label>
                    <select name="filter_product_status" id="product-status" class="form-control">
                        <?php foreach($mode as $item){ ?>
                            <option <?php if($filter_product_status==$item['value']){echo 'selected';}?> value="<?php echo $item['value'];?>"><?php echo $item['name'];?></option>
                        <?php } ?>
                    </select>
                </div>

              <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>
	<?
	
	$filter_date_end = date("Y-m-d");
	$filter_date_start = '2017-08-02';
	if($_GET['filter_date_start']) { $filter_date_start = $_GET['filter_date_start']; }
	if($_GET['filter_date_end']) { $filter_date_end = $_GET['filter_date_end'];	}
	
	$datetime1 = date_create($filter_date_start);
	$datetime2 = date_create($filter_date_end);
	$interval = date_diff($datetime1, $datetime2);
	$inter = $interval->format('%a');
	$znak = $interval->format('%R');
	if( $znak == '-' ) $inter = "$znak $inter дней";
	// echo $interval->format('%R%a дней');
	//  Array ( [0] => Array ( [order_option_id] => 6402 [order_id] => 1908 [order_product_id] => 51923 [product_option_id] => 430 [product_option_value_id] => 789 [name] => Додаткове ліжко [value] => Додаткове ліжко (1 шт.) [type] => select ) ) 
	?>	
	<style>
	@media print {* { display: none; }#print-content { display: block; } 
	
.contentpane .table-bordered > thead > tr > th, .contentpane .table-bordered > tbody > tr > th, .contentpane .table-bordered > tfoot > tr > th, .contentpane .table-bordered > thead > tr > td, .contentpane .table-bordered > tbody > tr > td, .contentpane .table-bordered > tfoot > tr > td {
    border: 2px solid #000000;
}
	}
	</style>
<script language="javascript">
function CallPrint(strid) { var prtContent = document.getElementById(strid); var prtCSS = 'http://eco-brech.com.ua/admin/view/stylesheet/bootstrap.css'; var WinPrint = window.open('','','left=50,top=50,width=800,height=640,toolbar=0,scrollbars=1,status=0'); WinPrint.document.write('<div id="print" class="contentpane">'); WinPrint.document.write(prtCSS); WinPrint.document.write(prtContent.innerHTML); WinPrint.document.write('</div>'); WinPrint.document.close(); WinPrint.focus(); WinPrint.print(); WinPrint.close(); prtContent.innerHTML=strOldOne;
}
</script>
<button type="button"  class="btn">
<a onClick="javascript:CallPrint('print-content');" title="Распечатать проект">Распечатать</a></button>
        <div id="print-content" class="table-responsive">
		<style>
	 table {
    border-collapse: collapse;
    border-spacing: 0;
}
	.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}
.contentpane .table-bordered > thead > tr > th, .contentpane .table-bordered > tbody > tr > th, .contentpane .table-bordered > tfoot > tr > th, .contentpane .table-bordered > thead > tr > td, .contentpane .table-bordered > tbody > tr > td, .contentpane .table-bordered > tfoot > tr > td {
    border: 2px solid #000000;
	border-collapse: collapse;
	padding: 8px;

	}
	</style>
          <table  class="table table-bordered">
            <thead>
              <tr>
                <td class="text-left"><?php echo $column_name; ?></td>
                <td class="text-left"><?php echo $column_model; ?></td>
				<td class="text-left">Кол-во суток с доп. Постель</td>
				<td class="text-left">Кол-во суток с доп. Местом</td>
				<td class="text-left">Кол-во суток с доп. Крылом</td>
				<td class="text-left">Кол-во суток с увелич. кол-ва прожив.</td>
				<td class="text-left">Общая загрузка с доп.опциями</td>
				<td class="text-left">% загрузки с доп.опциями к общей</td>
				<td class="text-left"><?php // echo $column_model; ?>За период, дней</td>
                <td class="text-right"><?php echo $column_quantity; ?></td>
                <td class="text-right"><?php echo $column_total; ?></td>
              </tr>
            </thead>
            <tbody>
			
              <?php if ($products) { ?>
              <?php foreach ($products as $product) { 
			 // print_r($product);
			  if(( $product['name'] != 'Оплата наличкой')  && ( $product['name'] != 'Оплата картой')) {
				
			  ?>
              <tr>
                <td class="text-left"><?php echo $product['name']; ?></td>
                <td class="text-left"><?php echo $product['model']; ?></td>
				<td class="text-left"><?php echo $product['lijko']; ?></td>
				<td class="text-left"><?php echo $product['miscye']; ?></td>
				<td class="text-left"><?php echo $product['zbilsh']; ?></td>
				<td class="text-left"><?php echo $product['postyl']; ?></td>
			<td class="text-right"><?php echo (0+$product['lijko']+$product['miscye']+$product['zbilsh']+$product['postyl']); ?></td>
				<td class="text-right"><?php  echo round((0+$product['lijko']+$product['miscye']+$product['zbilsh']+$product['postyl'])/$product['quantity']*100, 2); ?> %</td>
				<td class="text-right"><?php echo $inter; ?></td>
                <td class="text-right"><?php echo $product['quantity']; ?></td>
                <td class="text-right"><?php  echo round($product['quantity']/$inter*100, 2); ?>  %</td>
              </tr>
			  <?php } ?>
              <?php } ?>
              <?php } else { ?>
              <tr>
                <td class="text-center" colspan="4"><?php echo $text_no_results; ?></td>
              </tr>
              <?php } ?>
            </tbody>
          </table>
        </div>
		<button type="button"  class="btn">
<a onClick="javascript:CallPrint('print-content-2');" title="Распечатать проект">Распечатать</a></button>
        
		<div id="print-content-2" class="table-responsive"> <h3>Статистика по Категориям Номеров</h3>
		
			<style>
	 table {
    border-collapse: collapse;
    border-spacing: 0;
}
	.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}
.contentpane .table-bordered > thead > tr > th, .contentpane .table-bordered > tbody > tr > th, .contentpane .table-bordered > tfoot > tr > th, .contentpane .table-bordered > thead > tr > td, .contentpane .table-bordered > tbody > tr > td, .contentpane .table-bordered > tfoot > tr > td {
    border: 2px solid #000000;
	border-collapse: collapse;
	padding: 8px;

	}
	</style>
          <table class="table table-bordered">
          <thead>
              <tr>
               
                <td class="text-left"><?php echo $column_model; ?></td>
				<td class="text-left">Кол-во суток с доп. Постель</td>
				<td class="text-left">Кол-во суток с доп. Местом</td>
				<td class="text-left">Кол-во суток с доп. Крылом</td>
				<td class="text-left">Кол-во суток с увелич. кол-ва прожив.</td>
				<td class="text-left">Общая загрузка с доп.опциями</td>
				<td class="text-left">% загрузки с доп.опциями к общей</td>
				<td class="text-left">За период, дней</td>
				<td class="text-left">Отчетный период, дней</td>
                <td class="text-right"><?php echo $column_quantity; ?></td>
                <td class="text-right"><?php echo $column_total; ?></td>
              </tr>
            </thead>
            <tbody>
	<?
		$lijko = $miscye = $zbilsh = $postyl = 0;
		$j_cot = $j_vip = $j_kit = $j_luks = $j_stand = 0;
	?>		
              <?php if ($products) { ?>
              <?php foreach ($products as $product) { 
			  if(( $product['name'] != 'Оплата наличкой')  && ( $product['name'] != 'Оплата картой')) {
			// Vip-котедж
			if((  trim($product['model']) == 'Vip-котедж' )	 OR (  trim($product['model']) == 'Китайский домик' ) 
			 OR  (  trim($product['model']) == 'Котедж' ))				
			{ 
		$prodix = $product['quantity'] *1;
				$lijko += $product['lijko'] *1;
				$miscye += $product['miscye'] *1;
				$zbilsh += $product['zbilsh'] *1;
				$postyl += $product['postyl'] *1;
		$pro_cot += $prodix;
		$j_cot++;
			}
			
	/*		
		elseif((  trim($product['model']) == 'Vip-котедж' )	 OR (  trim($product['model']) == 'Китайский домик' ) 
			 OR  (  trim($product['model']) == 'Котедж' ))		{ 
		$prodix = $product['quantity'] *1;
		$pro_vip += $prodix;
		$j_vip++;
			}
		elseif(  trim($product['model']) == 'Китайский домик' )		{ 
		$prodix = $product['quantity'] *1;
		$pro_kit += $prodix;
		$j_kit++;
			}
	*/	elseif(  trim($product['model']) == 'Люкс' )				{ 
		$prodix = $product['quantity'] *1;
				$lijkol += $product['lijko'] *1;
				$miscyel += $product['miscye'] *1;
				$zbilshl += $product['zbilsh'] *1;
				$postyll += $product['postyl'] *1;
		$pro_luks += $prodix;
		$j_luks++;
			}
		elseif(  trim($product['model']) == 'Стандарт' )			{ 
		$prodix = $product['quantity'] *1;
				$lijkos += $product['lijko'] *1;
				$miscyes += $product['miscye'] *1;
				$zbilshs += $product['zbilsh'] *1;
				$postyls += $product['postyl'] *1;
		$pro_stand += $prodix;
		$j_stand++;
			}
			
		else{ $prod = '--- "'.$product['model'].'"';}
		
		 } 	
		 }
		 }
		 ?>
			 
			   <?php 
		$totalyty = $pro_cot + $pro_vip + $pro_kit + $pro_luks + $pro_stand;
		$j_sum = $j_cot + $j_vip + $j_kit + $j_luks + $j_stand;	
		$j_cot = 13;
		$j_luks = 21;
		$j_stand = 7;
			   $tabys .= '<tr>
                <td class="text-left">Котеджи</td>
                <td class="text-left">'. $lijko .'</td> 
				<td class="text-left">'. $miscye .'</td>
				<td class="text-left">'. $zbilsh .'</td>
				<td class="text-left">'. $postyl .'</td>
				<td class="text-right">'. ($lijko + $miscye + $zbilsh + $postyl) .'</td>
				<td class="text-right">'. round((0+$lijko + $miscye + $zbilsh + $postyl)/($j_cot * $inter)*100, 2) .' %</td>
				<td class="text-right">'. $j_cot * $inter .'</td>
				<td class="text-right">'. $inter .'</td>
                <td class="text-right">'. $pro_cot .'</td>
                <td class="text-right">'.round($pro_cot/($j_cot * $inter)*100, 2).'  %</td>
              </tr>';
		/*	  
			   $tabys .= '<tr>
                <td class="text-left">Vip-котедж</td>
                <td class="text-left"></td>
				<td class="text-left"> грн.</td>
				<td class="text-left"> 1 или больше</td>
				<td class="text-right">'. $inter .'</td>
				<td class="text-right">'. $j_vip .'</td>
				<td class="text-right">'. $j_vip * $inter .'</td>
                <td class="text-right">'. $pro_vip .'</td>
                <td class="text-right">'.round($pro_vip/($j_vip * $inter)*100, 2).'  %</td>
              </tr>';
			   
			  $tabys .= '<tr>
                <td class="text-left">Китайский домик</td>
                <td class="text-left"></td>
				<td class="text-left">  грн.</td>
				<td class="text-left"> 1 или больше</td>
				<td class="text-right">'. $inter .'</td>
				<td class="text-right">'. $j_kit .'</td>
				<td class="text-right">'. $j_kit * $inter .'</td>
                <td class="text-right">'. $pro_kit .'</td>
                <td class="text-right">'.round($pro_kit/($j_kit * $inter)*100, 2).'  %</td>
              </tr>'; 
	*/		   
			$tabys .= '<tr>
                <td class="text-left">Люкс</td>
                <td class="text-left">'. $lijkol .'</td> 
				<td class="text-left">'. $miscyel .'</td>
				<td class="text-left">'. $zbilshl .'</td>
				<td class="text-left">'. $postyll .'</td>
				<td class="text-right">'. ($lijkol + $miscyel + $zbilshl + $postyll) .'</td>
				<td class="text-right">'. round((0+$lijkol + $miscyel + $zbilshl + $postyll)/($j_luks * $inter)*100, 2) .' %</td>
				<td class="text-right">'. $j_luks * $inter .'</td>
				<td class="text-right">'. $inter .'</td>
                <td class="text-right">'. $pro_luks .'</td>
                <td class="text-right">'.round($pro_luks/($j_luks * $inter)*100, 2).'  %</td>
              </tr>';   
			   
			   $tabys .= '<tr>
			   <td class="text-left">Стандарт</td>
                <td class="text-left">'. $lijkos .'</td> 
				<td class="text-left">'. $miscyes .'</td>
				<td class="text-left">'. $zbilshs .'</td>
				<td class="text-left">'. $postyls .'</td>
				<td class="text-right">'. ($lijkos + $miscyes + $zbilshs + $postyls) .'</td>
				<td class="text-right">'. round((0+$lijkos + $miscyes + $zbilshs + $postyls)/($j_stand * $inter)*100, 2) .'  % </td>
				<td class="text-right">'. $j_stand * $inter .'</td>
				<td class="text-right">'. $inter .'</td>
                <td class="text-right">'. $pro_stand .'</td>
                <td class="text-right">'.round($pro_stand/($j_stand * $inter)*100, 2).'  %</td>
              </tr>';
	
	echo $tabys;

			   ?>  
			   
			   <tr>
                <td></td>
              </tr>
			   <tr>
                <td></td>
              </tr>
            
			 
             
              <tr>
                <td class="text-left"><?php echo 'Всего по Комплексу'; //$product['name']; ?></td>
                <td class="text-left"><? $lijko_sum = $lijko + $lijkol + $lijkos; echo $lijko_sum; ?></td> 
				<td class="text-left"><? $miscye_sum = $miscye + $miscyel + $miscyes; echo $miscye_sum; ?></td>
				<td class="text-left"><? $zbilsh_sum = $zbilsh + $zbilshl + $zbilshs; echo $zbilsh_sum; ?></td>
				<td class="text-left"><? $postyl_sum = $postyl + $postyll + $postyls; echo $postyl_sum; ?></td>
				<td class="text-right"><? echo ($lijko_sum + $miscye_sum + $zbilsh_sum + $postyl_sum) ?></td>
				<td class="text-right"><? echo round((0+$lijko_sum + $miscye_sum + $zbilsh_sum + $postyl_sum)/($j_sum * $inter)*100, 2) ?> %</td>
				<td class="text-right"><?php echo $j_sum  * $inter; ?></td>
				<td class="text-right"><?php echo $inter; ?></td>
                <td class="text-right"><?php echo $totalyty; ?></td>
                <td class="text-right"><?php $j_sum = 41; echo round($totalyty/($j_sum * $inter)*100, 2); ?>  %</td>
              </tr>
			 
            </tbody>
          </table>
        </div>
		<? // echo "totalyty = '$totalyty'<br>j_sum = '$j_sum'<br>inter = '$inter'<br>";  ?>
        <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"><!--
$('#button-filter').on('click', function() {
	url = 'index.php?route=report/product_stata&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_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);
	}
	var filter_product_status = $('select[name=\'filter_product_status\']').val();

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

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