<?php 
class eventclass_venta  extends eventsBase
{ 
	function eventclass_venta()
	{
	// fill list of events
		$this->events["ProcessValuesAdd"]=true;

		$this->events["AfterAdd"]=true;

		$this->events["AfterEdit"]=true;

		$this->events["BeforeShowAdd"]=true;


		$this->events["BeforeAdd"]=true;

		$this->events["ProcessValuesView"]=true;


//	onscreen events


	}
// Captchas functions	

//	handlers

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Process record values
function ProcessValuesAdd(&$values,&$pageObject)
{

		global $conn;
$strSQLExists = "select DATE(NOW()) as fecha";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
$values["fecha"] = $data["fecha"];

// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function ProcessValuesAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
				// After record added
function AfterAdd(&$values,&$keys,$inline,&$pageObject)
{

		
//**********  Redirect to another page  ************
header("Location: venta_list.php?status=success");
exit();




// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function AfterAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// After record updated
function AfterEdit(&$values,$where,&$oldvalues,&$keys,$inline,&$pageObject)
{

		
//**********  Redirect to another page  ************
header("Location: venta_list.php?status=success2");
exit();




// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function AfterEdit

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Before display
function BeforeShowAdd(&$xt,&$templatefile,&$pageObject)
{

		
global $conn;
//=============================================
$usuario = $_SESSION['UserName'];
//=============================================
$strSQLExists = "select * from usuario where nick='$usuario'";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);
//=============================================
$idusuario = $data['idusuario'];
$sql_movimiento = "select * from movimiento_caja where idusuario=$idusuario and estado = 'ABIERTO'";
$result = db_query($sql_movimiento,$conn);
$linea=db_fetch_array($result);
//=============================================
if($linea)
{
		//**********  Redirect to another page  ************
	header("Location: registrar_venta.php");
	exit();
}else{
	header("Location: venta_list.php?status=warning");
	exit();
}

// Place event code here.
// Use "Add Action" button to add code snippets.
;		
} // function BeforeShowAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
				// Before record added
function BeforeAdd(&$values,&$message,$inline,&$pageObject)
{

		//$values["total"] = str_replace(".", "", $values["total"]);

// Place event code here.
// Use "Add Action" button to add code snippets.
$values["total_venta"] = 0;
return true;
;		
} // function BeforeAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Process record values
function ProcessValuesView(&$values,&$pageObject)
{

		// Tu parámetro
$mi_parametro = $values["idventa"];
$parametro_seguro = urlencode($mi_parametro);

// Creamos la URL de destino
$url_destino = "generar_ticket.php?idventa=" . $parametro_seguro;

// Usamos JavaScript para abrir la pestaña automáticamente al cargar la página
echo "<script type='text/html'>/* Opcional: buffer de seguridad */</script>";
echo "<script type='text/javascript'>
				window.open('$url_destino', '_blank');
			</script>";


;		
} // function ProcessValuesView

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//	onscreen events

} 
?>
