noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
class_acc_account.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 account
00022  */
00023 /*!
00024  * \brief Manage the account from the table tmp_pcmn
00025  */
00026 require_once("class_iselect.php");
00027 require_once ('class_database.php');
00028 require_once ('class_dossier.php');
00029 
00030 class Acc_Account
00031 {
00032     var $db;          /*!< $db database connection */
00033     static private $variable = array("value"=>'pcm_val',
00034                                      'type'=>'pcm_type',
00035                                      'parent'=>'pcm_val_parent',
00036                                      'libelle'=>'pcm_lib');
00037     private  $pcm_val;
00038     private  $pcm_type;
00039     private  $pcm_parent;
00040     private  $pcm_lib;
00041     static public $type=array(
00042                             array('label'=>'Actif','value'=>'ACT'),
00043                             array('label'=>'Passif','value'=>'PAS'),
00044                             array('label'=>'Actif c. inverse','value'=>'ACTINV'),
00045                             array('label'=>'Passif c.inverse','value'=>'PASINV'),
00046                             array('label'=>'Produit','value'=>'PRO'),
00047                             array('label'=>'Produit Inverse','value'=>'PROINV'),
00048                             array('label'=>'Charge','value'=>'CHA'),
00049                             array('label'=>'Charge Inverse','value'=>'CHAINV'),
00050                             array('label'=>'Non defini','value'=>'CON')
00051                         );
00052 
00053     function __construct ($p_cn,$p_id=0)
00054     {
00055         $this->db=$p_cn;
00056         $this->pcm_val=$p_id;
00057     }
00058     public function get_parameter($p_string)
00059     {
00060         if ( array_key_exists($p_string,self::$variable) )
00061         {
00062             $idx=self::$variable[$p_string];
00063             return $this->$idx;
00064         }
00065         else
00066             exit (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
00067     }
00068 
00069     function set_parameter($p_string,$p_value)
00070     {
00071         if ( array_key_exists($p_string,self::$variable) )
00072         {
00073             $idx=self::$variable[$p_string];
00074             if ($this->check($idx,$p_value) == true )      $this->$idx=$p_value;
00075         }
00076         else
00077             exit (__FILE__.":".__LINE__._('Erreur attribut inexistant'));
00078 
00079 
00080     }
00081     /*!\brief Return the name of a account
00082      *        it doesn't change any data member
00083      * \return string with the pcm_lib
00084      */
00085     function get_lib()
00086     {
00087         $ret=$this->db->exec_sql(
00088                  "select pcm_lib from tmp_pcmn where
00089                  pcm_val=$1",array($this->pcm_val));
00090         if ( Database::num_row($ret) != 0)
00091         {
00092             $r=Database::fetch_array($ret);
00093             $this->pcm_lib=$r['pcm_lib'];
00094         }
00095         else
00096         {
00097             $this->pcm_lib=_("Poste inconnu");
00098         }
00099         return $this->pcm_lib;
00100     }
00101     /*!\brief Check that the value are valid
00102      *\return true if all value are valid otherwise false
00103      */
00104     function check ($p_member='',$p_value='')
00105     {
00106         // if there is no argument we check all the member
00107         if ($p_member == '' && $p_value== '' )
00108         {
00109             foreach (self::$variable as $l=>$k)
00110             {
00111                 $this->check($k,$this->$k);
00112             }
00113         }
00114         else
00115         {
00116             // otherwise we check only the value
00117             if ( strcmp ($p_member,'pcm_val') == 0 )
00118             {
00119                     return true;
00120             }
00121             else if ( strcmp ($p_member,'pcm_val_parent') == 0 )
00122             {
00123                     return true;
00124             }
00125             else if ( strcmp ($p_member,'pcm_lib') == 0 )
00126             {
00127                 return true;
00128             }
00129             else if ( strcmp ($p_member,'pcm_type') == 0 )
00130             {
00131                 foreach (self::$type as $l=>$k)
00132                 {
00133                     if ( strcmp ($k['value'],$p_value) == 0 ) return true;
00134 
00135                 }
00136                 throw new Exception(_('type de compte incorrect ').$p_value);
00137             }
00138             throw new Exception (_('Donnee member inconnue ').$p_member);
00139         }
00140 
00141     }
00142     /*!\brief Get all the value for this object from the database
00143      *        the data member are set
00144      * \return false if this account doesn't exist otherwise true
00145      */
00146     function load()
00147     {
00148         $ret=$this->db->exec_sql("select pcm_lib,pcm_val_parent,pcm_type from
00149                                  tmp_pcmn where pcm_val=$1",array($this->pcm_val));
00150         $r=Database::fetch_all($ret);
00151 
00152         if ( ! $r ) return false;
00153         $this->pcm_lib=$r[0]['pcm_lib'];
00154         $this->pcm_val_parent=$r[0]['pcm_val_parent'];
00155         $this->pcm_type=$r[0]['pcm_type'];
00156         return true;
00157 
00158     }
00159     function form($p_table=true)
00160     {
00161         $wType=new ISelect();
00162         $wType->name='p_type';
00163         $wType->value=self::$type;
00164 
00165         if ( ! $p_table )
00166         {
00167             $ret='    <TR>
00168                  <TD>
00169                  <INPUT TYPE="TEXT" NAME="p_val" SIZE=7>
00170                  </TD>
00171                  <TD>
00172                  <INPUT TYPE="TEXT" NAME="p_lib" size=50>
00173                  </TD>
00174                  <TD>
00175                  <INPUT TYPE="TEXT" NAME="p_parent" size=5>
00176                  </TD>
00177                  <TD>';
00178 
00179             $ret.=$wType->input().'</TD>';
00180             return $ret;
00181         }
00182         else
00183         {
00184             $ret='<TABLE><TR>';
00185             $ret.=sprintf ('<TD>'._('Numéro de classe').' </TD><TD><INPUT TYPE="TEXT" name="p_val" value="%s"></TD>',$this->pcm_val);
00186             $ret.="</TR><TR>";
00187             $ret.=sprintf('<TD>'._('Libellé').' </TD><TD><INPUT TYPE="TEXT" size="70" NAME="p_lib" value="%s"></TD>',h($this->pcm_lib));
00188             $ret.= "</TR><TR>";
00189             $ret.=sprintf ('<TD>'._('Classe Parent').'</TD><TD><INPUT TYPE="TEXT" name="p_parent" value="%s"></TD>',$this->pcm_val_parent);
00190             $ret.='</tr><tr>';
00191             $wType->selected=$this->pcm_type;
00192             $ret.="<td> Type de poste </td>";
00193             $ret.= '<td>'.$wType->input().'</td>';
00194             $ret.="</TR> </TABLE>";
00195             $ret.=dossier::hidden();
00196 
00197             return $ret;
00198         }
00199     }
00200     function count($p_value)
00201     {
00202         $sql="select count(*) from tmp_pcmn where pcm_val=$1";
00203         return $this->db->get_value($sql,array($p_value));
00204     }
00205     /*!\brief for developper only during test */
00206     static function test_me()
00207     {
00208         $cn=new Database(dossier::id());
00209 
00210     }
00211     /**
00212      *@brief update an accounting, but you can update pcm_val only if
00213      * this accounting has never been used before  */
00214     function update($p_old)
00215     {
00216         if (strcmp(trim($p_old), trim($this->pcm_val)) !=0 )
00217         {
00218             $count=$this->db->get_value('select count(*) from jrnx where j_poste=$1',
00219                                         array($p_old)
00220                                        );
00221             if ($count != 0)
00222                 throw new Exception(_('Impossible de changer la valeur: poste déjà utilisé'));
00223         }
00224         $this->pcm_lib=mb_substr($this->pcm_lib,0,150);
00225         $this->check();
00226         $sql="update tmp_pcmn set pcm_val=$1, pcm_lib=$2,pcm_val_parent=$3,pcm_type=$4 where pcm_val=$5";
00227         $Ret=$this->db->exec_sql($sql,array($this->pcm_val,
00228                                             $this->pcm_lib,
00229                                             $this->pcm_val_parent,
00230                                             $this->pcm_type,
00231                                             $p_old));
00232     }
00233 }
 All Data Structures Namespaces Files Functions Variables Enumerations