noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_document.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 // Copyright Author Dany De Bontridder danydb@aevalys.eu
20 require_once NOALYSS_INCLUDE.'/class/class_own.php';
21 require_once NOALYSS_INCLUDE.'/class/class_acc_account_ledger.php';
22 require_once NOALYSS_INCLUDE.'/class/class_follow_up.php';
23 require_once NOALYSS_INCLUDE.'/class/class_acc_tva.php';
24 require_once NOALYSS_INCLUDE.'/class/class_user.php';
25 require_once NOALYSS_INCLUDE.'/lib/class_zip_extended.php';
26 
27 /*! \file
28  * \brief Class Document corresponds to the table document
29  */
30 /*! \brief Class Document corresponds to the table document
31  */
32 class Document
33 {
34  var $db; /*!< $db Database connexion*/
35  var $d_id; /*!< $d_id Document id */
36  var $ag_id; /*!< $ag_id action_gestion.ag_id (pk) */
37  var $d_mimetype; /*!< $d_mimetype */
38  var $d_filename; /*!< $d_filename */
39  var $d_lob; /*!< $d_lob the oid of the lob */
40  var $d_description; /*!< Description of the file*/
41  var $d_number; /*!< $d_number number of the document */
42  var $md_id; /*!< $md_id document's template */
43  /* Constructor
44  * \param $p_cn Database connection
45  */
46  function __construct($p_cn,$p_d_id=0)
47  {
48  $this->db=$p_cn;
49  $this->d_id=$p_d_id;
50  $this->counter=0;
51  }
52  /*!\brief insert a minimal document and set the d_id
53  */
54  function blank()
55  {
56  $this->d_id=$this->db->get_next_seq("document_d_id_seq");
57  // affect a number
58  $this->d_number=$this->db->get_next_seq("seq_doc_type_".$this->md_type);
59  $sql=sprintf('insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
60  $this->d_id,
61  $this->ag_id,
62  $this->d_number);
63  $this->db->exec_sql($sql);
64 
65  }
66  /**
67  * Insert the receipt number into the filename , each generated file
68  * will have the name of the template (model) + receipt number)
69  * @param type $pj the receipt number
70  * @param type $filename the name of the file
71  * @return string
72  */
73  function compute_filename($pj,$filename)
74  {
75  foreach (array('/','*','<','>',';',',','\\','.',':','(',')',' ','[',']') as $i) {
76  $pj= str_replace($i, "-",$pj);
77  }
78  // save the suffix
79  $pos_prefix=strrpos($filename,".");
80  if ($pos_prefix == 0) $pos_prefix=strlen($filename);
81  $filename_no=substr($filename,0,$pos_prefix);
82  $filename_suff=substr($filename,$pos_prefix,strlen($filename));
83  $new_filename= strtolower($filename_no."-".$pj.$filename_suff);
84  return $new_filename;
85  }
86  /*!
87  * \brief Generate the document, Call $this->Replace to replace
88  * tag by value
89  *@param p_array contains the data normally it is the $_POST
90  *@param $p_filename contains the new filename
91  * \return an string : the url where the generated doc can be found, the name
92  * of the file and his mimetype
93  */
94  function Generate($p_array,$p_filename="")
95  {
96  // create a temp directory in /tmp to unpack file and to parse it
97  $dirname=tempnam($_ENV['TMP'],'doc_');
98 
99 
100  unlink($dirname);
101  mkdir ($dirname);
102  // Retrieve the lob and save it into $dirname
103  $this->db->start();
104  $dm_info="select md_name,md_type,md_lob,md_filename,md_mimetype
105  from document_modele where md_id=".$this->md_id;
106  $Res=$this->db->exec_sql($dm_info);
107 
109  $this->d_lob=$row['md_lob'];
110  $this->d_filename=$row['md_filename'];
111  $this->d_mimetype=$row['md_mimetype'];
112  $this->d_name=$row['md_name'];
113 
114 
115  chdir($dirname);
116  $filename=$row['md_filename'];
117  $exp=$this->db->lo_export($row['md_lob'],$dirname.DIRECTORY_SEPARATOR.$filename);
118  if ( $exp === false ) echo_warning( __FILE__.":".__LINE__."Export NOK $filename");
119 
120  $type="n";
121  // if the doc is a OOo, we need to unzip it first
122  // and the name of the file to change is always content.xml
123  if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
124  {
125  ob_start();
126  $zip = new Zip_Extended;
127  if ($zip->open($filename) === TRUE) {
128  $zip->extractTo($dirname.DIRECTORY_SEPARATOR);
129  $zip->close();
130  } else {
131  echo __FILE__.":".__LINE__."cannot unzip model ".$filename;
132  }
133 
134  // Remove the file we do not need anymore
135  unlink($filename);
136  ob_end_clean();
137  $file_to_parse="content.xml";
138  $type="OOo";
139  }
140  else
141  $file_to_parse=$filename;
142  // affect a number
143  $this->d_number=$this->db->get_next_seq("seq_doc_type_".$row['md_type']);
144 
145  // parse the document - return the doc number ?
146  $this->ParseDocument($dirname,$file_to_parse,$type,$p_array);
147 
148  $this->db->commit();
149  // if the doc is a OOo, we need to re-zip it
150  if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
151  {
152  ob_start();
153  $zip = new Zip_Extended;
154  $res = $zip->open($filename, ZipArchive::CREATE);
155  if($res !== TRUE)
156  {
157  throw new Exception ( __FILE__.":".__LINE__."cannot recreate zip");
158  }
159  $zip->add_recurse_folder($dirname.DIRECTORY_SEPARATOR);
160  $zip->close();
161 
162  ob_end_clean();
163 
164  $file_to_parse=$filename;
165  }
166  if ( $p_filename !="") {
167  $this->d_filename=$this->compute_filename($p_filename, $this->d_filename);
168  }
169  $this->SaveGenerated($dirname.DIRECTORY_SEPARATOR.$file_to_parse);
170  // Invoice
171  $href=http_build_query(array('gDossier'=>Dossier::id(),"d_id"=>$this->d_id,'act'=>'RAW:document'));
172  $ret='<A class="mtitle" HREF="export.php?'.$href.'">'._('Document').'</A>';
173 
174  return $ret;
175  }
176 
177  /*! ParseDocument
178  * \brief This function parse a document and replace all
179  * the predefined tags by a value. This functions
180  * generate diffent documents (invoice, order, letter)
181  * with the info from the database
182  *
183  * \param $p_dir directory name
184  * \param $p_file filename
185  * \param $p_type For the OOo document the tag are &lt and &gt instead of < and >
186  * \param $p_array variable from $_POST
187  */
188  function ParseDocument($p_dir,$p_file,$p_type,$p_array)
189  {
190 
191  /*!\note Replace in the doc the tags by their values.
192  * - MY_* table parameter
193  * - ART_VEN* table quant_sold for invoice
194  * - CUST_* table quant_sold and fiche for invoice
195  * - e_* for the invoice in the $_POST
196  */
197  // open the document
198  $infile_name=$p_dir.DIRECTORY_SEPARATOR.$p_file;
199  $h=fopen($infile_name,"r");
200 
201  // check if tmpdir exist otherwise create it
202  $temp_dir=$_ENV['TMP'];
203  if ( is_dir($temp_dir) == false )
204  {
205  if ( mkdir($temp_dir) == false )
206  {
207  $msg=_("Ne peut pas créer le répertoire ".$temp_dir);
208  throw new Exception($msg);
209  }
210  }
211  // Compute output_name
212  $output_name=tempnam($temp_dir,"gen_doc_");
213  $output_file=fopen($output_name,"w+");
214  // check if the opening is sucessfull
215  if ( $h === false )
216  {
217  echo __FILE__.":".__LINE__."cannot open $p_dir $p_file ";
218  $msg=_("Ne peut pas ouvrir $p_dir $p_file");
219  throw new Exception($msg);
220  }
221  if ( $output_file == false)
222  {
223  $msg=_("Ne peut pas ouvrir $p_dir $p_file");
224  echo $msg;
225  throw new Exception($msg);
226  }
227  // compute the regex
228  if ( $p_type=='OOo')
229  {
230  $regex="/=*&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;/i";
231  $lt="&lt;";
232  $gt="&gt;";
233  }
234  else
235  {
236  $regex="/=*<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[A-Z]*_*[0-9]*>>/i";
237  $lt="<";
238  $gt=">";
239  }
240 
241  //read the file
242  while(! feof($h))
243  {
244  // replace the tag
245  $buffer=fgets($h);
246  // search in the buffer the magic << and >>
247  // while preg_match_all finds something to replace
248  while ( preg_match_all ($regex,$buffer,$f) >0 )
249  {
250 
251 
252  foreach ( $f as $apattern )
253  {
254 
255 
256  foreach($apattern as $pattern)
257  {
258 
259 
260  $to_remove=$pattern;
261  // we remove the < and > from the pattern
262  $tag=str_replace($lt,'',$pattern);
263  $tag=str_replace($gt,'',$tag);
264 
265 
266  // if the pattern if found we replace it
267  $value=$this->Replace($tag,$p_array);
268  if ( strpos($value,'ERROR') != false ) $value="";
269  /*
270  * Change type of cell to numeric
271  * allow numeric cel in ODT for the formatting and formula
272  */
273  if ( is_numeric($value) && $p_type=='OOo')
274  {
275  $searched='/office:value-type="string"><text:p>'.$pattern.'/';
276  $replaced='office:value-type="float" office:value="'.$value.'"><text:p>'.$pattern;
277  $buffer=preg_replace($searched, $replaced, $buffer,1);
278  }
279  // replace into the $buffer
280  // take the position in the buffer
281  $pos=strpos($buffer,$to_remove);
282  // get the length of the string to remove
283  $len=strlen($to_remove);
284  if ( $p_type=='OOo' )
285  {
286  $value=str_replace('&','&amp;',$value);
287  $value=str_replace('<','&lt;',$value);
288  $value=str_replace('>','&gt;',$value);
289  $value=str_replace('"','&quot;',$value);
290  $value=str_replace("'",'&apos;',$value);
291  }
292  $buffer=substr_replace($buffer,$value,$pos,$len);
293 
294  // if the pattern if found we replace it
295  }
296  }
297  }
298  // write into the output_file
299  fwrite($output_file,$buffer);
300 
301  }
302  fclose($h);
303  fclose($output_file);
304  if ( ($ret=copy ($output_name,$infile_name)) == FALSE )
305  {
306  echo _('Ne peut pas sauver '.$output_name.' vers '.$infile_name.' code d\'erreur ='.$ret);
307  }
308 
309 
310  }
311  /*! SaveGenerated
312  * \brief Save the generated Document
313  * \param $p_file is the generated file
314  *
315  *
316  * \return 0 if no error otherwise 1
317  */
318  function SaveGenerated($p_file)
319  {
320  // We save the generated file
321  $doc=new Document($this->db);
322  $this->db->start();
323  $this->d_lob=$this->db->lo_import($p_file);
324  if ( $this->d_lob == false )
325  {
326  echo "ne peut pas importer [$p_file]";
327  return 1;
328  }
329 
330  $sql="insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype)
331  values ($1,$2,$3,$4,$5)";
332 
333  $this->db->exec_sql($sql, array($this->ag_id,
334  $this->d_lob,
335  $this->d_number,
336  $this->d_filename,
337  $this->d_mimetype));
338  $this->d_id=$this->db->get_current_seq("document_d_id_seq");
339  // Clean the file
340  unlink ($p_file);
341  $this->db->commit();
342  return 0;
343  }
344  /*! Upload
345  * \brief Upload a file into document
346  * all the needed data are in $_FILES we don't increment the seq
347  * \param $p_file : array containing by default $_FILES
348  *
349  * \return
350  */
351  function Upload($p_ag_id)
352  {
353  // nothing to save
354  if ( sizeof($_FILES) == 0 ) return;
355 
356  /* for several files */
357  /* $_FILES is now an array */
358  // Start Transaction
359  $this->db->start();
360  $name=$_FILES['file_upload']['name'];
361  for ($i = 0; $i < sizeof($name);$i++)
362  {
363  $new_name=tempnam($_ENV['TMP'],'doc_');
364  // check if a file is submitted
365  if ( strlen($_FILES['file_upload']['tmp_name'][$i]) != 0 )
366  {
367  // upload the file and move it to temp directory
368  if ( move_uploaded_file($_FILES['file_upload']['tmp_name'][$i],$new_name))
369  {
370  $oid=$this->db->lo_import($new_name);
371  // check if the lob is in the database
372  if ( $oid == false )
373  {
374  $this->db->rollback();
375  return 1;
376  }
377  }
378  // the upload in the database is successfull
379  $this->d_lob=$oid;
380  $this->d_filename=$_FILES['file_upload']['name'][$i];
381  $this->d_mimetype=$_FILES['file_upload']['type'][$i];
382  $this->d_description= strip_tags($_POST['input_desc'][$i]);
383  // insert into the table
384  $sql="insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
385  $this->db->exec_sql($sql,array($p_ag_id,$this->d_lob,$this->d_filename,$this->d_mimetype,1,$this->d_description));
386  }
387  } /* end for */
388  $this->db->commit();
389 
390  }
391  /**
392  * Copy a existing OID (LOB) into the table document
393  * @note use of global variable $cn which is the db connx to the current folder
394  * @param type $p_ag_id Follow_Up::ag_id
395  * @param type $p_lob oid of existing document
396  * @param type $p_filename filename of existing document
397  * @param type $p_mimetype mimetype of existing document
398  * @param type $p_description Description of existing document (default empty)
399  */
400  static function insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description = "")
401  {
402  global $cn;
403  // insert into the table
404  $sql = "insert into document (ag_id, d_lob,d_filename,d_mimetype,d_number,d_description) values ($1,$2,$3,$4,$5,$6)";
405  $cn->exec_sql($sql, array($p_ag_id, $p_lob, $p_filename, $p_mimetype, 1, $p_description));
406  }
407 
408  /*! a_ref
409  * \brief create and compute a string for reference the doc <A ...>
410  *
411  * \return a string
412  */
413  function anchor()
414  {
415  if ( $this->d_id == 0 )
416  return '';
417  $image='<IMG SRC="image/insert_table.gif" title="'.$this->d_filename.'" border="0">';
418  $r="";
419  $href=http_build_query(array('gDossier'=>Dossier::id(),"d_id"=>$this->d_id,'act'=>'RAW:document'));
420 
421  $r='<A class="mtitle" HREF="export.php?'.$href.'">'.$image.'</A>';
422  return $r;
423  }
424  /** Get
425  * \brief Send the document
426  */
427  function Send()
428  {
429  // retrieve the template and generate document
430  $this->db->start();
431  $ret=$this->db->exec_sql(
432  "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
433  if ( Database::num_row ($ret) == 0 )
434  return;
436  //the document is saved into file $tmp
437  $tmp=tempnam($_ENV['TMP'],'document_');
438  $this->db->lo_export($row['d_lob'],$tmp);
439  $this->d_mimetype=$row['d_mimetype'];
440  $this->d_filename=$row['d_filename'];
441 
442  // send it to stdout
443  ini_set('zlib.output_compression','Off');
444  header("Pragma: public");
445  header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
446  header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
447  header("Cache-Control: must-revalidate");
448  header('Content-type: '.$this->d_mimetype);
449  header('Content-Disposition: attachment;filename="'.$this->d_filename.'"',FALSE);
450  header("Accept-Ranges: bytes");
451  $file=fopen($tmp,'r');
452  while ( !feof ($file) )
453  {
454  echo fread($file,8192);
455  }
456  fclose($file);
457 
458  unlink ($tmp);
459 
460  $this->db->commit();
461 
462  }
463  /*!\brief get all the document of a given action
464  *\param $ag_id the ag_id from action::ag_id (primary key)
465  *\return an array of objects document or an empty array if nothing found
466  */
467  function get_all($ag_id)
468  {
469  $res=$this->db->get_array('select d_id, ag_id, d_lob, d_number, d_filename,'.
470  ' d_mimetype,d_description from document where ag_id=$1',array($ag_id));
471  $a=array();
472  for ($i=0;$i<sizeof($res); $i++ )
473  {
474  $doc=new Document($this->db);
475  $doc->d_id=$res[$i]['d_id'];
476  $doc->ag_id=$res[$i]['ag_id'];
477  $doc->d_lob=$res[$i]['d_lob'];
478  $doc->d_number=$res[$i]['d_number'];
479  $doc->d_filename=$res[$i]['d_filename'];
480  $doc->d_mimetype=$res[$i]['d_mimetype'];
481  $doc->d_description=$row['d_description'];
482  $a[$i]=clone $doc;
483  }
484  return $a;
485  }
486 
487  /*!\brief Get complete all the data member thx info from the database
488  */
489  function get()
490  {
491  $sql="select * from document where d_id=".$this->d_id;
492  $ret=$this->db->exec_sql($sql);
493  if ( Database::num_row($ret) == 0 )
494  return;
496  $this->ag_id=$row['ag_id'];
497  $this->d_mimetype=$row['d_mimetype'];
498  $this->d_filename=$row['d_filename'];
499  $this->d_lob=$row['d_lob'];
500  $this->d_number=$row['d_number'];
501  $this->d_description=$row['d_description'];
502 
503  }
504  /*!
505  * \brief replace the TAG by the real value, this value can be into
506  * the database or in $_POST
507  * The possible tags are
508  * - [CUST_NAME] customer's name
509  * - [CUST_ADDR_1] customer's address line 1
510  * - [CUST_CP] customer's ZIP code
511  * - [CUST_CO] customer's country
512  * - [CUST_CITY] customer's city
513  * - [CUST_VAT] customer's VAT
514  * - [MARCH_NEXT] end this item and increment the counter $i
515  * - [DATE_LIMIT]
516  * - [VEN_ART_NAME]
517  * - [VEN_ART_PRICE]
518  * - [VEN_ART_QUANT]
519  * - [VEN_ART_TVA_CODE]
520  * - [VEN_ART_STOCK_CODE]
521  * - [VEN_HTVA]
522  * - [VEN_TVAC]
523  * - [VEN_TVA]
524  * - [TOTAL_VEN_HTVA]
525  * - [DATE_CALC]
526  * - [DATE]
527  * - [DATE_LIMIT]
528  * - [DATE_LIMIT_CALC]
529  * - [NUMBER]
530  * - [MY_NAME]
531  * - [MY_CP]
532  * - [MY_COMMUNE]
533  * - [MY_TVA]
534  * - [MY_STREET]
535  * - [MY_NUMBER]
536  * - [TVA_CODE]
537  * - [TVA_RATE]
538  * - [BON_COMMANDE]
539  * - [OTHER_INFO]
540  * - [CUST_NUM]
541  * - [CUST_BANQUE_NAME]
542  * - [CUST_BANQUE_NO]
543  * - [USER]
544  * - [REFERENCE]
545  * - [BENEF_NAME]
546  * - [BENEF_BANQUE_NAME]
547  * - [BENEF_BANQUE_NO]
548  * - [BENEF_ADDR_1]
549  * - [BENEF_CP]
550  * - [BENEF_CO]
551  * - [BENEF_CITY]
552  * - [BENEF_VAT]
553  * - [ACOMPTE]
554  * - [TITLE]
555  * - [DESCRIPTION]
556  * - [COMM_PAYMENT]
557  *
558  * \param $p_tag TAG
559  * \param $p_array data from $_POST
560  * \return String which must replace the tag
561  */
562  function Replace($p_tag,$p_array)
563  {
564  global $g_parameter;
565  $p_tag=strtoupper($p_tag);
566  $p_tag=str_replace('=','',$p_tag);
567  $r="Tag inconnu";
568 
569  switch ($p_tag)
570  {
571  case 'DATE':
572  $r=(isset ($p_array['ag_timestamp']))?$p_array['ag_timestamp']:$p_array['e_date'];
573  break;
574  case 'DATE_CALC':
575  $r=' Date inconnue ';
576  // Date are in $p_array['ag_date']
577  // or $p_array['e_date']
578  if ( isset ($p_array['ag_timestamp'])) {
579  $date=format_date($p_array['ag_timestamp'],'DD.MM.YYYY','YYYY-MM-DD');
580  $r=$date;
581  }
582  if ( isset ($p_array['e_date'])) {
583  $date=format_date($p_array['e_date'],'DD.MM.YYYY','YYYY-MM-DD');
584  $r=$date;
585  }
586  break;
587  //
588  // the company priv
589 
590  case 'MY_NAME':
591  $r=$g_parameter->MY_NAME;
592  break;
593  case 'MY_CP':
594  $r=$g_parameter->MY_CP;
595  break;
596  case 'MY_COMMUNE':
597  $r=$g_parameter->MY_COMMUNE;
598  break;
599  case 'MY_TVA':
600  $r=$g_parameter->MY_TVA;
601  break;
602  case 'MY_STREET':
603  $r=$g_parameter->MY_STREET;
604  break;
605  case 'MY_NUMBER':
606  $r=$g_parameter->MY_NUMBER;
607  break;
608  case 'MY_TEL':
609  $r=$g_parameter->MY_TEL;
610  break;
611  case 'MY_FAX':
612  $r=$g_parameter->MY_FAX;
613  break;
614  case 'MY_PAYS':
615  $r=$g_parameter->MY_PAYS;
616  break;
617 
618  // customer
619  /*\note The CUST_* are retrieved thx the $p_array['tiers']
620  * which contains the quick_code
621  */
622  case 'SOLDE':
623  $tiers=new Fiche($this->db);
624  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
625  $tiers->get_by_qcode($qcode,false);
626  $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
627  $poste=new Acc_Account_Ledger($this->db,$p);
628  $r=$poste->get_solde(' true' );
629  break;
630  case 'CUST_NAME':
631  $tiers=new Fiche($this->db);
632  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
633  $tiers->get_by_qcode($qcode,false);
634  $r=$tiers->strAttribut(ATTR_DEF_NAME);
635  break;
636  case 'CUST_ADDR_1':
637  $tiers=new Fiche($this->db);
638  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
639  $tiers->get_by_qcode($qcode,false);
640  $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
641 
642  break ;
643  case 'CUST_CP':
644  $tiers=new Fiche($this->db);
645 
646  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
647  $tiers->get_by_qcode($qcode,false);
648  $r=$tiers->strAttribut(ATTR_DEF_CP);
649 
650  break;
651  case 'CUST_CITY':
652  $tiers=new Fiche($this->db);
653 
654  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
655  $tiers->get_by_qcode($qcode,false);
656  $r=$tiers->strAttribut(ATTR_DEF_CITY);
657 
658  break;
659 
660  case 'CUST_CO':
661  $tiers=new Fiche($this->db);
662 
663  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
664  $tiers->get_by_qcode($qcode,false);
665  $r=$tiers->strAttribut(ATTR_DEF_PAYS);
666 
667  break;
668  // Marchandise in $p_array['e_march*']
669  // \see user_form_achat.php or user_form_ven.php
670  case 'CUST_VAT':
671  $tiers=new Fiche($this->db);
672 
673  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
674  $tiers->get_by_qcode($qcode,false);
675  $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
676  break;
677  case 'CUST_NUM':
678  $tiers=new Fiche($this->db);
679  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
680  $tiers->get_by_qcode($qcode,false);
681  $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
682  break;
683  case 'CUST_BANQUE_NO':
684  $tiers=new Fiche($this->db);
685  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
686  $tiers->get_by_qcode($qcode,false);
687  $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
688  break;
689  case 'CUST_BANQUE_NAME':
690  $tiers=new Fiche($this->db);
691  $qcode=isset($p_array['qcode_dest'])?$p_array['qcode_dest']:$p_array['e_client'];
692  $tiers->get_by_qcode($qcode,false);
693  $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
694  break;
695  /* -------------------------------------------------------------------------------- */
696  /* BENEFIT (fee notes */
697  case 'BENEF_NAME':
698  $tiers=new Fiche($this->db);
699  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
700  if ( $qcode=='')
701  {
702  $r='';
703  break;
704  }
705  $tiers->get_by_qcode($qcode,false);
706  $r=$tiers->strAttribut(ATTR_DEF_NAME);
707  break;
708  case 'BENEF_ADDR_1':
709  $tiers=new Fiche($this->db);
710  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
711  if ( $qcode=='')
712  {
713  $r='';
714  break;
715  }
716  $tiers->get_by_qcode($qcode,false);
717  $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
718 
719  break ;
720  case 'BENEF_CP':
721  $tiers=new Fiche($this->db);
722 
723  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
724  if ( $qcode=='')
725  {
726  $r='';
727  break;
728  }
729  $tiers->get_by_qcode($qcode,false);
730  $r=$tiers->strAttribut(ATTR_DEF_CP);
731 
732  break;
733  case 'BENEF_CITY':
734  $tiers=new Fiche($this->db);
735 
736  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
737  if ( $qcode=='')
738  {
739  $r='';
740  break;
741  }
742  $tiers->get_by_qcode($qcode,false);
743  $r=$tiers->strAttribut(ATTR_DEF_CITY);
744 
745  break;
746 
747  case 'BENEF_CO':
748  $tiers=new Fiche($this->db);
749 
750  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
751  if ( $qcode=='')
752  {
753  $r='';
754  break;
755  }
756  $tiers->get_by_qcode($qcode,false);
757  $r=$tiers->strAttribut(ATTR_DEF_PAYS);
758 
759  break;
760  // Marchandise in $p_array['e_march*']
761  // \see user_form_achat.php or user_form_ven.php
762  case 'BENEF_VAT':
763  $tiers=new Fiche($this->db);
764 
765  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
766  if ( $qcode=='')
767  {
768  $r='';
769  break;
770  }
771  $tiers->get_by_qcode($qcode,false);
772  $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
773  break;
774  case 'BENEF_NUM':
775  $tiers=new Fiche($this->db);
776  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
777  if ( $qcode=='')
778  {
779  $r='';
780  break;
781  }
782  $tiers->get_by_qcode($qcode,false);
783  $r=$tiers->strAttribut(ATTR_DEF_NUMBER_CUSTOMER);
784  break;
785  case 'BENEF_BANQUE_NO':
786  $tiers=new Fiche($this->db);
787  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
788  if ( $qcode=='')
789  {
790  $r='';
791  break;
792  }
793  $tiers->get_by_qcode($qcode,false);
794  $r=$tiers->strAttribut(ATTR_DEF_BQ_NO);
795  break;
796  case 'BENEF_BANQUE_NAME':
797  $tiers=new Fiche($this->db);
798  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
799  if ( $qcode=='')
800  {
801  $r='';
802  break;
803  }
804  $tiers->get_by_qcode($qcode,false);
805  $r=$tiers->strAttribut(ATTR_DEF_BQ_NAME);
806  break;
807 
808  // Marchandise in $p_array['e_march*']
809  // \see user_form_achat.php or user_form_ven.php
810  case 'NUMBER':
812  break;
813 
814  case 'USER' :
815  return $_SESSION['use_name'].', '.$_SESSION['use_first_name'];
816 
817  break;
818  case 'REFERENCE':
819  $act=new Follow_Up($this->db);
820  $act->ag_id=$this->ag_id;
821  $act->get();
822  $r=$act->ag_ref;
823  break;
824 
825  /*
826  * - [VEN_ART_NAME]
827  * - [VEN_ART_PRICE]
828  * - [VEN_ART_QUANT]
829  * - [VEN_ART_TVA_CODE]
830  * - [VEN_ART_STOCK_CODE]
831  * - [VEN_HTVA]
832  * - [VEN_TVAC]
833  * - [VEN_TVA]
834  * - [TOTAL_VEN_HTVA]
835  * - [DATE_LIMIT]
836  */
837  case 'DATE_LIMIT_CALC':
838  extract ($p_array, EXTR_SKIP);
839  $id='e_ech' ;
840  if ( !isset (${$id}) ) return "";
841  $r=format_date(${$id},'DD.MM.YYYY','YYYY-MM-DD');
842  break;
843  case 'DATE_LIMIT':
844  extract ($p_array, EXTR_SKIP);
845  $id='e_ech' ;
846  if ( !isset (${$id}) ) return "";
847  $r=${$id};
848  break;
849  case 'MARCH_NEXT':
850  $this->counter++;
851  $r='';
852  break;
853 
854  case 'VEN_ART_NAME':
855  extract ($p_array, EXTR_SKIP);
856  $id='e_march'.$this->counter;
857  // check if the march exists
858  if ( ! isset (${$id})) return "";
859  // check that something is sold
860  if ( ${'e_march'.$this->counter.'_price'} != 0 && ${'e_quant'.$this->counter} != 0 )
861  {
862  $f=new Fiche($this->db);
863  $f->get_by_qcode(${$id},false);
864  $r=$f->strAttribut(ATTR_DEF_NAME);
865  }
866  else $r = "";
867  break;
868  case 'VEN_ART_LABEL':
869  extract ($p_array, EXTR_SKIP);
870  $id='e_march'.$this->counter."_label";
871  // check if the march exists
872 
873  if (! isset (${$id}) || (isset (${$id}) && strlen(trim(${$id})) == 0))
874  {
875  $id = 'e_march' . $this->counter;
876  // check if the march exists
877  if (!isset(${$id}))
878  $r= "";
879  else
880  {
881  // check that something is sold
882  if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0)
883  {
884  $f = new Fiche($this->db);
885  $f->get_by_qcode(${$id}, false);
886  $r = $f->strAttribut(ATTR_DEF_NAME);
887  } else
888  $r = "";
889  }
890  }
891  else
892  $r=${'e_march'.$this->counter.'_label'};
893  break;
894  case 'VEN_ART_STOCK_CODE':
895  extract ($p_array, EXTR_SKIP);
896  $id = 'e_march' . $this->counter;
897  // check if the march exists
898  if (!isset(${$id}))
899  $r= "";
900  else
901  {
902  // check that something is sold
903  if (${'e_march' . $this->counter . '_price'} != 0 && ${'e_quant' . $this->counter} != 0)
904  {
905  $f = new Fiche($this->db);
906  $f->get_by_qcode(${$id}, false);
907  $r = $f->strAttribut(ATTR_DEF_STOCK);
908  $r=($r == NOTFOUND)?'':$r;
909  }
910  }
911  break;
912  case 'VEN_ART_PRICE':
913  extract ($p_array, EXTR_SKIP);
914  $id='e_march'.$this->counter.'_price' ;
915  if ( !isset (${$id}) ) return "";
916  if (${$id} == 0 ) return "";
917  $r=${$id};
918  break;
919 
920  case 'TVA_RATE':
921  case 'VEN_ART_TVA_RATE':
922  extract ($p_array, EXTR_SKIP);
923  $id='e_march'.$this->counter.'_tva_id';
924  if ( !isset (${$id}) ) return "";
925  if ( ${$id} == -1 || ${$id}=='' ) return "";
926  $march_id='e_march'.$this->counter.'_price' ;
927  if ( ! isset (${$march_id})) return '';
928  $tva=new Acc_Tva($this->db);
929  $tva->set_parameter("id",${$id});
930  if ( $tva->load() == -1) return '';
931  return $tva->get_parameter("rate");
932  break;
933 
934  case 'TVA_CODE':
935  case 'VEN_ART_TVA_CODE':
936  extract ($p_array, EXTR_SKIP);
937  $id='e_march'.$this->counter.'_tva_id';
938  if ( !isset (${$id}) ) return "";
939  if ( ${$id} == -1 ) return "";
940  $qt='e_quant'.$this->counter;
941  $price='e_march'.$this->counter.'_price' ;
942  if ( ${$price} == 0 || ${$qt} == 0
943  || strlen(trim( $price )) ==0
944  || strlen(trim($qt)) ==0)
945  return "";
946 
947  $r=${$id};
948  break;
949 
950  case 'TVA_LABEL':
951  extract ($p_array, EXTR_SKIP);
952  $id='e_march'.$this->counter.'_tva_id';
953  if ( !isset (${$id}) ) return "";
954  $march_id='e_march'.$this->counter.'_price' ;
955  if ( ! isset (${$march_id})) return '';
956  if ( ${$march_id} == 0) return '';
957  $tva=new Acc_Tva($this->db,${$id});
958  if ($tva->load() == -1 ) return "";
959  $r=$tva->get_parameter('label');
960 
961  break;
962 
963  /* total VAT for one sold */
964  case 'TVA_AMOUNT':
965  case 'VEN_TVA':
966  extract ($p_array, EXTR_SKIP);
967  $qt='e_quant'.$this->counter;
968  $price='e_march'.$this->counter.'_price' ;
969  $tva='e_march'.$this->counter.'_tva_id';
970  /* if we do not use vat this var. is not set */
971  if ( !isset(${$tva}) ) return '';
972  if ( !isset (${'e_march'.$this->counter}) ) return "";
973  // check that something is sold
974  if ( ${$price} == 0 || ${$qt} == 0
975  || strlen(trim( $price )) ==0
976  || strlen(trim($qt)) ==0)
977  return "";
978  $r=${'e_march'.$this->counter.'_tva_amount'};
979  break;
980  /* TVA automatically computed */
981  case 'VEN_ART_TVA':
982 
983  extract ($p_array, EXTR_SKIP);
984  $qt='e_quant'.$this->counter;
985  $price='e_march'.$this->counter.'_price' ;
986  $tva='e_march'.$this->counter.'_tva_id';
987  if ( !isset (${'e_march'.$this->counter}) ) return "";
988  // check that something is sold
989  if ( ${$price} == 0 || ${$qt} == 0
990  || strlen(trim( $price )) ==0
991  || strlen(trim($qt)) ==0)
992  return "";
993  $oTva=new Acc_Tva($this->db,${$tva});
994  if ($oTva->load() == -1 ) return "";
995  $r=round(${$price},2)*$oTva->get_parameter('rate');
996  $r=round($r,2);
997  break;
998 
999  case 'VEN_ART_TVAC':
1000  extract ($p_array, EXTR_SKIP);
1001  $qt='e_quant'.$this->counter;
1002  $price='e_march'.$this->counter.'_price' ;
1003  $tva='e_march'.$this->counter.'_tva_id';
1004  if ( !isset (${'e_march'.$this->counter}) ) return "";
1005  // check that something is sold
1006  if ( ${$price} == 0 || ${$qt} == 0
1007  || strlen(trim( $price )) ==0
1008  || strlen(trim($qt)) ==0)
1009  return "";
1010  if ( ! isset (${$tva}) ) return '';
1011  $tva=new Acc_Tva($this->db,${$tva});
1012  if ($tva->load() == -1 )
1013  {
1014  $r=round(${$price},2);
1015  }
1016  else
1017  {
1018  $r=round(${$price}*$tva->get_parameter('rate')+${$price},2);
1019  }
1020 
1021  break;
1022 
1023  case 'VEN_ART_QUANT':
1024  extract ($p_array, EXTR_SKIP);
1025  $id='e_quant'.$this->counter;
1026  if ( !isset (${$id}) ) return "";
1027  // check that something is sold
1028  if ( ${'e_march'.$this->counter.'_price'} == 0
1029  || ${'e_quant'.$this->counter} == 0
1030  || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
1031  || strlen(trim(${'e_quant'.$this->counter})) ==0 )
1032  return "";
1033  $r=${$id};
1034  break;
1035 
1036  case 'VEN_HTVA':
1037  extract ($p_array, EXTR_SKIP);
1038  $id='e_march'.$this->counter.'_price' ;
1039  $quant='e_quant'.$this->counter;
1040  if ( !isset (${$id}) ) return "";
1041 
1042  // check that something is sold
1043  if ( ${'e_march'.$this->counter.'_price'} == 0 || ${'e_quant'.$this->counter} == 0
1044  || strlen(trim( ${'e_march'.$this->counter.'_price'} )) ==0
1045  || strlen(trim(${'e_quant'.$this->counter})) ==0)
1046  return "";
1047  bcscale(4);
1048  $r=bcmul(${$id},${$quant});
1049  $r=round($r,2);
1050  break;
1051 
1052  case 'VEN_TVAC':
1053  extract ($p_array, EXTR_SKIP);
1054  $id='e_march'.$this->counter.'_tva_amount' ;
1055  $price='e_march'.$this->counter.'_price' ;
1056  $quant='e_quant'.$this->counter;
1057  if ( ! isset(${'e_march'.$this->counter.'_price'})|| !isset(${'e_quant'.$this->counter})) return "";
1058  // check that something is sold
1059  if ( ${'e_march'.$this->counter.'_price'} == 0 || ${'e_quant'.$this->counter} == 0 ) return "";
1060  bcscale(4);
1061  // if TVA not exist
1062  if ( ! isset(${$id}))
1063  $r= bcmul(${$price},${$quant});
1064  else{
1065  $r= bcmul(${$price},${$quant});
1066  $r=bcadd($r,${$id});
1067  }
1068  $r=round($r,2);
1069  return $r;
1070  break;
1071 
1072  case 'TOTAL_VEN_HTVA':
1073  extract($p_array, EXTR_SKIP);
1074  bcscale(4);
1075  $sum=0.0;
1076  for ($i=0;$i<$nb_item;$i++)
1077  {
1078  $sell='e_march'.$i.'_price';
1079  $qt='e_quant'.$i;
1080 
1081  if ( ! isset (${$sell}) ) break;
1082 
1083  if ( strlen(trim(${$sell})) == 0 ||
1084  strlen(trim(${$qt})) == 0 ||
1085  ${$qt}==0 || ${$sell}==0)
1086  continue;
1087  $tmp1=bcmul(${$sell},${$qt});
1088  $sum=bcadd($sum,$tmp1);
1089 
1090 
1091  }
1092  $r=round($sum,2);
1093  break;
1094  case 'TOTAL_VEN_TVAC':
1095  extract($p_array, EXTR_SKIP);
1096  $sum=0.0;
1097  bcscale(4);
1098  for ($i=0;$i<$nb_item;$i++)
1099  {
1100  $tva='e_march'.$i.'_tva_amount';
1101  $tva_amount=0;
1102  /* if we do not use vat this var. is not set */
1103  if ( isset(${$tva}) )
1104  {
1105  $tva_amount=${$tva};
1106  }
1107  $sell=${'e_march'.$i.'_price'};
1108  $qt=${'e_quant'.$i};
1109  $tot=bcmul($sell,$qt);
1110  $tot=bcadd($tot,$tva_amount);
1111  $sum=bcadd($sum,$tot);
1112  }
1113  $r=round($sum,2);
1114 
1115  break;
1116  case 'TOTAL_TVA':
1117  extract($p_array, EXTR_SKIP);
1118  $sum=0.0;
1119  for ($i=0;$i<$nb_item;$i++)
1120  {
1121  $tva='e_march'.$i.'_tva_amount';
1122  if (! isset(${$tva})) $tva_amount=0.0;
1123  else $tva_amount=$
1124  {
1125  $tva
1126  };
1127  $sum+=$tva_amount;
1128  $sum=round($sum,2);
1129  }
1130  $r=$sum;
1131 
1132  break;
1133  case 'BON_COMMANDE':
1134  if ( isset($p_array['bon_comm']))
1135  return $p_array['bon_comm'];
1136  else
1137  return "";
1138  break;
1139  case 'PJ':
1140  if ( isset($p_array['e_pj']))
1141  return $p_array['e_pj'];
1142  else
1143  return "";
1144 
1145  case 'OTHER_INFO':
1146  if ( isset($p_array['other_info']))
1147  return $p_array['other_info'];
1148  else
1149  return "";
1150  break;
1151  case 'COMMENT':
1152  if ( isset($p_array['e_comm']))
1153  return $p_array['e_comm'];
1154  break;
1155  case 'ACOMPTE':
1156  if ( isset($p_array['acompte']))
1157  return $p_array['acompte'];
1158  return "0";
1159  break;
1160  case 'STOCK_NAME':
1161  if ( ! isset ($p_array['repo'])) return "";
1162  $ret=$this->db->get_value('select r_name from public.stock_repository where r_id=$1',array($p_array['repo']));
1163  return $ret;
1164  case 'STOCK_ADRESS':
1165  if ( ! isset ($p_array['repo'])) return "";
1166  $ret=$this->db->get_value('select r_adress from public.stock_repository where r_id=$1',array($p_array['repo']));
1167  return $ret;
1168  case 'STOCK_COUNTRY':
1169  if ( ! isset ($p_array['repo'])) return "";
1170  $ret=$this->db->get_value('select r_country from public.stock_repository where r_id=$1',array($p_array['repo']));
1171  return $ret;
1172  case 'STOCK_CITY':
1173  if ( ! isset ($p_array['repo'])) return "";
1174  $ret=$this->db->get_value('select r_city from public.stock_repository where r_id=$1',array($p_array['repo']));
1175  return $ret;
1176  case 'STOCK_PHONE':
1177  if ( ! isset ($p_array['repo'])) return "";
1178  $ret=$this->db->get_value('select r_phone from public.stock_repository where r_id=$1',array($p_array['repo']));
1179  return $ret;
1180  case 'TITLE':
1181  $title=HtmlInput::default_value_request("ag_title", "");
1182  return $title;
1183  case 'COMM_PAYMENT':
1184  if ( isset($p_array["e_comm_paiement"])) {
1185  return $p_array["e_comm_paiement"];
1186  } else return "";
1187  }
1188  /*
1189  * retrieve the value of ATTR for e_march
1190  */
1191  if (preg_match('/^ATTR/', $p_tag) == 1)
1192  {
1193  $r="";
1194  // Retrieve f_id
1195  if ( isset ($p_array['e_march'.$this->counter]))
1196  {
1197  $id = $p_array['e_march' . $this->counter];
1198  $r=$this->replace_special_tag($id,$p_tag);
1199  }
1200  }
1201  /*
1202  * retrieve the value of ATTR for e_march
1203  */
1204  if (preg_match('/^BENEFATTR/', $p_tag) == 1)
1205  {
1206  $r="";
1207  $qcode=isset($p_array['qcode_benef'])?$p_array['qcode_benef']:'';
1208  // Retrieve f_id
1209  $r=$this->replace_special_tag($qcode,$p_tag);
1210  }
1211  if (preg_match('/^CUSTATTR/', $p_tag) == 1)
1212  {
1213  $r="";
1214  if ( isset($p_array['qcode_dest']) || isset($p_array['e_client']) )
1215  {
1216  $qcode=(isset($p_array['qcode_dest']))?$p_array['qcode_dest']:$p_array['e_client'];
1217  $r=$this->replace_special_tag($qcode,$p_tag);
1218  }
1219  }
1220  return $r;
1221  }
1222  /*!\brief remove a row from the table document, the lob object is not deleted
1223  * because can be linked elsewhere
1224  */
1225  function remove()
1226  {
1227  $d_lob=$this->db->get_value('select d_lob from document where d_id=$1',
1228  array($this->d_id));
1229  $sql='delete from document where d_id='.$this->d_id;
1230  $this->db->exec_sql($sql);
1231  if ( $d_lob != 0 )
1232  $this->db->lo_unlink($d_lob);
1233  }
1234  /*!\brief Move a document from the table document into the concerned row
1235  * the document is not copied : it is only a link
1236  *
1237  * \param $p_internal internal code
1238  *
1239  */
1240  function MoveDocumentPj($p_internal)
1241  {
1242  $sql="update jrn set jr_pj=$1,jr_pj_name=$2,jr_pj_type=$3 where jr_internal=$4";
1243 
1244  $this->db->exec_sql($sql,array($this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal));
1245  // clean the table document
1246  $sql='delete from document where d_id='.$this->d_id;
1247  $this->db->exec_sql($sql);
1248 
1249 
1250  }
1251  /**
1252  *Replace a special tag *TAGxxxx with the value from fiche_detail, the xxxx
1253  * is the ad_value
1254  * @param $p_qcode qcode of the card
1255  * @param $p_tag tag to parse
1256  * @return the ad_value contained in fiche_detail or for the type "select" the
1257  * label
1258  */
1259  function replace_special_tag($p_qcode, $p_tag)
1260  {
1261  // check if the march exists
1262  if ($p_qcode == "")
1263  return "";
1264 
1265  $f = new Fiche($this->db);
1266  $found = $f->get_by_qcode($p_qcode, false);
1267  // if not found exit
1268  if ($found == 1)
1269  return "";
1270 
1271  // get the ad_id
1272  $attr=preg_replace("/^.*ATTR/","",$p_tag);
1273 
1274  if (isNumber($attr) == 0) return "";
1275  $ad_type=$this->db->get_value("select ad_type from attr_def where ad_id=$1",array($attr));
1276 
1277  // get ad_value
1278  $ad_value=$this->db->get_value("select ad_value from fiche_detail where f_id=$1 and ad_id=$2",array($f->id,$attr));
1279 
1280  // if ad_id is type select execute select and get value
1281  if ( $ad_type=="select")
1282  {
1283  $sql=$this->db->get_value("select ad_extra from attr_def where ad_id=$1",array($attr));
1284  $array= $this->db->make_array($sql);
1285  for ($a=0;$a<count ($array);$a++)
1286  {
1287  if ($array[$a]['value']==$ad_value)
1288  return $array[$a]['label'];
1289  }
1290 
1291  }
1292  // if ad_id is not type select get value
1293  return $ad_value;
1294  }
1295  function update_description ($p_desc)
1296  {
1297  $this->db->exec_sql('update document set d_description = $1 where d_id=$2',
1298  array($p_desc,$this->d_id));
1299  }
1300 
1301 }
$_POST['ac']
Definition: do.php:279
update_description($p_desc)
const ATTR_DEF_ADRESS
Definition: constant.php:192
const ATTR_DEF_BQ_NAME
Definition: constant.php:187
Generate($p_array, $p_filename="")
Generate the document, Call $this->Replace to replace tag by value.
static num_row($ret)
wrapper for the function pg_NumRows
Class Document corresponds to the table document.
blank()
insert a minimal document and set the d_id
Manage the account from the table jrn, jrnx or tmp_pcmn.
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
Definition: ac_common.php:767
const ATTR_DEF_CP
Definition: constant.php:193
isNumber(&$p_int)
Definition: ac_common.php:202
const ATTR_DEF_STOCK
Definition: constant.php:195
$value
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...
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 generat...
if($_GET['clear']==1) $tag
switch($ss_action) $f
Acc_Tva is used for to map the table tva_rate parameter 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.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
class_action for manipulating actions action can be :
if(!isset($_REQUEST['act'])||!isset($_REQUEST['jr_id'])||!isset($_REQUEST['div'])) global $g_parameter
Definition: ajax_ledger.php:46
static insert_existing_document($p_ag_id, $p_lob, $p_filename, $p_mimetype, $p_description="")
Copy a existing OID (LOB) into the table document.
MoveDocumentPj($p_internal)
Move a document from the table document into the concerned row the document is not copied : it is onl...
define Class fiche and fiche def, those class are using class attribut. When adding or modifing new c...
Definition: class_fiche.php:44
get_all($ag_id)
get all the document of a given action
function clone(object)
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
static id()
return the $_REQUEST['gDossier'] after a check
$fl ag_id
const ATTR_DEF_CITY
Definition: constant.php:198
anchor()
create and compute a string for reference the doc <A ...>
$SecUser db
const ATTR_DEF_PAYS
Definition: constant.php:194
const ATTR_DEF_BQ_NO
Definition: constant.php:186
__construct($p_cn, $p_d_id=0)
Upload($p_ag_id)
Upload a file into document all the needed data are in $_FILES we don't increment the seq...
const ATTR_DEF_NAME
Definition: constant.php:185
const ATTR_DEF_ACCOUNT
Definition: constant.php:184
$p
Definition: array.php:34
static default_value_request($ind, $default)
return default if the value if the value doesn't exist in $_REQUEST
SaveGenerated($p_file)
Save the generated Document.
const ATTR_DEF_NUMTVA
Definition: constant.php:191
const NOTFOUND
Definition: constant.php:114
$type
echo_warning($p_string)
warns
Definition: ac_common.php:546
$href
Definition: adm.inc.php:38
$dirname
Definition: constant.php:32
compute_filename($pj, $filename)
Insert the receipt number into the filename , each generated file will have the name of the template ...
const ATTR_DEF_NUMBER_CUSTOMER
Definition: constant.php:201