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