noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_acc_tva.php
Go to the documentation of this file.
1 <?php
2 /*
3  * This file is part of NOALYSS.
4  *
5  * NOALYSS is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * NOALYSS is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with NOALYSS; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 
20 // Copyright Author Dany De Bontridder danydb@aevalys.eu
21 
22 /*!\file
23  * \brief this class is used for the table tva_rate
24  */
25 require_once NOALYSS_INCLUDE.'/class/class_dossier.php';
26 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
27 
28 /*!\brief Acc_Tva is used for to map the table tva_rate
29  * parameter are
30 - private static $cn; database connection
31 - private static $variable=array("id"=>"tva_id",
32  "label"=>"tva_label",
33  "rate"=>"tva_rate",
34  "comment"=>"tva_comment",
35  "account"=>"tva_poste");
36 
37 */
38 class Acc_Tva
39 {
40  private $cn; /*!< $cn database connection */
41  private static $variable=array("id"=>"tva_id",
42  "label"=>"tva_label",
43  "rate"=>"tva_rate",
44  "comment"=>"tva_comment",
45  "account"=>"tva_poste",
46  "both_side"=>'tva_both_side');
47 
48  function __construct ($p_init,$p_tva_id=0)
49  {
50  $this->cn=$p_init;
51  $this->tva_id=$p_tva_id;
52  $this->poste="";
53  $this->tva_label=null;
54  $this->tva_rate=0;
55  $this->tva_comment=null;
56  $this->tva_poste=null;
57  $this->tva_both_side='f';
58  }
59  public function get_parameter($p_string)
60  {
61  if ( array_key_exists($p_string,self::$variable) )
62  {
63  $idx=self::$variable[$p_string];
64  return $this->$idx;
65  }
66 
67  echo (__FILE__.":".__LINE__.'Erreur attribut inexistant');
68  }
69  public function set_parameter($p_string,$p_value)
70  {
71  if ( array_key_exists($p_string,self::$variable) )
72  {
73  $idx=self::$variable[$p_string];
74  $this->$idx=$p_value;
75  }
76  else
77  throw new Exception("Attribut inexistant $p_string");
78 
79 
80  }
81  public function get_info()
82  {
83  return var_export(self::$variable,true);
84  }
85 
86  public function verify()
87  {
88  // Verify that the elt we want to add is correct
89  }
90  public function save()
91  {
92 
93  if ( $this->tva_id == 0 )
94  $this->insert();
95  else
96  $this->update();
97  }
98 
99  public function insert()
100  {
101  if ( $this->verify() != 0 ) return;
102  $sql="select tva_insert($1,$2,$3,$4,$5)";
103 
104  $res=$this->cn->exec_sql(
105  $sql,
106  array($this->tva_label,
107  $this->tva_rate,
108  $this->tva_comment,
109  $this->tva_poste,
110  $this->tva_both_side)
111  );
112  $this->tva_id=$this->cn->get_current_seq('s_tva');
114  }
115 
116  public function update()
117  {
118  if ( $this->verify() != 0 ) return;
119  $sql="update tva_rate set tva_label=$1,tva_rate=$2,tva_comment=$3,tva_poste=$4,tva_both_side=$5 ".
120  " where tva_id = $6";
121  $res=$this->cn->exec_sql(
122  $sql,
123  array($this->tva_label,
124  $this->tva_rate,
125  $this->tva_comment,
126  $this->tva_poste,
127  $this->tva_both_side,
128  $this->tva_id)
129  );
130 
131  }
132  /**
133  *Load the VAT,
134  *@note if the label is not found then we get an message error, so the best is probably
135  *to initialize the VAT object with default value
136  */
137  public function load()
138  {
139  $sql="select tva_id,tva_label,tva_rate, tva_comment,tva_poste,tva_both_side from tva_rate where tva_id=$1";
140  $res=$this->cn->exec_sql(
141  $sql,
142  array($this->tva_id)
143  );
144 
145  if ( $this->cn->size() == 0 ) return -1;
146 
148  foreach ($row as $idx=>$value)
149  {
150  $this->$idx=$value;
151  }
152  return 0;
153  }
154  /*!\brief get the account of the side (debit or credit)
155  *\param $p_side is d or C
156  *\return the account to use
157  *\note call first load if tva_poste is empty
158  */
159  public function get_side($p_side)
160  {
161  if ( strlen($this->tva_poste) == 0 ) $this->load();
162  list($deb,$cred)=explode(",",$this->tva_poste);
163  switch ($p_side)
164  {
165  case 'd':
166  return $deb;
167  break;
168  case 'c':
169  return $cred;
170  break;
171  default:
172  throw (new Exception (__FILE__.':'.__LINE__." param est d ou c, on a recu [ $p_side ]"));
173  }
174  }
175  public function delete()
176  {
177  $sql="delete from tva_rate where tva_id=$1";
178  $res=$this->cn->exec_sql($sql,array($this->tva_id));
179  }
180  /*!\brief
181  * Test function
182  */
183  static function test_me()
184  {
186  $a=new Acc_Tva($cn);
187  echo $a->get_info();
188  $a->set_parameter("id",1);
189  $a->load();
190  $a->set_parameter("id",0);
191  $a->set_parameter("rate","0.2222");
192  $a->set_parameter("label","test");
193  $a->save();
194  $a->load();
195  print_r($a);
196 
197  $a->set_parameter("comment","un cht'it test");
198  $a->save();
199  $a->load();
200  print_r($a);
201 
202  $a->delete();
203  }
204 
205 }
206 
207 /* test::test_me(); */
static $variable
$value
$idx
static test_me()
Test function.
Acc_Tva is used for to map the table tva_rate parameter are.
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
load()
Load the VAT,.
for($i=0;$i<$nb_jrn;$i++) $deb
__construct($p_init, $p_tva_id=0)
$input_from cn
Definition: balance.inc.php:71
static fetch_result($ret, $p_row=0, $p_col=0)
wrapper for the function pg_fetch_all
static connect()
set_parameter($p_string, $p_value)
get_parameter($p_string)
get_side($p_side)
get the account of the side (debit or credit)