noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_follow_up_detail.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   NOALYSS is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 require_once ('class_fiche.php');
00020 require_once ('class_database.php');
00021 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00022 
00023 /*!\file
00024  * \brief Follow_Up details are the details for a actions
00025  */
00026 
00027 /*!\brief Follow_Up Details are the details for an actions, it means
00028  * the details of an order, delivery order, submit a quote...
00029  * this class is linked to the table action_detail
00030  * - "id"=>"ad_id", primary key
00031  * - "qcode"=>"f_id", quick_code
00032  * - "text"=>"ad_text", description lines
00033  * - "price_unit"=>"ad_pu", price by unit
00034  * - "quantity"=>"ad_quant", quantity
00035  * - "tva_id"=>"ad_tva_id", tva_od
00036  * - "tva_amount"=>"ad_tva_amount", vat amount
00037  * - "total"=>"ad_total_amount", total amount including vat
00038  * - "ag_id"=>"ag_id" => foreign key to action_gestion
00039  * -  db is the database connection
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         // Verify that the elt we want to add is correct
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     /*!\brief retrieve all the details of an Follow_Up
00143      *\return array of Action_Detail
00144      *\see Follow_Up::get
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     /*!\brief Fill an Action_Detail Object with the data contained in an array
00194     *\param $array
00195      - [ad_id7] => ad_id
00196      - [e_march7] =>  f_id
00197      - [e_march7_label] => ad_text
00198      - [e_march7_price] => ad_pu
00199      - [e_quant7] => ad_quant
00200      - [e_march7_tva_id] => ad_tva_id
00201      - [e_march7_tva_amount] => ad_tva_amount
00202      - [tvac_march7] => ad_total_amount
00203      - [ag_id] => ag_id
00204      *\param $idx is the idx (example 7)
00205      *\note    */
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         /* protect numeric */
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     /*!\brief
00237      *\param
00238      *\return
00239      *\note
00240      *\see
00241      */
00242     static function test_me()
00243 {}
00244 
00245 }
00246 
00247 /* test::test_me(); */
00248 
 All Data Structures Namespaces Files Functions Variables Enumerations