<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include ("varfun.php");
include("JQUERY.inc");
$nr=0;
$adultos="";
$f_f="";
$tohb1="";
$f_m="";
?>
<html>
<HEAD> 
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<meta name="tipo_contenido" content="text/html;" http-equiv="content-type" charset="utf-8">
<script type="text/javascript" language="JavaScript1.2" src="js/searchtable.js"></script>
<script>
    $(function() {
		  theTable = $("#latabla");
		  $("#q").keyup(function() {
			$.uiTableFilter(theTable, this.value);
		  });
		});
</script>
</HEAD>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>

<div align="left">

</div>
<div align="center">
  <form name="frm1" id="frm1" method="post" action="<?php
 echo $_SERVER['PHP_SELF']; ?>" target="_self">
    <table width="441" border="0">
	<tr>
	  <th colspan="2"><span class="Estilo23">REPORTE DE HUESPEDES</span></th>
	  </tr>
	<tr>
	  <td><div align="right" class="Estilo31"><span class="Estilo29"><span class="Estilo30"><img src="magnifier.png" alt="Buscar" onClick="alert('Buscar')" />FECHA</span></span></div></td>
	  <td><span class="Estilo31">
	    <input name="r2" type="checkbox" value="f" tabindex="5" <?php
 //if(!isset($_POST['r2']))$_POST['r2']=""; 
 if(isset($_POST['r2']) && $_POST['r2']=='f') echo 'checked';?>/>
	    De:
             <?php $fech=(isset($_POST['fec']))?$_POST['fec']:date('d/m/Y'); ?>
        <input name="fec" type="text" class="emplea date" 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"/>
        -->
        
        </span></td>
	  </tr>
	  <tr>
	  <td colspan="2" height="25">	  </td>
	  </tr>
      <tr>
        <td colspan="2">
            <div align="center">
              <a style="text-decoration:underline;cursor:pointer;" href="menu_PR.php"/></a>
              <input name="Submit" type="submit" class="original"  value="Buscar"/>
			  <input name="bot4" type="button" class="bot_WsW" onClick="openpage('ger_huespedes_IM.php','_self')" value="Imprimir "/>
		  </div></td>  </tr>  
    </table>  
  </form> </div>
<div align="center">
  <form method="post" action="" >
     <div style="height:450px; overflow:scroll; width:1150;" align="center">
         
         <div id="busqueda" style="color:#000">
		Busqueda Rapida <input type="text" style="width: 70%" id="q" name="q" value="" />
		</div>
	<table id='latabla'>
            <thead>
	<tr><th colspan="15"><span class="Estilo23">
	<?php
 if (isset($_POST['r2']) && $_POST['r2']=='f'){ 
	echo "HUESPEDES DEL ".$_POST['fec']."";
	}else{
	echo "TODOS LOS HUESPEDES";
	}
	?> </span></th></tr>
      <tr>
		<th><div align="center">HAB</div></th>
		<th><div align="center">TIPO</div></th>
		<th><div align="center">HUESPED</div></th>
		<th><div align="center">FOLIO</div></th>
		<th><div align="center">ADUL</div></th>
		<th><div align="center">MEN</div></th>
		<th><div align="center">FECHA DE LLEGADA</div></th>
		<th><div align="center">FECHA DE SALIDA</div></th>
		<th><div align="center">FORMA DE PAGO</div></th>
		<th><div align="center">TARIFA</div></th>
		<th><div align="center">TAR-XTRA</div></th>
		<th><div align="center">MERCADO</div></th>		
		<th><div align="center">SEGMENTO</div></th>		
		<th><div align="center">NOTAS</div></th>
        </tr></thead><tbody>
	  <?php

	  
	  $walk=mysqli_query($con ,"select n_reg,fnumcto from valeryus19 where status='HUESPED'");
	  while($mun=mysqli_fetch_array($walk)){
	  $fmuncto=mysqli_query($con ,"UPDATE valeryus19 set fmuncto='".$mun['fnumcto']."' where n_reg='".$mun['n_reg']."'");
	  }
	 // --->
	 $fec=date("d/m/Y");

	 if(!isset($_POST['fec']))$fec=date("d/m/Y");
	  else	$fec = $_POST['fec'];
		include('DF20000.php');
		$fecha_inicial = $f_m;
	  // -->
	  
	  
	  //echo $fecha_inicial."sdas";
	  //if(!isset($_POST['r2']))$_POST['r2']="";
           if(isset($_POST['r2']) && $_POST['r2']=='f'){
		  
   	      @$huesped=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 WHERE ffecllegada <= '".$fecha_inicial."' and ffecsalida >= '".$fecha_inicial."' and cancelado='0'"));

	      }else{
		  
	      @$huesped=mysqli_fetch_array(mysqli_query($con ,"select count(*) as total, SUM(fnumadu) AS adultos, SUM(fnummenor) AS menores from valeryus19 where (status='HUESPED' or status='MISCELANEOS')"));
		  
		  }
	
	$d=0;
	
		$seccion=mysqli_query($con ,"select distinct(seccion) from valeryus08 order by seccion");
	//if(!$seccion)die(mysqli_error($con));
	while($secciones=mysqli_fetch_array($seccion)){
	
		echo "<tr>";
		echo "<td style='#C60636' colspan='14'> <div align='left'><strong>SECCION: " . $secciones["seccion"] ." &nbsp;</strong></div></td>";
		echo "</tr>";
		 if(isset($_POST['r2']) && $_POST['r2']=='f'){
	  	    $result = mysqli_query($con ,"SELECT * FROM valeryus19 inner join valeryus08 on valeryus19.fmuncto=valeryus08.ncto WHERE  (valeryus19.ffecllegada <= '".$fecha_inicial."' AND valeryus19.ffecsalida >= '".$fecha_inicial."' and valeryus19.cancelado='0') and valeryus08.seccion='".$secciones['seccion']."' order by valeryus08.ncto");
		}else{
		    $result=mysqli_query($con ,"select * from valeryus19 left join valeryus08 on valeryus19.fnumcto=valeryus08.ncto where valeryus08.seccion = '".$secciones['seccion']."' and (valeryus19.status='HUESPED' or  valeryus19.status='MISCELANEOS') order by valeryus08.ncto");
		}
		
	    while($reg=mysqli_fetch_array($result)){
	    	
		$nr = $nr + 1;
		$v1 = $nr / 2;
		$v2 = (int) ($nr / 2);
		  if($v1 == $v2){
			$col ="";
		   }else{
			$col =" ";
		   }
	  	echo "<tr>";
		if ($reg["fnumcto"]==''){
		$reg["fnumcto"]=$reg["fmuncto"];
		}
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fnumcto"] . "&nbsp;</strong></div></td>";
		if ($reg["ftipocto"]!='MAESTRA'){
		echo "<td style='#C60636'> <div align='center'><strong>" . $reg["ftipocto"] . "&nbsp;</strong></div></td>";
		}else{
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["ftipocto"] . "&nbsp;</strong></div></td>";
		}
		echo "<td style='".$col."'> <div align='left'><strong> &nbsp;". $reg["fapellido"] . ' '. $reg["fnombre"] . "&nbsp;</strong></div></td>";
			$Foli=mysqli_fetch_array(mysqli_query($con ,"select * from valeryus19 where fnumcto='".$reg['fnumcto']."' and fapellido='".$reg['fapellido']."' and folio='".$reg['folio']."'"));
	    //$pdf-> Cell(12,5, $Folio["n_reg"],10,0,'C',0);
		echo "<td style='".$col."'> <div align='center'><strong>" . $Foli["n_reg"] . "&nbsp;</strong></div></td>";
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fnumadu"] . "&nbsp;</strong></div></td>";
		$adultos+= $reg["fnumadu"];
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fnummenor"] . "&nbsp;</strong></div></td>";
		$fec1=$reg["ffecllegada"];
            
		include('DF20000.php');
		echo "<td style='".$col."'> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		$fec1=$reg["ffecsalida"];
              
		include('DF20000.php');
		echo "<td style='".$col."'> <div align='center'><strong>" . $f_f . "&nbsp</strong></div></td>";
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fformpago"] . "&nbsp;</strong></div></td>";
		$tarext=$reg["fmonmen"]+$reg["fmonadu"];
		echo "<td style='".$col."'> <div align='center'><strong>$" .number_format(floatval($reg['tex4']), 2, '.', ',') . "</strong></div></td>";
		echo "<td style='".$col."'> <div align='center'><strong>$" .number_format($tarext,2,'.', ','). "</strong></div></td>";
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fcodmeca"] . "&nbsp;</strong></div></td>";
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["codseg"] . "&nbsp;</strong></div></td>";	
		echo "<td style='".$col."'> <div align='center'><strong>" . $reg["fnorasvip"] . "&nbsp;</strong></div></td>";					
		if ($reg["ftipocto"]!='MAESTRA' and $reg["extra1"]=='0'){
		$d++;
		}
		}
	    	}
	    echo "<tr><th><div align='center' style=' '><strong>HABS :</strong></div></th>
				  <th><div align=\"center\" style=' '><strong>".$d."</strong></div></th>
                  <th colspan='2'><div align='center' style=' '><strong>PERSONAS :</strong></div></th>
	              <th><div align=\"center\" style=' '><strong>".$huesped["adultos"]."</strong></div></th>
	              <th><div align=\"center\" style=' '><strong>".$huesped["menores"]."</strong></div></th>
				  <th colspan='8'><div align=\"center\" style=' '><strong> &nbsp;" . $tohb1 . "</strong></div></th>   	 				
	          </tr>";	
	mysqli_close($con);
	?>
            </tbody>
    </table></div> </form>  </div>  </body>  </html>
