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

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



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

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

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


//	onscreen events


	}
// Captchas functions	

//	handlers

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

		$values["subtotal"] = str_replace(".", "", $values["subtotal"]);
$values["precio"] = str_replace(".", "", $values["precio"]);
$values["importe"] = str_replace(".", "", $values["importe"]);
//================================================================
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

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
				// After record deleted
function AfterDelete($where,&$deleted_values,&$message,&$pageObject)
{

		echo "<script>window.location.reload();</script>";

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

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
				// Before record updated
function BeforeEdit(&$values,$where,&$oldvalues,&$keys,&$message,$inline,&$pageObject)
{

		$values["subtotal"] = str_replace(".", "", $values["subtotal"]);
$values["precio"] = str_replace(".", "", $values["precio"]);
$values["importe"] = str_replace(".", "", $values["importe"]);
//================================================================
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 BeforeEdit

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

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

		echo "<script>window.parent.location.reload();</script>";
exit();
;		
} // function AfterAdd

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		

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

		echo "<script>window.parent.location.reload();</script>";
exit();
;		
} // function AfterEdit

		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
		
//	onscreen events

} 
?>
