<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DF80000.php");
//include("DFJQUERY.inc");
include("JQUERY.inc");
$o1=0;
$e1=0;
?>

<html>
<head> <meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>


</head>
  	
<body>

<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
    <table width="634" border="0">
	<tr>
	  <th colspan="2"><span class="Estilo23">PRONOSTICO DE rec_ocupacion </span> </th>
	  </tr>
	<tr>
	  <td width="111"> <div align="right" class="Estilo24"><span class="Estilo25">FECHA </span></div></td>
	  <td width="485"><strong>DEL</strong>
              <?php $fech=(isset($_POST['fec']))?$_POST['fec']:date('d/m/Y'); ?>
           <input name="fec" type="text" class="emplea datefrom " id="fec" size="9" maxlength="20" value="<?=$fech?>"
			<?php

				if(isset($_POST['fec'])){ //este es el truco
					echo 'value="' . $_POST['fec'] .  '"';
				}else{
					
                                    echo 'value="'.date("d/m/Y").'"';
				}
			?> onkeypress="return soloNumeros(event)"
		/>
            <!--<input name="bot" id="bot" type="image" value=" ... " src="logos/cal4.jpg"/>
            -->
            <strong> AL </strong>
             <?php $fech2=(isset($_POST['fec2']))?$_POST['fec2']:date('d/m/Y'); ?>
            <input name="fec2" type="text" class="emplea dateto" id="fec2" size="9" maxlength="20" value="<?=$fech2?>"
			<?php

				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?> onkeypress="return soloNumeros(event)"
		/>
           </td>
	</tr>
</table>


<div align="center">

      <table width="634" border="0">
         <td colspan="2">
          <div align="center">
		      <input name="Submit32" type="submit" class="original" value="Buscar" onClick="openpage('ger_pronostico_PR.php','_self')" />
              <input name="bot4" type="button" class="bot_WsW" onClick="openpage('ger_pronostico_IM.php','_self')" value="Imprimir "/>
          </div></td>
      </tr>
    </table>
 <table border="0" align="center" cellpadding="0" cellspacing="0"> 
    <tr>
      <td nowrap colspan="7"> </td>
      <th nowrap colspan="6">CIERRE</th>
    </tr>

    <tr>
      <th width="60" nowrap>FECHA</th>
      <th width="60" nowrap></th>
      <th width="60" nowrap>OCUP.</th>
      <th width="60" nowrap>DISPO.</th>
	  <th width="60" nowrap>ENT.</th>
      <th width="60" nowrap>SAL.</th>
	  <th width="10" nowrap></th>
	  <th width="60" nowrap>OCUP.</th>
	  <th width="60" nowrap>BLOQ.</th>
	  <th width="60" nowrap>DISPO.</th>
	  <th width="40" nowrap>%</th>
	  <th width="60" nowrap>ADUL.</th>
	  <th width="60" nowrap>MEN.</th>
    </tr>

  <?php

//if(!isset($_POST['Submit32']))$_POST['Submit32']=""; 
if (isset($_POST['Submit32']) && $_POST['Submit32']){
  	$fecIni=chfecha($_POST['fec'],'d/m/Y','Y-m-d');
	$fecFin=chfecha($_POST['fec2'],'d/m/Y','Y-m-d');
	$dias = daydiff ($fecFin,$fecIni,'Y-m-d'); 

	for ( $i = 0 ; $i <= $dias ; $i ++) {

		$fecha = $fecIni; 
		$timestamp = strtotime("+".$i." day", strtotime($fecha)); 
		$resultado = date("Y-m-d", $timestamp); 
		$fecha_m = date("d/m/Y", $timestamp); 
		$day = array('Domingo','Lunes','Martes','Miercoles','Jueves','Viernes','Sabado','Domingo');
		$fechaD = $day[date('N', strtotime($resultado))];
				
		echo'<tr>';
		echo '<td class="estiloDet"><div align="left">&nbsp;'.$fecha_m.'</div></td>';
 		echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;'.$fechaD.'</div></td>';
//++++++++++++++++++++++++++++++++++++++++++++++++OCUPADAS+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++		
		$sqor=mysqli_query($con ,"select n_reg,fnumadu,fnummenor,fnumcto,status,extra1 from valeryus19 where cancelado='0' and '$resultado'>ffecllegada and '$resultado'<=ffecsalida and ftipocto<>'MAESTRA' and extra1='0' order by fnumcto"); 
 		echo mysqli_error($con);
 		$b1=0;
		$adultos=0;
		$menores=0;
	if(!$sqor)die(mysqli_error($con));	
		while ($reg=mysqli_fetch_array($sqor)){ 
		$b1 ++;
		$adultos+= $reg['fnumadu'];
		$menores+= $reg['fnummenor'];
		//echo "--->".$reg['fnumcto']."-->".$reg['n_reg']."-->".$reg['status']."-->".$reg['extra1']."-->".$b1."<br>";
 		}
		
 $zzz=$adultos;
 $mmm=$menores;
 echo '<td class="estiloDet"><div align="left">'.$o1=$b1.'</div></td>';
 $sqtc=mysqli_query($con ,"select count(*) as cantid from valeryus08 WHERE ntipo<>'MAESTRA'");
 $tc=mysqli_fetch_array($sqtc);
 
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$d1=$tc['cantid']-$o1.'</div></td>';

//+++++++++++++++++++++++++++++++++++++++ENTRADAS+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
$sqer=mysqli_query($con ,"select n_reg,fnumadu,fnummenor from valeryus19 where cancelado='0' and ffecllegada='$resultado' and ftipocto<>'MAESTRA' and extra1='0'"); 
 echo mysqli_error($con);
 $adult=0;
 $menor=0;
 $ei=0;
 while ($reg=mysqli_fetch_array($sqer)){ 
	 $ei ++;
	 $adult+=$reg['fnumadu'];
     $menor+=$reg['fnummenor'];
 }

echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$e1=$ei.'</div></td>';

//+++++++++++++++++++++++++++++++++++++++SALIDAS++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$sqsa=mysqli_query($con ,"select n_reg,fnumadu,fnummenor from valeryus19 where ffecsalida='$resultado' and cancelado='0' and ftipocto<>'MAESTRA' and extra1='0'"); 
 echo mysqli_error($con);
 $s1=mysqli_num_rows($sqsa);
 $hhh=0;
 $eee=0;
 while($sqc=mysqli_fetch_array($sqsa)){
 $hhh+= $sqc['fnumadu'];
 $eee+= $sqc['fnummenor'];
 }
 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++BLOQUEADAS
 $sqblo=mysqli_query($con ,"select n_reg,fnumcto from valeryusst08 where '$resultado'>fec_ini and '$resultado'<=fec_fin and ftipocto<>'MAESTRA' "); 
 		echo mysqli_error($con);
		$bq=0;
		
		while ($regb=mysqli_fetch_array($sqblo)){ 
		$bq ++;
		//echo "------>".$regb['fnumcto']."<br>";
 		} 
		 
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$s1.'</div></td>';
 
 echo '<td class="estiloDet"><div align="left">&nbsp</div></td>';
 $o2=$o1+$e1-$s1; 
 
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$o2.'</div></td>';
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$bq.'</div></td>';
 $d2=($d1-$e1)+$s1-$bq;
 
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$d2.'</div></td>';
 if($tc['cantid']>0);{
 $p1=(($d2*100)/$tc['cantid']);
 $porc=100-$p1;
 
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.number_format($porc,2,'.',',').'%&nbsp;&nbsp;</div></td>';
 $totAdul=$zzz+$adult-$hhh;
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.number_format($totAdul,0,'.',',').'&nbsp;&nbsp;</div></td>';
 $totMenor=$mmm+$menor-$eee;
 echo '<td class="estiloDet"><div align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.number_format($totMenor,0,'.',',').'&nbsp;&nbsp;</div></td>';
 //echo "".$zzz."+".$adult."-".$hhh."";
echo '</tr>';			
}
}

}
//349-->300
?>
  </table>

</form>
</div>
</body>
</html>