db=$p_cn;
$this->p_code=$p_id;
if ( $p_id != -1 )
$this->load();
}
/*!
**************************************************
* \brief
* Load all parmCode
* return an array of Acc_Parm_Code object
*
* \return array
*/
function load_all()
{
$sql="select * from parm_code order by p_code";
$Res=$this->db->exec_sql($sql);
$r= Database::fetch_all($Res);
$idx=0;
$array=array();
if ( $r === false ) return null;
foreach ($r as $row )
{
$o=new Acc_Parm_Code($this->db,$row['p_code']);
$array[$idx]=$o;
$idx++;
}
return $array;
}
/*!
**************************************************
* \brief update a parm_object into the database
* p_code is _not_ updatable
* \return
* nothing
*/
function save()
{
// if p_code=="" nothing to save
if ( $this->p_code== -1) return;
// check if the account exists
$acc=new Acc_Account_Ledger($this->db,$this->p_value);
if ( $acc->load() == false )
{
alert(_("Ce compte n'existe pas"));
}
else
{
$this->p_comment=sql_string($this->p_comment);
$this->p_value=sql_string($this->p_value);
$this->p_code=sql_string($this->p_code);
$sql="update parm_code set ".
"p_comment='".$this->p_comment."' ".
",p_value='".$this->p_value."' ".
"where p_code='".$this->p_code."'";
$Res=$this->db->exec_sql($sql);
}
}
/*!
**************************************************
* \brief Display an object, with the
tag
*
* \return
* string
*/
function display()
{
$r="";
$r.= ' | '.$this->p_code.' | ';
$r.= ''.h($this->p_comment).' | ';
$r.= ''.$this->p_value.' | ';
return $r;
}
/*!
**************************************************
* \brief Display a form to enter info about
* a parm_code object with the tag
*
* \return string
*/
function form()
{
$comment=new IText();
$comment->name='p_comment';
$comment->value=$this->p_comment;
$comment->size=45;
$value=new IPoste();
$value->name='p_value';
$value->value=$this->p_value;
$value->size=7;
$value->set_attribute('ipopup','ipop_account');
$value->set_attribute('account','p_value');
$poste=new IText();
$poste->setReadOnly(true);
$poste->size=strlen($this->p_code)+1;
$poste->name='p_code';
$poste->value=$this->p_code;
$r="";
$r.=' | ';
$r.=' Code | ';
$r.= ''.$poste->input().' | ';
$r.='
';
$r.='';
$r.=' Commentaire | ';
$r.= ''.$comment->input().' | ';
$r.='
';
$r.='';
$r.=' Poste comptable | ';
$r.= ''.$value->input();
$r.=' | ';
$r.='
';
$r.=Dossier::hidden();
return $r;
}
/*!
**************************************************
* \brief
* Complete a parm_code object thanks the p_code
*
* \return array
*/
function load()
{
if ( $this->p_code == -1 ) return "p_code non initialisé";
$sql='select * from parm_code where p_code=$1 ';
$Res=$this->db->exec_sql($sql,array($this->p_code));
if ( Database::num_row($Res) == 0 ) return 'INCONNU';
$row= Database::fetch_array($Res,0);
$this->p_value=$row['p_value'];
$this->p_comment=$row['p_comment'];
}
}