noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Document Class Reference

Class Document corresponds to the table document. More...

+ Collaboration diagram for Document:

Public Member Functions

 __construct ($p_cn, $p_d_id=0)
 Constructor.
 
 anchor ()
 create and compute a string for reference the doc <A ...>
 
 blank ()
 insert a minimal document and set the d_id
 
 compute_filename ($pj, $filename)
 Insert the receipt number into the filename , each generated file will have the name of the template (model) + receipt number)
 
 download ($aDocument)
 Download all documents in a ZIP files.
 
 export_file ($p_destination_file)
 export the file to the file system and complet $this->d_mimetype, d_filename and
 
 generate ($p_array, $p_filename="")
 Generate the document, Call $this->replace to replace tag by value.
 
 get ()
 Get complete all the data member thx info from the database.
 
 get_all ($ag_id)
 get all the document of a given action
 
 moveDocumentPj ($p_internal)
 Move a document from the table document into the concerned row the document is not copied : it is only a link.
 
 parseDocument ($p_dir, $p_file, $p_type, $p_array)
 This function parse a document and replace all the predefined tags by a value.
 
 remove ()
 remove a row from the table document, the lob object is not deleted because can be linked elsewhere
 
 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 are
 
 replace_special_tag ($p_qcode, $p_tag)
 replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value
 
 saveGenerated ($p_file)
 Save the generated Document.
 
 send ()
 send the document
 
 transform2pdf ()
 transform the current Document to a PDF, returns the full path of the PDF from the TMP folder
 
 update_description ($p_desc)
 
 upload ($p_ag_id)
 upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : array containing by default $_FILES
 

Static Public Member Functions

static insert_existing_document ($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
 Copy a existing OID (LOB) into the table document.
 
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
 

Data Fields

 $ag_id
 
 $d_description
 
 $d_filename
 
 $d_id
 
 $d_lob
 
 $d_mimetype
 
 $d_name
 
 $d_number
 
 $db
 
 $f_id
 
 $md_id
 

Private Attributes

 $counter
 

Detailed Description

Class Document corresponds to the table document.

Definition at line 28 of file document.class.php.

Constructor & Destructor Documentation

◆ __construct()

Document::__construct ( $p_cn,
$p_d_id = 0 )

Constructor.

Parameters
$p_cnDatabase connection

Definition at line 48 of file document.class.php.

49 {
50 $this->db=$p_cn;
51 $this->d_id=$p_d_id;
52
53 // counter for MARCH_NEXT
54 $this->counter=0;
55 }
$SecUser db

References db.

Member Function Documentation

◆ anchor()

Document::anchor ( )

create and compute a string for reference the doc <A ...>

Returns
a string

Definition at line 537 of file document.class.php.

538 {
539 if ($this->d_id==0)
540 return '';
541 $image='<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.'" border="0">';
542 $r="";
543 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
544
545 $r='<A class="mtitle" HREF="export.php?'.$href.'">'.$image.'</A>';
546 return $r;
547 }
$href
Definition adm.inc.php:31
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r

References $href, and $r.

◆ blank()

Document::blank ( )

insert a minimal document and set the d_id

Definition at line 60 of file document.class.php.

61 {
62 $this->d_id=$this->db->get_next_seq("document_d_id_seq");
63 // affect a number
64 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
65 $sql='insert into document(d_id,ag_id,d_number) values($1,$2,$3)';
66
67 $this->db->exec_sql($sql,
68 array
69 ($this->d_id,
70 $this->ag_id,
71 $this->d_number));
72 }

References $sql, ag_id, and db.

◆ compute_filename()

Document::compute_filename ( $pj,
$filename )

Insert the receipt number into the filename , each generated file will have the name of the template (model) + receipt number)

Parameters
type$pjthe receipt number
type$filenamethe name of the file
Returns
string

Definition at line 81 of file document.class.php.

82 {
83 $pos_prefix=strrpos($filename, ".");
84 if ($pos_prefix==0)
85 $pos_prefix=strlen($filename);
86 $filename_no=substr($filename, 0, $pos_prefix);
87 $filename_suff=substr($filename, $pos_prefix, strlen($filename));
88
89 foreach (array('/', '*', '<', '>', ';', ',', '\\', '.', ':', '(', ')', ' ', '[', ']',"'") as $i)
90 {
91 $pj=noalyss_str_replace($i, "-", $pj);
92 $filename_no=noalyss_str_replace($i,"-",$filename_no);
93 }
94
95
96 $new_filename=strtolower($filename_no."-".$pj.$filename_suff);
97 $pj=noalyss_str_replace("---","-",$pj);
98 $pj=noalyss_str_replace("--","-",$pj);
99 $new_filename=noalyss_str_replace("---","-",$new_filename);
100 $new_filename=noalyss_str_replace("--","-",$new_filename);
101 return $new_filename;
102 }
noalyss_str_replace($search, $replace, $string)

References $i, and noalyss_str_replace().

Referenced by generate().

+ Here is the call graph for this function:

◆ download()

Document::download ( $aDocument)

Download all documents in a ZIP files.

The parameters is an array of Document, see DOcument::get_all

Parameters
arrayof Document $aDocument
See also
Document\get_all()

Definition at line 378 of file document.class.php.

379 {
380
381 if (empty($aDocument)||is_array($aDocument)==false)
382 {
383 throw new Exception("Document.download expects an array");
384 }
385 // make a temp folder
386 $dirname=tempnam($_ENV['TMP'], 'document_dwnall');
387 unlink($dirname);
388 mkdir($dirname);
389
390 // download each file into that folder
391 $nb_document=count($aDocument);
392 $nCopy=0;
393
394 // start a transaction to be able to export LOB
395 $this->db->start();
396 for ($i=0; $i<$nb_document; $i++)
397 {
398 // check that aDocument elt is a document object
399 if ( ! $aDocument[$i] instanceof Document ) {
400 throw new Exception("Document.download.2 element is not a document object");
401 }
402 $filename=$dirname.DIRECTORY_SEPARATOR.$aDocument[$i]->d_filename;
403 // if file exists then add a number
404 if (file_exists($filename))
405 {
406
407 while (true)
408 {
409 $nCopy++;
410 $filename=$dirname.DIRECTORY_SEPARATOR.$nCopy."-".$aDocument[$i]->d_filename;
411 if (!file_exists($filename))
412 {
413 $nCopy=0;
414 break;
415 }
416 } // end while true
417 } // end if fileexist
418 // export file
419 $this->db->lo_export($aDocument[$i]->d_lob,$filename);
420 } // end for $i
421 // make a large PDF and send it
422 $zip=new Zip_Extended();
423 $name="document-".date ("Ymd-His").".zip";
424 if ( $zip->open($_ENV['TMP'].DIRECTORY_SEPARATOR.$name , ZipArchive::CREATE) != true)
425 {
426 die("Cannot create zip file");
427 }
428 $zip->add_recurse_folder($dirname . "/");
429 $zip->close();
430 // send it to stdout
431 ini_set('zlib.output_compression', 'off');
432 header("Pragma: public");
433 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
434 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
435 header("Cache-Control: must-revalidate");
436 header('Content-type: zip/application');
437 header('Content-Disposition: attachment;filename="'.$name.'"', FALSE);
438 header("Accept-Ranges: bytes");
439 $file=fopen($_ENV['TMP'].DIRECTORY_SEPARATOR.$name, 'r');
440 while (!feof($file))
441 {
442 echo fread($file, 8192);
443 }
444 fclose($file);
445
446 $this->db->commit();
447
448 }
$dirname
Definition constant.php:42

References $dirname, $file, $i, $name, $nb_document, and db.

◆ export_file()

Document::export_file ( $p_destination_file)

export the file to the file system and complet $this->d_mimetype, d_filename and

Parameters
string$p_destination_filepath
Returns
bool false for failure and true for success

Definition at line 1886 of file document.class.php.

1887 {
1888 if ($this->d_id==0) {
1889 return;
1890 }
1891 $this->db->start();
1892 $ret=$this->db->exec_sql(
1893 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
1894 if (Database::num_row($ret)==0)
1895 {
1896 return;
1897 }
1899 //the document is saved into file $tmp
1900 $tmp=$p_destination_file;
1901 if ( $this->db->lo_export($row['d_lob'], $tmp) == true) {
1902 $this->d_mimetype=$row['d_mimetype'];
1903 $this->d_filename=$row['d_filename'];
1904 $this->db->commit();
1905 return true;
1906 } else {
1907 $this->db->commit();
1908 return false;
1909
1910 }
1911
1912 }
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

References $ret, $row, $tmp, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

Referenced by transform2pdf().

+ Here is the call graph for this function:

◆ generate()

Document::generate ( $p_array,
$p_filename = "" )

Generate the document, Call $this->replace to replace tag by value.

Parameters
p_arraycontains the data normally it is the $_POST
$p_filenamecontains the new filename
Returns
an string : the url where the generated doc can be found, the name of the file and his mimetype

Definition at line 113 of file document.class.php.

114 {
115 try {
116 // create a temp directory in /tmp to unpack file and to parse it
117 $dirname=tempnam($_ENV['TMP'], 'doc_');
118 if ($dirname == false) {
119 throw new Exception ('DC117 cannot create tmp file',5000);
120 }
121
122 unlink($dirname);
123 if ( mkdir($dirname) == false ) {
124 throw new Exception ("DC121 cannot create $dirname directory",5000);
125 }
126 // Retrieve the lob and save it into $dirname
127 $this->db->start();
128 $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
129 from document_modele where md_id=$1";
130 $Res=$this->db->exec_sql($dm_info, [$this->md_id]);
131
133 $this->d_lob=$row['md_lob'];
134 $this->d_filename=$row['md_filename'];
135 $this->d_mimetype=$row['md_mimetype'];
136 $this->d_name=$row['md_name'];
137
138
139 chdir($dirname);
140 $filename=$row['md_filename'];
141 $exp=$this->db->lo_export($row['md_lob'], $dirname.DIRECTORY_SEPARATOR.$filename);
142 if ($exp===false)
143 {
144 record_log(sprintf('DOCUMENT.GENERATE.D1 , export failed %s %s',$dirname, $filename));
145 throw new Exception(sprintf(_("Export a échoué pour %s"), $filename));
146 }
147
148 $type="n";
149 // if the doc is a OOo, we need to unzip it first
150 // and the name of the file to change is always content.xml
151 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
152 {
153 ob_start();
154 $zip=new Zip_Extended;
155 if ($zip->open($filename)===TRUE)
156 {
157 $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
158 $zip->close();
159 }
160 else
161 {
162 record_log(sprintf('DOCUMENT.GENERATE.D2 unzip failed %s', $filename));
163 throw new Exception(sprintf(_("Décompression a échoué %s", $filename)));
164 }
165
166 // Remove the file we do not need anymore
167 unlink($filename);
168 ob_end_clean();
169 $file_to_parse="content.xml";
170 $type="OOo";
171 }
172 else
173 {
174 $file_to_parse=$filename;
175 }
176 // affect a number
177 $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
178
179 // parse the document - return the doc number ?
180 $this->parseDocument($dirname, $file_to_parse, $type, $p_array);
181
182 $this->db->commit();
183 // if the doc is a OOo, we need to re-zip it
184 if (strpos($row['md_mimetype'], 'vnd.oasis')!=0)
185 {
186 ob_start();
187 $zip=new Zip_Extended;
188 $res=$zip->open($filename, ZipArchive::CREATE);
189 if ($res!==TRUE)
190 {
191 record_log(sprintf('DOCUMENT.GENERATE.D3 zip failed %s', $filename));
192 throw new Exception(_('Echec compression'),5000);
193 }
194 $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
195 $zip->close();
196
197 ob_end_clean();
198
199 $file_to_parse=$filename;
200 }
201 if ($p_filename!="")
202 {
203 $this->d_filename=$this->compute_filename($p_filename, $this->d_filename);
204 }
205 $this->saveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
206 // Invoice
207 $href=http_build_query(array('gDossier'=>Dossier::id(), "d_id"=>$this->d_id, 'act'=>'RAW:document'));
208 $ret='<A class="mtitle" HREF="export.php?'.$href.'">'._('Document').'</A>';
209
210 return $ret;
211 } catch (Exception $e) {
212 record_log($e->getMessage());
213 record_log($e->getTraceAsString());
214 return span(_("Génération du document a échoué"),'class="notice"');
215 }
216 }
span($p_string, $p_extra='')
Definition ac_common.php:43
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...
_("actif, passif,charge,...")
compute_filename($pj, $filename)
Insert the receipt number into the filename , each generated file will have the name of the template ...
parseDocument($p_dir, $p_file, $p_type, $p_array)
This function parse a document and replace all the predefined tags by a value.
saveGenerated($p_file)
Save the generated Document.

References $dirname, $e, $href, $p_array, $Res, $res, $ret, $row, $type, _, compute_filename(), db, DatabaseCore\fetch_array(), parseDocument(), record_log(), saveGenerated(), and span().

+ Here is the call graph for this function:

◆ get()

Document::get ( )

Get complete all the data member thx info from the database.

Definition at line 630 of file document.class.php.

631 {
632 $sql="select * from document where d_id=$1";
633 $ret=$this->db->exec_sql($sql,[$this->d_id]);
634 if (Database::num_row($ret)==0)
635 {
636 return;
637 }
639 $this->ag_id=$row['ag_id'];
640 $this->d_mimetype=$row['d_mimetype'];
641 $this->d_filename=$row['d_filename'];
642 $this->d_lob=$row['d_lob'];
643 $this->d_number=$row['d_number'];
644 $this->d_description=$row['d_description'];
645 }

References $ret, $row, $sql, ag_id, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ get_all()

Document::get_all ( $ag_id)

get all the document of a given action

Parameters
$ag_idthe ag_id from action::ag_id (primary key)
Returns
an array of objects document or an empty array if nothing found

Definition at line 605 of file document.class.php.

606 {
607 $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
608 ' d_mimetype,d_description from document where ag_id=$1', array($ag_id));
609 $a=array();
610 for ($i=0; $i<sizeof($res); $i++)
611 {
612 $doc=new Document($this->db);
613 $doc->d_id=$res[$i]['d_id'];
614 $doc->ag_id=$res[$i]['ag_id'];
615 $doc->d_lob=$res[$i]['d_lob'];
616 $doc->d_number=$res[$i]['d_number'];
617 $doc->d_filename=$res[$i]['d_filename'];
618 $doc->d_mimetype=$res[$i]['d_mimetype'];
619 $doc->d_description=$res[$i]['d_description'];
620 $a[$i]=clone $doc;
621 }
622 return $a;
623 }
global $doc

References $a, $ag_id, $doc, $i, $res, and db.

◆ insert_existing_document()

static Document::insert_existing_document ( $p_ag_id,
$p_lob,
$p_filename,
$p_mimetype,
$p_description = "" )
static

Copy a existing OID (LOB) into the table document.

Note
use of global variable $cn which is the db connx to the current folder
Parameters
type$p_ag_idFollow_Up::ag_id
type$p_loboid of existing document
type$p_filenamefilename of existing document
type$p_mimetypemimetype of existing document
type$p_descriptionDescription of existing document (default empty)

Definition at line 522 of file document.class.php.

523 {
524 global $cn;
525 // insert into the table
526 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) "
527 . "values ($1,$2,$3,$4,$5,$6)";
528 $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
529 }

References $cn, and $sql.

◆ moveDocumentPj()

Document::moveDocumentPj ( $p_internal)

Move a document from the table document into the concerned row the document is not copied : it is only a link.

Parameters
$p_internalinternal code

Definition at line 1775 of file document.class.php.

1776 {
1777 $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
1778
1779 $this->db->exec_sql($sql, array($this->d_lob, $this->d_filename, $this->d_mimetype, $p_internal));
1780 // clean the table document
1781 $sql='delete from document where d_id='.$this->d_id;
1782 $this->db->exec_sql($sql);
1783 }

References $sql, and db.

◆ parseDocument()

Document::parseDocument ( $p_dir,
$p_file,
$p_type,
$p_array )

This function parse a document and replace all the predefined tags by a value.

This functions generate diffent documents (invoice, order, letter) with the info from the database

Parameters
$p_dirdirectory name
$p_filefilename
$p_typeFor the OOo document the tag are &lt and &gt instead of < and >
$p_arrayvariable from $_POST
Note
replace in the doc the tags by their values.
  • MY_* table parameter
  • ART_VEN* table quant_sold for invoice
  • CUST_* table quant_sold and fiche for invoice
  • e_* for the invoice in the $_POST

Definition at line 231 of file document.class.php.

232 {
233
234 /*!\note replace in the doc the tags by their values.
235 * - MY_* table parameter
236 * - ART_VEN* table quant_sold for invoice
237 * - CUST_* table quant_sold and fiche for invoice
238 * - e_* for the invoice in the $_POST
239 */
240 // open the document
241 $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
242 $h=fopen($infile_name, "r");
243
244 // check if tmpdir exist otherwise create it
245 $temp_dir=$_ENV['TMP'];
246 if (is_dir($temp_dir)==false)
247 {
248 if (mkdir($temp_dir)==false)
249 {
250 $msg=sprintf("D221."._("Ne peut pas créer le répertoire %s", $temp_dir));
251 record_log("D221".$msg);
252 throw new Exception($msg);
253 }
254 }
255 // Compute output_name
256 $output_name=tempnam($temp_dir, "gen_doc_");
257 $output_file=fopen($output_name, "w+");
258 // check if the opening is sucessfull
259 if ($h===false)
260 {
261 $msg=sprintf("D232"._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $p_file);
262 record_log("D232".$msg);
263 throw new Exception($msg);
264 }
265 if ($output_file==false)
266 {
267 $msg=sprintf("D264."._("Ne peut pas ouvrir [%s] [%s]"), $p_dir, $output_name);
269 throw new Exception($msg);
270 }
271 // compute the regex
272 if ($p_type=='OOo')
273 {
274 $regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
275 $lt="&lt;";
276 $gt="&gt;";
277 }
278 else
279 {
280 $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
281 $lt="<";
282 $gt=">";
283 }
284 //read the file
285 while (!feof($h))
286 {
287 // replace the tag
288 $buffer=fgets($h);
289 // search in the buffer the magic << and >>
290 // while preg_match_all finds something to replace
291 while (preg_match_all($regex, $buffer, $f)>0)
292 {
293
294 foreach ($f as $apattern)
295 {
296
297 foreach ($apattern as $pattern)
298 {
299
300
301 $to_remove=$pattern;
302 // we remove the < and > from the pattern
303 $tag=noalyss_str_replace($lt, '', $pattern);
304 $tag=noalyss_str_replace($gt, '', $tag);
305
306
307 // if the pattern if found we replace it
308 $value=$this->replace($tag, $p_array);
309 if (strpos($value??"", 'ERROR')!=false)
310 $value="";
311 /*
312 * Change type of cell to numeric
313 * allow numeric cel in ODT for the formatting and formula
314 */
315
316 $buffer=\Document::replace_value($buffer, $pattern, $value, 1, $p_type);
317 }
318 }
319 }
320 // write into the output_file
321 fwrite($output_file, $buffer);
322 }
323 fclose($h);
324 fclose($output_file);
325 if (($ret=copy($output_name, $infile_name))==FALSE)
326 {
327 $msg="D299 ".sprintf(_('Ne peut pas sauver [%s] vers [%s] code erreur = [%s]'), $output_name, $infile_name,
328 $ret);
330 throw new Exception($msg);
331 }
332 }
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...

References $f, $msg, $p_array, $p_type, $ret, $tag, $value, _, noalyss_str_replace(), record_log(), replace(), and replace_value().

Referenced by generate().

+ Here is the call graph for this function:

◆ remove()

Document::remove ( )

remove a row from the table document, the lob object is not deleted because can be linked elsewhere

Definition at line 1758 of file document.class.php.

1759 {
1760 $d_lob=$this->db->get_value('select d_lob from document where d_id=$1', array($this->d_id));
1761 $sql='delete from document where d_id='.$this->d_id;
1762 $this->db->exec_sql($sql);
1763 if ($d_lob!=0)
1764 $this->db->lo_unlink($d_lob);
1765 }

References $d_lob, $sql, and db.

◆ replace()

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 are

  • [CUST_NAME] customer's name
  • [CUST_ADDR_1] customer's address line 1
  • [CUST_CP] customer's ZIP code
  • [CUST_CO] customer's country
  • [CUST_CITY] customer's city
  • [CUST_VAT] customer's VAT
  • [MARCH_NEXT] end this item and increment the counter $i
  • [DATE_LIMIT]
  • [VEN_ART_NAME]
  • [VEN_ART_PRICE]
  • [VEN_ART_QUANT]
  • [VEN_ART_TVA_CODE]
  • [VEN_ART_STOCK_CODE]
  • [VEN_HTVA]
  • [VEN_TVAC]
  • [VEN_TVA]
  • [TOTAL_VEN_HTVA]
  • [DATE_CALC]
  • [DATE]
  • [DATE_LIMIT]
  • [DATE_LIMIT_CALC]
  • [NUMBER]
  • [MY_NAME]
  • [MY_CP]
  • [MY_COMMUNE]
  • [MY_TVA]
  • [MY_STREET]
  • [MY_NUMBER]
  • [TVA_CODE]
  • [TVA_RATE]
  • [BON_COMMANDE]
  • [OTHER_INFO]
  • [CUST_NUM]
  • [CUST_BANQUE_NAME]
  • [CUST_BANQUE_NO]
  • [USER]
  • [REFERENCE]
  • [BENEF_NAME]
  • [BENEF_BANQUE_NAME]
  • [BENEF_BANQUE_NO]
  • [BENEF_ADDR_1]
  • [BENEF_CP]
  • [BENEF_CO]
  • [BENEF_CITY]
  • [BENEF_VAT]
  • [ACOMPTE]
  • [TITLE]
  • [DESCRIPTION]
  • [COMM_PAYMENT]
  • [LABELOP]
  • [COMMENT]
  • [DESCRIPTION]
  • [DOCUMENT_ID]
  • [DATE_PAID]
  • [NOTE] Note from SALE or PURCHASE
Parameters
$p_tagTAG
$p_arraydata from $_POST
Returns
String which must replace the tag
Note
The CUST_* are retrieved thx the $p_array['tiers'] which contains the quick_code

Definition at line 712 of file document.class.php.

713 {
714 global $g_parameter,$g_user;
715 $p_tag=strtoupper($p_tag);
716 $p_tag=noalyss_str_replace('=', '', $p_tag);
717 $r="Tag inconnu";
718 static $aComment=NULL;
719 static $counter_comment=1; /* <! counter for the comment , skip the first one which is the descrition */
720
721 static $aRelatedAction=NULL;
722 static $counter_related_action=0; /* <! counter for the related action */
723
724 static $aRelatedOperation=NULL;
725 static $counter_related_operation=0; /* <! counter for the related operation */
726
727 static $aFileAttached=NULL;
728 static $counter_file=0; /* <! counter for the file */
729
730 static $aOtherCard=NULL;
731 static $counter_other_card=0; /* <! counter for the other card */
732
733 static $aTag=NULL;
734 static $counter_tag=0; /* <! counter for the tags */
735
736 static $aParameterExtra=NULL; // Extra parameter for the company
737 switch ($p_tag)
738 {
739 case 'DATE':
740 $r=(isset($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
741 break;
742 case 'DATE_CALC':
743 $r=' ';
744 // Date are in $p_array['ag_date']
745 // or $p_array['e_date']
746 if (isset($p_array['ag_timestamp']))
747 {
748 $date=format_date($p_array['ag_timestamp'], 'DD.MM.YYYY', 'YYYY-MM-DD');
749 $r=$date;
750 }
751 if (isset($p_array['e_date']))
752 {
753 $date=format_date($p_array['e_date'], 'DD.MM.YYYY', 'YYYY-MM-DD');
754 $r=$date;
755 }
756 return $r;
757 break;
758 //
759 // the company priv
760
761 case 'MY_NAME':
762 $r=$g_parameter->MY_NAME;
763 break;
764 case 'MY_CP':
765 $r=$g_parameter->MY_CP;
766 break;
767 case 'MY_COMMUNE':
768 $r=$g_parameter->MY_COMMUNE;
769 break;
770 case 'MY_TVA':
771 $r=$g_parameter->MY_TVA;
772 break;
773 case 'MY_STREET':
774 $r=$g_parameter->MY_STREET;
775 break;
776 case 'MY_NUMBER':
777 $r=$g_parameter->MY_NUMBER;
778 break;
779 case 'MY_TEL':
780 $r=$g_parameter->MY_TEL;
781 break;
782 case 'MY_FAX':
783 $r=$g_parameter->MY_FAX;
784 break;
785 case 'MY_PAYS':
786 $r=$g_parameter->MY_PAYS;
787 break;
788
789
790
791 // customer
792 /**
793 * \note The CUST_* are retrieved thx the $p_array['tiers']
794 * which contains the quick_code
795 */
796 case 'SOLDE':
797 $tiers=new Fiche($this->db);
798 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
799 $tiers->get_by_qcode($qcode, false);
800 $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT,0);
801 // if exercice is open with a report, 1 day is 1st exercice's day
802 if ( $g_parameter->MY_REPORT == 'Y') {
803 // var $user_exercice (int) current user exercice (from his preference)
804 $user_exercice=$g_user->get_exercice();
805 // var $start_date (text) First day of this exercice
806 $start_date=$this->db->get_value("
807 select to_char(min(p_start),'YYYYMMDD') first_day
808 from parm_periode where p_exercice=$1"
809 ,[$user_exercice]);
810 // var $end_date (text) last day of this exercice
811 $end_date =$this->db->get_value("
812 select to_char(max(p_end),'YYYYMMDD') last_day
813 from parm_periode where p_exercice=$1"
814 ,[$user_exercice]);
815 $a=$tiers->get_solde_detail(" to_char(jrnx.j_date,'YYYYMMDD')>='{$start_date}' and to_char(jrnx.j_date,'YYYYMMDD') <= '{$end_date}' ");
816 $r = round($a['solde'],4);
817 }else {
818 $a=$tiers->get_solde_detail();
819 $r = round($a['solde'],4);
820 }
821 break;
822 case 'CUST_NAME':
823 $tiers=new Fiche($this->db);
824 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
825 $tiers->get_by_qcode($qcode, false);
826 $r=$tiers->strAttribut(ATTR_DEF_NAME,0);
827 break;
828 case 'CUST_ADDR_1':
829 $tiers=new Fiche($this->db);
830 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
831 $tiers->get_by_qcode($qcode, false);
832 $r=$tiers->strAttribut(ATTR_DEF_ADRESS,0);
833
834 break;
835 case 'CUST_CP':
836 $tiers=new Fiche($this->db);
837
838 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
839 $tiers->get_by_qcode($qcode, false);
840 $r=$tiers->strAttribut(ATTR_DEF_CP,0);
841
842 break;
843 case 'CUST_CITY':
844 $tiers=new Fiche($this->db);
845
846 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
847 $tiers->get_by_qcode($qcode, false);
848 $r=$tiers->strAttribut(ATTR_DEF_CITY,0);
849
850 break;
851
852 case 'CUST_CO':
853 $tiers=new Fiche($this->db);
854
855 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
856 $tiers->get_by_qcode($qcode, false);
857 $r=$tiers->strAttribut(ATTR_DEF_PAYS,0);
858
859 break;
860 // Marchandise in $p_array['e_march*']
861 // \see user_form_achat.php or user_form_ven.php
862 case 'CUST_VAT':
863 $tiers=new Fiche($this->db);
864
865 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
866 $tiers->get_by_qcode($qcode, false);
867 $r=$tiers->strAttribut(ATTR_DEF_NUMTVA,0);
868 break;
869 case 'CUST_NUM':
870 $tiers=new Fiche($this->db);
871 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
872 $tiers->get_by_qcode($qcode, false);
873 $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER,0);
874 break;
875 case 'CUST_BANQUE_NO':
876 $tiers=new Fiche($this->db);
877 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
878 $tiers->get_by_qcode($qcode, false);
879 $r=$tiers->strAttribut(ATTR_DEF_BQ_NO,0);
880 break;
881 case 'CUST_BANQUE_NAME':
882 $tiers=new Fiche($this->db);
883 $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
884 $tiers->get_by_qcode($qcode, false);
885 $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME,0);
886 break;
887 /* -------------------------------------------------------------------------------- */
888 /* BENEFIT (fee notes */
889 case 'BENEF_NAME':
890 $tiers=new Fiche($this->db);
891 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
892 if ($qcode=='')
893 {
894 $r='';
895 break;
896 }
897 $tiers->get_by_qcode($qcode, false);
898 $r=$tiers->strAttribut(ATTR_DEF_NAME,0);
899 break;
900 case 'BENEF_ADDR_1':
901 $tiers=new Fiche($this->db);
902 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
903 if ($qcode=='')
904 {
905 $r='';
906 break;
907 }
908 $tiers->get_by_qcode($qcode, false);
909 $r=$tiers->strAttribut(ATTR_DEF_ADRESS,0);
910
911 break;
912 case 'BENEF_CP':
913 $tiers=new Fiche($this->db);
914
915 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
916 if ($qcode=='')
917 {
918 $r='';
919 break;
920 }
921 $tiers->get_by_qcode($qcode, false);
922 $r=$tiers->strAttribut(ATTR_DEF_CP,0);
923
924 break;
925 case 'BENEF_CITY':
926 $tiers=new Fiche($this->db);
927
928 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
929 if ($qcode=='')
930 {
931 $r='';
932 break;
933 }
934 $tiers->get_by_qcode($qcode, false);
935 $r=$tiers->strAttribut(ATTR_DEF_CITY,0);
936
937 break;
938
939 case 'BENEF_CO':
940 $tiers=new Fiche($this->db);
941
942 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
943 if ($qcode=='')
944 {
945 $r='';
946 break;
947 }
948 $tiers->get_by_qcode($qcode, false);
949 $r=$tiers->strAttribut(ATTR_DEF_PAYS,0);
950
951 break;
952 // Marchandise in $p_array['e_march*']
953 // \see user_form_achat.php or user_form_ven.php
954 case 'BENEF_VAT':
955 $tiers=new Fiche($this->db);
956
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->strAttribut(ATTR_DEF_NUMTVA,0);
965 break;
966 case 'BENEF_NUM':
967 $tiers=new Fiche($this->db);
968 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
969 if ($qcode=='')
970 {
971 $r='';
972 break;
973 }
974 $tiers->get_by_qcode($qcode, false);
975 $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER,0);
976 break;
977 case 'BENEF_BANQUE_NO':
978 $tiers=new Fiche($this->db);
979 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
980 if ($qcode=='')
981 {
982 $r='';
983 break;
984 }
985 $tiers->get_by_qcode($qcode, false);
986 $r=$tiers->strAttribut(ATTR_DEF_BQ_NO,0);
987 break;
988 case 'BENEF_BANQUE_NAME':
989 $tiers=new Fiche($this->db);
990 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
991 if ($qcode=='')
992 {
993 $r='';
994 break;
995 }
996 $tiers->get_by_qcode($qcode, false);
997 $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME,0);
998 break;
999
1000 // Marchandise in $p_array['e_march*']
1001 // \see user_form_achat.php or user_form_ven.php
1002 case 'NUMBER':
1004 break;
1005 case "DOCUMENT_ID":
1006 if (isset($p_array['ag_id']))
1007 return $p_array['ag_id'];
1008 return "";
1009 break;
1010
1011 case 'USER' :
1012 return $_SESSION[SESSION_KEY.'use_name'].', '.$_SESSION[SESSION_KEY.'use_first_name'];
1013
1014 break;
1015 case 'REFERENCE':
1016 $act=new Follow_Up($this->db);
1017 $act->ag_id=$this->ag_id;
1018 $act->get();
1019 $r=$act->ag_ref;
1020 break;
1021
1022 /*
1023 * - [VEN_ART_NAME]
1024 * - [VEN_ART_PRICE]
1025 * - [VEN_ART_QUANT]
1026 * - [VEN_ART_TVA_CODE]
1027 * - [VEN_ART_STOCK_CODE]
1028 * - [VEN_HTVA]
1029 * - [VEN_TVAC]
1030 * - [VEN_TVA]
1031 * - [TOTAL_VEN_HTVA]
1032 * - [DATE_LIMIT]
1033 * - [DATE_PAID]
1034 */
1035 case 'DATE_LIMIT_CALC':
1036 if (isset($p_array["e_ech"]))
1037 return format_date($p_array["e_ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1038 if (isset($p_array["ech"]))
1039 return format_date($p_array["ech"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1040 if (isset($p_array["ag_remind_date"]))
1041 return format_date($p_array["ag_remind_date"], 'DD.MM.YYYY', 'YYYY-MM-DD');
1042 return "";
1043 break;
1044 case 'DATE_LIMIT':
1045 if (isset($p_array["ech"]))
1046 return $p_array["ech"];
1047 if (isset($p_array["e_ech"]))
1048 return $p_array["e_ech"];
1049 if (isset($p_array["ag_remind_date"]))
1050 return $p_array["ag_remind_date"];
1051 return "";
1052 break;
1053 case 'DATE_PAID':
1054 if ( isset ($p_array['jr_date_paid']) ) { return $p_array['jr_date_paid'];}
1055 break;
1056 case 'MARCH_NEXT':
1057 $this->counter++;
1058 $r='';
1059 break;
1060
1061 case 'VEN_ART_NAME':
1062 // check if the march exists
1063 if (!isset($p_array["e_march".$this->counter]))
1064 return "";
1065 // check that something is sold
1066 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1067 {
1068 $f=new Fiche($this->db);
1069 $f->get_by_qcode($p_array["e_march".$this->counter], false);
1070 $r=$f->strAttribut(ATTR_DEF_NAME,0);
1071 }
1072 else
1073 $r="";
1074 break;
1075 case 'VEN_ART_LABEL':
1076 $id='e_march'.$this->counter."_label";
1077 // check if the march exists
1078
1079 if (!isset($p_array[$id])||(isset($p_array[$id])&&noalyss_strlentrim($p_array[$id])==0))
1080 {
1081 $id='e_march'.$this->counter;
1082 // check if the march exists
1083 if (!isset($p_array[$id]))
1084 $r="";
1085 else
1086 {
1087 // check that something is sold
1088 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1089 {
1090 $f=new Fiche($this->db);
1091 $f->get_by_qcode($p_array[$id], false);
1092 $r=$f->strAttribut(ATTR_DEF_NAME,0);
1093 }
1094 else
1095 $r="";
1096 }
1097 }
1098 else
1099 $r=$p_array[$id];
1100 break;
1101 case 'VEN_ART_STOCK_CODE':
1102 $id='e_march'.$this->counter;
1103 // check if the march exists
1104 if (!isset($p_array[$id]))
1105 $r="";
1106 else
1107 {
1108 // check that something is sold
1109 if ($p_array['e_march'.$this->counter.'_price']!=0&&$p_array['e_quant'.$this->counter]!=0)
1110 {
1111 $f=new Fiche($this->db);
1112 $f->get_by_qcode($p_array[$id], false);
1113 $r=$f->strAttribut(ATTR_DEF_STOCK,0);
1114 $r=($r==NOTFOUND)?'':$r;
1115 }
1116 }
1117 break;
1118 case 'VEN_QCODE':
1119 $id='e_march'.$this->counter;
1120 if (!isset($p_array[$id]))
1121 return "";
1122 return $p_array[$id];
1123 break;
1124 case 'VEN_ART_PRICE':
1125 $id='e_march'.$this->counter.'_price';
1126 if (!isset($p_array[$id]))
1127 return "";
1128 if ($p_array[$id]==0)
1129 return "";
1130 $r=$p_array[$id];
1131 break;
1132
1133 case 'TVA_RATE':
1134 case 'VEN_ART_TVA_RATE':
1135 $id='e_march'.$this->counter.'_tva_id';
1136 if (!isset($p_array[$id]))
1137 return "";
1138 if ($p_array[$id]==-1||$p_array[$id]=='')
1139 return "";
1140 $march_id='e_march'.$this->counter.'_price';
1141 if (!isset($p_array[$march_id]))
1142 return '';
1143 $tva= Acc_Tva::build($this->db,$p_array[$id]);
1144 if ($tva->load()==-1)
1145 return '';
1146 return $tva->get_parameter("rate");
1147 break;
1148
1149 case 'TVA_CODE':
1150 case 'VEN_ART_TVA_CODE':
1151 $id='e_march'.$this->counter.'_tva_id';
1152 if (!isset($p_array[$id]))
1153 return "";
1154 if ($p_array[$id]==-1)
1155 return "";
1156 $qt='e_quant'.$this->counter;
1157 $price='e_march'.$this->counter.'_price';
1158 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1159 return "";
1160
1161 $r=$p_array[$id];
1162 break;
1163
1164 case 'TVA_LABEL':
1165 $id='e_march'.$this->counter.'_tva_id';
1166 if (!isset($p_array[$id]))
1167 return "";
1168 $march_id='e_march'.$this->counter.'_price';
1169 if (!isset($p_array[$march_id]))
1170 return '';
1171 if ($p_array[$march_id]==0)
1172 return '';
1173 $tva= Acc_Tva::build($this->db, $p_array[$id]);
1174 if ($tva->load()==-1)
1175 return "";
1176 $r=$tva->get_parameter('label');
1177
1178 break;
1179
1180 /* total VAT for one sold */
1181 case 'TVA_AMOUNT':
1182 case 'VEN_TVA':
1183 $qt='e_quant'.$this->counter;
1184 $price='e_march'.$this->counter.'_price';
1185 $tva='e_march'.$this->counter.'_tva_id';
1186 /* if we do not use vat this var. is not set */
1187 if (!isset($p_array[$tva]))
1188 return '';
1189 if (!isset($p_array ['e_march'.$this->counter]))
1190 return "";
1191 if (!isset($p_array[$tva]))
1192 return "";
1193 // check that something is sold
1194 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1195 return "";
1196 $r=$p_array['e_march'.$this->counter.'_tva_amount'];
1197 break;
1198 /* TVA automatically computed */
1199 case 'VEN_ART_TVA':
1200
1201 $qt='e_quant'.$this->counter;
1202 $price='e_march'.$this->counter.'_price';
1203 $tva='e_march'.$this->counter.'_tva_id';
1204 if (!isset($p_array['e_march'.$this->counter]))
1205 return "";
1206 if (!isset($p_array[$tva]))
1207 return "";
1208 // check that something is sold
1209 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1210 return "";
1211 $oTva= Acc_Tva::build($this->db, $p_array[$tva]);
1212 if ($oTva->load()==-1)
1213 return "";
1214 $r=noalyss_round($p_array[$price], 2)*$oTva->get_parameter('rate');
1215 $r=noalyss_round($r, 2);
1216 break;
1217
1218 case 'VEN_ART_TVAC':
1219 $qt='e_quant'.$this->counter;
1220 $price='e_march'.$this->counter.'_price';
1221 if (!isset($p_array['e_march'.$this->counter]))
1222 return "";
1223 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1224 return "";
1225 // check that something is sold
1226 if ($p_array[$price]==0||$p_array[$qt]==0||noalyss_strlentrim($p_array[$price])==0||noalyss_strlentrim($p_array[$qt])==0)
1227 return "";
1228 if (!isset($p_array['e_march'.$this->counter.'_tva_id']))
1229 return '';
1230 $tva=Acc_Tva::build($this->db, $p_array['e_march'.$this->counter.'_tva_id']);
1231 if ($tva->load()==-1)
1232 {
1233 $r=noalyss_round($p_array[$price], 2);
1234 }
1235 else
1236 {
1237 $r=noalyss_round($p_array[$price]*$tva->get_parameter('rate')+$p_array[$price], 2);
1238 }
1239
1240 break;
1241
1242 case 'VEN_ART_QUANT':
1243 $id='e_quant'.$this->counter;
1244 if (!isset($p_array[$id]))
1245 return "";
1246 // check that something is sold
1247 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)
1248 return "";
1249 $r=$p_array[$id];
1250 break;
1251
1252 case 'VEN_HTVA':
1253 $id='e_march'.$this->counter.'_price';
1254 $quant='e_quant'.$this->counter;
1255 if (!isset($p_array[$id]))
1256 return "";
1257
1258 // check that something is sold
1259 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)
1260 return "";
1261 bcscale(4);
1263 $r=noalyss_round($r, 2);
1264 break;
1265
1266 case 'VEN_TVAC':
1267 $id='e_march'.$this->counter.'_tva_amount';
1268 $price='e_march'.$this->counter.'_price';
1269 $quant='e_quant'.$this->counter;
1270 if (!isset($p_array['e_march'.$this->counter.'_price'])||!isset($p_array['e_quant'.$this->counter]))
1271 {
1272 return "";
1273 }
1274 // check that something is sold
1275 if ($p_array['e_march'.$this->counter.'_price']==0||$p_array['e_quant'.$this->counter]==0)
1276 {
1277 return "";
1278 }
1279 bcscale(4);
1280 // if TVA not exist
1281 if (!isset($p_array[$id]))
1282 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1283 else
1284 {
1285 $r=noalyss_bcmul($p_array[$price], $p_array[$quant]);
1287 }
1288 $r=noalyss_round($r, 2);
1289 return $r;
1290 break;
1291
1292 case 'TOTAL_VEN_HTVA':
1293 bcscale(4);
1294 $sum=0.0;
1295 if (!isset($p_array["nb_item"]))
1296 return "";
1297 for ($i=0; $i<$p_array["nb_item"]; $i++)
1298 {
1299 $sell='e_march'.$i.'_price';
1300 $qt='e_quant'.$i;
1301
1302 if (!isset($p_array[$sell]))
1303 break;
1304
1305 if (noalyss_strlentrim($p_array[$sell])==0||
1306 noalyss_strlentrim($p_array[$qt])==0||
1307 $p_array[$qt]==0||$p_array[$sell]==0)
1308 continue;
1309 $tmp1=noalyss_bcmul($p_array[$sell], $p_array[$qt]);
1310 $sum=noalyss_bcadd($sum, $tmp1);
1311 }
1312 $r=noalyss_round($sum, 2);
1313 break;
1314 case 'TOTAL_VEN_TVAC':
1315 if (!isset($p_array["nb_item"]))
1316 return "";
1317 $sum=0.0;
1318 bcscale(4);
1319 for ($i=0; $i<$p_array["nb_item"]; $i++)
1320 {
1321 $tva='e_march'.$i.'_tva_amount';
1322 $tva_amount=0;
1323 /* if we do not use vat this var. is not set */
1324 if (isset($p_array[$tva]))
1325 {
1326 $tva_amount=$p_array[$tva];
1327 }
1328
1329 $sell=$p_array['e_march'.$i.'_price'];
1330 $qt=$p_array['e_quant'.$i];
1331 $tot=noalyss_bcmul($sell, $qt);
1332 $tva_amount=noalyss_round($tva_amount,2);
1334 $tot=noalyss_bcadd($tot, $tva_amount);
1335 $sum=noalyss_bcadd($sum, $tot??0);
1336 }
1337 $r=noalyss_round($sum??0, 2);
1338
1339 break;
1340 case 'TOTAL_TVA':
1341 if (!isset($p_array["nb_item"]))
1342 return "";
1343 $sum=0.0;
1344 for ($i=0; $i<$p_array["nb_item"]; $i++)
1345 {
1346 $tva='e_march'.$i.'_tva_amount';
1347 if (!isset($p_array[$tva]))
1348 $tva_amount=0.0;
1349 else
1350 {
1351 $tva_amount=$p_array[$tva];
1352 $tva_amount=($tva_amount=="")?0:$tva_amount;
1353 }
1354 $sum+=$tva_amount;
1355 $sum=noalyss_round($sum, 2);
1356 }
1357 $r=$sum;
1358
1359 break;
1360 case 'BON_COMMANDE':
1361 if (isset($p_array['bon_comm']))
1362 return $p_array['bon_comm'];
1363 else
1364 return "";
1365 break;
1366 case 'PJ':
1367 if (isset($p_array['e_pj']))
1368 return $p_array['e_pj'];
1369 else
1370 return "";
1371
1372 case 'OTHER_INFO':
1373 if (isset($p_array['other_info']))
1374 return $p_array['other_info'];
1375 else
1376 return "";
1377 break;
1378 case 'LABELOP':
1379 if (isset($p_array['e_comm']))
1380 return $p_array['e_comm'];
1381 break;
1382 case 'ACOMPTE':
1383 if (isset($p_array['acompte']))
1384 return $p_array['acompte'];
1385 return "0";
1386 break;
1387 case 'STOCK_NAME':
1388 if (!isset($p_array['repo']))
1389 return "";
1390 $ret=$this->db->get_value('select r_name from public.stock_repository where r_id=$1',
1391 array($p_array['repo']));
1392 return $ret;
1393 case 'STOCK_ADRESS':
1394 if (!isset($p_array['repo']))
1395 return "";
1396 $ret=$this->db->get_value('select r_adress from public.stock_repository where r_id=$1',
1397 array($p_array['repo']));
1398 return $ret;
1399 case 'STOCK_COUNTRY':
1400 if (!isset($p_array['repo']))
1401 return "";
1402 $ret=$this->db->get_value('select r_country from public.stock_repository where r_id=$1',
1403 array($p_array['repo']));
1404 return $ret;
1405 case 'STOCK_CITY':
1406 if (!isset($p_array['repo']))
1407 return "";
1408 $ret=$this->db->get_value('select r_city from public.stock_repository where r_id=$1',
1409 array($p_array['repo']));
1410 return $ret;
1411 case 'STOCK_PHONE':
1412 if (!isset($p_array['repo']))
1413 return "";
1414 $ret=$this->db->get_value('select r_phone from public.stock_repository where r_id=$1',
1415 array($p_array['repo']));
1416 return $ret;
1417 // Follow up
1418 //Title
1419 case 'TITLE':
1420 if (isset($p_array['ag_title']))
1421 return $p_array['ag_title'];
1422 return "";
1423 break;
1424 // Description is the first comment
1425 case 'DESCRIPTION':
1426 if (isset($p_array['ag_id']))
1427 {
1428 // retrieve first comment
1429 $description=$this->db->get_value("select agc_comment "
1430 ." from action_gestion_comment "
1431 ."where ag_id=$1 order by AGC_ID asc limit 1"
1432 , [$p_array['ag_id']]);
1433 return $description;
1434 }
1435 if ( isset($p_array['e_comm'])) {return $p_array['e_comm'] ; }
1436
1437 return "";
1438 break;
1439
1440
1441 // Comments, use a counter to move to the next comment, only for Follow-Up
1442 //
1443 case 'COMMENT':
1444 if (isset($p_array['ag_id']))
1445 {
1446 // Static value, if null the retrieve all of them
1447 if ($aComment==NULL)
1448 {
1449 // retrieve comments
1450 $aComment=$this->db->get_array("select AGC_ID,agc_comment ,"
1451 ." to_char(agc_date,'DD-MM-YY HH24:MI') as str_date ,"
1452 ." tech_user "
1453 ." from action_gestion_comment "
1454 ."where ag_id=$1 order by 1"
1455 , [$p_array['ag_id']]);
1456 }
1457 $nb_comment=count($aComment);
1458 $description="";
1459 if (count($aComment)>$counter_comment)
1460 {
1461 $description.=sprintf(_('le %s , %s écrit %s'), $aComment[$counter_comment]['str_date'],
1462 $aComment[$counter_comment]['tech_user'], $aComment[$counter_comment]['agc_comment']);
1463 $counter_comment++;
1464 }
1465 return $description;
1466 }
1467 return "";
1468 break;
1469 // Related Action, use a counter to move to the next related action, only for Follow-Up
1470 //
1471 case 'RELATED_ACTION':
1472 if (isset($p_array['ag_id']))
1473 {
1474 // Static value, if null the retrieve all of them
1475 if ($aRelatedAction==NULL)
1476 {
1477 // retrieve parent
1478 $followup=new Follow_Up($this->db, $p_array["ag_id"]);
1479 $aRelatedAction=array();
1480 $aParent=$followup->get_parent();
1481 if ($aParent==-1)
1482 return "";
1483 $nb_parent=count($aParent);
1484 $sql_related_action="
1485 select ag_id,
1486 f_id_dest,
1487 (select ad_value from fiche_detail fd1 where fd1.ad_id=23 and fd1.f_id=f_id_dest) as qcode,
1488 (select ad_value from fiche_detail fd1 where fd1.ad_id=1 and fd1.f_id=f_id_dest) as card_name,
1489 (select ad_value from fiche_detail fd1 where fd1.ad_id=32 and fd1.f_id=f_id_dest) as card_fname,
1490 ag_title,
1491 to_char(ag_timestamp,'DD.MM.YYYY') as strdate,
1492 ag_ref
1493 from action_gestion ag where ag_id=$1 ";
1494
1495 for ($x=0; $x<$nb_parent; $x++)
1496 {
1497 $aRelatedAction[]=$this->db->get_row($sql_related_action, [$aParent[$x]['aga_least']]);
1498 $aChild=$followup->get_children($aParent[$x]['aga_least']);
1499 $nb_child=count($aChild);
1500 for ($y=0; $y<$nb_child; $y++)
1501 {
1502 $aRelatedAction[]=$this->db->get_row($sql_related_action,
1503 [$aChild[$y]['aga_greatest']]);
1504 }
1505 }
1506 }
1507 $description="";
1508 if (count($aRelatedAction)>$counter_related_action)
1509 {
1510 $description=sprintf("docid %s %s %s %s %s %s %s",
1511 $aRelatedAction[$counter_related_action]['ag_id'],
1512 $aRelatedAction[$counter_related_action]['ag_ref'],
1513 $aRelatedAction[$counter_related_action]['strdate'],
1514 $aRelatedAction[$counter_related_action]['qcode'],
1515 $aRelatedAction[$counter_related_action]['card_fname'],
1516 $aRelatedAction[$counter_related_action]['card_name'],
1517 $aRelatedAction[$counter_related_action]['ag_title']
1518 );
1519
1520 $counter_related_action++;
1521 }
1522 return $description;
1523 }
1524 return "";
1525 break;
1526
1527 // Concerned operation, use a counter to move to the next one, only for Follow-Up
1528 //
1529 case 'CONCERNED_OPERATION':
1530 if (isset($p_array['ag_id']))
1531 {
1532 // Static value, if null the retrieve all of them
1533 if ($aRelatedOperation==NULL)
1534 {
1535 // retrieve comments
1536 $aRelatedOperation=$this->db->get_array("select ago_id,
1537 j.jr_id,
1538 j.jr_internal,
1539 j.jr_comment,
1540 j.jr_pj_number,
1541 to_char(j.jr_date,'DD.MM.YY') as str_date
1542 from jrn as j
1543 join action_gestion_operation as ago on (j.jr_id=ago.jr_id)
1544 where ag_id=$1 order by jr_date,jr_id"
1545 , [$p_array['ag_id']]);
1546 }
1547 $description="";
1548 if (count($aRelatedOperation)>$counter_related_operation)
1549 {
1550 $description.=sprintf('%s %s %s %s ',
1551 $aRelatedOperation[$counter_related_operation]['str_date'],
1552 $aRelatedOperation[$counter_related_operation]['jr_internal'],
1553 $aRelatedOperation[$counter_related_operation]['jr_comment'],
1554 $aRelatedOperation[$counter_related_operation]['jr_pj_number']
1555 );
1556 $counter_related_operation++;
1557 }
1558 return $description;
1559 }
1560 return "";
1561 break;
1562 // Other card, use a counter to move to the next one, only for Follow-Up
1563 //
1564 case 'OTHER_CARDS':
1565 if (isset($p_array['ag_id']))
1566 {
1567 // Static value, if null the retrieve all of them
1568 if ($aOtherCard==NULL)
1569 {
1570 // retrieve comments
1571 $aOtherCard=$this->db->get_array("
1572 select
1573 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 1) as cname,
1574 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 32) as cfname,
1575 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 23) as qcode,
1576 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 18 ) as email,
1577 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 27 ) as mobile,
1578 (select ad_value from fiche_detail where f_id = ap.f_id and ad_id = 17 ) as phone
1579 from action_person ap
1580 where ag_id=$1
1581 "
1582 , [$p_array['ag_id']]);
1583 }
1584 $description="";
1585 if (count($aOtherCard)>$counter_other_card)
1586 {
1587 $description.=sprintf('%s %s %s %s %s %s ', $aOtherCard[$counter_other_card]['cname'],
1588 $aOtherCard[$counter_other_card]['cfname'], $aOtherCard[$counter_other_card]['qcode'],
1589 $aOtherCard[$counter_other_card]['email'], $aOtherCard[$counter_other_card]['phone'],
1590 $aOtherCard[$counter_other_card]['mobile']);
1591 $counter_other_card++;
1592 }
1593 return $description;
1594 }
1595 return "";
1596 break;
1597 // Attachment , use a counter to move to the next one, only for Follow-Up
1598 //
1599 case 'ATTACHED_FILES':
1600 if (isset($p_array['ag_id']))
1601 {
1602 // Static value, if null the retrieve all of them
1603 if ($aFileAttached==NULL)
1604 {
1605 // retrieve comments
1606 $aFileAttached=$this->db->get_array("
1607 select d_filename,d_description from document d where ag_id=$1
1608 "
1609 , [$p_array['ag_id']]);
1610 }
1611 $nb_comment=count($aFileAttached);
1612 $description="";
1613 if (count($aFileAttached)>$counter_file)
1614 {
1615 $description.=sprintf("%s %s ", $aFileAttached[$counter_file]['d_filename'],
1616 $aFileAttached [$counter_file]['d_description']);
1617 $counter_file++;
1618 }
1619 return $description;
1620 }
1621 return "";
1622 break;
1623 // Tag , use a counter to move to the next one
1624 case 'TAGS':
1625 if (isset($p_array['ag_id']))
1626 {
1627 // Static value, if null the retrieve all of them
1628 if ($aTag==NULL)
1629 {
1630 // retrieve comments
1631 $aTag=$this->db->get_array("
1632 select t_tag from action_tags at2 join tags t using(t_id) where ag_id=$1 order by upper(t_tag)
1633 "
1634 , [$p_array['ag_id']]);
1635 }
1636 $description="";
1637 if (count($aTag)>$counter_tag)
1638 {
1639 $description.=sprintf("%s ", $aTag [$counter_tag]['t_tag']);
1640 $counter_tag++;
1641 }
1642 return $description;
1643 }
1644
1645 return "";
1646 break;
1647 case 'COMM_PAYMENT':
1648 if (isset($p_array["e_comm_paiement"]))
1649 {
1650 return $p_array["e_comm_paiement"];
1651 }
1652 else
1653 {
1654 return "";
1655 }
1656
1657 // priority of the follow up document
1658 case 'PRIORITY':
1659 if (isset($p_array['ag_priority']))
1660 {
1661 $aPriority=array(1=>_("Haute"), 2=>_("Normale"), 3=>_("Basse"));
1662 return $aPriority[$p_array["ag_priority"]];
1663 }
1664 return "";
1665 // Priority of the follow up document
1666 case 'GROUPMGT':
1667 if (isset($p_array['ag_dest']))
1668 {
1669 $profile=$this->db->get_value("select p_name from profile where p_id=$1", array($p_array['ag_dest']));
1670 return $profile;
1671 }
1672 return "";
1673 // Hour in the follow up document
1674 case 'HOUR':
1675 if (isset($p_array['ag_hour']))
1676 {
1677 return $p_array["ag_hour"];
1678 }
1679 return "";
1680 // State in the follow up document
1681 case 'STATUS':
1682 if (isset($p_array['ag_state']))
1683 {
1684 $status=$this->db->get_value("
1685 select s_value from document_state where s_id=$1", array($p_array['ag_state']));
1686 return $status;
1687 }
1688 return "";
1689 // type of document
1690 case 'DOCUMENT_TYPE':
1691 $ret="";
1692 if (isset($p_array['ag_id']))
1693 {
1694 $ret=$this->db->get_value("select dt_value
1695 from action_gestion
1696 join document_type dt on (ag_type=dt.dt_id)
1697 where ag_id=$1", array($p_array["ag_id"]));
1698 } elseif (isset($p_array['gen_doc'])) {
1699 $ret = $this->db->get_value("
1700 select md_name from public.document_modele where md_id=$1",
1701 [$p_array['gen_doc']]);
1702 }
1703 return $ret;
1704 case 'NOTE':
1705 return $p_array['jrn_note_input']??"";
1706
1707
1708
1709 } // end switch
1710 /*
1711 * retrieve the value of ATTR for e_march
1712 */
1713 if (preg_match('/^ATTR/', $p_tag)==1)
1714 {
1715 $r="";
1716 // Retrieve f_id
1717 if (isset($p_array['e_march'.$this->counter]))
1718 {
1719 $id=$p_array['e_march'.$this->counter];
1720 $r=$this->replace_special_tag($id, $p_tag);
1721 return $r;
1722 }
1723 }
1724 /*
1725 * @brief retrieve the value of ATTR for e_march
1726 */
1727 if (preg_match('/^BENEFATTR/', $p_tag)==1)
1728 {
1729 $r="";
1730 $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1731 // Retrieve f_id
1732 $r=$this->replace_special_tag($qcode, $p_tag);
1733 return $r;
1734 }
1735 if (preg_match('/^CUSTATTR/', $p_tag)==1)
1736 {
1737 $r="";
1738 if (isset($p_array['qcode_dest'])||isset($p_array['e_client']))
1739 {
1740 $qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
1741 $r=$this->replace_special_tag($qcode, $p_tag);
1742 }
1743 return $r;
1744 }
1745
1746 // check also if the tag does exist in parameter_extra table
1747 $pe_value=$this->db->get_value("select pe_value from parameter_extra where pe_code=$1",[$p_tag]);
1748 if ( $this->db->count() > 0 ) { return $pe_value;}
1749
1750 return $r;
1751 }
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)
noalyss_strlentrim($p_string)
noalyss_bcmul($p_first, $p_second)
global $g_parameter
global $g_user
if no group available , then stop
if(!headers_sent())
– pour utiliser unoconv démarrer un server libreoffice commande libreoffice –headless –accept="socket...
$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.
replace_special_tag($p_qcode, $p_tag)
replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value
const NOTFOUND(!defined("SYSINFO_DISPLAY"))
Definition constant.php:130
const ATTR_DEF_ADRESS
Definition constant.php:223
const ATTR_DEF_NUMTVA
Definition constant.php:222
const ATTR_DEF_NAME
Definition constant.php:216
const ATTR_DEF_CP
Definition constant.php:224
const ATTR_DEF_BQ_NO
Definition constant.php:217
const ATTR_DEF_CITY
Definition constant.php:229
const ATTR_DEF_NUMBER_CUSTOMER
Definition constant.php:232
const ATTR_DEF_ACCOUNT
Definition constant.php:215
const ATTR_DEF_BQ_NAME
Definition constant.php:218
const ATTR_DEF_PAYS
Definition constant.php:225
const ATTR_DEF_STOCK
Definition constant.php:226
$user_exercice
Get exercice.
if( $delta< 0) elseif( $delta==0)

References $a, $act, $ag_id, $aTag, $d_number, $date, $description, $f, $g_parameter, $g_user, $i, $id, $p, $p_array, $profile, $qcode, $r, $ret, $status, $tiers, $tot, $user_exercice, _, ATTR_DEF_ACCOUNT, ATTR_DEF_ADRESS, ATTR_DEF_BQ_NAME, ATTR_DEF_BQ_NO, ATTR_DEF_CITY, ATTR_DEF_CP, ATTR_DEF_NAME, ATTR_DEF_NUMBER_CUSTOMER, ATTR_DEF_NUMTVA, ATTR_DEF_PAYS, ATTR_DEF_STOCK, Acc_Tva\build(), db, elseif, format_date(), if, noalyss_bcadd(), noalyss_bcmul(), noalyss_round(), noalyss_str_replace(), noalyss_strlentrim(), NOTFOUND, and replace_special_tag().

Referenced by parseDocument().

+ Here is the call graph for this function:

◆ replace_special_tag()

Document::replace_special_tag ( $p_qcode,
$p_tag )

replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx is the ad_value

Parameters
$p_qcodeqcode of the card
$p_tagtag to parse
Returns
the ad_value contained in fiche_detail or for the type "select" the label

Definition at line 1793 of file document.class.php.

1794 {
1795 // check if the march exists
1796 if ($p_qcode=="") return "";
1797
1798 $f=new Fiche($this->db);
1799 $found=$f->get_by_qcode($p_qcode, false);
1800 // if not found exit
1801 if ($found==1) return "";
1802
1803 // get the ad_id
1804 $attr=preg_replace("/^.*ATTR/", "", $p_tag);
1805
1806 if (isNumber($attr)==0) return "";
1807
1808 $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1", array($attr));
1809
1810 // get ad_value
1811 $ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",
1812 array($f->id, $attr));
1813
1814 // if ad_id is type select execute select and get value
1815 if ($ad_type=="select")
1816 {
1817 $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1", array($attr));
1818 $array=$this->db->make_array($sql);
1819 for ($a=0; $a<count($array); $a++)
1820 {
1821 if ($array[$a]['value']==$ad_value)
1822 return $array[$a]['label'];
1823 }
1824 }
1825 // if ad_id is not type select get value
1826 return $ad_value;
1827 }
isNumber($p_int)

References $a, $array, $attr, $f, $sql, db, and isNumber().

Referenced by replace().

+ Here is the call graph for this function:

◆ replace_value()

static Document::replace_value ( $p_buffer,
$p_pattern,
$p_value,
$p_limit = -1,
$p_type = 'OOo' )
static

replace a pattern with a value in the buffer , handle the change for OOo type file and amount

Parameters
string$p_buffer
string$_pattern
mixed$p_value

Definition at line 1841 of file document.class.php.

1842 {
1843 $check=$p_pattern;
1844 $p_value=$p_value??'';
1845 $check=str_replace(['&lt;', '&gt;', '<', '>', '='], "", $check);
1846 if (preg_replace('/[^[:alnum:]^_]/', '', $check)!=$check)
1847 {
1848 throw new Exception(sprintf(_("chaine à remplacer [%s] contient un caractère interdit"), $p_pattern));
1849 }
1850 $count=0;
1851 if (is_numeric($p_value)&&$p_type=='OOo')
1852 {
1853 /* -- works only with OOo Calc -- */
1854 $searched='/office:value-type="string"><text:p>'.$p_pattern.'/i';
1855 $replaced='office:value-type="float" office:value="'.$p_value.'"><text:p>'.$p_value;
1856 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1857 if ($count==0)
1858 {
1859 /* -- work with libreOffice > 5 -- */
1860 $searched='/office:value-type="string" calcext:value-type="string"><text:p>(<text:s\/>)*'.$p_pattern.'/i';
1861 $replaced='office:value-type="float" office:value="'.$p_value.'" calcext:value-type="float"><text:p>'.$p_value;
1862 $p_buffer=preg_replace($searched, $replaced, $p_buffer, $p_limit, $count);
1863 }
1864 }
1865 if ($count==0)
1866 {
1867
1868 if ($p_type=='OOo')
1869 {
1870 $p_value=noalyss_str_replace('&', '&amp;', $p_value);
1871 $p_value=noalyss_str_replace('<', '&lt;', $p_value);
1872 $p_value=noalyss_str_replace('>', '&gt;', $p_value);
1873 $p_value=noalyss_str_replace('"', '&quot;', $p_value);
1874 $p_value=noalyss_str_replace("'", '&apos;', $p_value);
1875 }
1876 $p_buffer=preg_replace('/'.$p_pattern.'/i', $p_value, $p_buffer, $p_limit);
1877 }
1878 return $p_buffer;
1879 }
$count
$check

References $check, $count, $p_type, _, and noalyss_str_replace().

Referenced by parseDocument().

+ Here is the call graph for this function:

◆ saveGenerated()

Document::saveGenerated ( $p_file)

Save the generated Document.

Parameters
$p_fileis the generated file
Returns
0 if no error otherwise 1

Definition at line 342 of file document.class.php.

343 {
344 // We save the generated file
345 $doc=new Document($this->db);
346 $this->db->start();
347 $this->d_lob=$this->db->lo_import($p_file);
348 if ($this->d_lob==false)
349 {
350 echo "ne peut pas importer [$p_file]";
351 return 1;
352 }
353
354 $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
355 values ($1,$2,$3,$4,$5)";
356
357 $this->db->exec_sql($sql,
358 array($this->ag_id,
359 $this->d_lob,
360 $this->d_number,
361 $this->d_filename,
362 $this->d_mimetype));
363 $this->d_id=$this->db->get_current_seq("document_d_id_seq");
364 // Clean the file
365 unlink($p_file);
366 $this->db->commit();
367 return 0;
368 }

References $doc, $sql, ag_id, and db.

Referenced by generate().

◆ send()

Document::send ( )

send the document

Definition at line 552 of file document.class.php.

553 {
554 // retrieve the template and generate document
555 $this->db->start();
556 $ret=$this->db->exec_sql(
557 "select d_id,d_lob,d_filename,d_mimetype from document where d_id=$1", [$this->d_id]);
558
559 if (Database::num_row($ret)==0)
560 {
561 // send it to stdout
562 ini_set('zlib.output_compression', 'Off');
563 header("Pragma: public");
564 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
565 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
566 header("Cache-Control: must-revalidate");
567 header('Content-type: text');
568 header('Content-Disposition: attachment;filename="vide.txt"', FALSE);
569 header("Accept-Ranges: bytes");
570 echo "VIDE-EMPTY";
571 return;
572 }
574 //the document is saved into file $tmp
575 $tmp=tempnam($_ENV['TMP'], 'document_');
576 $this->db->lo_export($row['d_lob'], $tmp);
577 $this->d_mimetype=$row['d_mimetype'];
578 $this->d_filename=$row['d_filename'];
579 $file=fopen($tmp, 'r');
580 // send it to stdout
581 ini_set('zlib.output_compression', 'Off');
582 header("Pragma: public");
583 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
584 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
585 header("Cache-Control: must-revalidate");
586 header('Content-type: '.$this->d_mimetype);
587 header('Content-Disposition: attachment;filename="'.$this->d_filename.'"', FALSE);
588 header("Accept-Ranges: bytes");
589 while (!feof($file))
590 {
591 echo fread($file, 8192);
592 }
593 fclose($file);
594
595 unlink($tmp);
596 $this->db->commit();
597 }

References $file, $ret, $row, $tmp, db, DatabaseCore\fetch_array(), and DatabaseCore\num_row().

+ Here is the call graph for this function:

◆ transform2pdf()

Document::transform2pdf ( )

transform the current Document to a PDF, returns the full path of the PDF from the TMP folder

Returns
string full path to the PDF file

Definition at line 1917 of file document.class.php.

1918 {
1919 if (GENERATE_PDF == 'NO' ) {
1920 \record_log(__FILE__."D1857 PDF not available");
1921 throw new \Exception("Cannot not transform to PDF",5000);
1922 }
1923 // Extract from public.document
1924 $dirname=tempnam($_ENV['TMP'],"document");
1925
1926 if ( $dirname == false ) {
1927 throw new Exception("D1862.cannot create tmp file",5000);
1928 }
1929 unlink($dirname);
1930 umask(0);
1931 if ( mkdir($dirname) == false ) {
1932 throw new Exception("D1868.cannot create tmp directory",5000);
1933 }
1934
1935 $destination_file=$dirname."/".$this->d_filename;
1936 $this->export_file($destination_file);
1937 ob_start();
1938 passthru(OFFICE . escapeshellarg($destination_file), $status);
1939 $result =ob_get_contents();
1940 ob_end_clean();
1941 if ($status != 0) {
1942 \record_log(__FILE__."D1879 Error cannot transform into PDF"." output [$result]");
1943 throw new \Exception("D1879 Cannot not transform to PDF");
1944 }
1945 // remove extension
1946 $ext = strrpos($this->d_filename, ".");
1947 $pdf_file = substr($this->d_filename, 0, $ext);
1948 $pdf_file .=".pdf";
1949 return $dirname."/".$pdf_file;
1950 }
export_file($p_destination_file)
export the file to the file system and complet $this->d_mimetype, d_filename and

References $d_filename, $dirname, $ext, $result, $status, export_file(), and record_log().

+ Here is the call graph for this function:

◆ update_description()

Document::update_description ( $p_desc)

Definition at line 1829 of file document.class.php.

1830 {
1831 $this->db->exec_sql('update document set d_description = $1 where d_id=$2', array($p_desc, $this->d_id));
1832 }

References db.

◆ upload()

Document::upload ( $p_ag_id)

upload a file into document all the needed data are in $_FILES we don't increment the seq $_FILES : array containing by default $_FILES

Parameters
int$p_ag_idACTION_GESTION.AG_ID
Returns
array of int DOCUMENT.D_ID (id of saved documents )

Definition at line 458 of file document.class.php.

459 {
460 // nothing to save
461 if (sizeof($_FILES)==0)
462 return;
463
464 /* for several files */
465 /* $_FILES is now an array */
466 // Start Transaction
467 $this->db->start();
468 $name=$_FILES['file_upload']['name'];
469 $document_saved=array();
470 $http=new HttpInput();
471 $aDescription=$http->post("input_desc","array",array());
472 $description="";
473 for ($i=0; $i<sizeof($name); $i++)
474 {
475 $new_name=tempnam($_ENV['TMP'], 'doc_');
476 // check if a file is submitted
477 if (strlen($_FILES['file_upload']['tmp_name'][$i])!=0)
478 {
479 // upload the file and move it to temp directory
480 if (move_uploaded_file($_FILES['file_upload']['tmp_name'][$i], $new_name))
481 {
482 $oid=$this->db->lo_import($new_name);
483 // check if the lob is in the database
484 if ($oid==false)
485 {
486 $this->db->rollback();
487 return 1;
488 }
489 }
490 // the upload in the database is successfull
491 $this->d_lob=$oid;
492 $this->d_filename=$_FILES['file_upload']['name'][$i];
493 $this->d_mimetype=$_FILES['file_upload']['type'][$i];
494 if ( isset($aDescription[$i])) {
495 $description=strip_tags($aDescription[$i]??"");
496 }
497 $this->d_description=$description;
498 // insert into the table
499 $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description)"
500 . " values ($1,$2,$3,$4,$5,$6) returning d_id";
501 $document_id=$this->db->get_value($sql,
502 array($p_ag_id, $this->d_lob, $this->d_filename, $this->d_mimetype, 1, $this->d_description));
503
504
505 $document_saved[]=$document_id;
506
507 }
508 } /* end for */
509 $this->db->commit();
510 return $document_saved;
511 }
$new_name

References $description, $http, $i, $name, $new_name, $sql, and db.

Field Documentation

◆ $ag_id

Document::$ag_id

$ag_id action_gestion.ag_id (pk)

Definition at line 33 of file document.class.php.

Referenced by get_all(), and replace().

◆ $counter

Document::$counter
private

counter for the items ( goods )

Definition at line 41 of file document.class.php.

◆ $d_description

Document::$d_description

Description of the file

Definition at line 37 of file document.class.php.

◆ $d_filename

Document::$d_filename

$d_filename

Definition at line 35 of file document.class.php.

Referenced by transform2pdf().

◆ $d_id

Document::$d_id

$d_id Document id

Definition at line 32 of file document.class.php.

◆ $d_lob

Document::$d_lob

$d_lob the oid of the lob

Definition at line 36 of file document.class.php.

Referenced by remove().

◆ $d_mimetype

Document::$d_mimetype

$d_mimetype

Definition at line 34 of file document.class.php.

◆ $d_name

Document::$d_name

document name

Definition at line 42 of file document.class.php.

◆ $d_number

Document::$d_number

$d_number number of the document

Definition at line 38 of file document.class.php.

Referenced by replace().

◆ $db

Document::$db

$db Database connexion

Definition at line 31 of file document.class.php.

◆ $f_id

Document::$f_id

fiche.f_id

Definition at line 40 of file document.class.php.

◆ $md_id

Document::$md_id

$md_id document's template

Definition at line 39 of file document.class.php.


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