class_acc_parm_code.php

Go to the documentation of this file.
00001 <?php
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: 4271 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 /*! \file
00022  * \brief Manage the table parm_code which contains the custom parameter
00023  * for the module accountancy
00024  */
00025 /*!
00026  * \brief Manage the table parm_code which contains the custom parameter
00027  * for the module accountancy
00028  */
00029 require_once("class_itext.php");
00030 require_once('class_acc_account_ledger.php');
00031 
00032 class Acc_Parm_Code
00033 {
00034     var $db;        /*!< $db  database connection */
00035     var $p_code;    /*!< $p_code  parm_code.p_code primary key */
00036     var $p_value;   /*!< $p_value  parm_code.p_value  */
00037     var $p_comment; /*!< $p_comment parm_code.p_comment */
00038 // constructor
00039     function Acc_Parm_Code($p_cn,$p_id=-1)
00040     {
00041         $this->db=$p_cn;
00042         $this->p_code=$p_id;
00043         if ( $p_id != -1 )
00044             $this->load();
00045     }
00046     /*!
00047      **************************************************
00048      * \brief  
00049      *  Load all parmCode
00050      *  return an array of Acc_Parm_Code object
00051      *
00052      * \return array
00053      */
00054 
00055     function load_all()
00056     {
00057         $sql="select * from parm_code order by p_code";
00058         $Res=$this->db->exec_sql($sql);
00059         $r= Database::fetch_all($Res);
00060         $idx=0;
00061         $array=array();
00062 
00063         if ( $r === false ) return null;
00064         foreach ($r as $row )
00065         {
00066             $o=new Acc_Parm_Code($this->db,$row['p_code']);
00067             $array[$idx]=$o;
00068             $idx++;
00069         }
00070 
00071         return $array;
00072     }
00073     /*!
00074     **************************************************
00075     * \brief  update a parm_object into the database
00076     *        p_code is _not_ updatable
00077     * \return
00078     *     nothing
00079     */
00080     function save()
00081     {
00082         // if p_code=="" nothing to save
00083         if ( $this->p_code== -1) return;
00084         // check if the account exists
00085         $acc=new Acc_Account_Ledger($this->db,$this->p_value);
00086         if ( $acc->load() == false )
00087         {
00088             alert("Ce compte n'existe pas");
00089         }
00090         else
00091         {
00092             $this->p_comment=sql_string($this->p_comment);
00093             $this->p_value=sql_string($this->p_value);
00094             $this->p_code=sql_string($this->p_code);
00095             $sql="update parm_code set ".
00096                  "p_comment='".$this->p_comment."'  ".
00097                  ",p_value='".$this->p_value."'  ".
00098                  "where p_code='".$this->p_code."'";
00099             $Res=$this->db->exec_sql($sql);
00100         }
00101     }
00102     /*!
00103      **************************************************
00104      * \brief  Display an object, with the <TD> tag
00105      *        
00106      * \return
00107      *     string
00108      */
00109     function display()
00110     {
00111         $r="";
00112         $r.= '<TD>'.$this->p_code.'</TD>';
00113         $r.= '<TD>'.h($this->p_comment).'</TD>';
00114         $r.= '<TD>'.$this->p_value.'</TD>';
00115 
00116         return $r;
00117     }
00118     /*!
00119      **************************************************
00120      * \brief  Display a form to enter info about
00121      *        a parm_code object with the <TD> tag
00122      *    
00123      * \return string
00124      */
00125     function form()
00126     {
00127         $comment=new IText();
00128         $comment->name='p_comment';
00129         $comment->value=$this->p_comment;
00130         $comment->size=45;
00131         $value=new IPoste();
00132         $value->name='p_value';
00133         $value->value=$this->p_value;
00134         $value->size=7;
00135         $value->set_attribute('ipopup','ipop_account');
00136         $value->set_attribute('account','p_value');
00137         $poste=new IText();
00138         $poste->setReadOnly(true);
00139         $poste->size=strlen($this->p_code)+1;
00140         $poste->name='p_code';
00141         $poste->value=$this->p_code;
00142         $r="";
00143         $r.='<tr>';
00144         $r.='<td align="right"> Code </td>';
00145         $r.= '<TD>'.$poste->input().'</TD>';
00146         $r.='</tr>';
00147         $r.='<tr>';
00148         $r.='<td align="right"> Commentaire </td>';
00149         $r.= '<TD>'.$comment->input().'</TD>';
00150         $r.='</tr>';
00151         $r.='<tr>';
00152         $r.='<td align="right"> Poste comptable </td>';
00153         $r.= '<TD>'.$value->input();
00154         $r.='<span id="p_value_label"></span></td>';
00155         $r.='</tr>';
00156         $r.=Dossier::hidden();
00157         return $r;
00158 
00159     }
00160 
00161     /*!
00162      **************************************************
00163      * \brief  
00164      * Complete a parm_code object thanks the p_code 
00165      *        
00166      * \return array
00167      */
00168 
00169     function load()
00170     {
00171         if ( $this->p_code == -1 ) return "p_code non initialisé";
00172         $sql='select * from parm_code where p_code=$1 ';
00173 
00174         $Res=$this->db->exec_sql($sql,array($this->p_code));
00175 
00176         if ( Database::num_row($Res) == 0 ) return 'INCONNU';
00177         $row= Database::fetch_array($Res,0);
00178         $this->p_value=$row['p_value'];
00179         $this->p_comment=$row['p_comment'];
00180 
00181     }
00182 
00183 }