<?PHP 
	$pass=$_POST['Clave'];
if ($_POST['txtipo']=='1'){
	/*@$w=mysqli_query($con ,"select codigo from ctmeser where cvpvta=$_POST['txtpunto'] order by nparte1");
	 codigo para checar meseros por punto de venta */
	@$w=mysqli_query($con ,"select codigo from ctmeser order by nparte1");
		while (@$pas=mysqli_fetch_array($w)){
			if ($pas['codigo']==$pass)
			{
				echo 
				"<script type='text/javascript'>
				window.open('MESA4000_PR.php?mesero=".$_POST['Clave']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."','mainFrame','Keypad');
				window.close();
				</script> ";
			}else {	}	
		}

} elseif ($_POST['txtipo']=='11'){
$hp=mysqli_fetch_array(mysqli_query($con ,"select * from fcomhues where cvmesa=".$_POST['txtmesa']." and status=1"));
	@$w=mysqli_query($con ,"select codigo from ctmeser where nparte1=".$hp['cvmesero']." ");
		while (@$pas=mysqli_fetch_array($w)){
			if ($pas['codigo']==$pass)
			{
				echo 
				"<script type='text/javascript'>
				window.open('MESA5000_PR.php?mesero=".$_POST['Clave'] ."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['txtpos']."','mainFrame','Keypad');
				window.close();
				</script> ";
			}else {	}
		}
		@$w1=mysqli_query($con ,"select pasw from dgcatven");
		while (@$pas1=mysqli_fetch_array($w1)){
			if ($pas1['pasw']==$pass)
			{
				echo 
				"<script type='text/javascript'>
			window.open('MESA5000_PR.php?mesero=".$_POST['Clave'] ."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['txtpos']."','mainFrame','Keypad');
				window.close();
				</script> ";
			}else {	}	
		}


}elseif ($_POST['txtipo']=='2'){
				echo 
				"<script type='text/javascript'>
				window.open('MESA4000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&cant=".$_POST['Clave'] ."','mainFrame','Keypad');
				window.close();
				</script> ";
}elseif ($_POST['txtipo']==3){
				echo 
				"<script type='text/javascript'>
				window.open('MESA4000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&cant=".$_POST['txtcant'] ."&hab=".$_POST['Clave'] ."','mainFrame','Keypad');				
				window.close();
				</script> ";
				
}
elseif ($_POST['txtipo']==89){
				
				echo 
				"<script type='text/javascript'>
				window.open('MESA5000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=11','mainFrame','Keypad');				
				window.close();
				</script> ";
				
				//<input name="button" type="button" class="botunn" style="background-color: #FF0000; font-family:Arial, Helvetica, sans-serif; font-size:12px" onClick="abrir('CALMES00.php?ms=<?php
 echo $reg['nparte1'];?H>&ar=<?Hphp echo $reg['area'];?H>&pt=<?php
 echo $reg['descripcion'];?H>&pos=<?php
 echo $reg['posicion'];?H>&tpo=11')" target="_blank" value="<?phHp echo $reg['np_desc1']; ?H>">
				//&pos=".$_POST['Clave']."
				
				
				//echo 
				//"<script type='text/javascript'>
				//window.open('MESA5000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&cant=".$_POST['txtcant'] ."&hab=".$_POST['Clave'] ."','mainFrame','Keypad');				
				//window.close();
				//<//script> ";
				
}
elseif ($_POST['txtipo']==4){
/*				xajax_mod_rec(xajax.getFormValues('Keypad'));
				xajax_ing_comd(xajax.getFormValues('Keypad')); */

				$ssql = "UPDATE ctmesas SET status=1,posicion='".$_POST['txtcont']."',acc_fec='".$dt_empres['fec_alta']."' where nparte1='" .$_POST["txtmesa"]. "' and descripcion='" . $_POST["txtpunto"] . "' and area='" . $_POST["txtarea"] . "' ";	
	if (mysqli_query($con ,$ssql)){
    	$salida = "Insertado correctamente";
	}else{
	    $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
	}

$sql_fcom=mysqli_query($con ,"select fol_comd from fcomanda where fol_ven='".$_GET['folio']."'");
$regf=mysqli_fetch_array($sql_fcom);

				echo
				"<script type='text/javascript'>
				window.open('CAJA1.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&comand=".$_POST['Clave']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."','mainFrame');				
				window.close();
				</script> ";
				
}elseif ($_POST['txtipo']==5){
// ingresa comanda
		$sql = "SELECT fol_comd FROM fcomanda WHERE fol_comd = '$pass' and fol_ven=".$_POST['txtfolio']."";
	   	@$result = mysqli_query($con ,$sql);
	   	@$num_salidas=mysqli_num_rows($result); 
		if($num_salidas>=1){
		echo "<script type='text/javascript'>
		alert('No. COMANDA EXISTENTE');
		</script> ";
		}elseif($num_salidas==0){
		echo"<script type='text/javascript'>
		xajax_ing_comd(xajax.getFormValues('Keypad'));				window.open('CAJA1.php?mesero=".$_POST['txtmeser'] ."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&fol=".$_POST['txtfolio']."&comand=".$_POST['Clave']."','mainFrame','Keypad');				
		window.close();
		</script> ";
		}
}elseif ($_POST['txtipo']==6){
		$sql = "SELECT fol_ven FROM dgpemema WHERE fol_ven = '$pass'";
	   	@$result = mysqli_query($con ,$sql);
	   	@$num_salidas=mysqli_num_rows($result); 
		$sql2 = "SELECT pedido FROM dgger_cajerosj WHERE pedido = '$pass'";
	   	@$result2 = mysqli_query($con ,$sql2);
	   	@$num_salidas2=mysqli_num_rows($result2); 
		@$sql3="select * from dgpemema where fol_ven='$pass' and cancelado=1";
		@$result3=mysqli_query($con ,$sql3);
	   	@$num_salidas3=mysqli_num_rows($result3); 
		if($num_salidas>=1){
			if (($num_salidas2==0)&&($num_salidas3==0)){
				
			//cancela la orden y la mesa 
				@$mod="update dgpemema set cancelado=1 where fol_ven='".$_POST['Clave']."'";		
				if (mysqli_query($con ,$mod)){
					echo $salida = "Insertado correctamente";
				}else{
					echo $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
				}
				@$modm="update ctmesas set status=0,fol_ven=0 where fol_ven='".$_POST['Clave']."'";		
				if (mysqli_query($con ,$modm)){
					echo $salida = "Insertado correctamente";
				}else{
					echo $salida = "No se ha insertado. Este es el error: " . mysqli_error($con);
				}
				echo "<script type='text/javascript'>
				alert('SE CANCELO EL FOLIO:".$_POST['Clave']."!!');
				window.close();
				</script> ";
			}else{
				if ($num_salidas2!=0)  {
					echo "<script type='text/javascript'>
					alert('EL FOLIO No.".$pass." ESTA PAGADO');
					</script> ";
				}elseif ($num_salidas3!=0) {
					echo "<script type='text/javascript'>
					alert('EL FOLIO No.".$pass." YA SE ENCUENTRA CANCELADO');
					</script> ";
				}
			}
	
		}elseif($num_salidas==0){
		echo "<script type='text/javascript'>
		alert('EL FOLIO No.".$pass." NO EXISTE');
		</script> ";

		}			
				
}elseif ($_POST['txtipo']==7){
		@$w=mysqli_query($con ,"select pasw from dgcatven order by cod_ven");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['pasw']==$pass)
			{
			echo "<script type='text/javascript'>
						window.open('CAJA2.php?cajero=".$_POST['Clave']."&ms=".$_POST['txtmesa']."&pt=".$_POST['txtpunto']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&mesero=".$_POST['txtmeser']."','mainFrame','Keypad');				
						window.close();
						</script> "; 
			}	
		}
				
}elseif ($_POST['txtipo']==8){
				echo 
				"<script type='text/javascript'>
				window.open('CAL10000.php?mesero=".$_POST['Clave']."&tpo=8','_self','Keypad');
				</script> ";

}elseif ($_POST['txtipo']==12){
//ingresa comanda

				echo 
				"<script type='text/javascript'>
				window.open('MESA5000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['Clave']."','mainFrame','Keypad');				
				window.close();
				</script> ";
				
}elseif ($_POST['txtipo']==13){
//cancela la posicion 
@$w=mysqli_query($con ,"select pasw from dgcatven order by cod_ven");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['pasw']==$pass)
			{
			//codigo de cancelacion 
			$ca_fpos=mysqli_query($con ,"update fpos set status=0 where fol_ven=$_POST['txtfolio']");
			$res_fpos=mysqli_query($con ,"update fposres set status=0 where fol_ven=$_POST['txtfolio']");
			echo mysqli_error($con);
			$ca_dgpma=mysqli_query($con ,"update dgpemema set cancela=1,mt_cancela='".$_POST['cancela']."' where fol_ven=$_POST['txtfolio']");
			echo mysqli_error($con);
			@$fol=mysqli_fetch_array(mysqli_query($con ,"select con_ven as folio from dgpemema where fol_ven='".$_POST['txtfolio']."'")); 
			echo "<script type='text/javascript'>
			alert (' SE CANCELO LA CTA. ".$fol['folio']."');
			window.open('MESA5000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['txtcont']."','mainFrame','Keypad');				
			window.close(); 

				</script> "; 
			
			}	
		}


}elseif ($_POST['txtipo']==14){ //calve del mesero en pago de cuenta total 
		@$w=mysqli_query($con ,"select pasw from dgcatven order by cod_ven");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['pasw']==$pass)
			{
			echo "<script type='text/javascript'>
						window.open('CAJA4.php?cajero=".$_POST['Clave']."&ms=".$_POST['txtmesa']."&pt=".$_POST['txtpunto']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&mesero=".$_POST['txtmeser']."','mainFrame','Keypad');				
						window.close();
						</script> "; 
			}	
		}
				
}elseif ($_POST['txtipo']==15){ //Numero de mesa y numero de posicion 
		@$w=mysqli_query($con ,"select nparte1 from ctmesas where status=1 and area IN (select area from ctmesas where nparte1='".$_POST['txtmesa']."') and nparte1 <> ".$_POST['txtmesa']." order by nparte1");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['nparte1']==$pass)
			{
			echo "<script type='text/javascript'>
					window.open('CAL10000.php?pms=".$_POST['Clave']."&mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&tpo=16','VENTANA','width=280,height=260,scrollbars=NO,minimize=0');								
				  </script>"; 
			}	
		}
				
}elseif ($_POST['txtipo']==16){ //numero de posicion en la mesa seleccionada
		@$w=mysqli_query($con ,"select nparte1 from fpos where status=1 and mesa='".$_POST['txtposm']."' order by nparte1");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['nparte1']==$pass)
			{
				echo "<script type='text/javascript'>
				window.open('CAJA1.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&pms=".$_POST['txtposm']."&posn=".$_POST['Clave']."','mainFrame','Keypad');		
				alert('Selecciona el producto!!');		
				window.close();
				</script> "; 
			} 
		}
}elseif ($_POST['txtipo']==17){ //calve del mesero en pago de cuenta total 
			if (isset($_POST['Clave']))
			{
			echo "<script type='text/javascript'>
			var ventana=CAJA4.php;
Input = ventana.document.getElementById('tipp'); 
Input.value = 'Globe Roses' 
						window.close();
						</script> "; 
			}	
}	

//				window.open('CAJA4.php?cajero=".$_POST['Clave']."&ms=".$_POST['txtmesa']."&pt=".$_POST['txtpunto']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&mesero=".$_POST['txtmeser']."','mainFrame','Keypad');				


	?>
