Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_rapav_declaration.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 
21 /* $Revision$ */
22 
23 // Copyright (c) 2002 Author Dany De Bontridder dany@alchimerys.be
24 
25 /**
26  * @file
27  * @brief compute all the formulaire_row and save them into rappport_advanced.declaration
28  *
29  */
30 require_once 'class_rapav_formulaire.php';
31 require_once 'class_formulaire_param_detail.php';
32 require_once 'class_rapport_avance_sql.php';
33 
34 /**
35  * @brief compute, save and display a declaration
36  */
38 {
39 
40  function __construct()
41  {
42  $this->form = new RAPAV_Formulaire();
43  parent::__construct();
44  }
45  function load_formulaire() {
46  $this->form->load();
47  }
48  /**
49  * @brief export a declaration to CSV
50  * @global $cn database conx
51  * @param $p_id pk of rapav_declaration
52  * @param $p_orient
53  * value :
54  * - list : for a list
55  * - table : to have a table (if using step)
56  */
57  static function to_csv($p_id,$p_orient="list")
58  {
59  global $cn;
60 
61  $a_title = $cn->get_array("select d_title
62  ,to_char(d_start,'DD.MM.YYYY') as start
63  ,to_char(d_end,'DD.MM.YYYY') as end
64  from
65  rapport_advanced.declaration
66  where
67  d_id=$1 ", array($p_id));
68  $title = $a_title[0]['d_title'] . "-" . $a_title[0]['start'] . "-" . $a_title[0]['end'];
69  $title = mb_strtolower($title, 'UTF-8');
70  $title = str_replace(array('/', '*', '<', '>', '*', '.', '+', ':', '?', '!', " ", ";"), "_", $title);
71  $out = fopen("php://output", "w");
72 
73  header('Pragma: public');
74  header('Content-type: application/csv');
75  header('Content-Disposition: attachment;filename="' . $title . '.csv"', FALSE);
76  if ($p_orient == "list")
77  {
78  fputcsv($out, $a_title[0], ";");
79 
80  $a_row = $cn->get_array('select dr_code,dr_libelle,dr_amount,dr_start,dr_end,dr_account
81  from rapport_advanced.declaration_row
82  where d_id=$1 order by dr_order,dr_start', array($p_id));
83 
84  for ($i = 0; $i < count($a_row); $i++)
85  {
86  printf('"%s";"%s";"%s";%s;"%s";"%s"' . "\r\n", $a_row[$i]['dr_code'],$a_row[$i]['dr_account'],$a_row[$i]['dr_libelle'], nb($a_row[$i]['dr_amount']), format_date($a_row[$i]['dr_start']), format_date($a_row[$i]['dr_end'])
87  );
88  }
89  }
90  elseif ($p_orient=="table")
91  {
92  fputcsv($out, $a_title[0], ";");
93  // Only the period
94  $a_periode = $cn->get_array('select distinct dr_start,dr_end
95  from rapport_advanced.declaration_row
96  where d_id=$1 order by dr_start', array($p_id));
97 
98  // 3 blank columns
99  printf(';;');
100  for ($i = 0; $i < count($a_periode); $i++)
101  {
102  printf(';"%s-%s"', format_date($a_periode[$i]['dr_start']), format_date($a_periode[$i]['dr_end']));
103  }
104  printf("\r\n");
105 
106  // print each code on one line
107  $a_row = $cn->get_array('select dr_code,dr_libelle,dr_amount,dr_start,dr_end,dr_account
108  from rapport_advanced.declaration_row
109  where d_id=$1 order by dr_order,dr_start', array($p_id));
110  $last_code=""; $last_lib="";
111  for ($i = 0; $i < count($a_row); $i++)
112  {
113  if ( $last_code != $a_row[$i]['dr_code'] || $last_lib != $a_row[$i]['dr_libelle'])
114  {
115  if ($last_code!=""){ printf("\r\n"); }
116  printf('"%s";"%s";"%s"', $a_row[$i]['dr_account'],$a_row[$i]['dr_code'],$a_row[$i]['dr_libelle']);
117  $last_code=$a_row[$i]['dr_code'];
118  $last_lib=$a_row[$i]['dr_libelle'];
119  }
120  printf(';%s',nb($a_row[$i]['dr_amount']));
121  }
122  printf("\r\n");
123  }
124  }
125 
126  function get_file_to_parse()
127  {
128  global $cn;
129  // create a temp directory in /tmp to unpack file and to parse it
130  $dirname = tempnam($_ENV['TMP'], 'rapav_');
131 
132 
133  unlink($dirname);
134  mkdir($dirname);
135  chdir($dirname);
136  // Retrieve the lob and save it into $dirname
137  $cn->start();
138 
139 
140  $filename = $this->d_filename;
141  $exp = $cn->lo_export($this->d_lob, $dirname . DIRECTORY_SEPARATOR . $filename);
142 
143  if ($exp === false)
144  echo_warning(__FILE__ . ":" . __LINE__ . "Export NOK $filename");
145 
146  $type = "n";
147  // if the doc is a OOo, we need to unzip it first
148  // and the name of the file to change is always content.xml
149  if (strpos($this->d_mimetype, 'vnd.oasis') != 0)
150  {
151  ob_start();
152  $zip = new Zip_Extended;
153  if ($zip->open($filename) === TRUE)
154  {
155  $zip->extractTo($dirname . DIRECTORY_SEPARATOR);
156  $zip->close();
157  } else
158  {
159  echo __FILE__ . ":" . __LINE__ . "cannot unzip model " . $filename;
160  }
161 
162  // Remove the file we do not need anymore
163  unlink($filename);
164  ob_end_clean();
165  $file_to_parse = "content.xml";
166  $type = "OOo";
167  } else
168  $file_to_parse = $filename;
169 
170  $cn->commit();
171  return array($file_to_parse, $dirname, $type);
172  }
173 
174  function generate_document()
175  {
176  global $cn;
177  if ($this->d_filename == "")
178  return;
179 
180  list($file_to_parse, $dirname, $type) = $this->get_file_to_parse();
181 
182  // parse the document
183  $this->parse_document($dirname, $file_to_parse, $type);
184 
185  // Add special tag
186  $this->special_tag($dirname, $file_to_parse, $type);
187 
188  // if the doc is a OOo, we need to re-zip it
189  if ($type == 'OOo')
190  {
191  ob_start();
192  $zip = new Zip_Extended;
193  $res = $zip->open($this->d_filename, ZipArchive::CREATE);
194  if ($res !== TRUE)
195  {
196  echo __FILE__ . ":" . __LINE__ . "cannot recreate zip";
197  exit;
198  }
199  $zip->add_recurse_folder($dirname . DIRECTORY_SEPARATOR);
200  $zip->close();
201 
202  ob_end_clean();
203 
204  $file_to_save = $this->d_filename;
205  } else
206  {
207  $file_to_save = $file_to_parse;
208  }
209 
210  $this->load_document($dirname . DIRECTORY_SEPARATOR . $file_to_save);
211  }
212 
213  function parse_document($p_dir, $p_filename, $p_type)
214  {
215  global $cn;
216  // Retrieve all the code + amount
217  if ($p_type == "OOo")
218  {
219  $array = $cn->get_array("select '&lt;&lt;'||dr_code||'&gt;&gt;' as code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and dr_type=3", array($this->d_id));
220  $array_mult = $cn->get_array("select '&lt;&lt;'||dr_code||'&gt;&gt;' as code,
221  '&lt;&lt;'||dr_code||'_LIB&gt;&gt;' as code_lib,
222  '&lt;&lt;'||dr_code||'_ACC&gt;&gt;' as code_acc,
223  dr_account,
224  dr_amount,dr_libelle from rapport_advanced.declaration_row where d_id=$1 and dr_type=9 and dr_amount <> 0", array($this->d_id));
225  } else
226  {
227  $array = $cn->get_array("select '<<'||dr_code||'>>' as code,dr_amount from rapport_advanced.declaration_row where d_id=$1 and dr_type=3", array($this->d_id));
228  $array_mult = $cn->get_array("select '<<'||dr_code||'>>' as code,
229  '<<'||dr_code||'_LIB>>' as code_lib,
230  '<<'||dr_code||'_ACC>>' as code_acc,
231  dr_account,
232  dr_amount,dr_libelle from rapport_advanced.declaration_row where d_id=$1 and dr_type=9 and dr_amount <> 0 order by dr_order", array($this->d_id));
233  }
234 
235  // open the files
236  $ifilename=$p_dir . '/' . $p_filename;
237  $ifile = fopen($ifilename, 'r');
238 
239  // check if tmpdir exist otherwise create it
240  $temp_dir = $_ENV['TMP'];
241  if (is_dir($temp_dir) == false)
242  {
243  if (mkdir($temp_dir) == false)
244  {
245  echo "Ne peut pas créer le répertoire " . $temp_dir;
246  exit();
247  }
248  }
249  // Compute output_name
250  $oname = tempnam($temp_dir, "rapport_avance_");
251  $ofile = fopen($oname, "w+");
252 
253  // read ifile
254  $buffer = fread($ifile, filesize($ifilename));
255  // for each code replace in p_filename the code surrounded by << >> by the amount (value) or &lt; or &gt;
256  foreach ($array as $key => $value)
257  {
258  if (is_numeric($value['dr_amount']))
259  {
260  /* -- works only with OOo Calc -- */
261  $searched = 'office:value-type="string"><text:p>' . $value['code'];
262  $replaced = 'office:value-type="float" office:value="' . $value['dr_amount'] . '"><text:p>' . $value['code'];
263  $buffer = str_replace($searched, $replaced, $buffer);
264  }
265  $buffer = str_replace($value['code'], $value['dr_amount'], $buffer);
266  }
267  // Do the same but for multiple account
268  if ($array_mult==false)
269  {
270 
271  }
272  else
273  {
274  $a_code_clean=array();
275  $a_code_lib_clean=array();
276  $a_code_acc_clean=array();
277  $idx=0;
278  foreach ($array_mult as $key=> $value)
279  {
280  // Get all the code to replace without duplicate
281 
282  if ( $idx == 0 ) {
283  $a_code_clean[$idx]=$value['code'];
284  $a_code_lib_clean[$idx]=$value['code_lib'];
285  $a_code_acc_clean[$idx]=$value['code_acc'];
286  $idx++;
287  } else {
288  if ( ! in_array($value['code'], $a_code_clean)){
289  $a_code_clean[$idx]=$value['code'];
290  $a_code_lib_clean[$idx]=$value['code_lib'];
291  $a_code_acc_clean[$idx]=$value['code_acc'];
292  $idx++;
293  }
294  }
295  if (is_numeric($value['dr_amount']))
296  {
297  /* -- works only with OOo Calc -- */
298  $searched='office:value-type="string"><text:p>'.$value['code'];
299  $replaced='office:value-type="float" office:value="'.$value['dr_amount'].'"><text:p>'.$value['code'];
300  $buffer=preg_replace("/".$searched."/", $replaced, $buffer,1);
301  }
302  $buffer=preg_replace("/".$value['code']."/", $value['dr_amount'],$buffer,1);
303  $buffer=preg_replace("/".$value['code_lib']."/", $value['dr_libelle'],$buffer,1);
304  $buffer=preg_replace("/".$value['code_acc']."/", $value['dr_account'],$buffer,1);
305  }
306  // clean all unused
307  for ($k=0;$k<$idx;$k++){
308  $code=$a_code_clean[$k];
309  $code_lib=$a_code_lib_clean[$k];
310  $code_acc=$a_code_acc_clean[$k];
311  $buffer=preg_replace("/".$code."/","",$buffer);
312  $buffer=preg_replace("/".$code_lib."/", "",$buffer);
313  $buffer=preg_replace("/".$code_acc."/", "",$buffer);
314 
315  }
316 
317  }
318  // write to output
319  fwrite($ofile, $buffer);
320 
321 
322  // copy the output to input
323  fclose($ifile);
324  fclose($ofile);
325 
326  if (($ret = copy($oname, $p_dir . '/' . $p_filename)) == FALSE)
327  {
328  echo _('Ne peut pas sauver ' . $oname . ' vers ' . $p_dir . '/' . $p_filename . ' code d\'erreur =' . $ret);
329  }
330  unlink($oname);
331  }
332 
333  function special_tag($p_dir, $p_filename, $p_type)
334  {
335  global $cn, $g_parameter;
336  // Retrieve all the code + libelle
337  $array[] = array('code' => 'PERIODE_DECLARATION', 'value' => format_date($this->d_start) . " - " . format_date($this->d_end));
338  $array[] = array('code' => 'TITRE', 'value' => $this->d_title);
339  $array[] = array('code' => 'DOSSIER', 'value' => $cn->format_name($_REQUEST['gDossier'], 'dos'));
340  $array[] = array('code' => 'NAME', 'value' => $g_parameter->MY_NAME);
341  $array[] = array('code' => 'STREET', 'value' => $g_parameter->MY_STREET);
342  $array[] = array('code' => 'NUMBER', 'value' => $g_parameter->MY_NUMBER);
343  $array[] = array('code' => 'LOCALITE', 'value' => $g_parameter->MY_COMMUNE);
344  $array[] = array('code' => 'COUNTRY', 'value' => $g_parameter->MY_PAYS);
345  $array[] = array('code' => 'PHONE', 'value' => $g_parameter->MY_TEL);
346  $array[] = array('code' => 'CEDEX', 'value' => $g_parameter->MY_CP);
347  $array[] = array('code' => 'FAX', 'value' => $g_parameter->MY_FAX);
348  $array[] = array('code' => 'NOTE', 'value' => $this->d_description);
349  $array[] = array('code' => 'TODAY', 'value' => date('d.m.Y'));
350 
351  // open the files
352  $ifile = fopen($p_dir . '/' . $p_filename, 'r');
353 
354  // check if tmpdir exist otherwise create it
355  $temp_dir = $_SERVER["DOCUMENT_ROOT"] . DIRECTORY_SEPARATOR . 'tmp';
356  if (is_dir($temp_dir) == false)
357  {
358  if (mkdir($temp_dir) == false)
359  {
360  echo "Ne peut pas créer le répertoire " . $temp_dir;
361  exit();
362  }
363  }
364  // Compute output_name
365  $oname = tempnam($temp_dir, "rapport_avance_");
366  $ofile = fopen($oname, "w+");
367 
368  // read ifile
369  while (!feof($ifile))
370  {
371  $buffer = fgets($ifile);
372  // for each code replace in p_filename the code surrounded by << >> by the amount (value) or &lt; or &gt;
373  foreach ($array as $key => $value)
374  {
375  if ($p_type == 'OOo')
376  {
377  $replace = '&lt;&lt;' . $value['code'] . '&gt;&gt;';
378  $fmt_value = $value['value'];
379  $fmt_value = str_replace('&', '&amp;', $fmt_value);
380  $fmt_value = str_replace('<', '&lt;', $fmt_value);
381  $fmt_value = str_replace('>', '&gt;', $fmt_value);
382  $fmt_value = str_replace('"', '&quot;', $fmt_value);
383  $fmt_value = str_replace("'", '&apos;', $fmt_value);
384  } else
385  {
386  $replace = '<<' . $value['code'] . '>>';
387  $fmt_value = $value['value'];
388  }
389  $buffer = str_replace($replace, $fmt_value, $buffer);
390  }
391  // write to output
392  fwrite($ofile, $buffer);
393  }
394 
395  // copy the output to input
396  fclose($ifile);
397  fclose($ofile);
398 
399  if (($ret = copy($oname, $p_dir . '/' . $p_filename)) == FALSE)
400  {
401  echo _('Ne peut pas sauver ' . $oname . ' vers ' . $p_dir . '/' . $p_filename . ' code d\'erreur =' . $ret);
402  }
403  unlink($oname);
404  }
405 
406  function load_document($p_file)
407  {
408  global $cn;
409  $cn->start();
410  $this->d_lob = $cn->lo_import($p_file);
411  if ($this->d_lob == false)
412  {
413  echo "ne peut pas importer [$p_file]";
414  return 1;
415  }
416  $this->d_size = filesize($p_file);
417  $date = date('ymd-Hi');
418  $this->d_filename = $date . '-' . $this->d_filename;
419  $this->update();
420  $cn->commit();
421  }
422 
423  /**
424  *
425  * @global $cn $cn
426  * @param type $p_id
427  * @param type $p_start
428  * @param type $p_end
429  * @param type $p_step
430  */
431  function compute($p_id, $p_start, $p_end, $p_step)
432  {
433  global $cn;
434  $cn->start();
435  // Load the parameter from formulaire_param_detail
436  // create object_rapav_declaration
437  // compute
438  // save the parameter
439  $this->form->f_id = $p_id;
440  $this->form->load();
441  $this->d_title = $this->form->f_title;
442  $this->d_start = $p_start;
443  $this->d_end = $p_end;
444  $this->to_keep = 'N';
445  $this->d_lob = $this->form->f_lob;
446  $this->d_filename = $this->form->f_filename;
447  $this->d_mimetype = $this->form->f_mimetype;
448  $this->d_size = $this->form->f_size;
449  $this->d_step = $p_step;
450  $this->insert();
451  /*
452  * First we compute the formula and tva_code for each detail
453  */
454  $array = $cn->get_array("select p_id,p_code,p_libelle,p_type,p_order,f_id,t_id
455  from rapport_advanced.formulaire_param
456  where
457  f_id=$1
458  order by p_order", array($p_id));
459  /**
460  * if step != 0, recompute the date
461  */
462  if ($p_step == 0)
463  {
464  // compute each row
465  for ($i = 0; $i < count($array); $i++)
466  {
468  $row->d_id = $this->d_id;
469  $row->dr_id = $cn->get_next_seq('rapport_advanced.declaration_param_seq');
470  $row->from_array($array[$i]);
471  $row->dr_start = $p_start;
472  $row->dr_end = $p_end;
473  $row->dr_account=null;
474  if ($array[$i]['p_type'] == 3 )
475  {
476  $row->compute($p_start, $p_end);
477  // insert into DECLARATION_ROW
478  $row->insert();
479  } elseif ($array[$i]['p_type'] == 9)
480  {
481  /**
482  * children must be inserted into DECLARATION_ROW and
483  * DECLARARION_ROW_DETAIL for each depending accounting
484  * impact also order(use of decimal)
485  */
486 
487  $this->add_child_account($row,$array[$i], $p_start, $p_end);
488 
489  }else
490  {
491  $row->amount = 0;
492  $row->dr_start = $p_start;
493  $row->dr_end = $p_end;
494  $row->insert();
495  }
496 
497  }
498  } else
499  {
500  // compute new date, stored in $this->start and $this->end
501  while ($this->compute_interval($p_start, $p_end, $p_step) == 1)
502  {
503  for ($i = 0; $i < count($array); $i++)
504  {
506  $row->d_id = $this->d_id;
507  $row->dr_id = $cn->get_next_seq('rapport_advanced.declaration_param_seq');
508  $row->from_array($array[$i]);
509  $row->dr_account=null;
510  if ($array[$i]['p_type'] == 3)
511  {
512  $row->compute($this->start, $this->end);
513  $row->dr_start = $this->start;
514  $row->dr_end = $this->end;
515  $row->insert();
516  }
517  elseif ($array[$i]['p_type'] == 9)
518  {
519  /**
520  * children must be inserted into DECLARATION_ROW and
521  * DECLARARION_ROW_DETAIL for each depending accounting
522  * impact also order(use of decimal)
523  */
524 
525  $this->add_child_account($row,$array[$i], $this->start, $this->end);
526 
527  }
528  }
529  }
530  }
531  $cn->commit();
532  }
533  function add_child_account(Rapav_Declaration_Param $row,$p_array,$p_start,$p_end)
534  {
535  global $cn;
536  $a_depending=$row->get_depending();
537  if ($a_depending==false)
538  {
539  $row->amount=0;
540  $row->dr_start=$p_start;
541  $row->dr_end=$p_end;
542  $row->insert();
543  }
544  else
545  {
546  $nb_depending=count($a_depending);
547  for ($j=0; $j<$nb_depending; $j++)
548  {
549  $row=new Rapav_Declaration_Param();
550  $row->d_id=$this->d_id;
551  $row->dr_id=$cn->get_next_seq('rapport_advanced.declaration_param_seq');
552  $row->from_array($p_array);
553  $row->dr_start=$p_start;
554  $row->dr_end=$p_end;
555  $row->compute_child($a_depending[$j]['pcm_val'], $p_start,$p_end);
556  $row->dr_account=$a_depending[$j]['pcm_val'];
557  $row->param->p_libelle=$a_depending[$j]['pcm_lib'];
558  $row->param->p_order=$row->param->p_order+$j/1000;
559  // insert into DECLARATION_ROW
560  $row->insert();
561  }
562  }
563  }
564 
565  function compute_interval($p_start, $p_end, $p_step)
566  {
567  static $s_start = "";
568  static $s_count = 0;
569 
570  if ($s_start == "")
571  {
572  $s_start = $p_start;
573  }
574  $s_count++;
575  // initialize datetime object
576  $date_start = DateTime::createFromFormat('d.m.Y', $s_start);
577  $date_end = DateTime::createFromFormat('d.m.Y', $s_start);
578  $date_finish = DateTime::createFromFormat('d.m.Y', $p_end);
579 
580  $add = $this->get_interval($p_step);
581 
582 
583  if ($s_count > 1)
584  {
585  $date_start->add($add);
586  $date_end->add($add);
587  }
588  // compute date_end
589  $date_end->add($add);
590  $date_end->sub(new DateInterval('P1D'));
591  // if date_end > date_finish then stop
592  if ($date_end > $date_finish)
593  return 0;
594  $this->start = $date_start->format("d.m.Y");
595  $this->end = $date_end->format("d.m.Y");
596  $s_start = $this->start;
597  return 1;
598  }
599 
600  function get_interval($p_step)
601  {
602  $array_interval = array("", "P7D", "P14D", "P1M", "P2M", "P3M",'P6M','P1Y');
603  return new DateInterval($array_interval[$p_step]);
604  }
605 
606  function anchor_document()
607  {
608  $url = HtmlInput::request_to_string(array('gDossier', 'ac', 'plugin_code'));
609  $url = 'extension.raw.php' . $url . '&amp;act=export_decla_document&amp;id=' . $this->d_id;
610  return HtmlInput::anchor($this->d_filename, $url);
611  }
612 
613  function display()
614  {
615  global $cn;
616  $array = $cn->get_array('select * from rapport_advanced.declaration_row where d_id=$1 order by dr_order,dr_start', array($this->d_id));
617  require_once 'template/declaration_display.php';
618  }
619 
620  function save()
621  {
622  global $cn;
623  try
624  {
625  $cn->start();
626  $this->to_keep = 'Y';
627  $this->update();
628  $code = $_POST['code'];
629  $amount = $_POST['amount'];
630  for ($i = 0; $i < count($code); $i++)
631  {
632  $cn->exec_sql('update rapport_advanced.declaration_row set dr_amount=$2 where dr_id=$1', array($code[$i], $amount[$i]));
633  }
634  $cn->commit();
635  } catch (Exception $e)
636  {
637  alert($e->getTraceAsString());
638  }
639  }
640 
641 }
642 
643 /**
644  * @brief Match each row of a form, this row can have several details
645  *
646  */
648 {
649 
650  /**
651  * @brief insert into rapport_advanced.formulaire_param
652  */
653  function insert()
654  {
656  $data->dr_code = $this->param->p_code;
657  $data->dr_libelle = $this->param->p_libelle;
658  $data->dr_order = $this->param->p_order;
659  $data->dr_amount = $this->amount;
660  $data->d_id = $this->d_id;
661  $data->dr_id = $this->dr_id;
662  $data->dr_type = $this->param->p_type;
663  $data->dr_start = $this->dr_start;
664  $data->dr_end = $this->dr_end;
665  $data->dr_account=$this->dr_account;
666  $data->insert();
667  }
668 
669  /**
670  * @brief set the attribute param with the content of the array.
671  * keys :
672  * - 'p_id',
673  * - 'p_code',
674  * - 'p_libelle',
675  * - 'p_type',
676  * - 'p_order',
677  * - 'f_id',
678  * - 't_id'
679  * @param type $p_array
680  */
681  function from_array($p_array)
682  {
683  $this->param = new Formulaire_Param();
684  foreach (array('p_id', 'p_code', 'p_libelle', 'p_type', 'p_order', 'f_id', 't_id') as $e)
685  {
686  $this->param->$e = $p_array[$e];
687  }
688  $this->param->load();
689 
690  }
691 
692  /**
693  * @brief compute the date following the attribute t_id (match rapport_advanced.periode_type and
694  * store the result into $this->start and $this-> end
695  * - 1 date from the FORM
696  * - 2 N
697  * - 3 N-1
698  * - 4 N-2
699  * - 5 N-3
700  * @param $p_start requested date
701  * @param $p_end requested date
702  */
703  function compute_date($p_start, $p_end)
704  {
705  global $g_user;
706  switch ($this->param->t_id)
707  {
708  case 1:
709  $this->start = $p_start;
710  $this->end = $p_end;
711  return;
712  break;
713  case 2:
714  list($this->start, $this->end) = $g_user->get_limit_current_exercice();
715  return;
716  break;
717  case 3:
718  $exercice = $g_user->get_exercice();
719  $exercice--;
720  break;
721  case 4:
722  $exercice = $g_user->get_exercice();
723  $exercice-=2;
724  break;
725  case 5:
726  $exercice = $g_user->get_exercice();
727  $exercice-=3;
728  break;
729  case 6:
730  list($this->start, $this->end) = $g_user->get_limit_current_exercice();
731  $this->end = $p_end;
732  return;
733  break;
734  default:
735  throw new Exception('compute_date : t_id est incorrect');
736  }
737  global $cn;
738 
739  // If exercice does not exist then
740  // set the date end and start to 01.01.1900
741 
742  $exist_exercice = $cn->get_value('select count(p_id) from parm_periode where p_exercice=$1', array($exercice));
743  if ($exist_exercice == 0)
744  {
745  $this->start = '01.01.1900';
746  $this->end = '01.01.1900';
747  return;
748  }
749  // Retrieve start & end date
750  $periode = new Periode($cn);
751  list($per_start, $per_end) = $periode->get_limit($exercice);
752  $this->start = $per_start->first_day();
753  $this->end = $per_end->last_day();
754  }
755  /***
756  * @brief compute amount of all the detail of apport_advanced.formulaire_param
757  * @param $p_pcm_val accounting
758  * @param $p_start requested start date
759  * @param $p_start requested end date
760  *
761  *
762  */
763 
764  function compute_child($p_pcm_val,$p_start, $p_end)
765  {
766  global $cn;
767  bcscale(2);
768  $this->amount = "0";
769 
770  $array = $cn->get_array("select fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,
771  with_tmp_val,type_sum_account,operation_pcm_val,jrn_def_id,date_paid
772  from rapport_advanced.formulaire_param_detail where p_id=$1", array($this->param->p_id));
773  $this->compute_date($p_start, $p_end);
774  for ($e = 0; $e < count($array); $e++)
775  {
776  $row_detail = Rapav_Declaration_Detail::factory($array[$e]);
777  $row_detail->form->tmp_val=$p_pcm_val;
778  $row_detail->dr_id = $this->dr_id;
779  $row_detail->d_id = $this->d_id;
780  $tmp_amount = $row_detail->compute($this->start, $this->end);
781  $this->amount = bcadd("$tmp_amount", "$this->amount");
782  $row_detail->insert();
783  }
784  }
785  /***
786  * @brief compute amount of all the detail of apport_advanced.formulaire_param
787  * @param $p_start requested start date
788  * @param $p_start requested end date
789  *
790  *
791  */
792 
793  function compute($p_start, $p_end)
794  {
795  global $cn;
796  bcscale(2);
797  $this->amount = "0";
798 
799  $array = $cn->get_array("select fp_id,p_id,tmp_val,tva_id,fp_formula,fp_signed,jrn_def_type,tt_id,type_detail,
800  with_tmp_val,type_sum_account,operation_pcm_val,jrn_def_id,date_paid
801  from rapport_advanced.formulaire_param_detail where p_id=$1", array($this->param->p_id));
802  $this->compute_date($p_start, $p_end);
803  for ($e = 0; $e < count($array); $e++)
804  {
805  $row_detail = Rapav_Declaration_Detail::factory($array[$e]);
806  $row_detail->dr_id = $this->dr_id;
807  $row_detail->d_id = $this->d_id;
808  $tmp_amount = $row_detail->compute($this->start, $this->end);
809  $this->amount = bcadd("$tmp_amount", "$this->amount");
810  $row_detail->insert();
811  }
812  }
813  /**
814  * @brief find depending accounting
815  */
816  function get_depending()
817  {
818  global $cn;
819  $accounting = $cn->get_value(" select tmp_val
820  from rapport_advanced.formulaire_param_detail
821  where p_id=$1", array($this->param->p_id));
822 
823  $array=$cn->get_array("select pcm_val,pcm_lib from tmp_pcmn where
824  pcm_val like $1||'%' order by pcm_val::text",array($accounting));
825 
826  return $array;
827  }
828 
829 }
830 
831 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
832 // Compute the detail for each row
833 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
835 {
836 
837  /**
838  * @brief create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute following the idx type_detail
839  * @param type $p_array
840  * @return object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute
841  * @throws if the type is not known
842  */
843  static function factory($p_array)
844  {
845  switch ($p_array['type_detail'])
846  {
847  case '1':
848  $ret = new Rapav_dd_Formula();
849  break;
850  case '2':
851  $ret = new Rapav_dd_Account_Tva();
852  break;
853  case '3':
854  $ret = new Rapav_dd_Compute();
855  break;
856  case '4':
857  $ret = new Rapav_dd_Account();
858  break;
859  case '5':
860  $ret = new Rapav_dd_Reconcile();
861  break;
862  case '6' :
863  // For each child we have a Rapav_dd_Account
864  $ret = new Rapav_dd_Account();
865  break;
866  default:
867  throw new Exception("Type inconnu");
868  }
869 
870  $ret->from_array($p_array);
871  $ret->ddr_amount = 0; // cannot be null
872  return $ret;
873  }
874 
875  /**
876  * @brief the p_array contains a row from formulaire_param_detail
877  * it will be copied into this->form.
878  * @param type $p_array match formulaire_param_detail table structure
879  */
880  function from_array($p_array)
881  {
882  $this->form = new Formulaire_Param_Detail();
883  $attribute = explode(',', 'fp_id,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,jrn_def_id,date_paid');
884  foreach ($attribute as $e)
885  {
886  $this->form->$e = $p_array[$e];
887  }
888  }
889 
890 }
891 
892 /**
893  * @brief compute a formula
894  * @see Impress::parse_formula RAPAV_Formula
895  */
897 {
898 
899  /**
900  * compute the amount for one detail of type formula
901  * rapport_advanced.formulaire_param_detail
902  * @global type $cn database connexion
903  * @param $p_start (date) : computed start date
904  * @param $p_end (date) computed start date
905  * @return numeric amount computed
906  */
907  function compute($p_start, $p_end)
908  {
909  global $cn;
910  $sql = "";
911  if ($this->form->jrn_def_id != null)
912  {
913  $sql = ' and j_jrn_def =' . $this->form->jrn_def_id;
914  }
915  if ($this->form->date_paid == 1)
916  {
917  $sql.=sprintf(" and j_id in ( select j_id from jrnx join jrn on (j_grpt=jr_grpt_id) where jr_date_paid >= to_date('%s','DD.MM.YYYY') and jr_date_paid <= to_date ('%s','DD.MM.YYYY'))", $p_start, $p_end);
918  $p_start = '01.01.1900';
919  $p_end = '01.01.2100';
920  }
921  if ($this->form->date_paid == 2)
922  {
923  $sql.=sprintf(" and j_id in ( select j_id from jrnx join jrn on (j_grpt=jr_grpt_id) where jr_ech >= to_date('%s','DD.MM.YYYY') and jr_ech <= to_date ('%s','DD.MM.YYYY'))", $p_start, $p_end);
924  $p_start = '01.01.1900';
925  $p_end = '01.01.2100';
926  }
927  $amount = Impress::parse_formula($cn, "", $this->form->fp_formula, $p_start, $p_end, true, 1, $sql);
928  return $amount['montant'];
929  }
930 
931 }
932 
933 /**
934  * @brief handle the param_detail type Compute
935  * @see RAPAV_Compute
936  */
938 {
939 
940  /**
941  * compute the amount for one detail
942  * rapport_advanced.formulaire_param_detail
943  * the attribute d_id and dr_id must be set before the call
944  * @global type $cn database connexion
945  * @param $p_start (date) : computed start date not used
946  * @param $p_end (date) computed start date not used
947  * @return numeric amount computed
948  */
949  function compute($p_start, $p_end)
950  {
951  global $cn;
952  $amount = 0;
953  bcscale(2);
954 
955  // copy $this->form->fp_formula to a variable
956  $formula = $this->form->fp_formula;
957 
958  // split the string from into smaller piece
959  preg_match_all("/\[([A-Z]*[0-9]*)*_*([0-9]*[A-Z]*)\]/i", $formula, $e);
960  $tmp = $e[0];
961 
962  foreach ($tmp as $piece)
963  {
964  // Find the code in the database
965  $search = str_replace('[', '', $piece);
966  $search = str_replace(']', '', $search);
967  $value = $cn->get_value('select coalesce(sum(dr_amount),0) as value
968  from rapport_advanced.declaration_row where d_id=$1 and dr_code=$2', array($this->d_id, $search));
969  $formula = str_replace($piece, $value, $formula);
970  }
971 
972  eval('$amount = ' . $formula . ';');
973  //
974  return $amount;
975  }
976 
977 }
978 
979 /**
980  * @brief handle the param_detail type Account_Tva
981  * The t_id gives the type of total
982  * - 0 TVA + Account
983  * - 1 TVA
984  * - 2 Account
985  * the jrn_def_type is either ACH or VEN
986  *
987  * @see RAPAV_Account_Tva
988  */
990 {
991 
992  /**
993  * compute the amount of tva using the given account in either the ledger ACH or VEN
994  * following the $this->form->jrn_def_type.
995  * set the $this->errcode if something wrong has happened
996  * @param $p_start start date
997  * @param $p_end end date
998  * @return amount
999  */
1000  private function compute_tva($p_start, $p_end)
1001  {
1002  $filter_ledger = "";
1003  if ($this->form->jrn_def_id != "")
1004  {
1005  $filter_ledger = " and j_jrn_def = " . sql_string($this->form->jrn_def_id);
1006  }
1007  $sql_date=RAPAV::get_sql_date($this->form->date_paid );
1008 
1009  if ($this->form->jrn_def_type == 'ACH')
1010  {
1011 
1012  $sql = "select coalesce(sum(qp_vat),0) as amount
1013  from quant_purchase join jrnx as jrn1 using (j_id)
1014  where qp_vat_code=$1
1015  $sql_date
1016  and j_poste::text like ($4) $filter_ledger";
1017  $amount = $this->cn->get_value($sql, array($this->form->tva_id,
1018  $p_start,
1019  $p_end,
1020  $this->form->tmp_val));
1021  return $amount;
1022  }
1023  if ($this->form->jrn_def_type == 'VEN')
1024  {
1025  $sql = "select coalesce(sum(qs_vat),0) as amount
1026  from quant_sold join jrnx as jrn1 using (j_id)
1027  where qs_vat_code=$1
1028  $sql_date
1029  and j_poste::text like ($4) $filter_ledger";
1030 
1031  $amount = $this->cn->get_value($sql, array($this->form->tva_id,
1032  $p_start,
1033  $p_end,
1034  $this->form->tmp_val));
1035  return $amount;
1036  }
1037  $this->errcode = 'Erreur dans le journal';
1038  return 0;
1039  }
1040 
1041  /**
1042  * compute the amount of account using the given tva_id in either the ledger ACH or VEN
1043  * following the $this->form->jrn_def_type.
1044  * Set the $this->errcode if something wrong has happened
1045  * @param $p_start start date
1046  * @param $p_end end date
1047  * @return amount
1048  * @param type $p_start
1049  * @param type $p_end
1050  * @return \amount|int
1051  */
1052  private function compute_amount($p_start, $p_end)
1053  {
1054  $filter_ledger = "";
1055  if ($this->form->jrn_def_id != "")
1056  {
1057  $filter_ledger = " and j_jrn_def = " . sql_string($this->form->jrn_def_id);
1058  }
1059  $sql_date=RAPAV::get_sql_date($this->form->date_paid );
1060 
1061  if ($this->form->jrn_def_type == 'ACH')
1062  {
1063  $sql = "select coalesce(sum(qp_price),0) as amount from quant_purchase join jrnx as jrn1 using (j_id)
1064  where qp_vat_code=$1 $sql_date
1065  and j_poste::text like ($4) $filter_ledger";
1066 
1067  $amount = $this->cn->get_value($sql, array($this->form->tva_id,
1068  $p_start,
1069  $p_end,
1070  $this->form->tmp_val));
1071  return $amount;
1072  }
1073  if ($this->form->jrn_def_type == 'VEN')
1074  {
1075  $sql = "select coalesce(sum(qs_price),0) as amount from quant_sold
1076  join jrnx as jrn1 using (j_id)
1077  where qs_vat_code=$1 $sql_date
1078  and j_poste::text like ($4) $filter_ledger";
1079  $amount = $this->cn->get_value($sql, array($this->form->tva_id,
1080  $p_start,
1081  $p_end,
1082  $this->form->tmp_val));
1083  return $amount;
1084  }
1085  $this->errcode = 'Erreur dans le journal';
1086  return 0;
1087  }
1088 
1089  /**
1090  * Compute the amount of TVA or Account, call internally private functions
1091  * @see Rapav_dd_Account_Tva::computa_amount Rapav_dd_Account_Tva::compute_tva
1092  * @param $p_start start date
1093  * @param $p_end end date
1094  * @return amount computed
1095  * @throws Exception
1096  */
1097  function compute($p_start, $p_end)
1098  {
1099  bcscale(2);
1100  // Retrieve the account for the tva_id, we need the DEB for VEN and CRED for ACH
1101  //
1102  // tt_id gives the type of total
1103  // - 0 TVA + Account
1104  // - 1 TVA
1105  // - 2 Account
1106  switch ($this->form->tt_id)
1107  {
1108  case 0:
1109  $t1_amount = $this->compute_amount($p_start, $p_end);
1110  $t2_amount = $this->compute_tva($p_start, $p_end);
1111  $amount = bcadd($t1_amount, $t2_amount);
1112  break;
1113  case 1:
1114  $amount = $this->compute_tva($p_start, $p_end);
1115  $amount = bcadd($amount, 0);
1116  break;
1117 
1118  case 2:
1119  $amount = $this->compute_amount($p_start, $p_end);
1120  $amount = bcadd($amount, 0);
1121  break;
1122 
1123  default:
1124  throw new Exception('Type de total invalide');
1125  break;
1126  }
1127  return $amount;
1128  }
1129 
1130 }
1131 
1132 /**
1133  * @brief handle the param_detail type Account
1134  * The type_sum_account gives the type of total
1135  * - 0 D-C
1136  * - 1 C-D
1137  * - 2 D
1138  * - 4 C
1139  * it uses tmp_val, with_tmp_val and type_sum_account
1140  * @see RAPAV_Account
1141  */
1143 {
1144 
1145  function compute($p_start, $p_end)
1146  {
1147  global $cn;
1148  $filter_ledger = "";
1149  if ($this->form->jrn_def_id != "")
1150  {
1151  $filter_ledger = " and jrn1.j_jrn_def = " . sql_string($this->form->jrn_def_id);
1152  }
1153 
1154  $amount=0;
1155 
1156  bcscale(2);
1157  switch ($this->form->type_sum_account)
1158  {
1159  // Saldo
1160  case 1:
1161  case 2:
1162  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1163  // Compute D-C
1164  $sql = "
1165  select sum(jrnx_amount)
1166  from (
1167  select distinct jrn1.j_id,case when jrn1.j_debit = 't' then jrn1.j_montant else jrn1.j_montant*(-1) end as jrnx_amount
1168  from jrnx as jrn1
1169  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1170  where
1171  jrn1.j_poste like $1
1172  $sql_date
1173  and
1174  jrn2.j_poste like $4
1175  $filter_ledger
1176  ) as tv_amount
1177  ";
1178  $amount = $cn->get_value($sql, array(
1179  $this->form->tmp_val,
1180  $p_start,
1181  $p_end,
1182  $this->form->with_tmp_val
1183  ));
1184  // if C-D is asked then reverse the result
1185  if ($this->form->type_sum_account == 2)
1186  $amount = bcmul($amount, -1);
1187  break;
1188  // Only DEBIT
1189  case 3:
1190  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1191  $sql = "
1192  select sum(jrnx_amount)
1193  from (
1194  select distinct jrn1.j_id,jrn1.j_montant as jrnx_amount
1195  from jrnx as jrn1
1196  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1197  where
1198  jrn1.j_poste like $1
1199  $sql_date
1200  and
1201  jrn2.j_poste like $4
1202  and
1203  jrn1.j_debit='t'
1204  $filter_ledger
1205  ) as tv_amount
1206  ";
1207  $amount = $cn->get_value($sql, array(
1208  $this->form->tmp_val,
1209  $p_start,
1210  $p_end,
1211  $this->form->with_tmp_val
1212  ));
1213  break;
1214  // Only CREDIT
1215  case 4:
1216  $sql_date=RAPAV::get_sql_date($this->form->date_paid,'jrn1' );
1217  $sql = "
1218  select sum(jrnx_amount)
1219  from (
1220  select distinct jrn1.j_id,jrn1.j_montant as jrnx_amount
1221  from jrnx as jrn1
1222  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1223  where
1224  jrn1.j_poste like $1
1225  $sql_date
1226  and
1227  jrn2.j_poste like $4
1228  and
1229  jrn1.j_debit='f'
1230  $filter_ledger
1231  ) as tv_amount
1232  ";
1233  $amount = $cn->get_value($sql, array(
1234  $this->form->tmp_val,
1235  $p_start,
1236  $p_end,
1237  $this->form->with_tmp_val,
1238  ));
1239  break;
1240 
1241  default:
1242  if (DEBUG)
1243  var_dump($this);
1244  die(__FILE__ . ":" . __LINE__ . " UNKNOW SUM TYPE");
1245  break;
1246  }
1247  /*
1248  * 4 possibilities with type_sum_account
1249  */
1250  return $amount;
1251  }
1252 
1253 }
1254 
1255 /**
1256  * @brief handle the param_detail type Account
1257  * The type_sum_account gives the type of total
1258  * - 0 D-C
1259  * - 1 C-D
1260  * - 2 D
1261  * - 4 C
1262  * it uses tmp_val, with_tmp_val and type_sum_account
1263  * @see RAPAV_Account
1264  */
1266 {
1267 
1268  function compute($p_start, $p_end)
1269  {
1270  global $cn;
1271  bcscale(2);
1272  $filter_ledger = "";
1273  if ($this->form->jrn_def_id != "")
1274  {
1275  $filter_ledger = " and jrn1.j_jrn_def = " . sql_string($this->form->jrn_def_id);
1276  }
1277  switch ($this->form->type_sum_account)
1278  {
1279  // Saldo
1280  case 1:
1281  case 2:
1282  // Compute D-C
1283  $sql = "
1284  select sum(tv_amount.jrnx_amount)
1285  from (
1286  select distinct jrn1.j_id,j1.jr_id,
1287  case when jrn1.j_debit = 't' then jrn1.j_montant else jrn1.j_montant*(-1) end as jrnx_amount
1288  from jrnx as jrn1
1289  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1290  join jrn as j1 on (jrn1.j_grpt=j1.jr_grpt_id)
1291  where
1292  jrn1.j_poste like $1
1293  and jrn2.j_poste like $2
1294  $filter_ledger
1295  ) as tv_amount
1296  join jrn_rapt as rap1 on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
1297  join (select distinct jrn3.j_id,j2.jr_id
1298  from jrnx as jrn3
1299  join jrn as j2 on (j2.jr_grpt_id=jrn3.j_grpt)
1300  where
1301  (jrn3.j_date >= to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
1302  jrn3.j_poste like $5) as reconc on (rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
1303 
1304  ";
1305  $amount = $cn->get_value($sql, array(
1306  $this->form->tmp_val,
1307  $this->form->with_tmp_val,
1308  $p_start,
1309  $p_end,
1310  $this->form->operation_pcm_val
1311  ));
1312  // if C-D is asked then reverse the result
1313  if ($this->form->type_sum_account == 2)
1314  $amount = bcmul($amount, -1);
1315  break;
1316  // Only DEBIT
1317  case 3:
1318  $sql = "
1319  select sum(tv_amount.jrnx_amount)
1320  from (
1321  select distinct jrn1.j_id,j1.jr_id,
1322  jrn1.j_montant as jrnx_amount
1323  from jrnx as jrn1
1324  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1325  join jrn as j1 on (jrn1.j_grpt=j1.jr_grpt_id)
1326  where
1327  jrn1.j_poste like $1
1328  and jrn2.j_poste like $2
1329  and jrn1.j_debit='t'
1330  $filter_ledger
1331  ) as tv_amount
1332  join jrn_rapt as rap1 on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
1333  join (select distinct jrn3.j_id,j2.jr_id
1334  from jrnx as jrn3
1335  join jrn as j2 on (j2.jr_grpt_id=jrn3.j_grpt)
1336  where
1337  (jrn3.j_date >= to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
1338  jrn3.j_poste like $5) as reconc on (rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
1339 
1340  ";
1341  $amount = $cn->get_value($sql, array(
1342  $this->form->tmp_val,
1343  $this->form->with_tmp_val,
1344  $p_start,
1345  $p_end,
1346  $this->form->operation_pcm_val
1347  ));
1348  break;
1349  // Only CREDIT
1350  case 4:
1351  $sql = "
1352  select sum(tv_amount.jrnx_amount)
1353  from (
1354  select distinct jrn1.j_id,j1.jr_id,
1355  jrn1.j_montant as jrnx_amount
1356  from jrnx as jrn1
1357  join jrnx as jrn2 on (jrn1.j_grpt=jrn2.j_grpt)
1358  join jrn as j1 on (jrn1.j_grpt=j1.jr_grpt_id)
1359  where
1360  jrn1.j_poste like $1
1361  and jrn2.j_poste like $2
1362  and jrn1.j_debit='f'
1363  $filter_ledger
1364  ) as tv_amount
1365  join jrn_rapt as rap1 on (rap1.jr_id=tv_amount.jr_id or rap1.jra_concerned=tv_amount.jr_id)
1366  join (select distinct jrn3.j_id,j2.jr_id
1367  from jrnx as jrn3
1368  join jrn as j2 on (j2.jr_grpt_id=jrn3.j_grpt)
1369  where
1370  (jrn3.j_date >= to_date($3,'DD.MM.YYYY') and jrn3.j_date <= to_date($4,'DD.MM.YYYY')) and
1371  jrn3.j_poste like $5) as reconc on (rap1.jr_id=reconc.jr_id or rap1.jra_concerned=reconc.jr_id)
1372 
1373  ";
1374  $amount = $cn->get_value($sql, array(
1375  $this->form->tmp_val,
1376  $this->form->with_tmp_val,
1377  $p_start,
1378  $p_end,
1379  $this->form->operation_pcm_val
1380  ));
1381  break;
1382 
1383  default:
1384  if (DEBUG)
1385  var_dump($this);
1386  die(__FILE__ . ":" . __LINE__ . " UNKNOW SUM TYPE");
1387  break;
1388  }
1389  /*
1390  * 4 possibilities with type_sum_account
1391  */
1392  return $amount;
1393  }
1394 
1395 }
1396 
1397 ?>
$url
compute_tva($p_start, $p_end)
compute the amount of tva using the given account in either the ledger ACH or VEN following the $this...
$ret
if(isset($_POST['save'])) $exercice
compute($p_start, $p_end)
compute the amount for one detail rapport_advanced.formulaire_param_detail the attribute d_id and dr_...
parse_document($p_dir, $p_filename, $p_type)
$periode
for($i=0;$i< Database::num_row($ret);$i++) $row
$type
Retrouve le type de row si == 3.
handle the param_detail type Compute
add_child_account(Rapav_Declaration_Param $row, $p_array, $p_start, $p_end)
$date_end
compute, save and display a declaration
compute($p_start, $p_end)
Compute the amount of TVA or Account, call internally private functions.
insert()
insert into rapport_advanced.formulaire_param
compute_interval($p_start, $p_end, $p_step)
handle the param_detail type Account The type_sum_account gives the type of total ...
global $g_parameter
Definition: ajax.php:27
compute($p_id, $p_start, $p_end, $p_step)
$cn $cn
if(isset($_POST['remove'])) $array
Match each row of a form, this row can have several details.
compute_amount($p_start, $p_end)
compute the amount of account using the given tva_id in either the ledger ACH or VEN following the $t...
from_array($p_array)
the p_array contains a row from formulaire_param_detail it will be copied into this->form.
compute_child($p_pcm_val, $p_start, $p_end)
manage the table rapport_avance.formulaire_param
$key
compute_date($p_start, $p_end)
compute the date following the attribute t_id (match rapport_advanced.periode_type and store the resu...
get_depending()
find depending accounting
$j
Definition: index.php:36
$res
static to_csv($p_id, $p_orient="list")
export a declaration to CSV $cn database conx
static factory($p_array)
create an object RAPAV_dd_Formula, RAPAV_dd_Account_Tva or Rapav_dd_compute following the idx type_de...
static get_sql_date($p_date, $p_prefix="")
Compute the SQL for the date.
Definition: class_rapav.php:84
handle the param_detail type Account The type_sum_account gives the type of total ...
handle the param_detail type Account_Tva The t_id gives the type of total
if(isset($_POST['save'])) if(isset($_GET['compute'])) $date_start
$_REQUEST['sb']
Definition: am_print.php:39
$sql
special_tag($p_dir, $p_filename, $p_type)
global $cn
from_array($p_array)
set the attribute param with the content of the array.
compute($p_start, $p_end)
compute the amount for one detail of type formula rapport_advanced.formulaire_param_detail type $cn ...