id ( Primary key ) - mp_lib ==> lib (label) - mp_type ==> type (type of the ledger ACH or VEN ) - mp_jrn_def_id ==> ledger (Number of the ledger where to save) - mp_fd_id ==> fiche_def (fiche class to use) - mp_qcode ==> qcode (quick_code of the card) * */ class Acc_Payment { private static $variable=array("id"=>"mp_id", "lib"=>"mp_lib", "qcode"=>"mp_qcode", "type"=>"mp_type", "ledger"=>"mp_jrn_def_id", "fiche_def"=>"mp_fd_id"); private $mp_lib; private $mp_qcode; private $mp_type; private $mp_jrn_def_if; private $mp_fd_id; function __construct ($p_cn,$p_init=0) { $this->cn=$p_cn; $this->mp_id=$p_init; } public function get_parameter($p_string) { if ( array_key_exists($p_string,self::$variable) ) { $idx=self::$variable[$p_string]; return $this->$idx; } else exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'); } public function set_parameter($p_string,$p_value) { if ( array_key_exists($p_string,self::$variable) ) { $idx=self::$variable[$p_string]; $this->$idx=$p_value; } else exit (__FILE__.":".__LINE__.'Erreur attribut inexistant'); } public function get_info() { return var_export(self::$variable,true); } public function verify() { // Verify that the elt we want to add is correct } public function save() { /* please adapt */ if ( $this->get_parameter("id") == 0 ) $this->insert(); else $this->update(); } public function insert() { if ( $this->verify() != 0 ) return; /* please adapt $sql="insert into tva_rate (tva_label,tva_rate,tva_comment,tva_poste) ". " values ($1,$2,$3,$4) returning tva_id"; $res=ExecSqlParam($this->cn, $sql, array($this->tva_label, $this->tva_rate, $this->tva_comment, $this->tva_poste) ); $this->tva_id=pg_fetch_result($res,0,0); */ } public function update() { if ( $this->verify() != 0 ) return; $sql="update mod_payment set mp_lib=$1,mp_qcode=$2,mp_type=$3,mp_jrn_def_id=$4,mp_fd_id=$5 ". " where mp_id = $6"; $res=ExecSqlParam($this->cn, $sql, array($this->mp_lib, $this->mp_qcode, $this->mp_type, $this->mp_jrn_def_id, $this->mp_fd_id, $this->mp_id) ); if ( strlen (trim($this->mp_jrn_def_id))==0) ExecSqlParam($this->cn, 'update mod_payment '. 'set mp_jrn_def_id = null where mp_id=$1', array($this->mp_id)); if ( strlen (trim($this->mp_qcode))==0) ExecSqlParam($this->cn, 'update mod_payment '. 'set mp_qcode = null where mp_id=$1', array($this->mp_id)); if ( strlen (trim($this->mp_fd_id))==0) ExecSqlParam($this->cn, 'update mod_payment '. 'set mp_fd_id = null where mp_id=$1', array($this->mp_id)); } public function load() { $sql='select mp_id,mp_lib,mp_fd_id,mp_jrn_def_id,mp_qcode,mp_type from mod_payment '. ' where mp_id = $1'; $res=ExecSqlParam($this->cn, $sql, array($this->mp_id) ); if ( pg_NumRows($res) == 0 ) return; $row=pg_fetch_array($res,0); foreach ($row as $idx=>$value) { $this->$idx=$value; } } public function delete() { /* $sql="delete from tva_rate where tva_id=$1"; $res=ExecSqlParam($this->cn,$sql,array($this->tva_id)); */ } /*!\brief retrieve all the data for a certain type *\param non *\return an array of row */ public function get_all() { $sql='select mp_id '. ' from mod_payment '. ' where mp_type=$1'; $array=get_array($this->cn,$sql,array($this->mp_type)); $ret=array(); if ( !empty($array) ) { foreach ($array as $row) { $t=new Acc_Payment($this->cn,$row['mp_id']); $t->load(); $ret[]=$t; } } return $ret; } /*!\brief retrieve all the data for a certain type but filter on the *valid record (jrn and fd not null *\param non *\return an array of row */ public function get_valide() { $sql='select mp_id '. ' from mod_payment '. ' where mp_type=$1 and mp_jrn_def_id is not null and '. ' (mp_fd_id is not null or mp_qcode is not null)'; $array=get_array($this->cn,$sql,array($this->mp_type)); $ret=array(); if ( !empty($array) ) { foreach ($array as $row) { $t=new Acc_Payment($this->cn,$row['mp_id']); $t->load(); $ret[]=$t; } } return $ret; } public function row() { //--------------------------------------------------------------------------- // Common variable $td='