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

class_invoice.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision$ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00030 class Invoice {
00031   var $cn;          
00032   var $id;          
00033   var $template;    
00035         //Constructor parameter = database connexion
00036         function Invoice($p_cn) {
00037                 $this->cn=$p_cn;        
00038         }
00039         // show the stored invoice template
00040         function myList() { 
00041                 $sql="select iv_id,iv_name from invoice";
00042                 $Res=ExecSql($this->cn,$sql);
00043                 $all=pg_fetch_all($Res);
00044                 if ( pg_NumRows($Res) == 0 ) return "";
00045                 foreach ( $all as $row) {
00046                         var_dump($row);
00047                 } 
00048         }
00049         // Save a template in the database
00050         function Save() {
00051         // Values are in $_POST
00052         StartSql($this->cn);
00053         // Save data into the table invoice
00054 
00055         // Save the file
00056         $new_name=tempnam('/tmp','invoice_');
00057         echo_debug('class_invoice.php',__LINE__,"new name=".$new_name);
00058         if ( strlen ($_FILES['pj']['tmp_name']) != 0 ) 
00059                 {
00060                 if (move_uploaded_file($_FILES['invoice']['tmp_name'],
00061                                         $new_name)) 
00062                         {
00063                         // echo "Image saved";
00064                         $oid= pg_lo_import($this->cn,$new_name);
00065                         if ( $oid == false ) 
00066                         {
00067                         echo_error('class_invoice.php',__LINE__,"cannot upload document");
00068                         Rollback($cn);
00069                         return;
00070                         }
00071                         echo_debug('class_invoice.php',__LINE__,"Loading document");
00072                         // Remove old document
00073                         $ret=ExecSql($this->cn,"select iv_file from invoice where iv_id=".$this->id);
00074                         if (pg_num_rows($ret) != 0) 
00075                         {
00076                                 $r=pg_fetch_array($ret,0);
00077                                 $old_oid=$r['iv_file'];
00078                                 if (strlen($old_oid) != 0) 
00079                                         pg_lo_unlink($this->cn,$old_oid);
00080                         }
00081                                 // Load new document
00082                                 ExecSql($this->cn,"update invoice set iv_file where iv_id=".$this->id);
00083                 }
00084                 else 
00085                 {
00086                         echo "<H1>Error</H1>";
00087                         Rollback($this->cn);
00088                         exit;
00089                 }
00090         }
00091         }
00092         // Remove a template 
00093         function Delete() {
00094         }
00095         // return the string containing the form for
00096         // adding a template
00097         function FormAdd() {
00098                 $r="";
00099                 $r='<FORM METHOD="POST" ACTION="dossier_prefs.php">';
00100                 $r.="</FORM>";
00101                 return $r;
00102         }
00103         // return the string containing the form for
00104         // removing a template
00105         function FormDelete() {
00106         }
00107         // Parse and remplace the tag in the invoice 
00108         // By the value found in quant_sold
00109         // p_id is the id of the invoice
00110         // p_internal reference (quant_sold qs_internal)
00111         function Get($p_id,$p_internal) 
00112         {
00113         // retrieve info from the table invoice
00114                 
00115         // retrieve the template and generate document
00116                 StartSql($this->cn);
00117                 $ret=ExecSql($cn,"select iv_name,iv_file from invoice where iv_id".$this->iv_id);
00118                 if ( pg_num_rows ($ret) == 0 )
00119                         return;
00120                 $row=pg_fetch_array($ret,0);
00121                 //the template is saved into file $tmp
00122                 $tmp=tempnam('/tmp/','invoice_');
00123                 pg_lo_export($cn,$row['iv_file'],$tmp);
00124                 // Parse the file 
00125 
00126 
00127 
00128 
00129                 // send it to stdout
00130                 ini_set('zlib.output_compression','Off');
00131                 header("Pragma: public");
00132                 header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
00133                 header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
00134                 header("Cache-Control: must-revalidate");
00135                 header('Content-type: rtf/x-application');
00136                 header('Content-Disposition: attachment;filename="invoice'.$p_internal.'.rtf"',FALSE);
00137                 header("Accept-Ranges: bytes");
00138                 $file=fopen($tmp,'r');
00139                 while ( !feof ($file) )
00140                 {
00141                         echo fread($file,8192);
00142                 }
00143                 fclose($file);
00144                 
00145                 unlink ($tmp);
00146                 
00147                 Commit($cn);
00148 
00149         }
00150 }
00151 ?>

Generated on Fri Jun 23 00:12:45 2006 for phpcompta by  doxygen 1.4.4