Calculated Field example: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
[[Category:ATK]] | |||
Custom Calculated Field Sample | Custom Calculated Field Sample | ||
{code} | |||
class fsMovAttribute extends atkAttribute | |||
{ | { | ||
function hasStore($mode) { Return True; } | function hasStore($mode) { Return True; } | ||
| Line 24: | Line 26: | ||
} | } | ||
} | } | ||
{/code} | |||
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. | ||
{code} | |||
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)); | ||
{/code} | |||
Here is how to use a calculated field | Here is how to use a calculated field | ||
Revision as of 08:10, 23 February 2006
Custom Calculated Field Sample
{code} 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;
}
} {/code}
You can define you Calculated field inside function __load__ the query is only for reference you can it as you need.
{code} include_once (moduleDir("..Your Module here..")."class.YourClassHere.inc");
$this->add(new __fsMovAttribute__("Rimanenza", AF_HIDE_ADD | AF_READONLY)); {/code}
Here is how to use a calculated field