Jump to content

Calculated Field example

From NusaATK
(Redirected from SpecialNodes)


ATK Examples: Calculated Field example

Complexity: basic
Author: Fabio Saitta <webmaster@saitta.it>

List of other Examples

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