Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_formulaire_param.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19  */
20 /* $Revision$ */
21 
22 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
23 
24 /**
25  * @file
26  * @brief factory display the definition and parameters of a form
27  *
28  */
29 require_once 'class_rapport_avance_sql.php';
30 require_once 'class_formulaire_param_detail.php';
31 
32 /**
33  * @brief manage the table rapport_avance.formulaire_param
34  */
35 class Formulaire_Param extends Formulaire_Param_Sql
36 {
37 
38  /**
39  * Factory, create an object following the $form->p_type,
40  * @param Formulaire_Param_Sql $form
41  * @return Formulaire_Title1| Formulaire_Title2| Formulaire_Title3| Formulaire_Formula
42  */
43  static function factory(Formulaire_Param_Sql $form)
44  {
45  switch ($form->p_type)
46  {
47  case 1:
48  return new Formulaire_Title1($form);
49  case 2:
50  return new Formulaire_Title2($form);
51  case 6:
52  return new Formulaire_Title3($form);
53  case 3:
54  return new Formulaire_Formula($form);
55  case 7:
56  return new Formulaire_Text($form);
57  case 8:
58  return new Formulaire_Notice($form);
59  case 9:
60  return new Formulaire_Child($form);
61  }
62  }
63 
64  /**
65  * @brief export a form to CSV to stdout
66  * @global type $cn database connx
67  * @param type $p_id the formulaire.f_id
68  */
69  static function to_csv($p_id)
70  {
71  global $cn;
72  $form = new formulaire_sql($p_id);
73  $form->load();
74  $title = mb_strtolower($form->f_title, 'UTF-8');
75  $title = str_replace(array('/', '*', '<', '>', '*', '.', '+', ':', '?', '!', " ", ";"), "_", $title);
76 
77  $out = fopen("php://output", "w");
78  header('Pragma: public');
79  header('Content-type: application/bin');
80  header('Content-Disposition: attachment;filename="' . $title . '.bin"', FALSE);
81  fputcsv($out, array("RAPAV", '4'), ";");
82  fputcsv($out, array($form->f_title, $form->f_description), ";");
83  $array = $cn->get_array("select p_id,p_code, p_libelle, p_type, p_order, f_id, t_id
84  from rapport_advanced.formulaire_param where f_id=$1", array($p_id));
85  for ($i = 0; $i < count($array); $i++)
86  {
87  fputcsv($out, $array[$i], ";");
88  }
89  fputcsv($out, array('RAPAV_DETAIL'), ";");
90  $array = $cn->get_array("select
91  fp_id, p_id, tmp_val, tva_id, fp_formula, fp_signed, jrn_def_type,
92  tt_id, type_detail, with_tmp_val, type_sum_account, operation_pcm_val,date_paid
93  from rapport_advanced.formulaire_param_detail where p_id in (select p_id from rapport_advanced.formulaire_param where f_id=$1)", array($p_id));
94  for ($i = 0; $i < count($array); $i++)
95  {
96  fputcsv($out, $array[$i], ";");
97  }
98  }
99 
100  static function from_csv($filename)
101  {
102  global $cn;
103  $in = fopen($filename, "r");
104  $cn->start();
105  try
106  {
107  $a = fgetcsv($in, 0, ";");
108  if ($a[0] != "RAPAV")
109  {
110  throw new Exception('Formulaire invalide');
111  }
112  // $a[1] contains the version
113  $rapav_version=$a[1];
114  // first line is the title and description
115  $form = new formulaire_sql();
116  $first = fgetcsv($in, 0, ";");
117  $form->f_title = $first[0];
118  if (isset($first[1]))
119  $form->f_description = $first[1];
120  $form->insert();
121  // now come the formulaire_param until the keyword RAPAV_DETAIL is met
122  while (($csv = fgetcsv($in, 0, ";")) != FALSE)
123  {
124  if ($csv[0] != "RAPAV_DETAIL")
125  {
126  if ( $rapav_version == 2 ) {
127  unset($csv[6]);
128  }
129  $csv[5]=$form->f_id;
130  $cn->get_array("INSERT INTO rapport_advanced.restore_formulaire_param(
131  p_id, p_code, p_libelle, p_type, p_order, f_id, t_id)
132  VALUES ($1, $2, $3, $4, $5, $6, $7)", $csv);
133  } else
134  break;
135  }
136  while (($csv = fgetcsv($in, 0, ";")) != FALSE)
137  {
138  $t = array();
139  for ($o = 0; $o < count($csv); $o++)
140  {
141  if ($csv[$o] == "")
142  $t[$o] = null;
143  else
144  {
145  $t[$o] = $csv[$o];
146  }
147  }
148  if ($rapav_version < 4 )
149  {
150  $t[12]=0;
151  }
152  $cn->get_array("INSERT INTO rapport_advanced.restore_formulaire_param_detail(
153  fp_id, p_id, tmp_val, tva_id, fp_formula, fp_signed, jrn_def_type,
154  tt_id, type_detail, with_tmp_val, type_sum_account, operation_pcm_val,date_paid)
155  VALUES ($1, $2, $3, $4, $5, $6, $7,$8, $9, $10, $11, $12,$13)", $t);
156  }
157  /// Update now the table rapport_advanced.restore_formulaire_param and set the correct pk
158  /// $cn->exec_sql("update rapport_advanced.restore_formulaire_param set p_id=nextval('rapport_advanced.formulaire_param_p_id_seq')");
159 
160  // Insert row by row + detail
161  $array=$cn->get_array("select p_id,p_code,p_libelle,p_order,f_id,t_id from rapport_advanced.restore_formulaire_param where f_id=$1",array($form->f_id));
162  // Prepare stmt for the details
163  $cn->prepare('detail','select p_id,tmp_val,tva_id,fp_formula,fp_signed, jrn_def_type,tt_id,type_detail,with_tmp_val,type_sum_account,operation_pcm_val,date_paid
164  from rapport_advanced.restore_formulaire_param_detail where p_id=$1');
165  $nb=count($array);
166  for ($e=0;$e<$nb;$e++)
167  {
168  // Insert first into rapport_advanced.formulaire_param
169  $new_pid=$cn->get_value("insert into rapport_advanced.formulaire_param (p_code, p_libelle, p_type, p_order, f_id, t_id)
170  select p_code, p_libelle, p_type, p_order, f_id, t_id
171  from rapport_advanced.restore_formulaire_param where p_id=$1 returning p_id",array($array[$e]['p_id']));
172  // Insert detail
173  $cn->exec_sql("insert into rapport_advanced.formulaire_param_detail
174  (fp_id,
175  p_id,
176  tmp_val,
177  tva_id,
178  fp_formula,
179  fp_signed,
180  jrn_def_type,
181  tt_id,
182  type_detail,
183  with_tmp_val,
184  type_sum_account,
185  operation_pcm_val,
186  jrn_def_id,
187  date_paid
188  )
189  select
190  nextval('rapport_advanced.formulaire_param_detail_fp_id_seq'),
191  $new_pid,
192  tmp_val,
193  tva_id,
194  fp_formula,
195  fp_signed,
196  jrn_def_type,
197  tt_id,
198  type_detail,
199  with_tmp_val,
200  type_sum_account,
201  operation_pcm_val,
202  -1,
203  date_paid
204  from
205  rapport_advanced.restore_formulaire_param_detail where p_id =$1
206  ",array($array[$e]['p_id']));
207  }
208 
209 
210  $cn->exec_sql('delete from rapport_advanced.restore_formulaire_param where f_id=$1',array($form->f_id));
211  $cn->commit();
212  }
213  catch (Exception $exc)
214  {
215  echo $exc->getMessage();
216  error_log($exc->getMessage());
217  error_log($exc->getTraceAsString());
218  throw $exc;
219  }
220  }
221 
222 }
223 
224 /**
225  * @brief mother class of Formulaire_Title1| Formulaire_Title2| Formulaire_Title3| Formulaire_Formula
226  */
228 {
229 
231  {
232  $this->obj = $e;
233  }
234 
235  function display()
236  {
237 
238  }
239 
240  function input()
241  {
242 
243  }
244 
245  /**
246  * @brief load all the row from formulaire_param_detail, children of formulaire_param
247  * return an array of objects Formulaire_Param_Detail
248  * @param type $p_id
249  */
250  static function load_all($p_id)
251  {
252  global $cn;
253  $a_value = $cn->get_array("select fp_id,type_detail from rapport_advanced.formulaire_param_detail where p_id=$1", array($p_id));
254  return $a_value;
255  }
256 
257 }
258 
259 /**
260  * @brief display title level 1
261  */
263 {
264 
265  function display()
266  {
267  echo h1($this->obj->p_libelle, "");
268  }
269 
270  function input()
271  {
272  echo h1($this->obj->p_libelle, ' class="title"');
273  }
274 
275 }
276 /**
277  * @brief display title level 1
278  */
280 {
281 
282  function display()
283  {
284  echo '<p>'.$this->obj->p_libelle.'<p>';
285  }
286 
287  function input()
288  {
289  echo '<p>'.$this->obj->p_libelle.'<p>';
290  }
291 
292 }
293 /**
294  * @brief display title level 1
295  */
297 {
298 
299  function display()
300  {
301  echo span($this->obj->p_libelle, ' class="notice" ');
302  }
303 
304  function input()
305  {
306  echo span($this->obj->p_libelle, ' class="notice"');
307  }
308 
309 }
310 
311 /**
312  * @brief display title level 2
313  */
315 {
316 
317  function display()
318  {
319  echo h2($this->obj->p_libelle, 'class="title"');
320  }
321 
322  function input()
323  {
324  echo h2($this->obj->p_libelle, 'class="title"');
325  }
326 
327 }
328 
329 /**
330  * @brief display title level 3
331  */
333 {
334 
335  function display()
336  {
337  echo "<h3>" . $this->obj->p_libelle . "</h3>";
338  }
339 
340  function input()
341  {
342  echo "<h3 class=\"title\">" . $this->obj->p_libelle . "</h3>";
343  }
344 
345 }
346 
347 /**
348  * @brief display the formula : depending of the type of formula, a factory is used and an object RAPAV_Formula, RAPAV_Account_TVA
349  * or RAPAV_compute will be used for the display of the details
350  */
352 {
353 
355  {
356  $this->obj = $e;
357  $this->id = $e->p_id;
358  $this->parametre = Formulaire_Row::load_all($this->id);
359  }
360 
361  function display()
362  {
363  echo $this->obj->p_libelle;
364  }
365 
366  /**
367  * @brief return an object following the key type_detail of the array passed in parameter
368  *
369  * @param type $p_index
370  * @return RAPAV_Formula| RAPAV_Account_Tva| RAPAV_Compute
371  */
372  function make_object($p_index)
373  {
374  $elt = $this->parametre[$p_index]['type_detail'];
375  switch ($elt)
376  {
377  case '1':
378  return new RAPAV_Formula($this->parametre[$p_index]['fp_id']);
379  break;
380  case '2':
381  return new RAPAV_Account_Tva($this->parametre[$p_index]['fp_id']);
382  break;
383  case '3':
384  return new RAPAV_Compute($this->parametre[$p_index]['fp_id']);
385  break;
386  case '4':
387  return new RAPAV_Account($this->parametre[$p_index]['fp_id']);
388  break;
389  case '5':
390  return new RAPAV_Reconcile($this->parametre[$p_index]['fp_id']);
391  break;
392  }
393  }
394 
395  /**
396  * @brief input value
397  */
398  function input()
399  {
400  echo '<h4 class="title">' . $this->obj->p_libelle . "(" . $this->obj->p_code . ")" . '</h4>';
401  echo HtmlInput::hidden('p_id[]', $this->obj->p_id);
402  $max = count($this->parametre);
403  echo HtmlInput::hidden("count_" . $this->id, $max);
404  //echo '<h5 class="title">' . 'code ' . $this->obj->p_code . '</h5>';
405  echo '<p>';
406  echo '<table id="table_' . $this->id . '">';
407  for ($i = 0; $i < $max; $i++)
408  {
409  $formula = $this->make_object($i);
410 
411  echo '<tr id="tr_' . $formula->fp_id . '">';
412  echo '<td>';
413  echo $formula->display_row();
414  echo '</td>';
415  echo $formula->button_delete();
416  echo $formula->button_modify();
417  echo '</tr>';
418  }
419  if ($max == 0)
420  echo '<tr></tr>';
421  echo "</table>";
422  echo '</p>';
423  echo HtmlInput::button_anchor(
424  "Ajout d'une ligne", "javascript:void(0)", "add_row" . $this->id, sprintf("onclick=\"add_param_detail('%s','%s','%s','%s');\"", $_REQUEST['plugin_code'], $_REQUEST['ac'], $_REQUEST['gDossier'], $this->id)
425  );
426  }
427 
428 }
430 {
432  {
433  parent::__construct($e);
434  }
435  function make_object($p_index)
436  {
437  $elt = $this->parametre[$p_index]['type_detail'];
438  return new RAPAV_Account($this->parametre[$p_index]['fp_id']);
439  }
440  /**
441  * @brief input value
442  */
443  function input()
444  {
445  echo '<h4 class="title">' . $this->obj->p_libelle . "(" . $this->obj->p_code . ")" . '</h4>';
446  echo HtmlInput::hidden('p_id[]', $this->obj->p_id);
447  $max = count($this->parametre);
448  echo HtmlInput::hidden("count_" . $this->id, $max);
449  //echo '<h5 class="title">' . 'code ' . $this->obj->p_code . '</h5>';
450  echo '<p>';
451  echo '<table id="table_' . $this->id . '">';
452  for ($i = 0; $i < $max; $i++)
453  {
454  $formula = $this->make_object($i);
455 
456  echo '<tr id="tr_' . $formula->fp_id . '">';
457  echo '<td>';
458  echo $formula->display_row();
459  echo '</td>';
460  echo $formula->button_delete();
461  echo $formula->button_modify();
462  echo '</tr>';
463  }
464  if ($max == 0)
465  echo '<tr></tr>';
466  echo "</table>";
467  echo '</p>';
468  echo HtmlInput::button_anchor(
469  "Ajout d'une ligne", "javascript:void(0)", "add_row" . $this->id, sprintf("onclick=\"add_param_detail('%s','%s','%s','%s');\"", $_REQUEST['plugin_code'], $_REQUEST['ac'], $_REQUEST['gDossier'], $this->id)
470  );
471  if ( $max > 0 ) {
472  echo "<script>
473  $('add_row".$this->id."').hide();
474  </script>
475  ";
476  }
477  }
478 }
479 ?>
display title level 1
__construct(formulaire_param_sql $e)
poste comptable utilisé avec le poste comptable, choix entre diff crédit - debit, diff débit-crédit...
static load_all($p_id)
load all the row from formulaire_param_detail, children of formulaire_param return an array of object...
display title level 2
mother class of Formulaire_Title1| Formulaire_Title2| Formulaire_Title3| Formulaire_Formula ...
static to_csv($p_id)
export a form to CSV to stdout type $cn database connx
display title level 3
__construct(formulaire_param_sql $e)
global $rapav_version
make_object($p_index)
return an object following the key type_detail of the array passed in parameter
poste comptable utilisé avec le poste comptable, choix entre diff crédit - debit, diff débit-crédit...
if(isset($_POST['remove'])) $array
display title level 1
__construct(formulaire_param_sql $e)
manage the table rapport_avance.formulaire_param
display title level 1
static factory(Formulaire_Param_Sql $form)
Factory, create an object following the $form->p_type,.
$_REQUEST['sb']
Definition: am_print.php:39
display the formula : depending of the type of formula, a factory is used and an object RAPAV_Formula...
global $cn
static from_csv($filename)