Plugins  LAST
 All Data Structures Files Functions Variables Pages
Public Member Functions | Static Public Member Functions
Rapav_Declaration Class Reference

compute, save and display a declaration More...

Inheritance diagram for Rapav_Declaration:
Inheritance graph
Collaboration diagram for Rapav_Declaration:
Collaboration graph

Public Member Functions

 __construct ()
 
 load_formulaire ()
 
 get_file_to_parse ()
 
 generate_document ()
 
 parse_document ($p_dir, $p_filename, $p_type)
 
 special_tag ($p_dir, $p_filename, $p_type)
 
 load_document ($p_file)
 
 compute ($p_id, $p_start, $p_end, $p_step)
 $cn $cn More...
 
 add_child_account (Rapav_Declaration_Param $row, $p_array, $p_start, $p_end)
 
 compute_interval ($p_start, $p_end, $p_step)
 
 get_interval ($p_step)
 
 anchor_document ()
 
 display ()
 
 save ()
 

Static Public Member Functions

static to_csv ($p_id, $p_orient="list")
 export a declaration to CSV $cn database conx More...
 

Detailed Description

compute, save and display a declaration

Definition at line 37 of file class_rapav_declaration.php.

Constructor & Destructor Documentation

Rapav_Declaration::__construct ( )

Definition at line 40 of file class_rapav_declaration.php.

41  {
42  $this->form = new RAPAV_Formulaire();
43  parent::__construct();
44  }

Member Function Documentation

Rapav_Declaration::add_child_account ( Rapav_Declaration_Param  $row,
  $p_array,
  $p_start,
  $p_end 
)

Definition at line 533 of file class_rapav_declaration.php.

References $cn, $j, Rapav_Declaration_Param\compute_child(), Rapav_Declaration_Param\from_array(), Rapav_Declaration_Param\get_depending(), and Rapav_Declaration_Param\insert().

Referenced by compute().

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  }
insert()
insert into rapport_advanced.formulaire_param
Match each row of a form, this row can have several details.
compute_child($p_pcm_val, $p_start, $p_end)
get_depending()
find depending accounting
$j
Definition: index.php:36
global $cn
from_array($p_array)
set the attribute param with the content of the array.
Rapav_Declaration::anchor_document ( )

Definition at line 606 of file class_rapav_declaration.php.

References $url.

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  }
$url
Rapav_Declaration::compute (   $p_id,
  $p_start,
  $p_end,
  $p_step 
)

$cn $cn

Parameters
type$p_id
type$p_start
type$p_end
type$p_step

if step != 0, recompute the date

children must be inserted into DECLARATION_ROW and DECLARARION_ROW_DETAIL for each depending accounting impact also order(use of decimal)

children must be inserted into DECLARATION_ROW and DECLARARION_ROW_DETAIL for each depending accounting impact also order(use of decimal)

Definition at line 431 of file class_rapav_declaration.php.

References $array, $cn, $row, add_child_account(), and compute_interval().

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  }
for($i=0;$i< Database::num_row($ret);$i++) $row
add_child_account(Rapav_Declaration_Param $row, $p_array, $p_start, $p_end)
compute_interval($p_start, $p_end, $p_step)
if(isset($_POST['remove'])) $array
Match each row of a form, this row can have several details.
global $cn
Rapav_Declaration::compute_interval (   $p_start,
  $p_end,
  $p_step 
)

Definition at line 565 of file class_rapav_declaration.php.

References $date_end, $date_start, and get_interval().

Referenced by compute().

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  }
$date_end
if(isset($_POST['save'])) if(isset($_GET['compute'])) $date_start
Rapav_Declaration::display ( )

Definition at line 613 of file class_rapav_declaration.php.

References $array, $cn, and d_id.

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  }
if(isset($_POST['remove'])) $array
global $cn
Rapav_Declaration::generate_document ( )

Definition at line 174 of file class_rapav_declaration.php.

References $cn, $res, $type, get_file_to_parse(), load_document(), parse_document(), and special_tag().

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  }
parse_document($p_dir, $p_filename, $p_type)
$type
Retrouve le type de row si == 3.
$res
special_tag($p_dir, $p_filename, $p_type)
global $cn
Rapav_Declaration::get_file_to_parse ( )

Definition at line 126 of file class_rapav_declaration.php.

References $cn, and $type.

Referenced by generate_document().

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  }
$type
Retrouve le type de row si == 3.
global $cn
Rapav_Declaration::get_interval (   $p_step)

Definition at line 600 of file class_rapav_declaration.php.

Referenced by compute_interval().

601  {
602  $array_interval = array("", "P7D", "P14D", "P1M", "P2M", "P3M",'P6M','P1Y');
603  return new DateInterval($array_interval[$p_step]);
604  }
Rapav_Declaration::load_document (   $p_file)

Definition at line 406 of file class_rapav_declaration.php.

References $cn, and $date.

Referenced by generate_document().

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  }
global $cn
Rapav_Declaration::load_formulaire ( )

Definition at line 45 of file class_rapav_declaration.php.

45  {
46  $this->form->load();
47  }
Rapav_Declaration::parse_document (   $p_dir,
  $p_filename,
  $p_type 
)

Definition at line 213 of file class_rapav_declaration.php.

References $array, $cn, $ifile, $key, $p_type, $ret, and d_id.

Referenced by generate_document().

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  }
$ret
if(isset($_POST['remove'])) $array
$key
global $cn
Rapav_Declaration::save ( )

Definition at line 620 of file class_rapav_declaration.php.

References $amount, and $cn.

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  }
global $cn
Rapav_Declaration::special_tag (   $p_dir,
  $p_filename,
  $p_type 
)

Definition at line 333 of file class_rapav_declaration.php.

References $_REQUEST, $array, $cn, $g_parameter, $ifile, $key, $p_type, $ret, and d_description.

Referenced by generate_document().

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  }
$ret
global $g_parameter
Definition: ajax.php:27
if(isset($_POST['remove'])) $array
$key
$_REQUEST['sb']
Definition: am_print.php:39
global $cn
static Rapav_Declaration::to_csv (   $p_id,
  $p_orient = "list" 
)
static

export a declaration to CSV $cn database conx

Parameters
$p_idpk of rapav_declaration
$p_orientvalue :
  • list : for a list
  • table : to have a table (if using step)

Definition at line 57 of file class_rapav_declaration.php.

References $cn, and $title.

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  }
global $cn

The documentation for this class was generated from the following file: