noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_follow_up_detail.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 require_once NOALYSS_INCLUDE.'/class/class_fiche.php';
20 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
21 // Copyright Author Dany De Bontridder danydb@aevalys.eu
22 
23 /*!\file
24  * \brief Follow_Up details are the details for a actions
25  */
26 
27 /*!\brief Follow_Up Details are the details for an actions, it means
28  * the details of an order, delivery order, submit a quote...
29  * this class is linked to the table action_detail
30  * - "id"=>"ad_id", primary key
31  * - "qcode"=>"f_id", quick_code
32  * - "text"=>"ad_text", description lines
33  * - "price_unit"=>"ad_pu", price by unit
34  * - "quantity"=>"ad_quant", quantity
35  * - "tva_id"=>"ad_tva_id", tva_od
36  * - "tva_amount"=>"ad_tva_amount", vat amount
37  * - "total"=>"ad_total_amount", total amount including vat
38  * - "ag_id"=>"ag_id" => foreign key to action_gestion
39  * - db is the database connection
40  */
42 {
43  private static $variable=array(
44  "id"=>"ad_id",
45  "qcode"=>"f_id",
46  "text"=>"ad_text",
47  "price_unit"=>"ad_pu",
48  "quantity"=>"ad_quant",
49  "tva_id"=>"ad_tva_id",
50  "tva_amount"=>"ad_tva_amount",
51  "total"=>"ad_total_amount",
52  "ag_id"=>"ag_id"
53  );
54  function __construct ($p_cn,$p_id=0)
55  {
56  $this->db=$p_cn;
57  $this->ad_id=$p_id;
58  }
59  public function get_parameter($p_string)
60  {
61  if ( array_key_exists($p_string,self::$variable) )
62  {
63  $idx=self::$variable[$p_string];
64  return $this->$idx;
65  }
66  else
67  throw new Exception("Attribut inexistant $p_string");
68  }
69  public function set_parameter($p_string,$p_value)
70  {
71  if ( array_key_exists($p_string,self::$variable) )
72  {
73  $idx=self::$variable[$p_string];
74  $this->$idx=$p_value;
75  }
76  else
77  throw new Exception("Attribut inexistant $p_string");
78 
79 
80  }
81  public function get_info()
82  {
83  return var_export(self::$variable,true);
84  }
85  public function verify()
86  {
87  // Verify that the elt we want to add is correct
88  return 0;
89  }
90  public function save()
91  {
92  if ( $this->ad_id == 0 )
93  $this->insert();
94  else
95  $this->update();
96  }
97 
98  public function insert()
99  {
100  if ( $this->verify() != 0 ) return;
101  $sql='INSERT INTO action_detail('.
102  ' f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,'.
103  ' ad_total_amount, ag_id)'.
104  ' VALUES ($1, $2, $3, $4,$5,$6,$7,$8) returning ad_id';
105  $this->ad_id=$this->db->get_value($sql,array(
106  $this->f_id,
107  $this->ad_text,
108  $this->ad_pu,
109  $this->ad_quant,
110  $this->ad_tva_id,
111  $this->ad_tva_amount,
112  $this->ad_total_amount,
113  $this->ag_id
114  )
115  );
116 
117  }
118 
119  public function update()
120  {
121  if ( $this->verify() != 0 ) return;
122 
123  $sql='UPDATE action_detail '.
124  ' SET f_id=$1, ad_text=$2, ad_pu=$3, ad_quant=$4, ad_tva_id=$5,'.
125  ' ad_tva_amount=$6, ad_total_amount=$7, ag_id=$8'.
126  ' WHERE ad_id=$9';
127  $this->id=$this->db->exec_sql($sql,array(
128  $this->f_id,
129  $this->ad_text,
130  $this->ad_pu,
131  $this->ad_quant,
132  $this->ad_tva_id,
133  $this->ad_tva_amount,
134  $this->ad_total_amount,
135  $this->ag_id,
136  $this->ad_id
137  )
138  );
139 
140 
141  }
142  /*!\brief retrieve all the details of an Follow_Up
143  *\return array of Action_Detail
144  *\see Follow_Up::get
145  */
146  public function load_all()
147  {
148  $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
149  ad_total_amount, ag_id FROM action_detail ".
150  " where ag_id=$1 order by ad_id";
151  $res=$this->db->get_array(
152  $sql,
153  array($this->ag_id)
154  );
155  if ( $this->db->count() == 0 ) return;
156  $aRet=array();
157  for($i=0;$i<count($res);$i++)
158  {
159  $a=new Follow_Up_Detail($this->db);
160  $row=$res[$i];
161  foreach ($row as $idx=>$value)
162  {
163  $a->$idx=$value;
164  }
165  $aRet[$i]=clone $a;
166  }
167  return $aRet;
168  }
169 
170  public function load()
171  {
172  $sql="SELECT ad_id, f_id, ad_text, ad_pu, ad_quant, ad_tva_id, ad_tva_amount,
173  ad_total_amount, ag_id FROM action_detail".
174  " where ad_id=$1";
175 
176  $res=$this->db->get_array($this->db,
177  $sql,
178  array($this->ad_id)
179  );
180  if ( $this->db->count() == 0 ) return;
181  $row=$res[0];
182  foreach ($row as $idx=>$value)
183  {
184  $this->$idx=$value;
185  }
186 
187  }
188  public function delete()
189  {
190  $sql="delete from action_detail where ad_id=$1";
191  $this->db->exec_sql($sql,array($this->ad_id));
192  }
193  /*!\brief Fill an Action_Detail Object with the data contained in an array
194  *\param $array
195  - [ad_id7] => ad_id
196  - [e_march7] => f_id
197  - [e_march7_label] => ad_text
198  - [e_march7_price] => ad_pu
199  - [e_quant7] => ad_quant
200  - [e_march7_tva_id] => ad_tva_id
201  - [e_march7_tva_amount] => ad_tva_amount
202  - [tvac_march7] => ad_total_amount
203  - [ag_id] => ag_id
204  *\param $idx is the idx (example 7)
205  *\note */
206  public function from_array($array,$idx)
207  {
208  $row=$array;
209  $this->ad_id=(isset($row['ad_id'.$idx]))?$row['ad_id'.$idx]:0;
210 
211  $qcode=(isset($row['e_march'.$idx]))?$row['e_march'.$idx]:"";
212  if (trim($qcode)=='')
213  {
214  $this->f_id=0;
215  }
216  else
217  {
218  $tmp=new Fiche($this->db);
219  $tmp->get_by_qcode($qcode,false);
220  $this->f_id=$tmp->id;
221  }
222  $this->ad_text=(isset($row['e_march'.$idx.'_label']))?$row['e_march'.$idx.'_label']:"";
223  $this->ad_pu=(isset($row['e_march'.$idx.'_price']))?$row['e_march'.$idx.'_price']:0;
224  $this->ad_quant=(isset($row['e_quant'.$idx]))?$row['e_quant'.$idx]:0;
225  $this->ad_tva_id=(isset($row['e_march'.$idx.'_tva_id']))?$row['e_march'.$idx.'_tva_id']:0;
226  $this->ad_tva_amount=(isset($row['e_march'.$idx.'_tva_amount']))?$row['e_march'.$idx.'_tva_amount']:0;
227  $this->ad_total_amount=(isset($row['tvac_march'.$idx]))?$row['tvac_march'.$idx]:0;
228  $this->ag_id=(isset($array['ag_id']))?$array['ag_id']:0;
229  /* protect numeric */
230  if (trim($this->ad_pu)=="" || isNumber($this->ad_pu)==0) $this->ad_pu=0;
231  if (trim($this->ad_quant)=="" || isNumber($this->ad_quant)==0) $this->ad_quant=0;
232  if (trim($this->ad_tva_amount)==""||isNumber($this->ad_tva_amount)==0) $this->ad_tva_amount=0;
233  if (trim($this->ad_total_amount)==""||isNumber($this->ad_total_amount)==0) $this->ad_total_amount=0;
234  if (trim($this->ad_tva_id)=="" || isNumber($this->ad_tva_id)==0) $this->ad_tva_id=0;
235  }
236  /*!\brief
237  *\param
238  *\return
239  *\note
240  *\see
241  */
242  static function test_me()
243 {}
244 
245 }
246 
247 /* test::test_me(); */
248 
load_all()
retrieve all the details of an Follow_Up
isNumber(&$p_int)
Definition: ac_common.php:202
$value
$idx
Follow_Up Details are the details for an actions, it means the details of an order, delivery order, submit a quote... this class is linked to the table action_detail.
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
set_parameter($p_string, $p_value)
function clone(object)
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
__construct($p_cn, $p_id=0)
$fl ag_id
$SecUser db
from_array($array, $idx)
Fill an Action_Detail Object with the data contained in an array.