<?php
 
session_start();
include("DMMYSQLG.php");
?>
<html>
<link rel="stylesheet" href="css/estilo1.css" type="text/css"/>
<script type="text/javascript" language="JavaScript1.2" src="DSSCRIPT.js"></script>
<body>
<?php
 
$ayuda = 'DI3300A_AG1.php';
include("DYAYUDA.php");
?>
<?php
 
$fec=$_POST['tfec'];
include("DF20000.php");
//buscar almacen
if (isset($_POST['Submit22'])){
	
	$sql="INSERT INTO valeryus19 (fcodagen, fcodmeca, smerf, fempresa, fplan, codseg, fnorasvip, acc_fec, acc_hor, usuario, fcodgrupo, fnombre, status) VALUES ('".$_POST['fcodagen']."', '".$_POST['fcodmeca']."', '".$_POST['smerf']."', '".$_POST['fempresa']."', '".$_POST['fplan']."', '".$_POST['codseg']."', '".$_POST['fnorasvip']."', '".date('Y-m-d')."', '".date('H:i:s')."', '".$_SESSION['usuario']."', '".$_POST['fcodgrupo']."', '".$_POST['fnombre']."', '".$_POST['select1']."')";
	if (!mysqli_query($con ,$sql)){
		die('Error: ' . mysqli_error($con));
		exit();
	}
	$ultimo_id = mysqli_insert_id($con);
}
?>
<form name="frm1" id="frm1" method="post" action="">

<input name="s1" type="hidden" <?php
 echo 'value="'.$_REQUEST['s1'].'"' ?>>
<input name="s2" type="hidden" <?php
 echo 'value="'.$_REQUEST['s2'].'"' ?>>
<input name="s3" type="hidden" <?php
 echo 'value="'.$_REQUEST['s3'].'"' ?>>

<input name="controlSerie" type="hidden" <?php
 echo 'value="S"'; ?>>

  <table   align="center">
<tr>
<td colspan="4" class="men">
    <?php
  
	if(isset($_POST['Submit22'])){
		@$ultimo_id = mysqli_insert_id($con);
		echo '<input name="tnum" type="hidden" value="'.$ultimo_id.'">';
		echo 'NUMERO DE REQUISICION:'.$ultimo_id; 
		@$result = mysqli_query($con ,"SELECT * FROM dgrequie WHERE fol_ven = '$ultimo_id'");
	}else{
		echo '<input name="tnum" type="hidden" value="'.$_POST['tnum'].'">';
		echo 'NUMERO DE REQUISICION:'.$_POST['tnum']; 
		@$result = mysqli_query($con ,"SELECT * FROM dgrequie WHERE fol_ven = '".$_POST['tnum']."'");
	}	
	@$row = mysqli_fetch_array($result);
	$op1=$row["tip_ven"];
	$op2=$row["fec_ven"];
	$op3=$row["cod_cli"];
	$op4=$row["con_cre"];
	$op5=$row["alm_gen"];
	$op6=$row["sub_ven"];
	$op7=$row["iva_ven"];
	$op8=$row["tot_ven"];
	$op9=$row["iva_des"];
	$op10=$row["por_des"];
	$op11=$row["cod_ven"];
	$op12=$row["des_ven"];
	$op13=$row["nom_cli_alt"];
	$sta=$row['paso'];

if($sta=='2'){
	echo "<h2>Lo Sentimos, Esta Requisicion No Puede Ser Procesada Manualmente</h2>";
	echo '<meta content="3; url=DI33000_PR.php" HTTP-EQUIV="REFRESH">';	
	exit();
}

?>  </td>
  </tr>
  <tr>
    <th colspan="4" class=\"titulo\">REGISTRO DE RESERVACIONES POR GRUPO. </th>
  </tr>
  <tr>
    <td width="117">Tipo de Requisicion:</td>
    <td width="267">
	<?php
 
		//echo $op1.'<br>';
		
		if(isset($_POST['ver1']))
		{
			@$resultado=mysqli_query($con ,"select * from dgtipcar where tip_car = '".$_POST['ver1']."'");
			@$registro=mysqli_fetch_array($resultado);
			echo '<input name="ver1" type="hidden" value="'.$registro['tip_car'].'">';
			echo $registro['des_tipcar'];
		}else{
			@$resultado=mysqli_query($con ,"select * from dgtipcar where tip_car = '$op1'");
			@$registro=mysqli_fetch_array($resultado);
			echo '<input name="ver1" type="hidden" value="'.$registro['tip_car'].'">';
			echo $registro['des_tipcar'];
		}	
	?>
	&nbsp;</td>
    <td colspan="2">Fecha de Requisicion : 
	  <?php
 
		if(isset($_POST['ver2'])){
			echo '<input name="ver2" type="hidden" value="'.$_POST['ver2'].'">';
			echo $_POST['ver2'];
		}else{
			$fec1=$op2;
			include("DF20000.php");
			echo '<input name="ver2" type="hidden" value="'.$f_f.'">';
			echo $f_f;
		}
	?>	</td>
    </tr>
  <tr>
    <td>Observaciones:</td>
    <td colspan="3"><?php
echo $op13;?></td>
    </tr>
</table>
 <?php

/////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////si eprecionan el boton de eliminar/
/////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['Submit2'])){
	include('DI33000_AC7.php');	
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////Si se agrega un producto para la venta
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_POST['boton_car'])){
$dt_invent=mysqli_fetch_array(mysqli_query($con ,"SELECT cont_nser FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   n_reg ='".$_POST['producto']."'"));
	if($dt_invent["cont_nser"]=="S" && $_POST["controlaSerie"]=="S"){
	
	}
	else{	
		include('DI33000_AC6.php');
	}

}

?>

    <table  align="center">
  <tr>
    <th colspan="3" class=\"titulo\">SELECCIONAR CANTIDAD Y TIPODE HABITACION. </th>
    </tr>
  <tr>
    <td> 
        <input name="tbus" type="text" id="tbus"
		<?php
 
		echo 'value ="'.$_POST['tbus'].'"';
		?>
		>
          <input type="submit" name="Submit" value="Buscar" onClick="openpage('DI33000_AC.php','_self')"></td>
    <td colspan="2"><input name="r1" type="radio" value="clave" checked 
	<?php
 
	if($_POST['r1'] == "clave" ){
		echo ' checked';
	}
	?>
	>
Clave del producto
  <input name="r1" type="radio" value="des"
  <?php
 
	if($_POST['r1'] == "des"){
		echo ' checked';
	}
	?>
  >
Descripcion</td>
    <?php
 
@$resultado2=mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND n_reg  = '".$_POST['producto']."'");
$regist2=mysqli_fetch_array($resultado2);
/* 	$a1 = $registro2['n_reg']; 
	$a2 = $registro2['descripcion']; 
	$a3 = $registro2['exi_min']; 
	$a4 = $registro2['exi_max']; 
	$a5 = $registro2['linea']; 
	$a6 = $registro2['gpo_basico']; 
	$a7 = $registro2['cve_marca']; */
	$pp8 = $regist2['lim_vta1']; 
	$pp9 = $regist2['lim_vta2']; 
	$pp10 = $regist2['lim_vta3'];  
	$pp1 = $regist2['lim_1']; 
	$pp2 = $regist2['lim_2']; 
	$pp3 = $regist2['lim_3']; 
	/* $a14 = $registro2['tip_mon']; 
	$a15 = $registro2['uc_fec_doc']; 
	$a16 = $registro2['uc_num_doc']; 
	$a17 = $registro2['uc_pre_com']; 
	$a18 = $registro2['cos_prom']; 
	$a19 = $registro2['cos_prom_ant']; 
	$a20 = $registro2['exi_fis']; 
	$a21 = $registro2['exi_dis']; 
	$a22 = $registro2['fec_bck_ord']; 
	$a23 = $registro2['bck_ord']; 
	$a24 = $registro2['cve_uni_com']; */
	$a25 = $regist2['ven_esp1']; 
/* 	$a26 = $registro2['cve_uni_vta']; 
	$a27 = $registro2['cod_pro'];  */ 
?>
    </tr>
  
  <tr>
    <td colspan="3">TIPO DE HABITACION.
	
      <select name="producto" onChange="javascript: document.getElementById('frm1').submit()">
	  <option></option>
<?php
 
	if ($_POST['r1']=="clave"){//si 
		@$resultado=mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   n_reg like '%".$_POST['tbus']."%'");
		$nr = mysqli_num_rows($resultado);
		$x = 1;
		if($nr == 0){
			@$resultado=mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   n_reg like '%".$_POST['tbus']."%'");
			$nr1 = mysqli_num_rows($resultado);
			$x = 2;
		}
	}elseif($_POST['r1']=="des"){
		@$resultado=mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   descripcion like '%".$_POST['tbus']."%'");
		//$x = 3;
	}
	 while(@$registro=mysqli_fetch_array($resultado))
	{
		if(($_POST['producto'] == $registro['n_reg']) or (isset($_POST['Submit']) and $nr == 1)){
			echo '<option value="' . $registro['n_reg'] . '" selected>' . $registro['n_reg'] . ' | ' .$registro['descripcion'] . ' | </option>';
			$va =  $registro['n_reg'];
		}else{
			echo '<option value="' . $registro['n_reg'] . '">' . $registro['n_reg'] . ' | ' .$registro['descripcion'] . ' | </option>';
		}
	}			
?>
      </select>	  </td>
  </tr>
  <tr>
  <?php
 
  //sacar el precio del dolar
  	@$ress=mysqli_query($con ,"select * from dgparame");
	@$num_ro = mysqli_fetch_array($ress);
  ?>
    <td colspan="3"> 
	<?php
 
	//if($_POST['tbus']<>"" and isset($_POST['tbus']) or (isset($_POST['producto']))){
		//if(isset($_POST['Submit'])){
			//@$result = mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   n_reg ='".$_POST['producto']."'");
			//@$row = mysqli_fetch_array($result);
		/*  */
	//echo 'value="'.number_format($row['cos_prom'], 2, '.', ',').'"';	
	//echo 'value="'.$num_ro['tip_camb_ven'].'"';	
	?>
	CANTIDAD.
      <input name="tcan" type="text" size="10" maxlength="15" onKeyUp="seg_can(this.value)" onKeyPress="return soloNumeros(event)"
	 <?php
 /*  */ ?>></td>
    </tr>
</table>
    <div align="center"><br>
    <input type="submit" name="boton_car" value="Agregar Producto" onClick="sendFormNAS('frm1','DI33000_AC.php','_self')">
    <br>
</div>
<table border='1' align="center">
    <tr>
      <th> 
        <input type="submit" name="Submit2" value="Eliminar" onClick="sendFormNAS('frm1','DI33000_AC.php','_self')">
      </th>
      <th colspan="10"></th>
    </tr>
    <tr>
	  <th><div align="center">SEL.</div></th>
      <th><div align="center">CODIGO.</div></th>
      <th><div align="center">DESCRIPCION.</div></th>
	  <th><div align="center">CANTIDAD.</div></th>
	  
    </tr>

<?php

if (isset($_POST['boton_car']) || isset($_POST['producto']) || isset($_POST['Submit2']) || isset($_POST['Submit'])){
	//saca el numero de producto
	@$res=mysqli_query($con ,"select * from ftipcuartos where cons_ven = '".$_POST['tnum']."'");
	while($row = mysqli_fetch_array($res))
	{
		$npr[]=$row["n_reg"];	
		$nrx[]=$row["fol_ven1"];	
	}
	//contar cuantos registros
	$num_elementos=count($npr);
	//saca la descripcion del producto
	for($j=0;$j<=$num_elementos-1;$j++)
	{
		@$res=mysqli_query($con ,"SELECT * FROM valeryus05 WHERE valeryus05.modulo='".$_SESSION['mod_sis']."' AND   n_reg = '$npr[$j]'");
		while($row = mysqli_fetch_array($res))
		{
			$dpr[]=$row["descripcion"];	
		}
	}
	$num_elementos1=count($npr);
	for($y=0;$y<=$num_elementos1-1;$y++)
	{	
		//mostrar datos encontrados en dgrefodd
		@$res=mysqli_query($con ,"select * from ftipcuartos where cons_ven = '".$_POST['tnum']."' and n_reg = '$npr[$y]'");
		while($row = mysqli_fetch_array($res))
		{
			echo '<tr><td>';
			echo '<div align="center"><input name="r5" type="radio" value="'.$row['fol_ven1'].'"/></div></td>';
			echo '<input name="nu_re1'.$y.'" type="hidden" value="'.$nrx[$y].'">';
			echo '<input name="nu_re2'.$y.'" type="hidden" value="'. $npr[$y].'">';
			echo '<td><div align="center">' . $npr[$y] . '</div></td>';
			echo '<td><div align="center">' . $dpr[$y] . '</div></td>';
			$pbas=$row['pre_uni'];
			//echo '<td><div align="center">$ ' . number_format($row['pre_uni'], 4, '.', ',') . '</div></td>';
			$pbase =  $pbase + $pbas;
			$c = $c + $row['can_ref'];
			//echo '<td><div align="center">' . number_format($row['por_des'], 4, '.', ',') . '  %</div></td>';
			//echo '<td><div align="center">$ ' . number_format($row['des'], 4, '.', ',') . '</div></td>';
			$d = $d + $row['des'];
			$pre_u = $pbas - $row['des'];
			//echo '<td><div align="center">$ ' . number_format($pre_u, 4, '.', ',') . '</div></td>';
			$p = $p + $pre_u;
			//sacra el iva
			$sbt = $pre_u * $row['can_ref'];
			echo '<td><div align="center">' . $row['can_ref'] . '</div></td>';
			//echo '<td><div align="center">$ ' . number_format($sbt, 2, '.', ',') . '</div></td>';
			$s = $s + $sbt;
			//$ti = $sbt
			$ivpp = $row['iva_pre'] ;
			//echo '<td><div align="center">$ ' . number_format($ivpp, 2, '.', ',') . '</div></td>';
			$iv = $iv + $ivpp;
			$t = $ivpp + $sbt;
			//echo '<td><div align="center">$ ' . number_format($t, 2, '.', ',') . '</div></td>';
			$tot = $tot + $row['can_ref'];
			
			echo '</tr>'; 
		}
	}
 } 
 mysqli_close($con);
?>
  <th colspan="2">TOTAL DE HABITACIONES. </th>
     <th></th>
	 <th>
	<?php
 
	echo '<input name="txt_to" type="hidden" value="'.$tot.'">';
	echo $tot;
	?>	</th>
  </table>
  <div align="center">
    <input name="Submit5" type="Submit" value="Terminar Captura" onClick="openpage('DI33000_AG2.php','_self')">
  </div>
</form>
<?php

@$res=mysqli_query($con ,"select * from ftipcuartos where cons_ven = '".$_POST['tnum']."' and n_reg = '$npr[$y]'");
$ftipo = mysqli_fetch_array ($res);
?>
</body>
</html>
