Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_sql_impdol.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 
21 {
22 
23  function __construct($p_cn, $p_id = -1)
24  {
25  $this->cn = $p_cn;
26  $pk=$this->primary_key;
27  $this->$pk= $p_id;
28 
29  if ($p_id == -1)
30  {
31  /* Initialize an empty object */
32  foreach ($this->name as $key )
33  {
34  $this->$key= null;
35  }
36  $this->$pk= $p_id;
37  }
38  else
39  {
40  /* load it */
41  $this->load();
42  }
43  }
44 
45  public function getp($p_string)
46  {
47  if (array_key_exists( $p_string,$this->name))
48  {
49  $idx = $this->name[$p_string];
50  return $this->$idx;
51  }
52  else
53  throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant '.$p_string);
54  }
55 
56  public function setp($p_string, $p_value)
57  {
58  if (array_key_exists( $p_string,$this->name))
59  {
60  $idx = $this->name[$p_string];
61  $this->$idx = $p_value;
62  }
63  else
64  throw new Exception(__FILE__ . ":" . __LINE__ . $p_string . 'Erreur attribut inexistant '.$p_string);
65  }
66 
67  public function insert()
68  {
69  $this->verify();
70  $sql = "insert into " . $this->table . " ( ";
71  $sep = "";
72  $par = "";
73  $idx = 1;
74  $array = array();
75  foreach ($this->name as $key=>$value)
76  {
77  if (isset($this->default[$value]) && $this->default[$value] == "auto" && $this->$value ==null )
78  continue;
79  if ( $value==$this->primary_key && $this->$value == -1 ) continue;
80  $sql.=$sep.$value;
81  switch ($this->type[$value])
82  {
83  case "date":
84  $par .=$sep. 'to_date($' . $idx . ",'" . $this->date_format . "')" ;
85  break;
86  default:
87  $par .= $sep."$" . $idx ;
88  }
89 
90  $array[] = $this->$value;
91  $sep = ",";
92  $idx++;
93  }
94  $sql.=") values (" . $par . ") returning " . $this->primary_key;
95  $pk=$this->primary_key;
96  $this->$pk = $this->cn->get_value($sql, $array);
97  }
98 
99  public function delete()
100  {
101  $pk=$this->primary_key;
102  $sql = " delete from " . $this->table . " where " . $this->primary_key . "=" . sql_string($this->$pk);
103  $this->cn->exec_sql($sql);
104  }
105 
106  public function update()
107  {
108  $this->verify();
109  $pk=$this->primary_key;
110  $sql = "update " . $this->table . " ";
111  $sep = "";
112  $idx = 1;
113  $array = array();
114  $set=" set ";
115  foreach ($this->name as $key=>$value)
116  {
117  if (isset($this->default[$value]) && $this->default[$value] == "auto" )
118  continue;
119  switch ($this->type[$value])
120  {
121  case "date":
122  $par =$value. '=to_date($' . $idx . ",'" . $this->date_format . "')" ;
123  break;
124  default:
125  $par = $value."= $" . $idx ;
126  }
127  $sql.=$sep." $set " . $par ;
128  $array[] = $this->$value;
129  $sep = ",";$set="";$idx++;
130  }
131  $sql.=" where " . $this->primary_key . " =" . $this->$pk;
132  $this->cn->exec_sql($sql, $array);
133 
134  }
135 
136  public function load()
137  {
138  $sql = " select ";
139  $sep="";$par="";
140 
141  foreach ($this->name as $key)
142  {
143 
144  switch ($this->type[$key])
145  {
146  case "date":
147  $sql .= $sep.'to_char(' . $key . ",'" . $this->date_format . "') as ".$key ;
148  break;
149  default:
150  $sql.=$sep.$key ;
151  }
152  $sep = ",";
153  }
154  $pk=$this->primary_key;
155  $sql.=" from ".$this->table;
156  $sql.=" where " . $this->primary_key . " = " . $this->$pk;
157  $result = $this->cn->get_array($sql);
158  if ($this->cn->count() == 0 ) {
159  $this->$pk=-1;
160  return;
161  }
162 
163  foreach ($result[0] as $key=>$value) {
164  $this->$key=$value;
165  }
166  }
167 
168  public function get_info()
169  {
170  return var_export($this, true);
171  }
172 
173  public function verify()
174  {
175  foreach($this->name as $key){
176  if ( trim($this->$key)=='') $this->$key=null;
177  }
178  return 0;
179  }
180  public function from_array($p_array)
181  {
182  foreach ($this->name as $key=>$value)
183  {
184  if ( isset ($p_array[$value]))
185  {
186  $this->$value=$p_array[$value];
187  }
188  }
189  }
190  public function next($ret,$i) {
191  global $cn;
192  $array=$this->cn->fetch_array($ret,$i);
193  $this->from_array($array);
194  }
195 
196 }
197 
199 {
200 
201  function __construct($p_id=-1)
202  {
203  $this->table = "impdol.operation";
204  $this->primary_key = "o_id";
205 
206  $this->name=array(
207  "id"=>"o_id",
208  "dolibarr"=>"o_doli",
209  "date"=>"o_date",
210  "qcode"=>"o_qcode",
211  "fiche"=>"f_id",
212  "desc"=>"o_label",
213  "pj"=>"o_pj",
214  "amount_unit"=>"amount_unit",
215  "amount_vat"=>"amount_vat",
216  "number_unit"=>"number_unit",
217  "rate"=>"vat_rate",
218  "amount_total"=>"amount_total",
219  "jrn_def_id"=>"jrn_def_id",
220  "o_message"=>"o_message",
221  "import_id"=>"i_id",
222  "status"=>"o_status"
223 
224  );
225 
226  $this->type = array(
227  "o_id"=>"numeric",
228  "o_doli"=>"numeric",
229  "o_date"=>"date",
230  "o_qcode"=>"text",
231  "f_id"=>"numeric",
232  "o_label"=>"text",
233  "o_pj"=>"text",
234  "amount_unit"=>"numeric",
235  "amount_vat"=>"numeric",
236  "number_unit"=>"numeric",
237  "vat_rate"=>"numeric",
238  "amount_total"=>"numeric",
239  "jrn_def_id"=>"numeric",
240  "o_message"=>"text",
241  "i_id"=>"numeric",
242  "o_status"=>"text"
243  );
244 
245  $this->default = array(
246  "o_id" => "auto",
247  );
248  $this->date_format = "DD.MM.YYYY";
249  global $cn;
250 
251  parent::__construct($cn,$p_id);
252  }
253 
254 }
255 
257 {
258 
259  function __construct($p_id=-1)
260  {
261  $this->table = "impdol.operation_tmp";
262  $this->primary_key = "o_id";
263 
264  $this->name=array(
265  "id"=>"o_id",
266  "dolibarr"=>"o_doli",
267  "date"=>"o_date",
268  "qcode"=>"o_qcode",
269  "fiche"=>"f_id",
270  "desc"=>"o_label",
271  "pj"=>"o_pj",
272  "amount_unit"=>"amount_unit",
273  "amount_vat"=>"amount_vat",
274  "number_unit"=>"number_unit",
275  "rate"=>"vat_rate",
276  "amount_total"=>"amount_total",
277  "jrn_def_id"=>"jrn_def_id",
278  "message"=>"o_message",
279  "import_id"=>"i_id",
280  "code"=>"o_result",
281  "tva_id"=>"tva_id",
282  "type"=>"o_type",
283  "poste"=>"o_poste"
284 
285  );
286 
287  $this->type = array(
288  "o_id"=>"numeric",
289  "o_doli"=>"text",
290  "o_date"=>"text",
291  "o_qcode"=>"text",
292  "f_id"=>"text",
293  "o_label"=>"text",
294  "o_pj"=>"text",
295  "amount_unit"=>"text",
296  "amount_vat"=>"text",
297  "number_unit"=>"text",
298  "vat_rate"=>"text",
299  "amount_total"=>"text",
300  "jrn_def_id"=>"text",
301  "o_message"=>"text",
302  "i_id"=>"numeric",
303  "o_result"=>'text',
304  "tva_id"=>'numeric',
305  "o_type"=>'text',
306  "o_poste"=>"text"
307  );
308 
309  $this->default = array(
310  "o_id" => "auto",
311  );
312  $this->date_format = "DD.MM.YYYY";
313  global $cn;
314 
315  parent::__construct($cn,$p_id);
316  }
317 
318 }
319 
321 {
322  function __construct($p_id=-1)
323  {
324  $this->table = "impdol.import";
325  $this->primary_key = "i_id";
326 
327  $this->name=array(
328  "id"=>"i_id",
329  "send_file"=>"send_file",
330  "temp_file"=>"temp_file",
331  "date"=>"i_date",
332  "nbrow"=>"i_row"
333  );
334 
335  $this->type = array(
336  "i_id"=>"numeric",
337  "send_file"=>"text",
338  "temp_file"=>"text",
339  "i_date"=>"date",
340  "i_row"=>"numeric"
341  );
342 
343  $this->default = array(
344  "i_id" => "auto",
345  "i_date" => "auto"
346  );
347  $this->date_format = "DD.MM.YYYY";
348  global $cn;
349 
350  parent::__construct($cn,$p_id);
351  }
352 }
353 
354 
356 {
357  function __construct($p_id=-1)
358  {
359  $this->table = "impdol.operation_transfer";
360  $this->primary_key = "ot_id";
361 
362  $this->name=array(
363  "id"=>"ot_id",
364  "j_id"=>"j_id",
365  "o_id"=>"o_id"
366  );
367 
368  $this->type = array(
369  "ot_id"=>'numeric',
370  "j_id"=>'numeric',
371  "o_id"=>'numeric',
372  );
373 
374  $this->default = array(
375  "i_id" => "auto"
376  );
377  $this->date_format = "DD.MM.YYYY";
378  global $cn;
379 
380  parent::__construct($cn,$p_id);
381  }
382 }
383 ?>
$ret
getp($p_string)
next($ret, $i)
from_array($p_array)
if(isset($_POST['remove'])) $array
$key
$categorie_appel table
$categorie_appel name
__construct($p_cn, $p_id=-1)
$sql
setp($p_string, $p_value)
global $cn