00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 require_once('class_dossier.php');
00026 require_once('class_database.php');
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class Acc_Tva
00039 {
00040 private $cn;
00041 private static $variable=array("id"=>"tva_id",
00042 "label"=>"tva_label",
00043 "rate"=>"tva_rate",
00044 "comment"=>"tva_comment",
00045 "account"=>"tva_poste",
00046 "both_side"=>'tva_both_side');
00047
00048 function __construct ($p_init,$p_tva_id=0)
00049 {
00050 $this->cn=$p_init;
00051 $this->tva_id=$p_tva_id;
00052 $this->poste="";
00053 }
00054 public function get_parameter($p_string)
00055 {
00056 if ( array_key_exists($p_string,self::$variable) )
00057 {
00058 $idx=self::$variable[$p_string];
00059 return $this->$idx;
00060 }
00061
00062 echo (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00063 }
00064 public function set_parameter($p_string,$p_value)
00065 {
00066 if ( array_key_exists($p_string,self::$variable) )
00067 {
00068 $idx=self::$variable[$p_string];
00069 $this->$idx=$p_value;
00070 }
00071 else
00072 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00073
00074
00075 }
00076 public function get_info()
00077 {
00078 return var_export(self::$variable,true);
00079 }
00080
00081 public function verify()
00082 {
00083
00084 }
00085 public function save()
00086 {
00087
00088 if ( $this->tva_id == 0 )
00089 $this->insert();
00090 else
00091 $this->update();
00092 }
00093
00094 public function insert()
00095 {
00096 if ( $this->verify() != 0 ) return;
00097 $sql="select tva_insert($1,$2,$3,$4,$5)";
00098
00099 $res=$this->cn->exec_sql(
00100 $sql,
00101 array($this->tva_label,
00102 $this->tva_rate,
00103 $this->tva_comment,
00104 $this->tva_poste,
00105 $this->tva_both_side)
00106 );
00107 $this->tva_id=$this->cn->get_current_seq('s_tva');
00108 $err=Database::fetch_result($res);
00109 }
00110
00111 public function update()
00112 {
00113 if ( $this->verify() != 0 ) return;
00114 $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ".
00115 " where tva_id = $6";
00116 $res=$this->cn->exec_sql(
00117 $sql,
00118 array($this->tva_label,
00119 $this->tva_rate,
00120 $this->tva_comment,
00121 $this->tva_poste,
00122 $this->tva_both_side,
00123 $this->tva_id)
00124 );
00125
00126 }
00127
00128
00129
00130
00131
00132 public function load()
00133 {
00134 $sql="select tva_id,tva_label,tva_rate, tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1";
00135 $res=$this->cn->exec_sql(
00136 $sql,
00137 array($this->tva_id)
00138 );
00139
00140 if ( $this->cn->size() == 0 ) return -1;
00141
00142 $row=Database::fetch_array($res,0);
00143 foreach ($row as $idx=>$value)
00144 {
00145 $this->$idx=$value;
00146 }
00147 return 0;
00148 }
00149
00150
00151
00152
00153
00154 public function get_side($p_side)
00155 {
00156 if ( strlen($this->tva_poste) == 0 ) $this->load();
00157 list($deb,$cred)=explode(",",$this->tva_poste);
00158 switch ($p_side)
00159 {
00160 case 'd':
00161 return $deb;
00162 break;
00163 case 'c':
00164 return $cred;
00165 break;
00166 default:
00167 throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
00168 }
00169 }
00170 public function delete()
00171 {
00172 $sql="delete from tva_rate where tva_id=$1";
00173 $res=$this->cn->exec_sql($sql,array($this->tva_id));
00174 }
00175
00176
00177
00178 static function test_me()
00179 {
00180 $cn=new Database(dossier::id());
00181 $a=new Acc_Tva($cn);
00182 echo $a->get_info();
00183 $a->set_parameter("id",1);
00184 $a->load();
00185 $a->set_parameter("id",0);
00186 $a->set_parameter("rate","0.2222");
00187 $a->set_parameter("label","test");
00188 $a->save();
00189 $a->load();
00190 print_r($a);
00191
00192 $a->set_parameter("comment","un cht'it test");
00193 $a->save();
00194 $a->load();
00195 print_r($a);
00196
00197 $a->delete();
00198 }
00199
00200 }
00201
00202