<?php
 
session_start();
$com = "A";
include("DMMYSQLG.php");
include("DMMYSQLG.php");
include("DFJQUERY.inc");
include("DF80000.php");
include("DF30000.inc");
include ("varfun.php");
$sos = $_GET['n_reg'];
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<script language="javascript">
function openWindow(dataGen,valores){
	var objDate=new Date();
	var getVars,getVarsAux,distPage;
	var idVentana;
	for(getVarsAux in valores){
		getVars +='&'+getVarsAux+'='+valores['getVarsAux'];
	}
	if(typeof dataGen.width=='undefined') dataGen.width='800';
	if(typeof dataGen.height=='undefined') dataGen.height='600';
	distPage='?tmr='+objDate.getHours()+objDate.getMinutes()+objDate.getSeconds()+objDate.getDay()+objDate.getMonth()+objDate.getFullYear();
	idVentana=window.open(dataGen.action+distPage+getVars,dataGen.name,'width='+dataGen.width+',height='+dataGen.height+',top=100,left=50,scrollbars=yes,menubar=yes,status=yes');
	return idVentana;
}
</script>



<body>
<? 
/*Verifica que exista Variable contenedora del Id del Encabezado*/	
if (!isset($_REQUEST['bot'])){
	echo '<h2>!!! SELECCIONA UN REGISTRO... ACTUALIZANDO !!!</h2>';
	echo '<meta content="1; url=caj_checkout_PR.php"  HTTP-EQUIV="REFRESH">';
	exit();
}
/****************************************************************/

/*Llena Variable para verificar si esta en modo Update*/
if(!isset($_POST['block_mod'])){
	$bMod=false;			//Bandera de modificar, bloquea pagina en modo Modificar esperando el evento que la cambie de estado
	$bSel='';				//Id registro a modificar
}
else{
	$bMod=$_POST['block_mod'];
	$bSel=$_POST['reg_mod'];
}
/****************************************************/

$bModPri=false;				//Bandera de Modificar(True solo En el Primer Bloqueo o recarga de pagina en modo Modificar)
$id_enc=$sos; 	//Id de Encabezado
$id_det=$_POST['bot_det'];	//Id de Detalle (si se selecciono alguno)
/*Crear Objetos Necesarios para Manipular Encabezado y Detalle*/
include('DI21100_CL.php');
$dataEnc['idInvent']=$id_enc;
$dataDet['idInvent']=$id_enc;
$dataDet['idInvend']=$id_det;
//echo "DETALLE: $dataDet['idInvend']";
//$encInv = new EncFac($dataEnc);
//$detInv = new DetFac($dataDet);
/************************************************************/

/*Recuperar Información de Encabezado y la coloca en los objetos HTML*/
//$res=$encInv->busReg();
$dt_encinv=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM valeryus19 WHERE n_reg='$id_enc'"));
$_REQUEST['id_prod']=$dt_encinv['fnombre'];
$_REQUEST['des_prod']=$dt_encinv['fnumcto'];
$_REQUEST['fec_prod']=chfecha($dt_encinv['ffecsalida'],'Y-m-d','d/m/Y');
$_REQUEST['fac_prod']=$dt_encinv['fapellido'];
$_REQUEST['tip_prod']=$dt_encinv['almacen'];
$_REQUEST['n_reg']=$dt_encinv['n_reg'];
$_REQUEST['invmin']=$dt_encinv['ftipocto'];
$_REQUEST['invmax']=$dt_encinv['fnumctos'];
$_REQUEST['codigo']=$dt_encinv['n_reg'];
$_REQUEST['fnorasvip']=$dt_encinv['fnorasvip'];
//$_REQUEST['fcodgrupo']=$dt_encinv['fcodgrupo'];
//$_REQUEST['fcodmeca']=$dt_encinv['fcodmeca'];
//$_REQUEST['fcodagen']=$dt_encinv['fcodagen'];
//$_REQUEST['codseg']=$dt_encinv['codseg'];
$_REQUEST['ffecllegada']=chfecha($dt_encinv['ffecllegada'],'Y-m-d','d/m/Y');
$_REQUEST['fformpago']=$dt_encinv['fformpago'];
$_REQUEST['tex']=$dt_encinv['tex'];
$_REQUEST['tex4']=$dt_encinv['tex4'];
$_REQUEST['text1']=$dt_encinv['text1'];
$_REQUEST['text4']=$dt_encinv['text4'];
 if ($_REQUEST['text4'] == 0 && $_REQUEST['tex4'] != 0){
 	$tarifa=$_REQUEST['tex4'];
	}		
 if ($_REQUEST['text4'] != 0 && $_REQUEST['tex4'] == 0){
 	$tarifa=$_REQUEST['text4'];
	}		

 if ($_REQUEST['text4'] != 0 && $_REQUEST['tex4'] != 0){
		  $fecha1 = $dt_empres['fec_alta'];
		echo  $today = date('l', strtotime($fecha1));
		  if ($today == "Sunday"){	//domingo
		   	$tarifa=$_REQUEST['text4'];
		  }
		  if ($today == "Monday"){ //lunes
		   	$tarifa=$_REQUEST['text4'];
		  }
		  if ($today == "Tuesday"){ //martes 	
		   	$tarifa=$_REQUEST['text4'];
		  }
	      if ($today == "Wednesday"){ //miercoles
		   	$tarifa=$_REQUEST['text4'];
		  }
		  if ($today == "Thursday"){ //jueves 
		   	$tarifa=$_REQUEST['text4'];
		  }
		  if ($today == "Friday"){ //viernes
		   	$tarifa=$_REQUEST['tex4'];
		  }
	      if ($today == "Saturday"){ //sabado
		   	$tarifa=$_REQUEST['tex4'];
		  }

	  	   
	}	  

/*Si Se Realizaron Operaciones sobre detalle actualiza Totales Factura*/
if($rs){
	//$encInv->resetData($detInv->getTotFac());
	//$encInv->actTotFac();
}
/****************************************************************/

/*Busca los Registros pertenecientes al encabezado en cuestion*/
$sq_detfac=mysqli_query($con ,"SELECT * FROM valeryus030 WHERE nparte1='".$dataEnc['idInvent']."'");

/*************************************************************/
?>
<form name="frm1" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="DI21100_AGDET" id="DI21100_AGDET" value="DI21100_AGDET.php">
<input type="hidden" name="bot" id="bot" value="<? echo $_REQUEST['bot'];?>">
<input type="hidden" name="reg_mod" id="reg_mod" value="<? echo $bSel;?>">
<input type="hidden" name="block_mod" id="block_mod" value="<? echo $bMod;?>">

  <table   align="center">
    <tr>
      <th colspan="8" class=\"titulo\"><div align="center">CONSULTA DE CARGOS/HUESPEDES </div></th>
    </tr>
    <tr>
      <td width="160" rowspan="6" nowrap bordercolor="#FFFFFF" style="#5F84B1"><div align="center" id="capa"><?php

			$sql = mysqli_query($con ,"SELECT * FROM valeryus19 where n_reg = '".$_REQUEST['n_reg']."'");
			while($reg=mysqli_fetch_array($sql)){
			$fotografia = 'foto/valeryus19/NO_'. $reg["n_reg"] .'.JPG';
			if (file_exists($fotografia)) {
				echo '<img src="foto/valeryus19/NO_'.$reg["n_reg"].'.JPG" width="150" height="175">';
			}else{
				echo '<img src="foto/sin_producto.jpg" width="150" height="175">';
			}
			}
		  ?>
      </div>      </td>
	  
      <td><strong>APELLIDO Y NOMBRE.</strong></td>
      <td colspan="2"><input name="id_prod" type="text" tabindex="1" value="<? echo "".$_REQUEST['fac_prod'].' '.$_REQUEST['id_prod'].""?>" size="45" readonly/></td>
      <td width="71"><strong>FOLIO</strong></td>
      <td width="137" colspan="2"><input name="codigo" type="text" id="codigo" size="6" value="<? echo $_REQUEST['codigo']?>"></td>
    </tr>
    
    <tr>
      <td width="104"><strong>TIPO DE HABITACION</strong></td>
      <td width="271"><input name="invmin" type="text" id="invmin" size="25" value="<? echo $_REQUEST['invmin']?>"></td>
      <td width="130"><div align="right"><strong>DIAS</strong></div></td>
      <td colspan="3">&nbsp;&nbsp; <input name="inmax" type="text" id="inmax" size="8" value="<? echo $_REQUEST['invmax']?>"></td>
    </tr>
    <tr>
      <td><label><strong>No. DE HABITACION</strong></label></td>
      <td><input name="des_prod" type="text" id="des_prod" tabindex="2" value="<? echo $_REQUEST['des_prod']?>" size="10" readonly></td>
      <td colspan="4" rowspan="3"><label></label>
      <div align="center"><strong>NOTAS</strong></div>        
      <div align="center">
        <textarea name="fnorasvip" cols="26" rows="4" id="fnorasvip" onBlur="may(this)" tabindex="4"><? echo $_REQUEST['fnorasvip'];?></textarea>
      </div></td>
    </tr>
    <tr>
      <td><strong>FECHA DE LLEGADA</strong></td>
      <td><input name="fec_llegada" type="text" tabindex="1" readonly value="<? echo $_REQUEST['ffecllegada']?>"/></td>
    </tr>
    <tr>
      <td><strong>FECHA DE SALIDA</strong></td>
      <td><input name="fec_prod" type="text" tabindex="1" readonly value="<? echo $_REQUEST['fec_prod']?>"/></td>
    </tr>
    <tr>
      <td><strong>TARIFA</strong></td>
      <td><?php
 
	  if (($_REQUEST['tex4']!=0)&&($_REQUEST['text4']==0))
		  $tar="" .$_REQUEST['tex']."-".$_REQUEST['tex4']."";
		else if (($_REQUEST['tex4']==0)&&($_REQUEST['text4']!=0))
		  $tar="".$_REQUEST['text1']."-".$_REQUEST['text4']."";	
		else if (($_REQUEST['tex4']!=0)&&($_REQUEST['text4']!=0))  
          $tar="" .$_REQUEST['tex']."- $".$_REQUEST['tex4']."  |  ".$_REQUEST['text1']."- $".$_REQUEST['text4']."";
		else 
			$tar="";
	   ?>
      <input name="tarifa" type="text" id="tarifa" size="35" value="<? echo $tar; ?>"></td>
      <td><strong>FORMA DE PAGO </strong></td>
      <td colspan="3"><input name="forpag" type="text" id="forpag" size="30" value="<? echo $_REQUEST['fformpago'];?>"></td>
    </tr>
  </table>
  <p>&nbsp;</p>
  <table width="644" border="0" align="center" cellspacing="4" id="tableDetail">
   <tr>
     <td colspan="12">
       <div align="center">
         <span class="Estilo19">X PERIODO</span>
         <input name="r1" type="radio" value="f" tabindex="5"/>
         De:
         
         <input name="fecha1" type="text" class="emplea" id="fecha1" size="9" maxlength="20"
			<?php

				if(isset($_POST['fecha1'])){ //este es el truco
					echo 'value="' . $_POST['fecha1'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
         <input name="bot1" id="bot1" type="image" value="Cal" src="logos/cal4.jpg" />
         <script type="text/javascript">
  Calendar.setup(
    {
      inputField  : "fecha1",        // ID of the input field
      ifFormat    : "%d/%m/%Y",    // the date format
      button      : "bot1"      // ID of the button
    }
  );
            </script>
		 
         A:
         
		 <input name="fecha2" type="text" class="emplea" id="fecha2" size="9" maxlength="20"
			<?php

				if(isset($_POST['fecha2'])){ //este es el truco
					echo 'value="' . $_POST['fecha2'] .  '"';
				}else{
					echo 'value="'.date("d/m/Y").'"';
				}
			?>onkeypress="return soloNumeros(event)"//solo fechas
		/>
         <input name="bot2" id="bot2" type="image" value="Cal" src="logos/cal4.jpg" />
         <script type="text/javascript">
  Calendar.setup(
    {
      inputField  : "fecha2",        // ID of the input field
      ifFormat    : "%d/%m/%Y",    // the date format
      button      : "bot2"      // ID of the button
    }
  );
            </script>
         </div>
		 
		 
		 </td></tr>
   <tr>
    <td colspan="12">
	
	    <div align="right">
	      <label>
	      <input name="?3" type="button" class="form" onClick="
	  	openWindow(
		{
			action:'valeryus67000_TAR.php',
			width:700,
			height:350
		},{
			val:'tar',
			des:'tari',
			roc:'tarif'
			
		})" value="Buscar Nueva Tarifa" >
	      <input name="tar" type="text" id="tar" size="30">
	      </label>
	      <label>
	      <input name="tari" type="text" id="tari" size="10">
	      <input name="tarif" type="text" id="tarif" size="12">
	      <input name="TARIFA" type="submit" class="form" id="TARIFA" value="Modificar"/>
		  <?php

		  // --->
	  	$fec = $_POST['fecha1'];
		include('DF20000.php');
		$fecha_inicial = $f_m;
		//$pdf->Cell(15,5,$fecha_inicial,1,0,'C');
		$fec = $_POST['fecha2'];
		include('DF20000.php');
		$fecha_final = $f_m;
	  // -->
		  $tar = $_POST['tarif'];
		  if (isset($_POST["TARIFA"])){
		  if ($_POST['tarif'] == ''){
		  echo alert_JS ("¡¡¡SELECCIONE UNA TARIFA!!!");
		  }else{
		  if ($_POST['r1']=="f"){
		  $nueva = mysqli_query ("UPDATE valeryus030 SET costo = '$tar', usu_mod = '".$_SESSION['usuario']."' where acc_fec between '$fecha_inicial' and '$fecha_final' and nparte1_det = '1' and nparte1='".$dataEnc['idInvent']."'");
		  }else{
		  $nueva = mysqli_query ("UPDATE valeryus030 SET costo = '$tar', usu_mod = '".$_SESSION['usuario']."' where nparte1_det = '1' and nparte1='".$dataEnc['idInvent']."'");
		  }
		  }
		  echo "<script languaje=\"javascript\">document.getElementById('frm1').submit()</script>";
		  }
		  ?>
	      </label>
	    </div></td>
	</tr>
	<tr>
      <th width="41" nowrap>FECHA</th>
      <th width="37" nowrap>HORA</th>
	  <th width="61" nowrap># RECIBO </th>
      <th width="135" nowrap>DESCRIPCON /CARGO</th>
	  <th width="54" nowrap>CARGOS</th>
      <th width="55" nowrap>ABONOS</th>
	  <th width="60" nowrap>NOTAS</th>
	  <th width="70" nowrap>? AGREGO</th>
	  <th width="80" nowrap>? MODIFICO</th>
	  <th width="80" nowrap>? CANCELO</th>
	  <th width="85" nowrap>? TRASPASO</th>
    </tr>
    <?php

		//Codigo Mostrar Detalle
		$subTotDoc=0.00;
		$ivaTotDoc=0.00;
		$totDoc=0.00;
		$subTotPar=0.00;
		$ivaTotPar=0.00;
		$totPar=0.00;
		$tipCar='-1';
		$contador=0;
		while($dt_invend=mysqli_fetch_array($sq_detfac)){
			$contador++;
			$auxInvent=mysqli_fetch_array(mysqli_query($con ,"SELECT * FROM valeryus09 WHERE n_reg='".$dt_invend['nparte1_det']."'"));
			if($dt_invend['id_invend']!=$bSel){// nparte1, np_desc son de la table farticulos
				if($dt_invend['cancelado'] == 0){
					echo'<tr>
					
					<td><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td><div align="left">
							'.$dt_invend['usuario'].'&nbsp;
					</div></td>
					<td class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_mod'].'&nbsp;
					</div></td>
					<td class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_can'].'&nbsp;
					</div></td>
					<td class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_tra'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 1){
				    echo'<tr>
					
					<td style="#FF3300"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="left">
							'.$dt_invend['usuario'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_mod'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_can'].'&nbsp;
					</div></td>
					<td style="#FF3300" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_tra'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 2){
				    echo'<tr>
					
					<td style="#7970F1"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="#7970F1"><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="left">
							'.$dt_invend['usuario'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_mod'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_can'].'&nbsp;
					</div></td>
					<td style="#7970F1" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_tra'].'&nbsp;
					</div></td>
					
					</tr>';
					}if ($dt_invend['cancelado'] == 3){
				    echo'<tr>
					
					<td style="#CC3399"><div align="right">
							'.chfecha($dt_invend['acc_fec'],'Y-m-d','d/m/Y').'&nbsp;
					</div></td>
					<td style="#CC3399"><div align="right">
							'.$dt_invend['acc_hor'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="center">
							'.$dt_invend['can_ref'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="left">
							'.$auxInvent['descripcion'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['costo'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="right">
							'.number_format($dt_invend['total'],2,'.',',').'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="right">
							'.$dt_invend['proteina'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="left">
							'.$dt_invend['usuario'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_mod'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_can'].'&nbsp;
					</div></td>
					<td style="#CC3399" class="detailRowTable" ><div align="left">
							'.$dt_invend['usu_tra'].'&nbsp;
					</div></td>
					
					</tr>';
					}
					$numPun +=$auxInvent['num_pun'];
					$sbt = $sbt + $dt_invend['toldes'];
					$p = $p + $dt_invend['total'];
					$q = $q + $dt_invend['ivatotal'];
					$jiu = ($q +$p)-$sbt;
					$nk = $nk + $dt_invend['proteina'];
		$sqo = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(costo) AS tot FROM valeryus030 WHERE cancelado=0 AND nparte1 = '$id_enc'"));
		$sqk = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(costo) AS tat FROM valeryus030 WHERE cancelado=2 AND nparte1 = '$id_enc'"));
		$sqf = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(total) AS sos FROM valeryus030 WHERE cancelado=0 AND nparte1 = '$id_enc'"));
		$sqs = mysqli_fetch_array(mysqli_query($con ,"SELECT SUM(total) AS sas FROM valeryus030 WHERE cancelado=2 AND nparte1 = '$id_enc'"));
					
					$uij = $sqo['tot'] + $sqk['tat'];
				    $pol = $sqf['sos'] + $sqs['sas'];
					$asd = $uij - $pol;
				}
				
		}
		echo '
			<tr>
			<td colspan="4" class="inputcodigo"><div align="right">TOTAL: &nbsp;</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($uij,2,'.',',').'</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($pol,2,'.',',').'</div></td>
			<td colspan="2" class="inputcodigo"><div align="right">=======>>>>>> &nbsp;</div></td>
			<td colspan="1" class="inputcodigo"><div align="right">'.number_format($asd,2,'.',',').'</div></td>
			
			</tr>';		
		
	?>
    <tr>
      <td colspan="15"><div align="center">
  
  <input name="terminarCaptura" type="button" class="form" id="terminarCaptura" value="Regresar" onClick="openpage('valeryus67000_PR.php','_self')">
      </div></td>
    </tr>
  </table>
  <p>&nbsp;</p>
</form>
</body>
</html>
<?php
 mysqli_close($con);?>
<?php

//609 ultima actualizacion 25/abril/2011
//544                      13/julio/2011
?>
