noalyss  Version-6.9.1.8
 All Data Structures Namespaces Files Functions Variables Pages
class_anc_account.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 contains the object for the poste_analytique (table poste_analytique)
24  */
25 
26 /*!\brief contains the object for the poste_analytique (table poste_analytique)
27  *
28  */
29 require_once NOALYSS_INCLUDE.'/lib/class_ihidden.php';
30 require_once NOALYSS_INCLUDE.'/lib/class_itext.php';
31 require_once NOALYSS_INCLUDE.'/lib/class_iselect.php';
32 require_once NOALYSS_INCLUDE.'/lib/class_ispan.php';
33 require_once NOALYSS_INCLUDE.'/lib/class_database.php';
34 require_once NOALYSS_INCLUDE.'/class/class_anc_plan.php';
35 
37 {
38  var $id; /*!< $id is po_id */
39  var $name; /*!< po_name */
40  var $pa_id; /*!< pa_id fk to the plan_analytique(pa_id) */
41  var $amount; /*!< po_amount just an amount */
42  var $description; /*!< po_description description of the post */
43  var $db; /*!< database connection*/
44  var $ga_id; /*!< FK to the table groupe analytique */
45  function __construct($p_db,$p_id=0)
46  {
47  $this->db=$p_db;
48  $this->id=$p_id;
49  $this->ga_id=null;
50  }
51  /*! \brief retrieve data from the database and
52  * fill the object
53  * \param $p_where the where clause
54  */
55  private function fetch_from_db($p_where)
56  {
57  $sql="select po_id,
58  po_name ,
59  pa_id,
60  po_amount,
61  po_description,
62  ga_id
63  from poste_analytique
64  where ".
65  $p_where;
66 
67  $ret=$this->db->exec_sql($sql);
68  if ( Database::num_row($ret) == 0 )return null;
70 
71  $this->id=$line['po_id'];
72  $this->name=$line['po_name'];
73  $this->pa_id=$line['pa_id'];
74  $this->amount=$line['po_amount'];
75  $this->description=$line['po_description'];
76  $this->ga_id=$line['ga_id'];
77 
78 
79  }
80  function get_by_id()
81  {
82  $this->fetch_from_db("po_id=".$this->id);
83  }
84  /*!
85  * \brief retrieve data thanks the name
86  * \param $p_name name of the analytic account
87  *
88  */
89  function get_by_name($p_name)
90  {
91  $p_name=sql_string($p_name);
92  if ( $p_name == null )
93  $p_name=$this->name;
94 
95  $this->fetch_from_db("po_name='".$p_name."'");
96  echo "id = ".$this->id;
97  }
98  function add()
99  {
100  $this->format_data();
101  if ( strlen($this->name) == 0)
102  return;
103  if ( $this->ga_id == null || strlen(trim($this->ga_id)) == 0 )
104  $ga_id=NULL;
105  else
107  $sql="insert into poste_analytique (
108  po_name ,
109  pa_id,
110  po_amount,
111  po_description,
112  ga_id
113  ) values ($1,$2,$3,$4,$5)";
114 
115  try
116  {
117  $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,$this->description,$ga_id));
118 
119  }
120  catch (Exception $e)
121  {
122  if ( DEBUG ) print_r($e);
123  echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas sauve</p>";
124  }
125 
126  }
127  static function make_array_name($cn,$pa_id)
128  {
129  $a=$cn->make_array("select po_name,po_name from poste_analytique ".
130  " where ".
131  " pa_id = $1 order by po_name ",0,array($pa_id));
132  return $a;
133  }
134  function update()
135  {
136  $this->format_data();
137  if ( strlen($this->name) == 0)
138  return;
139  $sql="update poste_analytique ".
140  " set po_name=$1".
141  " ,pa_id=$2".
142  " ,po_amount=$3".
143  " ,po_description=$4".
144  " ,ga_id=$5".
145  " where po_id=$6";
146  try
147  {
148  $this->db->exec_sql($sql,array($this->name,$this->pa_id,$this->amount,
149  $this->description,$this->ga_id,$this->id));
150  }
151  catch (Exception $e)
152  {
153  echo "<p class=\"notice\">Doublon : l'enregistrement n'est pas sauve</p>";
154  }
155 
156  }
157  private function format_data()
158  {
159 
160  $this->name=$this->name;
161  $this->pa_id=$this->pa_id;
162  $this->amount=$this->amount;
163  if (strlen($this->amount) == 0 )
164  $this->amount=0.0;
165  if ( isNumber($this->amount) ==0 )
166  $this->amount=0;
167 
168  $this->description=$this->description;
169  }
170  function delete()
171  {
172  $sql="delete from poste_analytique where po_id=".$this->id;
173  $this->db->exec_sql($sql);
174  }
175  /*!
176  * \brief return an array of object Poste_Analytique
177  *
178  */
179  function get_list()
180  {
181  $sql="select po_id,
182  po_name ,
183  pa_id,
184  po_amount,
185  po_description,
186  ga_id
187  from poste_analytique ".
188  " order by po_name";
189 
190  $ex=$this->db->exec_sql($sql);
192  if ( $ret == null )
193  return null;
194 
195  $array=array();
196  foreach ($ret as $line)
197  {
198  $object=new Anc_Account($this->db);
199 
200  $object->id=$line['po_id'];
201  $object->name=$line['po_name'];
202  $object->pa_id=$line['pa_id'];
203  $object->amount=$line['po_amount'];
204  $object->description=$line['po_description'];
205  $object->ga_id=$line['ga_id'];
206  $array[]=clone $object;
207  }
208 
209  return $array;
210  }
211  function display_list()
212  {
213  $array=$this->get_list();
214  if ( empty($array) )
215  {
216  echo "Vide";
217  return;
218  }
219  foreach ($array as $line)
220  {
221  echo $line->id." / ".$line->name." / ".$line->description."/".
222  $line->amount." / ".$line->pa_id."/".$line->ga_id."<br>";
223  }
224  }
225  function debug()
226  {
227  echo "id ".$this->id."<br>";
228  echo "name ".$this->name."<br>";
229  echo "pa_id ".$this->pa_id."<br>";
230  echo "amount ".$this->amount."<br>";
231  echo "description ".$this->description."<br>";
232  echo "ga_id ".$this->ga_id."<br>";
233  }
234  function form()
235  {
236  $r='';
237  $wName=new IText("po_name",$this->name);
238  $wAmount=new INum("po_amount",$this->amount);
239  $wDescription=new IText("po_description",$this->description);
240  $aGroup_analytic=$this->db->make_array("select ga_id,ga_id from groupe_analytique where pa_id=".$this->pa_id,1);
241  if ( count($aGroup_analytic) > 1 )
242  {
243  $wGa_id=new ISelect("ga_id");
244  $wGa_id->value=$aGroup_analytic;
245  $wGa_id->selected=$this->ga_id;
246  $wGa_id->table=1;
247  }
248  else
249  {
250  $wGa_id=new ISpan();
251  }
252  $pa=new Anc_Plan($this->db,$this->pa_id);
253  $pa->get();
254  $wPaName=new IText("",$pa->name);
255  $wPaName->table=1;
256  $wPaName->readOnly=true;
257 
258  $wName->table=1;
259  $wAmount->table=1;
260  $wDescription->table=1;
261  $r.=HtmlInput::hidden("pa_id",$this->pa_id);
262  $r.=HtmlInput::hidden("po_id",$this->id);
263 
264  $r.="<table>";
265 
266  $r.="<tr>";
267  $r.=td(_('Nom'));
268  $r.=$wName->input();
269  $r.="</tr>";
270 
271  $r.="<tr>";
272  $r.=td(_('Montant'));
273  $r.=$wAmount->input();
274  $r.="</tr>";
275 
276 
277  $r.="<tr>";
278  $r.=td(_('Description'));
279  $r.=$wDescription->input();
280  $r.="</tr>";
281 
282  $r.="<tr>";
283  $r.=td(_('Plan Analytique'));
284  $r.=$wPaName->input();
285  $r.="</tr>";
286 
287  $r.="<tr>";
288  $r.=td(_('Groupe'));
289  $r.=$wGa_id->input();
290  $r.="</tr>";
291 
292  $r.="</table>";
293  return $r;
294 
295  }
297  {
298  $this->name=(isset ($p_array['po_name']))?$p_array['po_name']:"";
299  $this->description=(isset ($p_array['po_description']))?$p_array['po_description']:"";
300  $this->pa_id=(isset ($p_array['pa_id']))?$p_array['pa_id']:"";
301  $this->amount=(isset ($p_array['po_amount']))?$p_array['po_amount']:0;
302  $this->id=(isset ($p_array['po_id']))?$p_array['po_id']:-1;
303  // $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] == "-1" )?null:2;
304  $this->ga_id=(isset($p_array['ga_id']) && $p_array['ga_id'] != "-1" )?$p_array['ga_id']:null;
305  }
306  static function test_me()
307  {
309  $pa_id=$cn->get_value("select max(pa_id) from plan_analytique");
310  $o=new Anc_Account($cn);
311  echo "<h1>Poste_Analytique</h1>";
312  echo "<h2>get_list</h2>";
313  $ee=$o->get_list();
314  print_r($ee);
315  //var_dump($ee);
316 
317  echo "<h2>Add some </h2>";
318  $o->pa_id=$pa_id;
319  $o->name="test1";
320  $o->add();
321 
322 
323  $o->name="test2";
324  $o->add();
325 
326  $o->name="test3";
327  $o->add();
328 
329  $o->name="test4";
330  $o->add();
331 
332  $o->name="test5";
333  $o->add();
334 
335  echo "<h2> remove test1</h2>";
336  $o->get_by_name("test1");
337  $o->delete();
338  $o->display_list();
339 
340  $o->get_by_name("test4");
341  echo "<hr>".$o->id."<hr>";
342  $o->name="Test Four";
343  $o->update();
344  $o->display_list();
345  $o->delete();
346  $o->display_list();
347  }
348 }
349 ?>
if(isset($_POST['confirm_mod'])) $object
Definition: poste.inc.php:41
static fetch_all($ret)
wrapper for the function pg_fetch_all
sql_string($p_string)
Fix the problem with the quote char for the database.
Definition: ac_common.php:457
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
static num_row($ret)
wrapper for the function pg_NumRows
get_by_name($p_name)
retrieve data thanks the name
Concerns the Analytic plan (table plan_analytique)
isNumber(&$p_int)
Definition: ac_common.php:202
get_from_array($p_array)
static fetch_array($ret, $p_indice=0)
wrapper for the function pg_fetch_array
contains the object for the poste_analytique (table poste_analytique)
function clone(object)
$from_poste name
get_list()
return an array of object Poste_Analytique
function trim(s)
remove trailing and heading space
Definition: scripts.js:95
__construct($p_db, $p_id=0)
$pa
Definition: anc_od.inc.php:39
fetch_from_db($p_where)
retrieve data from the database and fill the object
static connect()
static make_array_name($cn, $pa_id)
$SecUser db
$ex
Definition: balance.inc.php:48
static hidden($p_name, $p_value, $p_id="")
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: class_inum.php:40