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


//	onscreen events


	}
// Captchas functions	

//	handlers

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

		global $conn;
$idarticulo = $values["idarticulo"];
$strSQLExists = "select * from articulo where idarticulo=$idarticulo";
$rsExists = db_query($strSQLExists,$conn);
$data=db_fetch_array($rsExists);

if(empty($values["importe"])){
	$values["importe"] = $data["precio"];
}

$values["costo"] = $data["costo"];
$values["precio"] = $data["precio"];
$values["subtotal"] = $values["importe"]*$values["cantidad"];
if($values["importe"] > $data["precio"]){
	$values["descuento"] = 0;
}else{
	$values["descuento"]= ($data["precio"]*$values["cantidad"]) - $values["subtotal"];
}

$values["ganancia"] = $values["subtotal"]-($data["costo"]*$values["cantidad"]);

return true;
;		
} // function BeforeAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//	onscreen events

} 
?>
