<?PHP 
	$pass=$_POST['Clave'];
if ($_POST['txtipo']==1){
	@$w=mysqli_query($con ,"select codigo from ctmeser where cvpvta='".$_POST['txtpunto']."' order by nparte1");
		while (@$pas=mysqli_fetch_array($w)){
			if ($pas['codigo']==$pass)
			{
//			xajax_mod_rec(xajax.getFormValues('Keypad'));
				echo 
				"<script type='text/javascript'>
				
				window.open('PBR4000_PR.php?mesero=".$_POST['Clave']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."','mainFrame','Keypad');
				window.close();
				</script> ";
			}else {	}
		}
} elseif ($_POST['txtipo']==11){
	@$w=mysqli_query($con ,"select codigo from ctmeser where cvpvta='".$_POST['txtpunto']."' order by nparte1");
		while (@$pas=mysqli_fetch_array($w)){
			if ($pas['codigo']==$pass)
			{
				echo 
				"<script type='text/javascript'>
				window.open('PBR5000_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('PBR4000_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('PBR4000_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){
// ingresa comanda 
//$sql1=mysqli_query($con ,"insert into fcomanda fol_ven=1122");
				echo
				"<script type='text/javascript'>
				xajax_mod_rec(xajax.getFormValues('Keypad'));
				xajax_ing_comd(xajax.getFormValues('Keypad')); 
				window.open('DG240001.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&comand=".$_POST['Clave']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."','mainFrame','Keypad');				
				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('DG240001.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 codigo from ctmeser order by nparte1");
		while (@$pas=mysqli_fetch_array($w))
		{ 
			if ($pas['codigo']==$pass)
			{
			echo "<script type='text/javascript'>
						window.open('DG240002.php?cajero=".$_POST['Clave']."&ms=".$_POST['txtmesa']."&pt=".$_POST['txtounto']."&pos=".$_POST['txtpos']."&cont=".$_POST['txtcont']."&mesero=".$_POST['txtmeser']."','mainFrame','Keypad');				
						window.close();
						</script> "; //el pass no es folio corregir
/*				$sql = "SELECT fol_ven FROM dgpemema WHERE fol_ven = '$pass' and tot_ven!=0";
			   	@$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){
					echo "<script type='text/javascript'>
						alert('existe folio');
						</script> ";
						if (($num_salidas2==0)&&($num_salidas3==0)){*/
							
					/*	}else{
							if ($num_salidas2!=0)  {
								echo "<script type='text/javascript'>
								alert('No. FOLIO PAGADO');
								</script> ";
							}elseif ($num_salidas3!=0) {
								echo "<script type='text/javascript'>
								alert('No. FOLIO CANCELADO');
								</script> ";
							}	
						}
	
					} elseif($num_salidas==0){
						echo "<script type='text/javascript'>
						alert('No. FOLIO NO EXISTENTE');
						</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('PBR5000_PR.php?mesero=".$_POST['txtmeser']."&pt=".$_POST['txtpunto']."&ar=".$_POST['txtarea']."&ms=".$_POST['txtmesa']."&pos=".$_POST['Clave']."','mainFrame','Keypad');				
				window.close();
				</script> ";
				
}


	?>
