noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
document.class.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// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!
23 * \file
24 * \brief Class Document corresponds to the table document
25 */
26/*!
27 * \class
28 * \brief
29 * Class Document corresponds to the table DOCUMENT
30 */
31
33{
34
35 var $db; /*!< $db Database connexion */
36 var $d_id; /*!< $d_id Document id */
37 var $ag_id; /*!< $ag_id action_gestion.ag_id (pk) */
38 var $d_mimetype; /*!< $d_mimetype */
39 var $d_filename; /*!< $d_filename */
40 var $d_lob; /*!< $d_lob the oid of the lob */
41 var $d_description; /*!< Description of the file */
42 var $d_number; /*!< $d_number number of the document */
43 var $md_id; /*!< $md_id document's template */
44 var $f_id; /*!< fiche.f_id */
45 protected $counter; /*!< counter for the items ( goods ) */
46 var $d_name; /*!< document name */
47 var $md_type ; /*!< Type of document */
48 /*!
49 * @brief Constructor
50 * \param $p_cn Database connection
51 */
52
53 function __construct($p_cn, $p_d_id=0)
54 {
55 $this->db=$p_cn;
56 $this->d_id=$p_d_id;
57
58 // counter for MARCH_NEXT
59 $this->counter=0;
60 }
61
62 function __toString(): string
63 {
64 return "Document[db=" . $this->db
65 . ", d_id=" . $this->d_id
66 . ", ag_id=" . $this->ag_id
67 . ", d_mimetype=" . $this->d_mimetype
68 . ", d_filename=" . $this->d_filename
69 . ", d_lob=" . $this->d_lob
70 . ", d_description=" . $this->d_description
71 . ", d_number=" . $this->d_number
72 . ", md_id=" . $this->md_id
73 . ", f_id=" . $this->f_id
74 . ", counter=" . $this->counter
75 . ", d_name=" . $this->d_name
76 . ", md_type=" . $this->md_type
77 . "]";
78 }
79
80 /**
81 * @brief insert a minimal document and set the d_id
82 */
83 function blank()
84 {
85 $this->d_id=$this->db->get_next_seq("document_d_id_seq");
86 // affect a number
87 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
88 $sql='insert into document(d_id,ag_id,d_number) values($1,$2,$3)';
89
90 $this->db->exec_sql($sql,
91 array
92 ($this->d_id,
93 $this->ag_id,
94 $this->d_number));
95 }
96
97 /**
98 * @brief Insert the receipt number into the filename , each generated file
99 * will have the name of the template (model) + receipt number)
100 * @param type $pj the receipt number
101 * @param type $filename the name of the file
102 * @return string
103 */
104 function compute_filename($pj, $filename)
105 {
106 $pos_prefix=strrpos($filename, ".");
107 if ($pos_prefix==0)
108 $pos_prefix=strlen($filename);
109 $filename_no=substr($filename, 0, $pos_prefix);
110 $filename_suff=substr($filename, $pos_prefix, strlen($filename));
111
112 foreach (array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']',"'") as $i)
113 {
114 $pj=noalyss_str_replace($i, "-", $pj);
115 $filename_no=noalyss_str_replace($i,"-",$filename_no);
116 }
117
118
119 $new_filename=strtolower($filename_no."-".$pj.$filename_suff);
120 $pj=noalyss_str_replace("---","-",$pj);
121 $pj=noalyss_str_replace("--","-",$pj);
122 $new_filename=noalyss_str_replace("---","-",$new_filename);
123 $new_filename=noalyss_str_replace("--","-",$new_filename);
124 return $new_filename;
125 }
126
127 /*!
128 * \brief Generate the document, Call $this->replace to replace
129 * tag by value
130 * @param p_array contains the data normally it is the $_POST (see Acc_Ledger_Sale or
131 * Acc_Ledger_Purchase)
132 * @see Acc_Ledger_Sale
133 * @see Acc_Ledger_Purchase
134 * @param $p_filename contains the new filename, if not given the filename will be generated
135 * \return an string : the url where the generated doc can be found, the name
136 * of the file and his mimetype
137 */
138
139 function generate($p_array, $p_filename="")
140 {
141
142 try {
143 ///@var $dirname (string) temp directory in /tmp to unpack file and to parse it
144 $dirname=tempnam($_ENV['TMP'], 'doc_');
145 if ($dirname == false) {
146 throw new Exception ('DC117 cannot create tmp file',5000);
147 }
148
149 unlink($dirname);
150 if ( mkdir($dirname) == false ) {
151 throw new Exception ("DC121 cannot create $dirname directory",5000);
152 }
153 /**
154 * md_id == -2 : INVOICE_STD is the standard PDF invoice, you don't parse or compute
155 * it
156 */
157 if ( $this->md_id == INVOICE_STD)
158 {
159 $file_to_parse=str_replace(
160 array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']')
161 , "-"
162 , "inv-std-".$p_array['e_pj']).".pdf";
163
164 $this->d_number=$this->db->get_next_seq("seq_doc_type_stdinv");
165 $this->d_filename=$file_to_parse;
166 $this->d_mimetype="application/pdf";
167 $this->d_name=$file_to_parse;
168 $standard_invoice=new \Noalyss\Invoice_PDF($this->db,$dirname,$file_to_parse);
169 $standard_invoice->set_data($p_array);
170 $standard_invoice->export();
171 $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
172 // Invoice
173 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
174 $ret='<A class="mtitle" HREF="export.php?'.$href.'">'._('Document').'</A>';
175 return $ret;
176 }
177
178 // Retrieve the lob and save it into $dirname
179 $this->db->start();
180 $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
181 from document_modele where md_id=$1";
182 $Res=$this->db->exec_sql($dm_info, [$this->md_id]);
183
185 $this->d_lob=$row['md_lob'];
186 $this->d_filename=$row['md_filename'];
187 $this->d_mimetype=$row['md_mimetype'];
188 $this->d_name=$row['md_name'];
189
190
191 chdir($dirname);
192 $filename=($p_filename == "")?$row['md_filename']:$p_filename;
193 $filename= sanitize_filename($filename,false);
194 $exp=$this->db->lo_export($row['md_lob'], $dirname.DIRECTORY_SEPARATOR.$filename);
195 if ($exp===false)
196 {
197 record_log(sprintf('DOCUMENT.GENERATE.D1 , export failed %s %s',$dirname, $filename));
198 throw new Exception(sprintf(_("Export a échoué pour %s"), $filename));
199 }
200 // $type (letter) type of document : OOo for openoffice otherwise n , with OOo the file
201 // is a ZIP XML
202 $type="n";
203 // if the doc is a OOo, we need to unzip it first
204 // and the name of the file to change is always content.xml
205 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
206 {
207 ob_start();
208 $zip=new Zip_Extended;
209 if ($zip->open($filename)===TRUE)
210 {
211 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
212 $zip->close();
213 }
214 else
215 {
216 record_log(sprintf('DOCUMENT.GENERATE.D2 unzip failed %s', $filename));
217 throw new Exception(sprintf(_("Décompression a échoué %s", $filename)));
218 }
219
220 // Remove the file we do not need anymore
221 unlink($filename);
222 ob_end_clean();
223 $file_to_parse="content.xml";
224 $type="OOo";
225 }
226 else
227 {
228 $file_to_parse=$filename;
229 }
230 // affect a number
231 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
232
233 // parse the document - return the doc number ?
234 $this->parseDocument($dirname, $file_to_parse, $type, $p_array);
235
236 $this->db->commit();
237 // if the doc is a OOo, we need to re-zip it
238 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
239 {
240 ob_start();
241 $zip=new Zip_Extended;
242 $res=$zip->open($filename, ZipArchive::CREATE);
243 if ($res!==TRUE)
244 {
245 record_log(sprintf('DOCUMENT.GENERATE.D3 zip failed %s', $filename));
246 throw new Exception(_('Echec compression'),5000);
247 }
248 $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
249 $zip->close();
250
251 ob_end_clean();
252
253 $file_to_parse=$filename;
254 }
255 if ($p_filename!="")
256 {
257 $this->d_filename=$this->compute_filename($p_filename, $this->d_filename);
258 }
259 $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
260 // Invoice
261 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
262 $ret='<A class="mtitle" HREF="export.php?'.$href.'">'._('Document').'</A>';
263
264 return $ret;
265 } catch (Exception $e) {
266 record_log($e);
267 return span(_("Génération du document a échoué"),'class="notice"');
268 }
269 }
270
271 /**
272 *
273 * \brief This function parse a document and replace all
274 * the predefined tags by a value. This functions
275 * generate diffent documents (invoice, order, letter)
276 * with the info from the database
277 *
278 * \param $p_dir directory name
279 * \param $p_file filename
280 * \param $p_type For the OOo document the tag are &lt and &gt instead of < and >
281 * \param $p_array variable from $_POST
282 */
283
284 function parseDocument($p_dir, $p_file, $p_type, $p_array)
285 {
286
287 /*!\note replace in the doc the tags by their values.
288 * - MY_* table parameter
289 * - ART_VEN* table quant_sold for invoice
290 * - CUST_* table quant_sold and fiche for invoice
291 * - e_* for the invoice in the $_POST
292 */
293 // open the document
294 $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
295 $h=fopen($infile_name, "r");
296
297 // check if tmpdir exist otherwise create it
298 $temp_dir=$_ENV['TMP'];
299 if (is_dir($temp_dir)==false)
300 {
301 if (mkdir($temp_dir)==false)
302 {
303 $msg=sprintf("D221."._("Ne peut pas créer le répertoire %s"), $temp_dir);
304 record_log("D221".$msg);
305 throw new Exception($msg);
306 }
307 }
308 // Compute output_name
309 $output_name=tempnam($temp_dir, "gen_doc_");
310 $output_file=fopen($output_name, "w+");
311 // check if the opening is sucessfull
312 if ($h===false)
313 {
314 $msg=sprintf("D232"._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $p_file);
315 record_log("D232".$msg);
316 throw new Exception($msg);
317 }
318 if ($output_file==false)
319 {
320 $msg=sprintf("D264."._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $output_name);
322 throw new Exception($msg);
323 }
324 // compute the regex
325 if ($p_type=='OOo')
326 {
327 $regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
328 $lt="&lt;";
329 $gt="&gt;";
330 }
331 else
332 {
333 $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
334 $lt="<";
335 $gt=">";
336 }
337 //read the file
338 while (!feof($h))
339 {
340 // replace the tag
341 $buffer=fgets($h);
342 // search in the buffer the magic << and >>
343 // while preg_match_all finds something to replace
344 while (preg_match_all($regex, $buffer, $f)>0)
345 {
346
347 foreach ($f as $apattern)
348 {
349
350 foreach ($apattern as $pattern)
351 {
352
353
354 $to_remove=$pattern;
355 // we remove the < and > from the pattern
356 $tag=noalyss_str_replace($lt, '', $pattern);
357 $tag=noalyss_str_replace($gt, '', $tag);
358
359
360 // if the pattern if found we replace it
361 $value=$this->replace($tag, $p_array);
362 if (strpos($value??"", 'ERROR')!=false)
363 $value="";
364 /*
365 * Change type of cell to numeric
366 * allow numeric cel in ODT for the formatting and formula
367 */
368
369 $buffer=\Document::replace_value($buffer, $pattern, $value, 1, $p_type);
370 }
371 }
372 }
373 // write into the output_file
374 fwrite($output_file, $buffer);
375 }
376 fclose($h);
377 fclose($output_file);
378 if (($ret=copy($output_name, $infile_name))==FALSE)
379 {
380 $msg="D299 ".sprintf(_('Ne peut pas sauver [%s] vers [%s] code erreur = [%s]'), $output_name, $infile_name,
381 $ret);
383 throw new Exception($msg);
384 }
385 }
386
387 /*!
388 * \brief insert the generated Document into the database, update the $this->d_id
389 * that is the PK of document. and load the PDF into the database.
390 * \param $p_file is the generated file
391 * \return 0 if no error otherwise 1
392 */
393 protected function saveGenerated($p_file)
394 {
395 // We save the generated file
396 $doc=new Document($this->db);
397 $this->db->start();
398 $this->d_lob=$this->db->lo_import($p_file);
399 if ($this->d_lob==false)
400 {
401 echo "ne peut pas importer [$p_file]";
402 return 1;
403 }
404
405 $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
406 values ($1,$2,$3,$4,$5)";
407
408 $this->db->exec_sql($sql,
409 array($this->ag_id,
410 $this->d_lob,
411 $this->d_number,
412 $this->d_filename,
413 $this->d_mimetype));
414 $this->d_id=$this->db->get_current_seq("document_d_id_seq");
415 // Clean the file
416 unlink($p_file);
417 $this->db->commit();
418 return 0;
419 }
420
421 /**
422 * @brief Download all documents in a ZIP files. The parameters is an array of Document, see
423 * DOcument::get_all
424 *
425 * @param array of Document $aDocument
426 *
427 * @see Document::get_all()
428 */
429 function download($aDocument)
430 {
431
432 if (empty($aDocument)||is_array($aDocument)==false)
433 {
434 throw new Exception("Document.download expects an array");
435 }
436 // make a temp folder
437 $dirname=tempnam($_ENV['TMP'], 'document_dwnall');
438 unlink($dirname);
439 mkdir($dirname);
440
441 // download each file into that folder
442 $nb_document=count($aDocument);
443 $nCopy=0;
444
445 // start a transaction to be able to export LOB
446 $this->db->start();
447 for ($i=0; $i<$nb_document; $i++)
448 {
449 // check that aDocument elt is a document object
450 if ( ! $aDocument[$i] instanceof Document ) {
451 throw new Exception("Document.download.2 element is not a document object");
452 }
453 $filename=$dirname.DIRECTORY_SEPARATOR.$aDocument[$i]->d_filename;
454 // if file exists then add a number
455 if (file_exists($filename))
456 {
457
458 while (true)
459 {
460 $nCopy++;
461 $filename=$dirname.DIRECTORY_SEPARATOR.$nCopy."-".$aDocument[$i]->d_filename;
462 if (!file_exists($filename))
463 {
464 $nCopy=0;
465 break;
466 }
467 } // end while true
468 } // end if fileexist
469 // export file
470 $this->db->lo_export($aDocument[$i]->d_lob,$filename);
471 } // end for $i
472 // make a large PDF and send it
473 $zip=new Zip_Extended();
474 $name="document-".date ("Ymd-His").".zip";
475 if ( $zip->open($_ENV['TMP'].DIRECTORY_SEPARATOR.$name , ZipArchive::CREATE) != true)
476 {
477 die("Cannot create zip file");
478 }
479 $zip->add_recurse_folder($dirname . "/");
480 $zip->close();
481 // send it to stdout
482 ini_set('zlib.output_compression', 'off');
483 header("Pragma: public");
484 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
485 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
486 header("Cache-Control: must-revalidate");
487 header('Content-type: zip/application');
488 header('Content-Disposition: attachment;filename="'.$name.'"', FALSE);
489 header("Accept-Ranges: bytes");
490 $file=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR.$name, 'r');
491 while (!feof($file))
492 {
493 echo fread($file, 8192);
494 }
495 fclose($file);
496
497 $this->db->commit();
498
499 }
500
501 /**
502 * @brief upload a file into document
503 * all the needed data are in $_FILES we don't increment the seq
504 * $_FILES : array containing by default $_FILES
505 * @param int $p_ag_id ACTION_GESTION.AG_ID
506 * @returns array of int DOCUMENT.D_ID (id of saved documents )
507 *
508 */
509 function upload($p_ag_id)
510 {
511 // nothing to save
512 if (sizeof($_FILES)==0)
513 return;
514
515 /* for several files */
516 /* $_FILES is now an array */
517 // Start Transaction
518 $this->db->start();
519 $name=$_FILES['file_upload']['name'];
520 $document_saved=array();
521 $http=new HttpInput();
522 $aDescription=$http->post("input_desc","array",array());
523 $description="";
524 for ($i=0; $i<sizeof($name); $i++)
525 {
526 $new_name=tempnam($_ENV['TMP'], 'doc_');
527 // check if a file is submitted
528 if (strlen($_FILES['file_upload']['tmp_name'][$i])!=0)
529 {
530 // upload the file and move it to temp directory
531 if (move_uploaded_file($_FILES['file_upload']['tmp_name'][$i], $new_name))
532 {
533 $oid=$this->db->lo_import($new_name);
534 // check if the lob is in the database
535 if ($oid==false)
536 {
537 $this->db->rollback();
538 return 1;
539 }
540 }
541 // the upload in the database is successfull
542 $this->d_lob=$oid;
543 $this->d_filename=$_FILES['file_upload']['name'][$i];
544 $this->d_mimetype=$_FILES['file_upload']['type'][$i];
545 if ( isset($aDescription[$i])) {
546 $description=strip_tags($aDescription[$i]??"");
547 }
548 $this->d_description=$description;
549 // insert into the table
550 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description)"
551 . " values ($1,$2,$3,$4,$5,$6) returning d_id";
552 $document_id=$this->db->get_value($sql,
553 array($p_ag_id, $this->d_lob, $this->d_filename, $this->d_mimetype, 1, $this->d_description));
554
555
556 $document_saved[]=$document_id;
557
558 }
559 } /* end for */
560 $this->db->commit();
561 return $document_saved;
562 }
563
564 /**
565 * Copy a existing OID (LOB) into the table document
566 * @note use of global variable $cn which is the db connx to the current folder
567 * @param type $p_ag_id Follow_Up::ag_id
568 * @param type $p_lob oid of existing document
569 * @param type $p_filename filename of existing document
570 * @param type $p_mimetype mimetype of existing document
571 * @param type $p_description Description of existing document (default empty)
572 */
573 static function insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
574 {
575 global $cn;
576 // insert into the table
577 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) "
578 . "values ($1,$2,$3,$4,$5,$6)";
579 $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
580 }
581
582 /*!
583 * \brief create and compute a string for reference the doc <A ...>
584 *
585 * \return a string
586 */
587
588 function anchor()
589 {
590 if ($this->d_id==0)
591 return '';
592 $image='<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.'" border="0">';
593 $r="";
594 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
595
596 $r='<A class="mtitle" HREF="export.php?'.$href.'">'.$image.'</A>';
597 return $r;
598 }
599
600 /**
601 * \brief send the document
602 */
603 function send()
604 {
605 // retrieve the template and generate document
606 $this->db->start();
607 $ret=$this->db->exec_sql(
608 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
609
610 if (Database::num_row($ret)==0)
611 {
612 // send it to stdout
613 ini_set('zlib.output_compression', 'Off');
614 header("Pragma: public");
615 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
616 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
617 header("Cache-Control: must-revalidate");
618 header('Content-type: text');
619 header('Content-Disposition: attachment;filename="vide.txt"', FALSE);
620 header("Accept-Ranges: bytes");
621 echo "VIDE-EMPTY";
622 return;
623 }
625 //the document is saved into file $tmp
626 $tmp=tempnam($_ENV['TMP'], 'document_');
627 $this->db->lo_export($row['d_lob'], $tmp);
628 $this->d_mimetype=$row['d_mimetype'];
629 $this->d_filename=$row['d_filename'];
630 $file=fopen($tmp, 'r');
631 // send it to stdout
632 ini_set('zlib.output_compression', 'Off');
633 header("Pragma: public");
634 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
635 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
636 header("Cache-Control: must-revalidate");
637 header('Content-type: '.$this->d_mimetype);
638 header('Content-Disposition: attachment;filename="'.$this->d_filename.'"', FALSE);
639 header("Accept-Ranges: bytes");
640 while (!feof($file))
641 {
642 echo fread($file, 8192);
643 }
644 fclose($file);
645
646 unlink($tmp);
647 $this->db->commit();
648 }
649
650 /**
651 * \brief get all the document of a given action
652 * \param $ag_id the ag_id from action::ag_id (primary key)
653 * \return an array of objects document or an empty array if nothing found
654 */
655
656 function get_all($ag_id)
657 {
658 $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
659 ' d_mimetype,d_description from document where ag_id=$1', array($ag_id));
660 $a=array();
661 for ($i=0; $i<sizeof($res); $i++)
662 {
663 $doc=new Document($this->db);
664 $doc->d_id=$res[$i]['d_id'];
665 $doc->ag_id=$res[$i]['ag_id'];
666 $doc->d_lob=$res[$i]['d_lob'];
667 $doc->d_number=$res[$i]['d_number'];
668 $doc->d_filename=$res[$i]['d_filename'];
669 $doc->d_mimetype=$res[$i]['d_mimetype'];
670 $doc->d_description=$res[$i]['d_description'];
671 $a[$i]=clone $doc;
672 }
673 return $a;
674 }
675
676
677 /**
678 * \brief Get complete all the data member thx info from the database
679 */
680
681 function get()
682 {
683 $sql="select * from document where d_id=$1";
684 $ret=$this->db->exec_sql($sql,[$this->d_id]);
685 if (Database::num_row($ret)==0)
686 {
687 return;
688 }
690 $this->ag_id=$row['ag_id'];
691 $this->d_mimetype=$row['d_mimetype'];
692 $this->d_filename=$row['d_filename'];
693 $this->d_lob=$row['d_lob'];
694 $this->d_number=$row['d_number'];
695 $this->d_description=$row['d_description'];
696 }
697
698 /*!
699 * \brief replace the TAG by the real value, this value can be into
700 * the database or in $_POST
701 * The possible tags are
702 * - [CUST_NAME] customer's name
703 * - [CUST_ADDR_1] customer's address line 1
704 * - [CUST_CP] customer's ZIP code
705 * - [CUST_CO] customer's country
706 * - [CUST_CITY] customer's city
707 * - [CUST_VAT] customer's VAT
708 * - [MARCH_NEXT] end this item and increment the counter $i
709 * - [DATE_LIMIT]
710 * - [VEN_ART_NAME]
711 * - [VEN_ART_PRICE]
712 * - [VEN_ART_QUANT]
713 * - [VEN_ART_TVA_CODE]
714 * - [VEN_ART_STOCK_CODE]
715 * - [VEN_HTVA]
716 * - [VEN_TVAC]
717 * - [VEN_TVA]
718 * - [TOTAL_VEN_HTVA]
719 * - [DATE_CALC]
720 * - [DATE]
721 * - [DATE_LIMIT]
722 * - [DATE_LIMIT_CALC]
723 * - [NUMBER]
724 * - [MY_NAME]
725 * - [MY_POSTCODE]
726 * - [MY_CITY]
727 * - [MY_TVA]
728 * - [MY_STREET]
729 * - [MY_NUMBER]
730 * - [TVA_CODE]
731 * - [TVA_RATE]
732 * - [BON_COMMANDE]
733 * - [OTHER_INFO]
734 * - [CUST_NUM]
735 * - [CUST_BANQUE_NAME]
736 * - [CUST_BANQUE_NO]
737 * - [USER]
738 * - [REFERENCE]
739 * - [BENEF_NAME]
740 * - [BENEF_BANQUE_NAME]
741 * - [BENEF_BANQUE_NO]
742 * - [BENEF_ADDR_1]
743 * - [BENEF_CP]
744 * - [BENEF_CO]
745 * - [BENEF_CITY]
746 * - [BENEF_VAT]
747 * - [ACOMPTE]
748 * - [TITLE]
749 * - [DESCRIPTION]
750 * - [COMM_PAYMENT]
751 * - [LABELOP]
752 * - [COMMENT]
753 * - [DESCRIPTION]
754 * - [DOCUMENT_ID]
755 * - [DATE_PAID]
756 * - [NOTE] Note from SALE or PURCHASE
757 *
758 * \param $p_tag TAG
759 * \param $p_array data from $_POST
760 * \return String which must replace the tag
761 */
762
763 function replace($p_tag, $p_array)
764 {
765 global $g_parameter,$g_user;
766 $p_tag=strtoupper($p_tag);
767 $p_tag=noalyss_str_replace('=', '', $p_tag);
768 $r="Tag inconnu";
769 static $aComment=NULL;
770 static $counter_comment=1; /*<! counter for the comment , skip the first one which is the descrition */
771
772 static $aRelatedAction=NULL;
773 static $counter_related_action=0; /*<! counter for the related action */
774
775 static $aRelatedOperation=NULL;
776 static $counter_related_operation=0; /*<! counter for the related operation */
777
778 static $aFileAttached=NULL;
779 static $counter_file=0; /*<! counter for the file */
780
781 static $aOtherCard=NULL;
782 static $counter_other_card=0; /*<! counter for the other card */
783
784 static $aTag=NULL;
785 static $counter_tag=0; /*<! counter for the tags */
786
787 static $aParameterExtra=NULL; // Extra parameter for the company
788 switch ($p_tag)
789 {
790 case 'DATE':
791 $r=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
792 break;
793 case 'DATE_CALC':
794 $r=' ';
795 // Date are in $p_array['ag_date']
796 // or $p_array['e_date']
797 if (isset($p_array['ag_timestamp']))
798 {
799 $date=format_date($p_array['ag_timestamp'], 'DD.MM.YYYY', 'YYYY-MM-DD');
800 $r=$date;
801 }
802 if (isset($p_array['e_date']))
803 {
804 $date=format_date($p_array['e_date'], 'DD.MM.YYYY', 'YYYY-MM-DD');
805 $r=$date;
806 }
807 return $r;
808 break;
809 //
810 // the company priv
811
812 case 'MY_NAME':
813 $r=$g_parameter->MY_NAME;
814 break;
815 case 'MY_POSTCODE':
816 case 'MY_CP':
817 $r=$g_parameter->MY_POSTCODE;
818 break;
819 case 'MY_CITY':
820 case 'MY_COMMUNE':
821 $r=$g_parameter->MY_CITY;
822 break;
823 case 'MY_TVA':
824 $r=$g_parameter->MY_TVA;
825 break;
826 case 'MY_STREET':
827 $r=$g_parameter->MY_STREET;
828 break;
829 case 'MY_NUMBER':
830 $r=$g_parameter->MY_NUMBER;
831 break;
832 case 'MY_PHONE':
833 case 'MY_TEL':
834 $r=$g_parameter->MY_PHONE;
835 break;
836 case 'MY_FAX':
837 $r=$g_parameter->MY_FAX;
838 break;
839 case 'MY_COUNTRY':
840 case 'MY_PAYS':
841 $r=$g_parameter->MY_COUNTRY;
842 break;
843
844
845
846 // customer
847 /**
848 * \note The CUST_* are retrieved thx the $p_array['tiers']
849 * which contains the quick_code
850 */
851 case 'SOLDE':
852 $tiers=new Fiche($this->db);
853 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
854 $tiers->get_by_qcode($qcode, false);
855 $p=$tiers->get_attribute(ATTR_DEF_ACCOUNT,0);
856 // if exercice is open with a report, 1 day is 1st exercice's day
857 if ( $g_parameter->MY_REPORT == 'Y') {
858 // var $user_exercice (int) current user exercice (from his preference)
859 $user_exercice=$g_user->get_exercice();
860 // var $start_date (text) First day of this exercice
861 $start_date=$this->db->get_value("
862 select to_char(min(p_start),'YYYYMMDD') first_day
863 from parm_periode where p_exercice=$1"
864 ,[$user_exercice]);
865 // var $end_date (text) last day of this exercice
866 $end_date =$this->db->get_value("
867 select to_char(max(p_end),'YYYYMMDD') last_day
868 from parm_periode where p_exercice=$1"
869 ,[$user_exercice]);
870 $a=$tiers->get_solde_detail(" to_char(jrnx.j_date,'YYYYMMDD')>='{$start_date}' and to_char(jrnx.j_date,'YYYYMMDD') <= '{$end_date}' ");
871 $r = round($a['solde'],4);
872 }else {
873 $a=$tiers->get_solde_detail();
874 $r = round($a['solde'],4);
875 }
876 break;
877 case 'CUST_NAME':
878 $tiers=new Fiche($this->db);
879 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
880 $tiers->get_by_qcode($qcode, false);
881 $r=$tiers->get_attribute(ATTR_DEF_NAME,0);
882 break;
883 case 'CUST_ADDR_1':
884 $tiers=new Fiche($this->db);
885 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
886 $tiers->get_by_qcode($qcode, false);
887 $r=$tiers->get_attribute(ATTR_DEF_ADRESS,0);
888
889 break;
890 case 'CUST_CP':
891 $tiers=new Fiche($this->db);
892
893 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
894 $tiers->get_by_qcode($qcode, false);
895 $r=$tiers->get_attribute(ATTR_DEF_POSTCODE,0);
896
897 break;
898 case 'CUST_CITY':
899 $tiers=new Fiche($this->db);
900
901 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
902 $tiers->get_by_qcode($qcode, false);
903 $r=$tiers->get_attribute(ATTR_DEF_CITY,0);
904
905 break;
906
907 case 'CUST_CO':
908 $tiers=new Fiche($this->db);
909
910 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
911 $tiers->get_by_qcode($qcode, false);
912 $r=$tiers->get_attribute(ATTR_DEF_COUNTRY,0);
913
914 break;
915 // Marchandise in $p_array['e_march*']
916 // \see user_form_achat.php or user_form_ven.php
917 case 'CUST_VAT':
918 $tiers=new Fiche($this->db);
919
920 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
921 $tiers->get_by_qcode($qcode, false);
922 $r=$tiers->get_attribute(ATTR_DEF_NUMTVA,0);
923 break;
924 case 'CUST_NUM':
925 $tiers=new Fiche($this->db);
926 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
927 $tiers->get_by_qcode($qcode, false);
928 $r=$tiers->get_attribute(ATTR_DEF_NUMBER_CUSTOMER,0);
929 break;
930 case 'CUST_BANQUE_NO':
931 $tiers=new Fiche($this->db);
932 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
933 $tiers->get_by_qcode($qcode, false);
934 $r=$tiers->get_attribute(ATTR_DEF_BQ_NO,0);
935 break;
936 case 'CUST_BANQUE_NAME':
937 $tiers=new Fiche($this->db);
938 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
939 $tiers->get_by_qcode($qcode, false);
940 $r=$tiers->get_attribute(ATTR_DEF_BQ_NAME,0);
941 break;
942 /* -------------------------------------------------------------------------------- */
943 /* BENEFIT (fee notes */
944 case 'BENEF_NAME':
945 $tiers=new Fiche($this->db);
946 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
947 if ($qcode=='')
948 {
949 $r='';
950 break;
951 }
952 $tiers->get_by_qcode($qcode, false);
953 $r=$tiers->get_attribute(ATTR_DEF_NAME,0);
954 break;
955 case 'BENEF_ADDR_1':
956 $tiers=new Fiche($this->db);
957 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
958 if ($qcode=='')
959 {
960 $r='';
961 break;
962 }
963 $tiers->get_by_qcode($qcode, false);
964 $r=$tiers->get_attribute(ATTR_DEF_ADRESS,0);
965
966 break;
967 case 'BENEF_CP':
968 $tiers=new Fiche($this->db);
969
970 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
971 if ($qcode=='')
972 {
973 $r='';
974 break;
975 }
976 $tiers->get_by_qcode($qcode, false);
977 $r=$tiers->get_attribute(ATTR_DEF_POSTCODE,0);
978
979 break;
980 case 'BENEF_CITY':
981 $tiers=new Fiche($this->db);
982
983 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
984 if ($qcode=='')
985 {
986 $r='';
987 break;
988 }
989 $tiers->get_by_qcode($qcode, false);
990 $r=$tiers->get_attribute(ATTR_DEF_CITY,0);
991
992 break;
993
994 case 'BENEF_CO':
995 $tiers=new Fiche($this->db);
996
997 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
998 if ($qcode=='')
999 {
1000 $r='';
1001 break;
1002 }
1003 $tiers->get_by_qcode($qcode, false);
1004 $r=$tiers->get_attribute(ATTR_DEF_COUNTRY,0);
1005
1006 break;
1007 // Marchandise in $p_array['e_march*']
1008 // \see user_form_achat.php or user_form_ven.php
1009 case 'BENEF_VAT':
1010 $tiers=new Fiche($this->db);
1011
1012 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1013 if ($qcode=='')
1014 {
1015 $r='';
1016 break;
1017 }
1018 $tiers->get_by_qcode($qcode, false);
1019 $r=$tiers->get_attribute(ATTR_DEF_NUMTVA,0);
1020 break;
1021 case 'BENEF_NUM':
1022 $tiers=new Fiche($this->db);
1023 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1024 if ($qcode=='')
1025 {
1026 $r='';
1027 break;
1028 }
1029 $tiers->get_by_qcode($qcode, false);
1030 $r=$tiers->get_attribute(ATTR_DEF_NUMBER_CUSTOMER,0);
1031 break;
1032 case 'BENEF_BANQUE_NO':
1033 $tiers=new Fiche($this->db);
1034 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1035 if ($qcode=='')
1036 {
1037 $r='';
1038 break;
1039 }
1040 $tiers->get_by_qcode($qcode, false);
1041 $r=$tiers->get_attribute(ATTR_DEF_BQ_NO,0);
1042 break;
1043 case 'BENEF_BANQUE_NAME':
1044 $tiers=new Fiche($this->db);
1045 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1046 if ($qcode=='')
1047 {
1048 $r='';
1049 break;
1050 }
1051 $tiers->get_by_qcode($qcode, false);
1052 $r=$tiers->get_attribute(ATTR_DEF_BQ_NAME,0);
1053 break;
1054
1055 // Marchandise in $p_array['e_march*']
1056 // \see user_form_achat.php or user_form_ven.php
1057 case 'NUMBER':
1059 break;
1060 case "DOCUMENT_ID":
1061 if (isset($p_array['ag_id']))
1062 return $p_array['ag_id'];
1063 return "";
1064 break;
1065
1066 case 'USER' :
1067 return $_SESSION[SESSION_KEY.'use_name'].', '.$_SESSION[SESSION_KEY.'use_first_name'];
1068
1069 break;
1070 case 'REFERENCE':
1071 $act=new Follow_Up($this->db);
1072 $act->ag_id=$this->ag_id;
1073 $act->get();
1074 $r=$act->ag_ref;
1075 break;
1076
1077 /*
1078 * - [VEN_ART_NAME]
1079 * - [VEN_ART_PRICE]
1080 * - [VEN_ART_QUANT]
1081 * - [VEN_ART_TVA_CODE]
1082 * - [VEN_ART_STOCK_CODE]
1083 * - [VEN_HTVA]
1084 * - [VEN_TVAC]
1085 * - [VEN_TVA]
1086 * - [TOTAL_VEN_HTVA]
1087 * - [DATE_LIMIT]
1088 * - [DATE_PAID]
1089 */
1090 case 'DATE_LIMIT_CALC':
1091 if (isset($p_array["e_ech"]))
1092 return format_date($p_array["e_ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1093 if (isset($p_array["ech"]))
1094 return format_date($p_array["ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1095 if (isset($p_array["ag_remind_date"]))
1096 return format_date($p_array["ag_remind_date"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1097 return "";
1098 break;
1099 case 'DATE_LIMIT':
1100 if (isset($p_array["ech"]))
1101 return $p_array["ech"];
1102 if (isset($p_array["e_ech"]))
1103 return $p_array["e_ech"];
1104 if (isset($p_array["ag_remind_date"]))
1105 return $p_array["ag_remind_date"];
1106 return "";
1107 break;
1108 case 'DATE_PAID':
1109 if ( isset ($p_array['jr_date_paid']) ) { return $p_array['jr_date_paid'];}
1110 break;
1111 case 'MARCH_NEXT':
1112 $this->counter++;
1113 $r='';
1114 break;
1115
1116 case 'VEN_ART_NAME':
1117 // check if the march exists
1118 if (!isset($p_array["e_march".$this->counter]))
1119 return "";
1120 // check that something is sold
1121 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1122 {
1123 $f=new Fiche($this->db);
1124 $f->get_by_qcode($p_array["e_march".$this->counter], false);
1125 $r=$f->get_attribute(ATTR_DEF_NAME,0);
1126 }
1127 else
1128 $r="";
1129 break;
1130 case 'VEN_ART_LABEL':
1131 $id='e_march'.$this->counter."_label";
1132 // check if the march exists
1133
1134 if (!isset($p_array[$id])||(isset($p_array[$id])&&noalyss_strlentrim($p_array[$id])==0))
1135 {
1136 $id='e_march'.$this->counter;
1137 // check if the march exists
1138 if (!isset($p_array[$id]))
1139 $r="";
1140 else
1141 {
1142 // check that something is sold
1143 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1144 {
1145 $f=new Fiche($this->db);
1146 $f->get_by_qcode($p_array[$id], false);
1147 $r=$f->get_attribute(ATTR_DEF_NAME,0);
1148 }
1149 else
1150 $r="";
1151 }
1152 }
1153 else
1154 $r=$p_array[$id];
1155 break;
1156 case 'VEN_ART_STOCK_CODE':
1157 $id='e_march'.$this->counter;
1158 // check if the march exists
1159 if (!isset($p_array[$id]))
1160 $r="";
1161 else
1162 {
1163 // check that something is sold
1164 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1165 {
1166 $f=new Fiche($this->db);
1167 $f->get_by_qcode($p_array[$id], false);
1168 $r=$f->get_attribute(ATTR_DEF_STOCK,0);
1169 $r=($r==NOTFOUND)?'':$r;
1170 }
1171 }
1172 break;
1173 case 'VEN_QCODE':
1174 $id='e_march'.$this->counter;
1175 if (!isset($p_array[$id]))
1176 return "";
1177 return $p_array[$id];
1178 break;
1179 case 'VEN_ART_PRICE':
1180 $id='e_march'.$this->counter.'_price';
1181 if (!isset($p_array[$id]))
1182 return "";
1183 if ($p_array[$id]==0)
1184 return "";
1185 $r=$p_array[$id];
1186 break;
1187
1188 case 'TVA_RATE':
1189 case 'VEN_ART_TVA_RATE':
1190 $id='e_march'.$this->counter.'_tva_id';
1191 if (!isset($p_array[$id]))
1192 return "";
1193 if ($p_array[$id]==-1||$p_array[$id]=='')
1194 return "";
1195 $march_id='e_march'.$this->counter.'_price';
1196 if (!isset($p_array[$march_id]))
1197 return '';
1198 $tva= Acc_Tva::build($this->db,$p_array[$id]);
1199 if ($tva->load()==-1)
1200 return '';
1201 return $tva->get_parameter("rate");
1202 break;
1203
1204 case 'TVA_CODE':
1205 case 'VEN_ART_TVA_CODE':
1206 $id='e_march'.$this->counter.'_tva_id';
1207 if (!isset($p_array[$id]))
1208 return "";
1209 if ($p_array[$id]==-1)
1210 return "";
1211 $qt='e_quant'.$this->counter;
1212 $price='e_march'.$this->counter.'_price';
1213 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1214 return "";
1215
1216 $r=$p_array[$id];
1217 break;
1218
1219 case 'TVA_LABEL':
1220 $id='e_march'.$this->counter.'_tva_id';
1221 if (!isset($p_array[$id]))
1222 return "";
1223 $march_id='e_march'.$this->counter.'_price';
1224 if (!isset($p_array[$march_id]))
1225 return '';
1226 if ($p_array[$march_id]==0)
1227 return '';
1228 $tva= Acc_Tva::build($this->db, $p_array[$id]);
1229 if ($tva->load()==-1)
1230 return "";
1231 $r=$tva->get_parameter('label');
1232
1233 break;
1234
1235 /* total VAT for one sold */
1236 case 'TVA_AMOUNT':
1237 case 'VEN_TVA':
1238 $qt='e_quant'.$this->counter;
1239 $price='e_march'.$this->counter.'_price';
1240 $tva='e_march'.$this->counter.'_tva_id';
1241 /* if we do not use vat this var. is not set */
1242 if (!isset($p_array[$tva]))
1243 return '';
1244 if (!isset($p_array ['e_march'.$this->counter]))
1245 return "";
1246 if (!isset($p_array[$tva]))
1247 return "";
1248 // check that something is sold
1249 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1250 return "";
1251 $r=$p_array['e_march'.$this->counter.'_tva_amount'];
1252 break;
1253 /* TVA automatically computed */
1254 case 'VEN_ART_TVA':
1255
1256 $qt='e_quant'.$this->counter;
1257 $price='e_march'.$this->counter.'_price';
1258 $tva='e_march'.$this->counter.'_tva_id';
1259 if (!isset($p_array['e_march'.$this->counter]))
1260 return "";
1261 if (!isset($p_array[$tva]))
1262 return "";
1263 // check that something is sold
1264 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1265 return "";
1266 $oTva= Acc_Tva::build($this->db, $p_array[$tva]);
1267 if ($oTva->load()==-1)
1268 return "";
1269 $r=noalyss_round($p_array[$price], 2)*$oTva->get_parameter('rate');
1270 $r=noalyss_round($r, 2);
1271 break;
1272
1273 case 'VEN_ART_TVAC':
1274 $qt='e_quant'.$this->counter;
1275 $price='e_march'.$this->counter.'_price';
1276 if (!isset($p_array['e_march'.$this->counter]))
1277 return "";
1278 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1279 return "";
1280 // check that something is sold
1281 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1282 return "";
1283 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1284 return '';
1285 $tva=Acc_Tva::build($this->db, $p_array['e_march'.$this->counter.'_tva_id']);
1286 if ($tva->load()==-1)
1287 {
1288 $r=noalyss_round($p_array[$price], 2);
1289 }
1290 else
1291 {
1292 $r=noalyss_round($p_array[$price]*$tva->get_parameter('rate')+$p_array[$price], 2);
1293 }
1294
1295 break;
1296
1297 case 'VEN_ART_QUANT':
1298 $id='e_quant'.$this->counter;
1299 if (!isset($p_array[$id]))
1300 return "";
1301 // check that something is sold
1302 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0||noalyss_strlentrim($p_array['e_march'.$this->counter.'_price'])==0||noalyss_strlentrim($p_array['e_quant'.$this->counter])==0)
1303 return "";
1304 $r=$p_array[$id];
1305 break;
1306
1307 case 'VEN_HTVA':
1308 $id='e_march'.$this->counter.'_price';
1309 $quant='e_quant'.$this->counter;
1310 if (!isset($p_array[$id]))
1311 return "";
1312
1313 // check that something is sold
1314 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0||noalyss_strlentrim($p_array['e_march'.$this->counter.'_price'])==0||noalyss_strlentrim($p_array['e_quant'.$this->counter])==0)
1315 return "";
1316 bcscale(4);
1318 $r=noalyss_round($r, 2);
1319 break;
1320
1321 case 'VEN_TVAC':
1322 $id='e_march'.$this->counter.'_tva_amount';
1323 $price='e_march'.$this->counter.'_price';
1324 $quant='e_quant'.$this->counter;
1325 if (!isset($p_array['e_march'.$this->counter.'_price'])||!isset($p_array['e_quant'.$this->counter]))
1326 {
1327 return "";
1328 }
1329 // check that something is sold
1330 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0)
1331 {
1332 return "";
1333 }
1334 bcscale(4);
1335 // if TVA not exist
1336 if (!isset($p_array[$id]))
1337 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1338 else
1339 {
1340 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1342 }
1343 $r=noalyss_round($r, 2);
1344 return $r;
1345 break;
1346
1347 case 'TOTAL_VEN_HTVA':
1348 bcscale(4);
1349 $sum=0.0;
1350 if (!isset($p_array["nb_item"]))
1351 return "";
1352 for ($i=0; $i<$p_array["nb_item"]; $i++)
1353 {
1354 $sell='e_march'.$i.'_price';
1355 $qt='e_quant'.$i;
1356
1357 if (!isset($p_array[$sell]))
1358 break;
1359
1360 if (noalyss_strlentrim($p_array[$sell])==0||
1361 noalyss_strlentrim($p_array[$qt])==0||
1362 $p_array[$qt]==0||$p_array[$sell]==0)
1363 continue;
1364 $tmp1=noalyss_bcmul($p_array[$sell], $p_array[$qt]);
1365 $sum=noalyss_bcadd($sum, $tmp1);
1366 }
1367 $r=noalyss_round($sum, 2);
1368 break;
1369 case 'TOTAL_VEN_TVAC':
1370 if (!isset($p_array["nb_item"]))
1371 return "";
1372 $sum=0.0;
1373 bcscale(4);
1374 for ($i=0; $i<$p_array["nb_item"]; $i++)
1375 {
1376 $tva='e_march'.$i.'_tva_amount';
1377 $tva_amount=0;
1378 /* if we do not use vat this var. is not set */
1379 if (isset($p_array[$tva]))
1380 {
1381 $tva_amount=$p_array[$tva];
1382 }
1383
1384 $sell=$p_array['e_march'.$i.'_price'];
1385 $qt=$p_array['e_quant'.$i];
1386 $tot=noalyss_bcmul($sell, $qt);
1387 $tva_amount=noalyss_round($tva_amount,2);
1389 $tot=noalyss_bcadd($tot, $tva_amount);
1390 $sum=noalyss_bcadd($sum, $tot??0);
1391 }
1392 $r=noalyss_round($sum??0, 2);
1393
1394 break;
1395 case 'TOTAL_TVA':
1396 if (!isset($p_array["nb_item"]))
1397 return "";
1398 $sum=0.0;
1399 for ($i=0; $i<$p_array["nb_item"]; $i++)
1400 {
1401 $tva='e_march'.$i.'_tva_amount';
1402 if (!isset($p_array[$tva]))
1403 $tva_amount=0.0;
1404 else
1405 {
1406 $tva_amount=$p_array[$tva];
1407 $tva_amount=($tva_amount=="")?0:$tva_amount;
1408 }
1409 $sum+=$tva_amount;
1410 $sum=noalyss_round($sum, 2);
1411 }
1412 $r=$sum;
1413
1414 break;
1415 case 'BON_COMMANDE':
1416 if (isset($p_array['bon_comm']))
1417 return $p_array['bon_comm'];
1418 else
1419 return "";
1420 break;
1421 case 'PJ':
1422 if (isset($p_array['e_pj']))
1423 return $p_array['e_pj'];
1424 else
1425 return "";
1426
1427 case 'OTHER_INFO':
1428 if (isset($p_array['other_info']))
1429 return $p_array['other_info'];
1430 else
1431 return "";
1432 break;
1433 case 'LABELOP':
1434 if (isset($p_array['e_comm']))
1435 return $p_array['e_comm'];
1436 break;
1437 case 'ACOMPTE':
1438 if (isset($p_array['acompte']))
1439 return $p_array['acompte'];
1440 return "0";
1441 break;
1442 case 'STOCK_NAME':
1443 if (!isset($p_array['repo']))
1444 return "";
1445 $ret=$this->db->get_value('select r_name from public.stock_repository where r_id=$1',
1446 array($p_array['repo']));
1447 return $ret;
1448 case 'STOCK_ADRESS':
1449 if (!isset($p_array['repo']))
1450 return "";
1451 $ret=$this->db->get_value('select r_adress from public.stock_repository where r_id=$1',
1452 array($p_array['repo']));
1453 return $ret;
1454 case 'STOCK_COUNTRY':
1455 if (!isset($p_array['repo']))
1456 return "";
1457 $ret=$this->db->get_value('select r_country from public.stock_repository where r_id=$1',
1458 array($p_array['repo']));
1459 return $ret;
1460 case 'STOCK_CITY':
1461 if (!isset($p_array['repo']))
1462 return "";
1463 $ret=$this->db->get_value('select r_city from public.stock_repository where r_id=$1',
1464 array($p_array['repo']));
1465 return $ret;
1466 case 'STOCK_PHONE':
1467 if (!isset($p_array['repo']))
1468 return "";
1469 $ret=$this->db->get_value('select r_phone from public.stock_repository where r_id=$1',
1470 array($p_array['repo']));
1471 return $ret;
1472 // Follow up
1473 //Title
1474 case 'TITLE':
1475 if (isset($p_array['ag_title']))
1476 return $p_array['ag_title'];
1477 return "";
1478 break;
1479 // Description is the first comment
1480 case 'DESCRIPTION':
1481 if (isset($p_array['ag_id']))
1482 {
1483 // retrieve first comment
1484 $description=$this->db->get_value("select agc_comment "
1485 ." from action_gestion_comment "
1486 ."where ag_id=$1 order by AGC_ID asc limit 1"
1487 , [$p_array['ag_id']]);
1488 return $description;
1489 }
1490 if ( isset($p_array['e_comm'])) {return $p_array['e_comm'] ; }
1491
1492 return "";
1493 break;
1494
1495
1496 // Comments, use a counter to move to the next comment, only for Follow-Up
1497 //
1498 case 'COMMENT':
1499 if (isset($p_array['ag_id']))
1500 {
1501 // Static value, if null the retrieve all of them
1502 if ($aComment==NULL)
1503 {
1504 // retrieve comments
1505 $aComment=$this->db->get_array("select AGC_ID,agc_comment ,"
1506 ." to_char(agc_date,'DD-MM-YY HH24:MI') as str_date ,"
1507 ." tech_user "
1508 ." from action_gestion_comment "
1509 ."where ag_id=$1 order by 1"
1510 , [$p_array['ag_id']]);
1511 }
1512 $nb_comment=count($aComment);
1513 $description="";
1514 if (count($aComment)>$counter_comment)
1515 {
1516 $description.=sprintf(_('le %s , %s écrit %s'), $aComment[$counter_comment]['str_date'],
1517 $aComment[$counter_comment]['tech_user'], $aComment[$counter_comment]['agc_comment']);
1518 $counter_comment++;
1519 }
1520 return $description;
1521 }
1522 return "";
1523 break;
1524 // Related Action, use a counter to move to the next related action, only for Follow-Up
1525 //
1526 case 'RELATED_ACTION':
1527 if (isset($p_array['ag_id']))
1528 {
1529 // Static value, if null the retrieve all of them
1530 if ($aRelatedAction==NULL)
1531 {
1532 // retrieve parent
1533 $followup=new Follow_Up($this->db, $p_array["ag_id"]);
1534 $aRelatedAction=array();
1535 $aParent=$followup->get_parent();
1536 if ($aParent==-1)
1537 return "";
1538 $nb_parent=count($aParent);
1539 $sql_related_action="
1540 select ag_id,
1541 f_id_dest,
1542 (select ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=f_id_dest) as qcode,
1543 (select ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=f_id_dest) as card_name,
1544 (select ad_value from fiche_detail fd1 where fd1.ad_id=32 and fd1.f_id=f_id_dest) as card_fname,
1545 ag_title,
1546 to_char(ag_timestamp,'DD.MM.YYYY') as strdate,
1547 ag_ref
1548 from action_gestion ag where ag_id=$1 ";
1549
1550 for ($x=0; $x<$nb_parent; $x++)
1551 {
1552 $aRelatedAction[]=$this->db->get_row($sql_related_action, [$aParent[$x]['aga_least']]);
1553 $aChild=$followup->get_children($aParent[$x]['aga_least']);
1554 $nb_child=count($aChild);
1555 for ($y=0; $y<$nb_child; $y++)
1556 {
1557 $aRelatedAction[]=$this->db->get_row($sql_related_action,
1558 [$aChild[$y]['aga_greatest']]);
1559 }
1560 }
1561 }
1562 $description="";
1563 if (count($aRelatedAction)>$counter_related_action)
1564 {
1565 $description=sprintf("docid %s %s %s %s %s %s %s",
1566 $aRelatedAction[$counter_related_action]['ag_id'],
1567 $aRelatedAction[$counter_related_action]['ag_ref'],
1568 $aRelatedAction[$counter_related_action]['strdate'],
1569 $aRelatedAction[$counter_related_action]['qcode'],
1570 $aRelatedAction[$counter_related_action]['card_fname'],
1571 $aRelatedAction[$counter_related_action]['card_name'],
1572 $aRelatedAction[$counter_related_action]['ag_title']
1573 );
1574
1575 $counter_related_action++;
1576 }
1577 return $description;
1578 }
1579 return "";
1580 break;
1581
1582 // Concerned operation, use a counter to move to the next one, only for Follow-Up
1583 //
1584 case 'CONCERNED_OPERATION':
1585 if (isset($p_array['ag_id']))
1586 {
1587 // Static value, if null the retrieve all of them
1588 if ($aRelatedOperation==NULL)
1589 {
1590 // retrieve comments
1591 $aRelatedOperation=$this->db->get_array("select ago_id,
1592 j.jr_id,
1593 j.jr_internal,
1594 j.jr_comment,
1595 j.jr_pj_number,
1596 to_char(j.jr_date,'DD.MM.YY') as str_date
1597 from jrn as j
1598 join action_gestion_operation as ago on (j.jr_id=ago.jr_id)
1599 where ag_id=$1 order by jr_date,jr_id"
1600 , [$p_array['ag_id']]);
1601 }
1602 $description="";
1603 if (count($aRelatedOperation)>$counter_related_operation)
1604 {
1605 $description.=sprintf('%s %s %s %s ',
1606 $aRelatedOperation[$counter_related_operation]['str_date'],
1607 $aRelatedOperation[$counter_related_operation]['jr_internal'],
1608 $aRelatedOperation[$counter_related_operation]['jr_comment'],
1609 $aRelatedOperation[$counter_related_operation]['jr_pj_number']
1610 );
1611 $counter_related_operation++;
1612 }
1613 return $description;
1614 }
1615 return "";
1616 break;
1617 // Other card, use a counter to move to the next one, only for Follow-Up
1618 //
1619 case 'OTHER_CARDS':
1620 if (isset($p_array['ag_id']))
1621 {
1622 // Static value, if null the retrieve all of them
1623 if ($aOtherCard==NULL)
1624 {
1625 // retrieve comments
1626 $aOtherCard=$this->db->get_array("
1627 select
1628 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 1) as cname,
1629 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 32) as cfname,
1630 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 23) as qcode,
1631 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 18 ) as email,
1632 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 27 ) as mobile,
1633 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 17 ) as phone
1634 from action_person ap
1635 where ag_id=$1
1636 "
1637 , [$p_array['ag_id']]);
1638 }
1639 $description="";
1640 if (count($aOtherCard)>$counter_other_card)
1641 {
1642 $description.=sprintf('%s %s %s %s %s %s ', $aOtherCard[$counter_other_card]['cname'],
1643 $aOtherCard[$counter_other_card]['cfname'], $aOtherCard[$counter_other_card]['qcode'],
1644 $aOtherCard[$counter_other_card]['email'], $aOtherCard[$counter_other_card]['phone'],
1645 $aOtherCard[$counter_other_card]['mobile']);
1646 $counter_other_card++;
1647 }
1648 return $description;
1649 }
1650 return "";
1651 break;
1652 // Attachment , use a counter to move to the next one, only for Follow-Up
1653 //
1654 case 'ATTACHED_FILES':
1655 if (isset($p_array['ag_id']))
1656 {
1657 // Static value, if null the retrieve all of them
1658 if ($aFileAttached==NULL)
1659 {
1660 // retrieve comments
1661 $aFileAttached=$this->db->get_array("
1662 select d_filename,d_description from document d where ag_id=$1
1663 "
1664 , [$p_array['ag_id']]);
1665 }
1666 $nb_comment=count($aFileAttached);
1667 $description="";
1668 if (count($aFileAttached)>$counter_file)
1669 {
1670 $description.=sprintf("%s %s ", $aFileAttached[$counter_file]['d_filename'],
1671 $aFileAttached [$counter_file]['d_description']);
1672 $counter_file++;
1673 }
1674 return $description;
1675 }
1676 return "";
1677 break;
1678 // Tag , use a counter to move to the next one
1679 case 'TAGS':
1680 if (isset($p_array['ag_id']))
1681 {
1682 // Static value, if null the retrieve all of them
1683 if ($aTag==NULL)
1684 {
1685 // retrieve comments
1686 $aTag=$this->db->get_array("
1687 select t_tag from action_tags at2 join tags t using(t_id) where ag_id=$1 order by upper(t_tag)
1688 "
1689 , [$p_array['ag_id']]);
1690 }
1691 $description="";
1692 if (count($aTag)>$counter_tag)
1693 {
1694 $description.=sprintf("%s ", $aTag [$counter_tag]['t_tag']);
1695 $counter_tag++;
1696 }
1697 return $description;
1698 }
1699
1700 return "";
1701 break;
1702 case 'COMM_PAYMENT':
1703 if (isset($p_array["e_comm_paiement"]))
1704 {
1705 return $p_array["e_comm_paiement"];
1706 }
1707 else
1708 {
1709 return "";
1710 }
1711
1712 // priority of the follow up document
1713 case 'PRIORITY':
1714 if (isset($p_array['ag_priority']))
1715 {
1716 $aPriority=array(1=>_("Haute"), 2=>_("Normale"), 3=>_("Basse"));
1717 return $aPriority[$p_array["ag_priority"]];
1718 }
1719 return "";
1720 // Priority of the follow up document
1721 case 'GROUPMGT':
1722 if (isset($p_array['ag_dest']))
1723 {
1724 $profile=$this->db->get_value("select p_name from profile where p_id=$1", array($p_array['ag_dest']));
1725 return $profile;
1726 }
1727 return "";
1728 // Hour in the follow up document
1729 case 'HOUR':
1730 if (isset($p_array['ag_hour']))
1731 {
1732 return $p_array["ag_hour"];
1733 }
1734 return "";
1735 // State in the follow up document
1736 case 'STATUS':
1737 if (isset($p_array['ag_state']))
1738 {
1739 $status=$this->db->get_value("
1740 select s_value from document_state where s_id=$1", array($p_array['ag_state']));
1741 return $status;
1742 }
1743 return "";
1744 // type of document
1745 case 'DOCUMENT_TYPE':
1746 $ret="";
1747 if (isset($p_array['ag_id']))
1748 {
1749 $ret=$this->db->get_value("select dt_value
1750 from action_gestion
1751 join document_type dt on (ag_type=dt.dt_id)
1752 where ag_id=$1", array($p_array["ag_id"]));
1753 } elseif (isset($p_array['gen_doc'])) {
1754 if ( $p_array['gen_doc'] == -2) return _("Facture standard");
1755 $ret = $this->db->get_value("
1756 select md_name from public.document_modele where md_id=$1",
1757 [$p_array['gen_doc']]);
1758 }
1759 return $ret;
1760 case 'NOTE':
1761 return strip_tags(html_entity_decode($p_array['jrn_note_input']??""));
1762
1763
1764
1765 } // end switch
1766 /*
1767 * retrieve the value of ATTR for e_march
1768 */
1769 if (preg_match('/^ATTR/', $p_tag)==1)
1770 {
1771 $r="";
1772 // Retrieve f_id
1773 if (isset($p_array['e_march'.$this->counter]))
1774 {
1775 $id=$p_array['e_march'.$this->counter];
1776 $r=$this->replace_special_tag($id, $p_tag);
1777 return $r;
1778 }
1779 }
1780 /*
1781 * @brief retrieve the value of ATTR for e_march
1782 */
1783 if (preg_match('/^BENEFATTR/', $p_tag)==1)
1784 {
1785 $r="";
1786 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1787 // Retrieve f_id
1788 $r=$this->replace_special_tag($qcode, $p_tag);
1789 return $r;
1790 }
1791 if (preg_match('/^CUSTATTR/', $p_tag)==1)
1792 {
1793 $r="";
1794 if (isset($p_array['qcode_dest'])||isset($p_array['e_client']))
1795 {
1796 $qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
1797 $r=$this->replace_special_tag($qcode, $p_tag);
1798 }
1799 return $r;
1800 }
1801
1802 // check also if the tag does exist in parameter_extra table
1803 $pe_value=$this->db->get_value("select pe_value from parameter_extra where pe_code=$1",[$p_tag]);
1804 if ( $this->db->count() > 0 ) { return $pe_value;}
1805
1806 return $r;
1807 }
1808
1809 /*!
1810 * \brief remove a row from the table document, the lob object is not deleted
1811 * because can be linked elsewhere
1812 */
1813
1814 function remove()
1815 {
1816 $d_lob=$this->db->get_value('select d_lob from document where d_id=$1', array($this->d_id));
1817 $sql='delete from document where d_id='.$this->d_id;
1818 $this->db->exec_sql($sql);
1819 if ($d_lob!=0)
1820 $this->db->lo_unlink($d_lob);
1821 }
1822
1823 /**
1824 * @brief replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
1825 * is the ad_value
1826 * @param $p_qcode qcode of the card
1827 * @param $p_tag tag to parse
1828 * @return the ad_value contained in fiche_detail or for the type "select" the
1829 * label
1830 */
1831 function replace_special_tag($p_qcode, $p_tag)
1832 {
1833 // check if the march exists
1834 if ($p_qcode=="") return "";
1835
1836 $f=new Fiche($this->db);
1837 $found=$f->get_by_qcode($p_qcode, false);
1838 // if not found exit
1839 if ($found==1) return "";
1840
1841 // get the ad_id
1842 $attr=preg_replace("/^.*ATTR/", "", $p_tag);
1843
1844 if (isNumber($attr)==0) return "";
1845
1846 $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1", array($attr));
1847
1848 // get ad_value
1849 $ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",
1850 array($f->id, $attr));
1851
1852 // if ad_id is type select execute select and get value
1853 if ($ad_type=="select")
1854 {
1855 $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1", array($attr));
1856 $array=$this->db->make_array($sql);
1857 for ($a=0; $a<count($array); $a++)
1858 {
1859 if ($array[$a]['value']==$ad_value)
1860 return $array[$a]['label'];
1861 }
1862 }
1863 // if ad_id is not type select get value
1864 return $ad_value;
1865 }
1866
1867 function update_description($p_desc)
1868 {
1869 $this->db->exec_sql('update document set d_description = $1 where d_id=$2', array($p_desc, $this->d_id));
1870 }
1871
1872 /**
1873 * @brief replace a pattern with a value in the buffer , handle the change for OOo type file and amount
1874 *
1875 * @param string $p_buffer
1876 * @param string $_pattern
1877 * @param mixed $p_value
1878 */
1879 static function replace_value($p_buffer, $p_pattern, $p_value, $p_limit=-1, $p_type='OOo')
1880 {
1881 $check=$p_pattern;
1882 $p_value=$p_value??'';
1883 $check=str_replace(['&lt;', '&gt;', '<', '>', '='], "", $check);
1884 if (preg_replace('/[^[:alnum:]^_]/', '', $check)!=$check)
1885 {
1886 throw new Exception(sprintf(_("chaine à remplacer [%s] contient un caractère interdit"), $p_pattern));
1887 }
1888 $count=0;
1889 if (is_numeric($p_value)&&$p_type=='OOo')
1890 {
1891 /* -- works only with OOo Calc -- */
1892 $searched='/office:value-type="string"><text:p>'.$p_pattern.'/i';
1893 $replaced='office:value-type="float" office:value="'.$p_value.'"><text:p>'.$p_value;
1894 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1895 if ($count==0)
1896 {
1897 /* -- work with libreOffice > 5 -- */
1898 $searched='/office:value-type="string" calcext:value-type="string"><text:p>(<text:s\/>)*'.$p_pattern.'/i';
1899 $replaced='office:value-type="float" office:value="'.$p_value.'" calcext:value-type="float"><text:p>'.$p_value;
1900 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1901 }
1902 }
1903 if ($count==0)
1904 {
1905
1906 if ($p_type=='OOo')
1907 {
1908 $p_value=noalyss_str_replace('&', '&amp;', $p_value);
1909 $p_value=noalyss_str_replace('<', '&lt;', $p_value);
1910 $p_value=noalyss_str_replace('>', '&gt;', $p_value);
1911 $p_value=noalyss_str_replace('"', '&quot;', $p_value);
1912 $p_value=noalyss_str_replace("'", '&apos;', $p_value);
1913 }
1914 $p_buffer=preg_replace('/'.$p_pattern.'/i', $p_value, $p_buffer, $p_limit);
1915 }
1916 return $p_buffer;
1917 }
1918
1919 /**
1920 * @brief export the file to the file system and complet $this->d_mimetype, d_filename and
1921 * @param string $p_destination_file path
1922 * @return bool false for failure and true for success
1923 */
1924 function export_file($p_destination_file)
1925 {
1926 if ($this->d_id==0) {
1927 return false;
1928 }
1929 $this->db->start();
1930 $ret=$this->db->exec_sql(
1931 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
1932 if (Database::num_row($ret)==0)
1933 {
1934 return false;
1935 }
1937 //the document is saved into file $tmp
1938 $tmp=$p_destination_file;
1939 if ( $this->db->lo_export($row['d_lob'], $tmp) == true) {
1940 $this->d_mimetype=$row['d_mimetype'];
1941 $this->d_filename=$row['d_filename'];
1942 $this->db->commit();
1943 return true;
1944 } else {
1945 $this->db->commit();
1946 return false;
1947
1948 }
1949
1950 }
1951 /**
1952 * @brief transform the current Document to a PDF, returns the full path of the PDF from the TMP folder
1953 * if the file IS a pdf , then export it and return the path to the file.
1954 *
1955 * @todo replace use of unoconv with a PHP lib to convert into PDF
1956 * @return string full path to the PDF file
1957 */
1958 function transform2pdf()
1959 {
1960 // Extract from public.document
1961 $dirname=tempnam($_ENV['TMP'],"document");
1962
1963 if ( $dirname == false ) {
1964 throw new Exception("D1862.cannot create tmp file",5000);
1965 }
1966 unlink($dirname);
1967 umask(0);
1968 if ( mkdir($dirname) == false ) {
1969 throw new Exception("D1868.cannot create tmp directory",5000);
1970 }
1971 if ( $this->d_mimetype == "application/pdf") {
1972 $destination_file=$dirname."/".$this->d_filename;
1973 $this->export_file($destination_file);
1974 return $dirname."/".$destination_file;
1975 return;
1976 }
1977 if (GENERATE_PDF == 'NO' ) {
1978 \record_log(__FILE__."D1857 PDF not available");
1979 throw new \Exception("Cannot not transform to PDF",5000);
1980 }
1981
1982 $destination_file=$dirname."/".$this->d_filename;
1983 $this->export_file($destination_file);
1984 ob_start();
1985 passthru(OFFICE . escapeshellarg($destination_file), $status);
1986 $result =ob_get_contents();
1987 ob_end_clean();
1988 if ($status != 0) {
1989 \record_log(__FILE__."D1879 Error cannot transform into PDF"." output [$result]");
1990 throw new \Exception("D1879 Cannot not transform to PDF");
1991 }
1992 // remove extension
1993 $ext = strrpos($this->d_filename, ".");
1994 $pdf_file = substr($this->d_filename, 0, $ext);
1995 $pdf_file .=".pdf";
1996 return $dirname."/".$pdf_file;
1997 }
1998}
noalyss_round($p_first, $p_second)
format_date($p_date, $p_from_format='YYYY-MM-DD', $p_to_format='DD.MM.YYYY')
format the date, when taken from the database the format is MM-DD-YYYY
noalyss_bcadd($p_first, $p_second, $p_decimal=4)
sanitize_filename($filename, $with_date=true)
removed invalid character when computing a filename, the suffix is kept
isNumber($p_int)
span($p_string, $p_extra='')
Definition ac_common.php:43
noalyss_strlentrim($p_string)
noalyss_str_replace($search, $replace, $string)
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
noalyss_bcmul($p_first, $p_second)
global $g_parameter
global $g_user
if no group available , then stop
$href
Definition adm.inc.php:31
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
global $doc
_("actif, passif,charge,...")
$p
Definition calendar.php:9
static build($db, $p_code)
retrieve TVA rate thanks the code that could be the tva_id or tva_code.
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
Class Document corresponds to the table DOCUMENT.
transform2pdf()
transform the current Document to a PDF, returns the full path of the PDF from the TMP folder if the ...
export_file($p_destination_file)
export the file to the file system and complet $this->d_mimetype, d_filename and
compute_filename($pj, $filename)
Insert the receipt number into the filename , each generated file will have the name of the template ...
replace_special_tag($p_qcode, $p_tag)
replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value
upload($p_ag_id)
upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : a...
get_all($ag_id)
get all the document of a given action
anchor()
create and compute a string for reference the doc <A ...>
download($aDocument)
Download all documents in a ZIP files.
static replace_value($p_buffer, $p_pattern, $p_value, $p_limit=-1, $p_type='OOo')
replace a pattern with a value in the buffer , handle the change for OOo type file and amount
parseDocument($p_dir, $p_file, $p_type, $p_array)
This function parse a document and replace all the predefined tags by a value.
send()
send the document
saveGenerated($p_file)
insert the generated Document into the database, update the $this->d_id that is the PK of document....
blank()
insert a minimal document and set the d_id
__construct($p_cn, $p_d_id=0)
Constructor.
static insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
Copy a existing OID (LOB) into the table document.
replace($p_tag, $p_array)
replace the TAG by the real value, this value can be into the database or in $_POST The possible tags...
update_description($p_desc)
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
class_action for manipulating actions action can be :
manage the http input (get , post, request) and extract from an array
extends the Zip object
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition constant.php:135
const ATTR_DEF_ADRESS
Definition constant.php:230
const ATTR_DEF_NUMTVA
Definition constant.php:229
const ATTR_DEF_NAME
Definition constant.php:223
const ATTR_DEF_COUNTRY
Definition constant.php:232
const INVOICE_STD
Definition constant.php:211
const ATTR_DEF_BQ_NO
Definition constant.php:224
const ATTR_DEF_POSTCODE
Definition constant.php:231
$dirname
Definition constant.php:42
const ATTR_DEF_CITY
Definition constant.php:236
const ATTR_DEF_NUMBER_CUSTOMER
Definition constant.php:239
const ATTR_DEF_ACCOUNT
Definition constant.php:222
const ATTR_DEF_BQ_NAME
Definition constant.php:225
const ATTR_DEF_STOCK
Definition constant.php:233
$count
$new_name
$SecUser db
$user_exercice
Get exercice.
if( $delta< 0) elseif( $delta==0)
$check