<?php
 
session_start();
include("DMMYSQLG.php");
include("DSA1000.php");
include("DF30000.inc");
include("DFJQUERY.inc");
include("JQUERY.inc");
$f_m=0;
$WdSd=0;
$dFgF=0;
$sdFg=0;
$nr=0;
$f_f="";
$AsDs=0;
?>
<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">
<style type="text/css">
<!--
.Estilo16 {font-size: 14px}
.Estilo19 {font-family: Verdana, Helvetica; font-weight: bold; font-size: 10px;  ; }
td {
   font-family:helvetica;
   font-style:italic;
   font-size:11px;
   color: #000000;
   }  
.Estilo20 {color: #FFFFFF}
-->
</style>
</HEAD>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>


<body>

<div align="center">
  <form name="frm1" id="frm1" method="post" action="">
    <table width="441" border="0">
	<tr> <th colspan="2"><span class="Estilo16">REPORTE DE SALDOS</span> </th> 
	</tr>
         <?php
          $fec=(isset($_POST['fec']))?$_POST['fec']:date('d/m/Y');
          ?>  
      <tr>
        <td width="33%"> <div align="right" class="Estilo19"><img src="magnifier.png" alt="Buscar" onClick="alert('Buscar')" /> PERIODO </div></td>
        <td width="67%"> <input name="r1" type="radio" value="f" tabindex="5"/>
          <span class="Estilo20">De:</span>
          <input name="fec" type="text" class="emplea datefrom" id="fec" size="9" maxlength="20" value="<?=$fec?>"
			<?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 class="Estilo20">A:</span>
          <input name="fec2" type="text" class="emplea dateto" id="fec2" size="9" maxlength="20" value="<?=date("d/m/Y")?>"
			<?php

				if(isset($_POST['fec2'])){ //este es el truco
					echo 'value="' . $_POST['fec2'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
		 ?> onkeypress="return soloNumeros(event)"
		/>
            <!--<input name="bot12" id="bot1" type="image" value="Cal" src="logos/cal4.jpg" />
            -->
      </tr>
	  <tr>
	  <td colspan="2" height="25">	  </td>
	  </tr>
      <tr>
        <td colspan="2">
          <div align="center">
            
            <input name="Submit" type="button" class="boton" onClick="openpage('ger_saldos_PR.php','_self')" value="Buscar"/>
			<input name="bot4" type="button" class="boton" onClick="openpage('ger_saldos_IM.php','_self')" value="Imprimir "/>
		  </div></td>
      </tr>
    </table>
     
  </form>
</div>
<div align="center">
  <form method="post" action="" >
    <?php

	@$result = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE status = 'HUESPED' or status = 'MISCELANEOS' order by fnumcto");
	?>
    <div style="height:450px; overflow:scroll; width:1050;">
	<!--div style="height:400px; overflow:auto;"-->
	<!--div style="height:400px; overflow:auto; width:auto; background-color:#FFF;"-->
	<table width="922"  border="0" align="center" bordercolor=" " bordercolordark=" ">
     
      <tr>
        <th width="63"><div align="center">FOLIO</div></th>
		<th width="138"><div align="center">HUESPED</div></th>
		<th width="50"><div align="center"> HAB</div></th>
		<th width="67"><div align="center">TIPO</div></th>
		<th width="92"><div align="center">FECHA DE LLEGADA</div></th>
		<th width="88"><div align="center">FECHA DE SALIDA</div></th>
		<th width="125"><div align="center">FORMA DE PAGO</div></th>
		<th width="70">CARGO</th>
		<th width="78">ABONO</th>
		<th width="109">TOTAL</th>
      </tr>
	  
	<?php

	 // --->
	 
	  	$fec =(isset($_POST['fec']))?$_POST['fec']:"";
		include('DF20000.php');
		$fecha_inicial = $f_m;
		//$pdf->Cell(15,5,$fecha_inicial,1,0,'C');
	
		$fec = (isset($_POST['fec2']))?$_POST['fec2']:"";
		include('DF20000.php');
		$fecha_final = $f_m;
	  // -->
	 //if(!isset($_POST['r1']))$_POST['r1']="";
	if(isset($_POST['r1']) && $_POST['r1']=="f"){
		echo '<input name="tbusqueda" type="hidden" value="f">';
		$result = mysqli_query($con ,"SELECT * FROM valeryus19 WHERE (ffecllegada <= '$fecha_final' and fecha_real >= '$fecha_final' and cancelado='0') or (ffecllegada <= '$fecha_final' and ffecsalida >= '$fecha_final' and cancelado='0') order by fmuncto, fnumcto");
   	   
	}
	include("DE10000.php");
	while($reg = mysqli_fetch_array($result))
	{
	  	$nr = $nr + 1;
		$v1 = $nr / 2;
		$v2 = (int) ($nr / 2);
		  if($v1 == $v2){
			$col ="";
		   }else{
			$col =" ";
		   }
		echo "<tr>";
		echo "<td style='".$col."' width='63'> <div align='center' style=' '><strong>" . $reg["n_reg"] . "&nbsp;</strong></div></td>";
		echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $reg["fapellido"] . ' '. $reg["fnombre"] . "&nbsp;</strong></div></td>";
		if ($reg["fnumcto"]==''){
		$reg["fnumcto"]=$reg["fmuncto"];
		}
		echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $reg["fnumcto"] . "&nbsp;</strong></div></td>";
		echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $reg["ftipocto"] . "&nbsp;</strong></div></td>";
		$fec1=$reg["ffecllegada"];
		include('DF20000.php');
		echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $f_f . "&nbsp</strong></div></td>";
		$fec1=$reg["ffecsalida"];
		include('DF20000.php');
		echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $f_f . "&nbsp</strong></div></td>";
        echo "<td style='".$col."'> <div align='center' style=' '><strong>" . $reg["fformpago"] . "&nbsp;</strong></div></td>";
		$folio = $reg["n_reg"];
		@$saldo=mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(costo) AS cargo, SUM(total) AS abono FROM valeryus030 WHERE nparte1='".$folio."' and (cancelado='0' OR cancelado='2')"));
		echo "<td style='".$col."'> <div align='center' style=' '><strong>$" . number_format($saldo['cargo'],2,'.',',') . "&nbsp;</strong></div></td>";
		echo "<td style='".$col."'> <div align='center' style=' '><strong>$" . number_format($saldo['abono'],2,'.',',') . "&nbsp;</strong></div></td>";
		$total=$saldo['cargo']-$saldo['abono'];
		echo "<td style='".$col."'> <div align='center' style=' '><strong>$" . number_format($total,2,'.',',') . "&nbsp;</strong></div></td>";
	    $WdSd += $saldo['cargo'];
		$dFgF += $saldo['abono'];
		$sdFg = $WdSd - $dFgF;
		$AsDs += $total;
	}
	    echo "<tr><th colspan='7'><div align='RIGHT' style=' '><strong>TOTALES :</strong></div></th>
   				  <th><div align=\"center\" style=' '><strong>$".number_format($WdSd,2,'.',',')."</strong></div></th>
				  <th><div align=\"center\" style=' '><strong>$".number_format($dFgF,2,'.',',')."</strong></div></th>
				  <th><div align=\"center\" style=' '><strong>$".number_format($sdFg,2,'.',',')."</strong></div></th>
	          </tr>";
	mysqli_close($con);
	//171-->100 ULTIMA ACTUALIACION 23/OCT/2012 MODIFICAR SALDOS
	?>
    </table>
	</div>
  </form>
</div>
</body>
</html>