<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");

$mes=0;
$dia=0;
$anio=0;
	//function cambioCelda(celda){
//echo "hola";
//}

error_reporting(E_ALL);
ini_set('display_errors', 1);

?>
  

  
    
  <?php

	
		$fini =$dt_empres['fec_alta'];

		$fsal1=addDay($fini,30); 
	
	?>
        	
	<?php
	$cont=0;
	$cont=0;
	$sql="";
	$fechas=array();
	 while ( dateCmp($fini,$fsal1)<=0) 
			  {
				  $fsal =addDay($fini,1); 
         //   if ($cont>0) $sql.=" union all ";
			$sql="select tipo.ncto,tipo.ntipo,count(tipo.ncto) as total,count(disponibles.ncto) as disponible,((count(disponibles.ncto)*100)/count(tipo.ncto) ) as proporcion from valeryus08 as tipo
left outer join 
(select valeryus08.*,COALESCE(table1.num1, 0) as canceled,COALESCE(table2.num2, 0) as bloked FROM valeryus08
left outer join
                    (
                    select count(*)as num1,fnumcto as id from reservados
                     WHERE  ((reservados.ffecllegada <= '$fini' AND reservados.ffecsalida > '$fini' )
                     OR(reservados.ffecllegada < '$fsal'  AND reservados.ffecsalida > '$fsal')
                     OR((reservados.ffecllegada >= '$fini' AND reservados.ffecsalida < '$fsal')
                     OR((reservados.ffecllegada < '$fsal'  AND reservados.ffecsalida >= '$fsal')))) and reservados.cancelado='0' 
                     group by reservados.fnumcto
                     )as table1
                     on  table1.id=valeryus08.ncto

                     left outer join

                     ( select count(*)as num2, fnumcto as id from valeryusst08 where  ((valeryusst08.fec_ini < '$fsal' AND valeryusst08.fec_fin > '$fsal') 
                      or (valeryusst08.fec_ini >= '$fini' AND valeryusst08.fec_fin < '$fsal')
                      or (valeryusst08.fec_ini <= '$fini' AND valeryusst08.fec_fin > '$fini') 
                      or (valeryusst08.fec_ini < '$fsal' AND valeryusst08.fec_fin >= '$fsal')) group by valeryusst08.fnumcto
                     )as table2
                     on table2.id=valeryus08.ncto
                    
                     WHERE ntipo <> 'MAESTRA' 
                     having canceled=0 and bloked=0
                    order by ncto) as disponibles
                    
                    on tipo.ncto=disponibles.ncto
                     WHERE tipo.ntipo <> 'MAESTRA' 
                      group by tipo.ntipo";
			 @$disponibles = mysqli_query($con ,$sql);
			
			while(@$reg = mysqli_fetch_array(@$disponibles))
	{
		if($reg['proporcion']<35){
			$fec1 = $fini;
		include('DF20000.php');
			$fechas[]=$f_f;
			
		}
	}
	
					$cont++;
                  $fini=addDay($fini,1); 
                 }
				$fechas=  array_values(array_unique($fechas));
				echo json_encode($fechas);
	
		?>
	