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

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

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


		$this->events["BeforeAdd"]=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"];
//  =====================================================
// ===========================================================
$usuario = $_SESSION["UserName"];
$sql_usuario = "select * from usuario where nick='$usuario'";
$result_usuario = db_query($sql_usuario,$conn);
$data_usuario=db_fetch_array($result_usuario);
//=============================
$idusuario = $data_usuario['idusuario'];
$sql_movimiento = "select * from movimiento_caja where idusuario=$idusuario and estado = 'ABIERTO'";
$result = db_query($sql_movimiento,$conn);
$linea=db_fetch_array($result);
$values["idmovimiento"] = $linea['idmovimiento'];
;		
} // function ProcessValuesAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
				// Add page: Before process
function BeforeProcessAdd(&$conn,&$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'];

if(!$idusuario) {
    header("Location: gasto_list.php");
    exit();
}

$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) {
    header("Location: gasto_list.php?status=warning");
    exit();
}

return true;
;		
} // function BeforeProcessAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

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

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




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

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

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

		//$values["total"] = str_replace(".", "", $values["total"]);
$values["total"] = 0;
// Place event code here.
// Use "Add Action" button to add code snippets.

return true;
;		
} // function BeforeAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//	onscreen events

} 
?>
