Calculated Field example: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
Custom Calculated Field Sample | Custom Calculated Field Sample | ||
<pre> | |||
class fsMovAttribute extends atkAttribute | class fsMovAttribute extends atkAttribute | ||
{ | { | ||
| Line 26: | Line 26: | ||
} | } | ||
} | } | ||
</pre> | |||
You can define you Calculated field inside function __load__ the query is only for reference you can it as you need. | You can define you Calculated field inside function __load__ the query is only for reference you can it as you need. | ||
<pre> | |||
include_once (moduleDir("..Your Module here..")."class.YourClassHere.inc"); | include_once (moduleDir("..Your Module here..")."class.YourClassHere.inc"); | ||
$this->add(new __fsMovAttribute__("Rimanenza", AF_HIDE_ADD | AF_READONLY)); | $this->add(new __fsMovAttribute__("Rimanenza", AF_HIDE_ADD | AF_READONLY)); | ||
</pre> | |||
Here is how to use a calculated field | Here is how to use a calculated field | ||
Revision as of 08:15, 23 February 2006
Custom Calculated Field Sample
class fsMovAttribute extends atkAttribute
{
function hasStore($mode) { Return True; }
function store($g_db, $record, $mode) { Return True; }
function load(&$db, $record)
{
$query = "select sum(importo) as totale from all_incassi where pagamento = ".$record["id"];
$raw = $db->getrows($query);
/*record found*/
if (count($raw)==1)
{
$tot=$raw[0]["totale"];
if ($record["Importo"]>$tot && $record["pagato"]==1)
$db->query("UPDATE all_movimenti SET pagato=0 WHERE id=".$record["id"]);
}
else
$tot=0;
return $record["Importo"]-$tot;
}
}
You can define you Calculated field inside function __load__ the query is only for reference you can it as you need.
include_once (moduleDir("..Your Module here..")."class.YourClassHere.inc");
$this->add(new __fsMovAttribute__("Rimanenza", AF_HIDE_ADD | AF_READONLY));
Here is how to use a calculated field