/* * This file is part of PhpCompta. * * PhpCompta is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * PhpCompta is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with PhpCompta; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr /*! \file * \brief Class invoice to manage the customer invoice * \todo obsolete ? then delete it */ /*! * \brief Class invoice to manage the customer invoice * */ class Invoice { var $cn; /*! \enum $cn database conx */ var $id; /*! \enum $id iv_id */ var $template; /*! \enum $template template's name */ //Constructor parameter = database connexion function Invoice($p_cn) { $this->cn=$p_cn; } // show the stored invoice template function myList() { $sql="select iv_id,iv_name from invoice"; $Res=ExecSql($this->cn,$sql); $all=pg_fetch_all($Res); if ( pg_NumRows($Res) == 0 ) return ""; foreach ( $all as $row) { var_dump($row); } } // Save a template in the database function Save() { // Values are in $_POST StartSql($this->cn); // Save data into the table invoice // Save the file $new_name=tempnam('/tmp','invoice_'); echo_debug('class_invoice.php',__LINE__,"new name=".$new_name); if ( strlen ($_FILES['pj']['tmp_name']) != 0 ) { if (move_uploaded_file($_FILES['invoice']['tmp_name'], $new_name)) { // echo "Image saved"; $oid= pg_lo_import($this->cn,$new_name); if ( $oid == false ) { echo_error('class_invoice.php',__LINE__,"cannot upload document"); Rollback($cn); return; } echo_debug('class_invoice.php',__LINE__,"Loading document"); // Remove old document $ret=ExecSql($this->cn,"select iv_file from invoice where iv_id=".$this->id); if (pg_num_rows($ret) != 0) { $r=pg_fetch_array($ret,0); $old_oid=$r['iv_file']; if (strlen($old_oid) != 0) pg_lo_unlink($this->cn,$old_oid); } // Load new document ExecSql($this->cn,"update invoice set iv_file where iv_id=".$this->id); } else { echo "