Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

Document Class Reference

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


Public Member Functions

 Document ($p_cn, $p_d_id=0)
 blank ()
 insert a minimal document and set the d_id
 save ()
 Save save the state of the document.
 Generate ()
 Generate the document, Call $this->Replace to replace tag by value.
 ParseDocument ($p_dir, $p_file, $p_type)
 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.
 SaveGenerated ($p_file)
 Save the generated Document.
 Upload ()
 Upload a file into document all the needed data are in $_FILES we don't increment the seq.
 a_ref ()
 create and compute a string for reference the doc <A ...>
 Send ()
 get ()
 Get complete all the data member thx info from the database.
 Replace ($p_tag)
 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_VAT] customer's VAT
  • [MARCH_NEXT] end this item and increment the counter $i
  • [VEN_ART_NAME]
  • [VEN_ART_PRICE]
  • [VEN_ART_QUANT]
  • [VEN_ART_TVA_CODE]
  • [VEN_ART_TVA_AMOUNT]
  • [VEN_ART_STOCK_CODE]
  • [VEN_HTVA]
  • [VEN_TVAC]
  • [VEN_TVA]
  • [TOTAL_VEN_HTVA]
  • [DATE]
  • [NUMBER_ID]
  • [MY_NAME]
  • [MY_CP]
  • [MY_COMMUNE]
  • [MY_TVA]
  • [MY_STREET]
  • [MY_NUMBER]

 remove ()
 remove a row from the table document, the lob object is not deleted because can be linked elsewhere
 MoveDocumentPj ($p_internal)
 Move a document from the table document into the concerned row the document is not copied : it is only a link.

Data Fields

 $db
 $ag_id
 $d_mimetype
 $d_filename
 $d_lob
 $d_number
 $md_id
 $d_state


Detailed Description

Class Document corresponds to the table document.

Definition at line 28 of file class_document.php.


Constructor & Destructor Documentation

Document::Document p_cn,
p_d_id = 0
 

Definition at line 42 of file class_document.php.

References d_id.

Referenced by SaveGenerated().

00043     {
00044       $this->db=$p_cn;
00045       $this->d_id=$p_d_id;
00046     } 


Member Function Documentation

Document::a_ref  ) 
 

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

a_ref

Returns:
a string

Definition at line 344 of file class_document.php.

References $r.

00345     {
00346       if ( $this->d_id == 0 )
00347         return '';
00348       $r="";
00349       $r='<A class="mtitle" HREF="show_document.php?d_id='.$this->d_id.'">Document</A>';
00350       return $r;
00351     }

Document::blank  ) 
 

insert a minimal document and set the d_id

Definition at line 49 of file class_document.php.

References $sql, ag_id, d_id, ExecSql(), and NextSequence().

00050     {
00051       $this->d_id=NextSequence($this->db,"document_d_id_seq");
00052       // affect a number
00053       $this->d_number=NextSequence($this->db,"seq_doc_type_".$this->md_type);
00054       $sql=sprintf('insert into document(d_id,ag_id,d_number) values(%d,%d,%d)',
00055                    $this->d_id,
00056                    $this->ag_id,
00057                    $this->d_number);
00058       ExecSql($this->db,$sql);
00059 
00060     }

Document::Generate  ) 
 

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

Parameters:
none 
Returns:
an array : the url where the generated doc can be found, the name of the file and his mimetype
Todo:
Carefull : the slash is not windows compliant

Definition at line 79 of file class_document.php.

References $Res, $ret, $row, Commit(), echo_debug(), ExecSql(), md_type, NextSequence(), ParseDocument(), SaveGenerated(), and StartSql().

00080     {
00081       // create a temp directory in /tmp to unpack file and to parse it
00082       $dirname=tempnam('/tmp','doc_');
00083       
00084 
00085       unlink($dirname);
00086       mkdir ($dirname);
00087       echo_debug('class_action',__LINE__,"Dirname is $dirname");
00088       // Retrieve the lob and save it into $dirname
00089       StartSql($this->db);
00090       $dm_info="select md_type,md_lob,md_filename,md_mimetype 
00091                    from document_modele where md_id=".$this->md_id;
00092       $Res=ExecSql($this->db,$dm_info);
00093 
00094       $row=pg_fetch_array($Res,0);
00095       $this->d_lob=$row['md_lob'];
00096       $this->d_filename=$row['md_filename'];
00097       $this->d_mimetype=$row['md_mimetype'];
00098 
00099       echo_debug('class_document',__LINE__,"OID is ".$row['md_lob']);
00101       chdir($dirname);
00102       $filename=$row['md_filename'];
00103       pg_lo_export($this->db,$row['md_lob'],$filename);
00104       $type="n";
00105       echo_debug('class_document',__LINE__,'The document type is '.$row['md_mimetype']);
00106       // if the doc is a OOo, we need to unzip it first
00107       // and the name of the file to change is always content.xml
00108       if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
00109         {
00110           echo_debug('class_document',__LINE__,'Unzip the OOo');
00111           echo '<span id="gen_msg">';
00112           echo '<blink><font color="red">Un moment de patience, le document se prépare...</font></blink>';
00113           echo '</span>';
00114           ob_start();
00115           system("unzip ".$filename);
00116           // Remove the file we do  not need anymore
00117           unlink($filename);
00118           ob_end_clean();
00119           $file_to_parse="content.xml";
00120           $type="OOo";
00121         }
00122       else 
00123         $file_to_parse=$filename;
00124       // affect a number
00125       $this->d_number=NextSequence($this->db,"seq_doc_type_".$row['md_type']);
00126 
00127 
00128       // parse the document - return the doc number ?
00129       $this->ParseDocument($dirname,$file_to_parse,$type);
00130 
00131       Commit($this->db);
00132       // if the doc is a OOo, we need to re-zip it 
00133       if ( strpos($row['md_mimetype'],'vnd.oasis') != 0 )
00134         {
00135           ob_start();
00136           system ("zip -r ".$filename." *");
00137           ob_end_clean();
00138           echo "le document est prêt  ";
00139 
00140           $file_to_parse=$filename;
00141         }
00142       // Create a directory 
00143       mkdir ($_SERVER['DOCUMENT_ROOT'].$dirname);
00144 
00145       // we need to rename the new generated file
00146       rename($dirname."/".$file_to_parse,$_SERVER['DOCUMENT_ROOT'].$dirname.'/'.$file_to_parse);
00147       $ret=sprintf('<A HREF="%s">Document généré</A>',
00148                    $dirname.'/'.$file_to_parse);
00149       $this->SaveGenerated($_SERVER['DOCUMENT_ROOT'].$dirname."/".$file_to_parse);
00150       return $ret;
00151     }

Document::get  ) 
 

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

Definition at line 393 of file class_document.php.

References $ret, $row, $sql, ag_id, and d_state.

00394     {
00395       $sql="select * from document where d_id=".$this->d_id;
00396       $ret=Exec($this->db,$sql);
00397       if ( pg_num_rows($ret) == 0 )
00398         return;
00399       $row=pg_fetch_array($ret,0);
00400       $this->ag_id=$row['ag_id'];
00401       $this->d_mimetype=$row['d_mimetype'];
00402       $this->d_filename=$row['d_filename'];
00403       $this->d_lob=$row['d_lob'];
00404       $this->d_number=$row[''];
00405       $this->d_state=$row['ag_id'];
00406       $this->d_number=$row['d_number'];
00407 
00408     }

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_internal internal code

Definition at line 751 of file class_document.php.

References $sql, and ExecSql().

00752     {
00753 
00754       $sql=sprintf("update jrn set jr_pj=%s,jr_pj_name='%s',jr_pj_type='%s' where jr_internal='%s'",
00755                    $this->d_lob,$this->d_filename,$this->d_mimetype,$p_internal);
00756       ExecSql($this->db,$sql);
00757       // clean the table document
00758       $this->remove();
00759     }

Document::ParseDocument p_dir,
p_file,
p_type
 

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.

ParseDocument

Parameters:
$p_dir directory name
$p_file filename
$p_type For the OOo document the tag are &lt and &gt instead of < and >
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 163 of file class_document.php.

References $h, echo_debug(), exit, Replace(), and value.

Referenced by Generate().

00164     {
00165 
00166       echo_debug('class_document',__LINE__,'Begin parsing of '.$p_dir.' '.$p_file.'Type = '.$p_type);
00167       
00174       // open the document
00175       $infile_name=$p_dir."/".$p_file;
00176       echo_debug("class_document.php",__LINE__,"Open the document $p_dir/$p_file");
00177       $h=fopen($infile_name,"r");
00178       $output_name=tempnam($_SERVER["DOCUMENT_ROOT"]."/tmp","gen_doc_");
00179       $output_file=fopen($output_name,"w+");
00180       // check if the opening is sucessfull
00181       if (  $h == false ) 
00182         {
00183           echo "cannot open $p_dir $p_file ";
00184           exit();
00185         }
00186       if ( $output_file == false) 
00187         {
00188           echo "ne peut pas ouvrir le fichier de sortie";
00189           exit();
00190         }
00191       // compute the regex
00192       if ( $p_type=='OOo')
00193         {
00194           $regex="&lt;&lt;[A-Z]+_*[A-Z]*_*[A-Z]*_*[0-9]*&gt;&gt;";
00195           $lt="&lt;";
00196           $gt="&gt;";
00197         }
00198       else
00199         {
00200           $regex="<<[A-Z]+_*[A-Z]*_*[A-Z]*_*[0-9]*>>";
00201           $lt="<";
00202           $gt=">";
00203         }
00204       //read the file
00205       while(! feof($h)) 
00206         {
00207           // replace the tag
00208           $buffer=fgets($h);
00209           // search in the buffer the magic << and >>
00210           // while ereg finds something to replace
00211           while ( ereg ($regex,$buffer,$f) )
00212             {
00213 
00214             echo_debug('class_document',__LINE__,'var_export '.var_export( $f,true));
00215             foreach ( $f as $pattern )
00216               {
00217                 echo_debug('class_document',__LINE__, "pattern");
00218                 echo_debug('class_document',__LINE__, var_export($pattern,true));
00219                 $to_remove=$pattern;
00220                 // we remove the < and > from the pattern
00221                 $pattern=str_replace($lt,'',$pattern);
00222                 $pattern=str_replace($gt,'',$pattern);
00223 
00224 
00225                 // if the pattern if found we replace it
00226                 $value=$this->Replace($pattern);
00227                 // replace into the $buffer
00228                 // take the position in the buffer 
00229                 $pos=strpos($buffer,$to_remove);
00230                 // get the length of the string to remove
00231                 $len=strlen($to_remove);
00232                 $buffer=substr_replace($buffer,$value,$pos,$len);
00233 
00234                 //              echo_debug('class_document',__LINE__, $buffer);
00235                 // if the pattern if found we replace it
00236                 echo_debug('class_document',__LINE__,"Transform $pattern by $value");
00237               }
00238           }
00239           // write into the output_file
00240           fwrite($output_file,$buffer);
00241 
00242         }
00243       fclose($h);
00244       fclose($output_file);
00245       rename ($output_name,$infile_name);
00246       // Save the document into the database
00247 
00248     }

Document::remove  ) 
 

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

Definition at line 740 of file class_document.php.

References $sql, d_id, and ExecSql().

00741     {
00742       $sql='delete from document where d_id='.$this->d_id;
00743       ExecSql($this->db,$sql);
00744     }

Document::Replace p_tag  ) 
 

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_VAT] customer's VAT
  • [MARCH_NEXT] end this item and increment the counter $i
  • [VEN_ART_NAME]
  • [VEN_ART_PRICE]
  • [VEN_ART_QUANT]
  • [VEN_ART_TVA_CODE]
  • [VEN_ART_TVA_AMOUNT]
  • [VEN_ART_STOCK_CODE]
  • [VEN_HTVA]
  • [VEN_TVAC]
  • [VEN_TVA]
  • [TOTAL_VEN_HTVA]
  • [DATE]
  • [NUMBER_ID]
  • [MY_NAME]
  • [MY_CP]
  • [MY_COMMUNE]
  • [MY_TVA]
  • [MY_STREET]
  • [MY_NUMBER]

Parameters:
TAG 
Returns:
String which must replace the tag
Todo:
verify that price and quant are numeric
Todo:
carefull round problem ?
Todo:
verify that price and quant are numeric
Todo:
carefull round problem ?

Definition at line 441 of file class_document.php.

References $act, $my, $p, $poste, $qcode, $r, ag_id, break, fiche, GetTvaRate(), MY_COMMUNE, MY_CP, MY_FAX, MY_NAME, MY_NUMBER, MY_PAYS, MY_STREET, MY_TEL, MY_TVA, and qcode_dest.

Referenced by ParseDocument().

00442     {
00443       $r="Tag inconnu";
00444       static $counter=0;
00445       switch ($p_tag)
00446         {
00447         case 'DATE':
00448           $r=' Date inconnue ';
00449           // Date are in $_REQUEST['ag_date'] 
00450           // or $_POST['e_date']
00451           if ( isset ($_REQUEST['ag_date']))
00452             $r=$_REQUEST['ag_date'];
00453           if ( isset ($_REQUEST['e_date']))
00454             $r=$_REQUEST['e_date'];
00455 
00456           break; 
00457           //
00458           //  the company priv
00459 
00460         case 'MY_NAME':
00461           $my=new own($this->db);
00462           $r=$my->MY_NAME;
00463           break;
00464         case 'MY_CP':
00465           $my=new own($this->db);
00466           $r=$my->MY_CP;
00467           break;
00468         case 'MY_COMMUNE':
00469           $my=new own($this->db);
00470           $r=$my->MY_COMMUNE;
00471           break;
00472         case 'MY_TVA':
00473           $my=new own($this->db);
00474           $r=$my->MY_TVA;
00475           break;
00476         case 'MY_STREET':
00477           $my=new own($this->db);
00478           $r=$my->MY_STREET;
00479           break;
00480         case 'MY_NUMBER':
00481           $my=new own($this->db);
00482           $r=$my->MY_NUMBER;
00483           break;
00484         case 'MY_TEL':
00485           $my=new own($this->db);
00486           $r=$my->MY_TEL;
00487           break;
00488         case 'MY_FAX':
00489           $my=new own($this->db);
00490           $r=$my->MY_FAX;
00491           break;
00492         case 'MY_PAYS':
00493           $my=new own($this->db);
00494           $r=$my->MY_PAYS;
00495           break;
00496 
00497           // customer 
00498           /*\note The CUST_* are retrieved thx the $_REQUEST['tiers'] 
00499            * which contains the quick_code
00500            */
00501         case 'SOLDE':
00502           $tiers=new fiche($this->db);
00503           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00504           $tiers->Getbyqcode($qcode,false);
00505           $p=$tiers->strAttribut(ATTR_DEF_ACCOUNT);
00506           $poste=new Poste($this->db,$p);
00507           $r=$poste->GetSolde(' true' );
00508           break;
00509         case 'CUST_NAME':
00510           $tiers=new fiche($this->db);
00511           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00512           $tiers->getByQcode($qcode,false);
00513           $r=$tiers->strAttribut(ATTR_DEF_NAME);
00514           break;
00515         case 'CUST_ADDR_1':
00516           $tiers=new fiche($this->db);
00517           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00518           $tiers->getByQcode($qcode,false);
00519           $r=$tiers->strAttribut(ATTR_DEF_ADRESS);
00520           
00521           break ;
00522         case 'CUST_CP':
00523           $tiers=new fiche($this->db);
00524           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00525           $tiers->getByQcode($qcode,false);
00526           $r=$tiers->strAttribut(ATTR_DEF_CP);
00527 
00528           break;
00529         case 'CUST_CO':
00530           $tiers=new fiche($this->db);
00531           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00532           $tiers->getByQcode($qcode,false);
00533           $r=$tiers->strAttribut(ATTR_DEF_PAYS);
00534 
00535           break; 
00536         case 'CUST_VAT':
00537           $tiers=new fiche($this->db);
00538           $qcode=isset($_REQUEST['qcode_dest'])?$_REQUEST['qcode_dest']:$_REQUEST['e_client'];
00539           $tiers->getByQcode($qcode,false);
00540           $r=$tiers->strAttribut(ATTR_DEF_NUMTVA);
00541           break; 
00542           // Marchandise in $_POST['e_march*']
00543           // \see user_form_achat.php or user_form_ven.php
00544         case 'NUMBER':
00545           $r=$this->d_number;
00546           break;
00547         case 'REFERENCE':
00548           $act=new action($this->db);
00549           $act->ag_id=$this->ag_id;
00550           $act->get();
00551           $r=$act->ag_ref;
00552           break;
00553 
00554           /*
00555            *  - [VEN_ART_NAME]
00556            *  - [VEN_ART_PRICE]
00557            *  - [VEN_ART_QUANT]
00558            *  - [VEN_ART_TVA_CODE]
00559            *  - [VEN_ART_TVA_AMOUNT]
00560            *  - [VEN_ART_STOCK_CODE]
00561            *  - [VEN_HTVA]
00562            *  - [VEN_TVAC]
00563            *  - [VEN_TVA]
00564            *  - [TOTAL_VEN_HTVA]
00565            */
00566         case 'MARCH_NEXT':
00567           $counter++;
00568           $r='';
00569           break;
00570           
00571         case 'VEN_ART_NAME':
00572           extract ($_POST);
00573           $id='e_march'.$counter;
00574           // check if the march exists
00575           if ( ! isset (${$id})) return "";
00576           // check that something is sold
00577           if ( ${'e_march'.$counter.'_sell'} != 0 && ${'e_quant'.$counter} != 0 )
00578             {
00579               $f=new fiche($this->db);
00580               $f->GetByQCode(${$id},false);
00581               $r=$f->strAttribut(ATTR_DEF_NAME);
00582             } else $r = "";
00583           break;
00584 
00585         case 'VEN_ART_PRICE':
00586           extract ($_POST);
00587           $id='e_march'.$counter.'_sell' ;
00588           if ( !isset (${$id}) ) return "";
00589           $r=${$id};
00590           break;
00591 
00592         case 'TVA_CODE':
00593           extract ($_POST);
00594           $id='e_march'.$counter.'_tva_id';
00595           if ( !isset (${$id}) ) return "";
00596           if ( ${$id} == -1 ) return "";
00597           $qt='e_quant'.$counter;
00598           $price='e_march'.$counter.'_sell' ;
00599           if ( ${$price} == 0 || ${$qt} == 0 
00600                || strlen(trim( $price )) ==0 
00601                || strlen(trim($qt)) ==0)
00602             return "";
00603 
00604           $r=${$id};
00605           break;
00606 
00607         case 'TVA_LABEL':
00608           extract ($_POST);
00609           $id='e_march'.$counter.'_tva_id';
00610           if ( !isset (${$id}) ) return "";
00611           $tva=GetTvaRate($this->db,${$id});
00612           if ( $tva == null || $tva==0 ) return "";
00613           $r=$tva['tva_label'];
00614           break;
00615 
00616 
00617         case 'TVA_AMOUNT':
00618           extract ($_POST);
00619           $qt='e_quant'.$counter;
00620           $price='e_march'.$counter.'_sell' ;
00621           $tva='e_march'.$counter.'_tva_id';
00622           if ( !isset (${'e_march'.$counter}) ) return "";
00623           // check that something is sold
00624           if ( ${$price} == 0 || ${$qt} == 0 
00625                || strlen(trim( $price )) ==0 
00626                || strlen(trim($qt)) ==0)
00627             return "";
00628           $a_tva=GetTvaRate($this->db,${$tva});
00629           echo_debug('class_document',__LINE__,'Tva  :'.var_export($a_tva,true));
00630           // if no vat returns 0
00631           if ( sizeof($a_tva) == 0 ) return "";
00632           $r=round(${$price},2)*${$qt}*$a_tva['tva_rate'];
00633           $r=round($r,2);
00634           break;
00635 
00636         case 'VEN_ART_QUANT':
00637           extract ($_POST);
00638           $id='e_quant'.$counter;
00639           if ( !isset (${$id}) ) return "";
00640           // check that something is sold
00641           if ( ${'e_march'.$counter.'_sell'} == 0 
00642                || ${'e_quant'.$counter} == 0 
00643                || strlen(trim( ${'e_march'.$counter.'_sell'} )) ==0 
00644                || strlen(trim(${'e_quant'.$counter})) ==0 )
00645             return "";
00646           $r=${$id};
00647           break;
00648 
00649         case 'VEN_HTVA':
00650           extract ($_POST);
00651           $id='e_march'.$counter.'_sell' ;
00652           $quant='e_quant'.$counter;
00653           if ( !isset (${$id}) ) return "";
00654 
00655           // check that something is sold
00656           if ( ${'e_march'.$counter.'_sell'} == 0 || ${'e_quant'.$counter} == 0 
00657                || strlen(trim( ${'e_march'.$counter.'_sell'} )) ==0 
00658                || strlen(trim(${'e_quant'.$counter})) ==0)
00659             return "";
00665           $r=round(${$id}*${$quant},2); 
00666           break;
00667 
00668         case 'VEN_TVAC':
00669           extract ($_POST);
00670           $id='e_march'.$counter.'_sell' ;
00671           $quant='e_quant'.$counter;
00672           // if it is exist
00673           if ( ! isset(${$id})) 
00674             return "";
00675           // check that something is sold
00676           if ( ${'e_march'.$counter.'_sell'} == 0 || ${'e_quant'.$counter} == 0 )
00677             return "";
00682           $r=${$id}*${$quant}; 
00683           $tva=GetTvaRate($this->db,${'e_march'.$counter.'_tva_id'});
00684           // if there is no vat we return now
00685           if ( $tva == null || $tva == 0 ) return $r;
00686           // we compute with the vat included
00687           $r=$r+$r*$tva['tva_rate'];
00688           $r=round($r,2);
00689           break;
00690         case 'TOTAL_VEN_HTVA':
00691           extract($_POST);
00692           echo_debug('class_document',__LINE__,'TOTAL_VEN_TVA item :'.$nb_item);
00693 
00694           $sum=0.0;
00695           for ($i=0;$i<$nb_item;$i++)
00696             {
00697               $sell='e_march'.$i.'_sell';
00698               $qt='e_quant'.$i;
00699               echo_debug('class_document',__LINE__,'sell :'.$sell.' qt = '.$qt);
00700 
00701               echo_debug('class_document',__LINE__,'counter :'.$i.' sur '.$nb_item);
00702               if ( ! isset (${$sell}) ) break;
00703               echo_debug('class_document',__LINE__,'sell :'.${$sell}.' qt = '.${$qt});
00704 
00705               if ( strlen(trim(${$sell})) == 0 ||
00706                    strlen(trim(${$qt})) == 0 ||
00707                    ${$qt}==0 || ${$sell}==0)
00708                 continue;
00709               $sum+=${$sell}*${$qt};
00710               echo_debug('class_document',__LINE__,'sum :'.$sum);
00711 
00712             }
00713           $r=round($sum,2);
00714           break;
00715         case 'TOTAL_VEN_TVAC':
00716           extract($_POST);
00717           $sum=0.0;
00718           for ($i=0;$i<$nb_item;$i++)
00719             {
00720               $tva=GetTvaRate($this->db,${'e_march'.$i.'_tva_id'});
00721               $tva_rate=( $tva == null || $tva == 0 )?0.0:$tva['tva_rate'];
00722               echo_debug('class_document',__LINE__,' :'.$i.' sur '.$nb_item);
00723               $sell=${'e_march'.$i.'_sell'};
00724               $qt=${'e_quant'.$i};
00725               echo_debug('class_document',__LINE__,'sell :'.$sell.' qt = '.$qt);
00726 
00727               $sum+=$sell*$qt*(1+$tva_rate);
00728               //              $sum+=${'e_march'.$i.'_sell'}*${'e_quant'.$i}*(1+$tva_rate);
00729             }
00730           $r=round($sum,2);
00731 
00732           break;
00733 
00734         }
00735       return $r;
00736     }

Document::save  ) 
 

Save save the state of the document.

Definition at line 63 of file class_document.php.

References $sql, and ExecSql().

00064     {
00065       $sql="update document set d_state=".$this->d_state.
00066         " where d_id=".$this->d_id;
00067       ExecSql($this->db,$sql);
00068     }

Document::SaveGenerated p_file  ) 
 

Save the generated Document.

SaveGenerated

Parameters:
$p_file is the generated file
Returns:
0 if no error otherwise 1

Definition at line 256 of file class_document.php.

References $doc, $sql, Commit(), d_id, Document(), echo_debug(), ExecSql(), GetSequence(), Rollback(), and StartSql().

Referenced by Generate().

00257     {
00258       echo_debug('class_document',__LINE__,'Save generated');
00259       // We save the generated file
00260       $doc=new Document($this->db);
00261       StartSql($this->db);
00262       $this->d_lob=pg_lo_import($this->db,$p_file);
00263       if ( $this->d_lob == false ) { 
00264         Rollback($this->db); echo_debug('class_document',__LINE__,"can't save file $p_file");
00265         return 1; }
00266     
00267       $sql=sprintf("insert into document(ag_id,d_lob,d_number,d_filename,d_mimetype,d_state) 
00268                         values (%d,%s,%d,'%s','%s',%d)",
00269                    $this->ag_id,
00270                    $this->d_lob,
00271                    $this->d_number,
00272                    $this->d_filename,
00273                    $this->d_mimetype,
00274                    $this->d_state
00275                    );
00276       ExecSql($this->db,$sql);
00277       $this->d_id=GetSequence($this->db,"document_d_id_seq");
00278       echo_debug('class_document',__LINE__,'document sauvé : d_id'.$this->d_id);
00279       Commit($this->db);
00280       return 0;
00281     }

Document::Send  ) 
 

Definition at line 355 of file class_document.php.

References $file, $ret, $row, $tmp, Commit(), ExecSql(), and StartSql().

00356     {
00357       // retrieve the template and generate document
00358       StartSql($this->db);
00359       $ret=ExecSql($this->db,
00360                    "select d_id,d_lob,d_filename,d_mimetype from document where d_id=".$this->d_id );
00361       if ( pg_num_rows ($ret) == 0 )
00362         return;
00363       $row=pg_fetch_array($ret,0);
00364       //the document  is saved into file $tmp
00365       $tmp=tempnam('/tmp/','document_');
00366       pg_lo_export($this->db,$row['d_lob'],$tmp);
00367       $this->d_mimetype=$row['d_mimetype'];
00368       $this->d_filename=$row['d_filename'];
00369 
00370       // send it to stdout
00371       ini_set('zlib.output_compression','Off');
00372       header("Pragma: public");
00373       header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00374       header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00375       header("Cache-Control: must-revalidate");
00376       header('Content-type: "'.$this->d_mimetype.'"');
00377       header('Content-Disposition: attachment;filename="'.$this->d_filename.'"',FALSE);
00378       header("Accept-Ranges: bytes");
00379       $file=fopen($tmp,'r');
00380       while ( !feof ($file) )
00381         {
00382           echo fread($file,8192);
00383         }
00384       fclose($file);
00385       
00386       unlink ($tmp);
00387       
00388       Commit($this->db);
00389       
00390     }

Document::Upload  ) 
 

Upload a file into document all the needed data are in $_FILES we don't increment the seq.

Upload

Returns:

Definition at line 289 of file class_document.php.

References $old_oid, $r, $ret, $sql, Commit(), ExecSql(), name, Rollback(), and StartSql().

00290     {
00291 
00292       // nothing to save
00293       if ( sizeof($_FILES) == 0 ) return;
00294 
00295       // Start Transaction
00296       StartSql($this->db);
00297       $new_name=tempnam('/tmp','doc_');
00298 
00299 
00300       // check if a file is submitted
00301       if ( strlen($_FILES['file_upload']['tmp_name']) != 0 )
00302         {
00303           // upload the file and move it to temp directory
00304           if ( move_uploaded_file($_FILES['file_upload']['tmp_name'],$new_name))
00305           {
00306             $oid=pg_lo_import($this->db,$new_name);
00307             // check if the lob is in the database
00308             if ( $oid == false ) 
00309               {
00310                 Rollback($this->db);
00311                 return 1;
00312               }
00313           }
00314           // the upload in the database is successfull
00315           $this->d_lob=$oid;
00316           $this->d_filename=$_FILES['file_upload']['name'];
00317           $this->d_mimetype=$_FILES['file_upload']['type'];
00318           // now we have to update the col.
00319           // We retrieve the row to remove a possible existing lob (replace)
00320           $sql="select d_lob from document where d_id=".$this->d_id;
00321           $ret=ExecSql($this->db,$sql);
00322 
00323           if (pg_num_rows($ret) != 0)  
00324             {
00325               // a result is found, the old oid is keept in order to
00326               // remove it later
00327               $r=pg_fetch_array($ret,0) ;
00328               $old_oid=$r['d_lob'] ;
00329               if (strlen($old_oid) != 0) { pg_lo_unlink ($this->db,$old_oid);}
00330             }
00331           // Update the table
00332           $sql=sprintf("update document set d_lob=%s,d_filename='%s',d_mimetype='%s' where d_id=%d",
00333                        $this->d_lob,$this->d_filename,$this->d_mimetype,$this->d_id);
00334           ExecSql($this->db,$sql);
00335         }
00336       Commit($this->db);
00337 
00338     }


Field Documentation

Document::$ag_id
 

action_gestion.ag_id (pk)

Definition at line 32 of file class_document.php.

Document::$d_filename
 

Definition at line 34 of file class_document.php.

Document::$d_lob
 

the oid of the lob

Definition at line 35 of file class_document.php.

Document::$d_mimetype
 

Definition at line 33 of file class_document.php.

Document::$d_number
 

number of the document

Definition at line 36 of file class_document.php.

Document::$d_state
 

document.d_state status of the document

Definition at line 38 of file class_document.php.

Document::$db
 

Database connexion var $d_id; /*!

Definition at line 30 of file class_document.php.

Document::$md_id
 

document's template

Definition at line 37 of file class_document.php.


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