Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once ('class_dossier.php');
00022 require_once ('class_database.php');
00023 require_once('ac_common.php');
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Acc_Ledger_Info
00035 {
00036 var $cn;
00037 var $ji_id;
00038 var $id_type;
00039 var $jr_id;
00040 var $ji_value;
00041 function __construct($p_cn,$p_ji_id=0)
00042 {
00043 $this->cn=$p_cn;
00044 $this->ji_id=$p_ji_id;
00045 }
00046 function insert()
00047 {
00048 if ( ! isset ($this->jr_id) ||
00049 ! isset ($this->ji_value) ||
00050 ! isset ($this->id_type ) )
00051 {
00052 echo 'Appel incorrecte '.__FILE__.__LINE__;
00053 var_dump($this);
00054 exit();
00055 }
00056 try
00057 {
00058 $sql=$this->cn->exec_sql('insert into jrn_info(jr_id,id_type,ji_value) values ($1,$2,$3)'.
00059 ' returning ji_id ',
00060 array ($this->jr_id,$this->id_type,$this->ji_value)
00061 );
00062 $this->ji_id=Database::fetch_result($sql,0,0);
00063 }
00064 catch (Exception $e)
00065 {
00066 echo "Echec sauvegarde info additionnelles";
00067 throw $e;
00068 }
00069 }
00070 function update()
00071 {
00072 if ( ! isset ($this->jr_id) ||
00073 ! isset ($this->ji_value) ||
00074 ! isset ($this->jr_id ) )
00075 {
00076 echo 'Appel incorrecte '.__FILE__.__LINE__;
00077 var_dump($this);
00078 exit();
00079 }
00080 try
00081 {
00082 $sql=$this->exec_sql('update jrn_info set jr_id=$1 ,id_type=$2,ji_value=$3 where ji_id=$4)'.
00083 array ($this->jr_id,$this->id_type,$this->ji_value,$this->ji_id)
00084 );
00085 }
00086 catch (Exception $e)
00087 {
00088 $this->cn->rollback();
00089 echo "Echec sauvegarde info additionnelles";
00090 throw $e;
00091 }
00092 }
00093 function load()
00094 {
00095 $sql="select jr_id,id_type,ji_value from jrn_info where ji_id=".$this->ji_id;
00096 $r=$this->cn->exec_sql($sql);
00097 if (Database::num_row ($r) > 0 )
00098 {
00099 $this->from_array(Database::fetch_array($r,0));
00100 return 0;
00101 }
00102 else
00103 {
00104 return 1;
00105 }
00106
00107 }
00108 function from_array($p_array)
00109 {
00110 foreach ($p_array as $col=>$value)
00111 {
00112 $this->$col=$value;
00113 }
00114 }
00115 function set_id($p_ji_id)
00116 {
00117 $this->$ji_id=$p_ji_id;
00118 }
00119 function set_jrn_id($p_id)
00120 {
00121 $this->jr_id=$p_id;
00122 }
00123 function set_type($p_id)
00124 {
00125 $this->id_type=$p_id;
00126 }
00127 function set_value($p_id)
00128 {
00129 $this->ji_value=$p_id;
00130 }
00131
00132
00133
00134 function load_all()
00135 {
00136 if ( ! isset ($this->jr_id) )
00137 {
00138 echo "jr_id is not set ".__FILE__.__LINE__;
00139 exit();
00140 }
00141
00142 $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
00143 $r=$this->cn->exec_sql($sql);
00144 if (Database::num_row($r) == 0 )
00145 return array();
00146 $array=Database::fetch_all($r);
00147 $ret=array();
00148 foreach ($array as $row)
00149 {
00150 $o=new Acc_Ledger_Info($this->cn,$row['ji_id']);
00151 $o->load();
00152 $ret[]=clone $o;
00153 }
00154 return $ret;
00155
00156 }
00157 function count()
00158 {
00159 $sql="select ji_id from jrn_info where jr_id=".$this->jr_id;
00160 return $this->cn->count_sql($sql);
00161 }
00162 function search_id_internal($p_internal)
00163 {
00164 $sql="select jr_id from jrn where jr_internal='$p_internal'";
00165 $r=$this->cn->exec_sql($sql);
00166 if (Database::num_row($r) > 0 )
00167 {
00168 $this->jr_id=Database::fetch_result($r,0,0);
00169 return $this->jr_id;
00170 }
00171 else
00172 {
00173 $this->jr_id=-1;
00174 return $this->jr_id;
00175 }
00176 }
00177
00178
00179
00180
00181
00182
00183
00184 function save_extra($p_jr_id,$p_array)
00185 {
00186 $this->jr_id=$p_jr_id;
00187 if (strlen(trim($p_array['bon_comm'] )) != 0 )
00188 {
00189 $this->set_type('BON_COMMANDE');
00190 $this->set_value($p_array['bon_comm']);
00191 $this->insert();
00192 }
00193 if (strlen(trim($p_array['other_info'] )) != 0 )
00194 {
00195 $this->set_type('OTHER');
00196 $this->set_value($p_array['other_info']);
00197 $this->insert();
00198 }
00199 }
00200 static function test_me()
00201 {
00202 echo "Dossier = ".Dossier::id();
00203 $cn=new Database(Dossier::id());
00204 $a=new Acc_Ledger_Info($cn);
00205 $a->jr_id=3;
00206 $a->id_type='BON_COMMANDE';
00207 $a->ji_value='BON';
00208 var_dump($a);
00209 $a->insert();
00210
00211 $a->set_jrn_id(7);
00212 $a->set_type('OTHER');
00213 $a->set_value('Autre test');
00214 $a->insert();
00215 }
00216 }