00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 require_once ('class_fiche.php');
00020 require_once ('class_database.php');
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 class Follow_Up_Detail
00042 {
00043 private static $variable=array(
00044 "id"=>"ad_id",
00045 "qcode"=>"f_id",
00046 "text"=>"ad_text",
00047 "price_unit"=>"ad_pu",
00048 "quantity"=>"ad_quant",
00049 "tva_id"=>"ad_tva_id",
00050 "tva_amount"=>"ad_tva_amount",
00051 "total"=>"ad_total_amount",
00052 "ag_id"=>"ag_id"
00053 );
00054 function __construct ($p_cn,$p_id=0)
00055 {
00056 $this->db=$p_cn;
00057 $this->ad_id=$p_id;
00058 }
00059 public function get_parameter($p_string)
00060 {
00061 if ( array_key_exists($p_string,self::$variable) )
00062 {
00063 $idx=self::$variable[$p_string];
00064 return $this->$idx;
00065 }
00066 else
00067 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00068 }
00069 public function set_parameter($p_string,$p_value)
00070 {
00071 if ( array_key_exists($p_string,self::$variable) )
00072 {
00073 $idx=self::$variable[$p_string];
00074 $this->$idx=$p_value;
00075 }
00076 else
00077 exit (__FILE__.":".__LINE__.'Erreur attribut inexistant');
00078
00079
00080 }
00081 public function get_info()
00082 {
00083 return var_export(self::$variable,true);
00084 }
00085 public function verify()
00086 {
00087
00088 return 0;
00089 }
00090 public function save()
00091 {
00092 if ( $this->ad_id == 0 )
00093 $this->insert();
00094 else
00095 $this->update();
00096 }
00097
00098 public function insert()
00099 {
00100 if ( $this->verify() != 0 ) return;
00101 $sql='INSERT INTO action_detail('.
00102 ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
00103 ' ad_total_amount, ag_id)'.
00104 ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
00105 $this->ad_id=$this->db->get_value($sql,array(
00106 $this->f_id,
00107 $this->ad_text,
00108 $this->ad_pu,
00109 $this->ad_quant,
00110 $this->ad_tva_id,
00111 $this->ad_tva_amount,
00112 $this->ad_total_amount,
00113 $this->ag_id
00114 )
00115 );
00116
00117 }
00118
00119 public function update()
00120 {
00121 if ( $this->verify() != 0 ) return;
00122
00123 $sql='UPDATE action_detail '.
00124 ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
00125 ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
00126 ' WHERE ad_id=$9';
00127 $this->id=$this->db->exec_sql($sql,array(
00128 $this->f_id,
00129 $this->ad_text,
00130 $this->ad_pu,
00131 $this->ad_quant,
00132 $this->ad_tva_id,
00133 $this->ad_tva_amount,
00134 $this->ad_total_amount,
00135 $this->ag_id,
00136 $this->ad_id
00137 )
00138 );
00139
00140
00141 }
00142
00143
00144
00145
00146 public function load_all()
00147 {
00148 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
00149 ad_total_amount, ag_id FROM action_detail ".
00150 " where ag_id=$1 order by ad_id";
00151 $res=$this->db->get_array(
00152 $sql,
00153 array($this->ag_id)
00154 );
00155 if ( $this->db->count() == 0 ) return;
00156 $aRet=array();
00157 for($i=0;$i<count($res);$i++)
00158 {
00159 $a=new Follow_Up_Detail($this->db);
00160 $row=$res[$i];
00161 foreach ($row as $idx=>$value)
00162 {
00163 $a->$idx=$value;
00164 }
00165 $aRet[$i]=clone $a;
00166 }
00167 return $aRet;
00168 }
00169
00170 public function load()
00171 {
00172 $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
00173 ad_total_amount, ag_id FROM action_detail".
00174 " where ad_id=$1";
00175
00176 $res=$this->db->get_array($this->db,
00177 $sql,
00178 array($this->ad_id)
00179 );
00180 if ( $this->db->count() == 0 ) return;
00181 $row=$res[0];
00182 foreach ($row as $idx=>$value)
00183 {
00184 $this->$idx=$value;
00185 }
00186
00187 }
00188 public function delete()
00189 {
00190 $sql="delete from action_detail where ad_id=$1";
00191 $this->db->exec_sql($sql,array($this->ad_id));
00192 }
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206 public function from_array($array,$idx)
00207 {
00208 $row=$array;
00209 $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
00210
00211 $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
00212 if (trim($qcode)=='')
00213 {
00214 $this->f_id=0;
00215 }
00216 else
00217 {
00218 $tmp=new Fiche($this->db);
00219 $tmp->get_by_qcode($qcode,false);
00220 $this->f_id=$tmp->id;
00221 }
00222 $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
00223 $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
00224 $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
00225 $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
00226 $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
00227 $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
00228 $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
00229
00230 if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
00231 if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
00232 if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
00233 if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
00234 if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
00235 }
00236
00237
00238
00239
00240
00241
00242 static function test_me()
00243 {}
00244
00245 }
00246
00247
00248