Plugins  LAST
 All Data Structures Files Functions Variables Pages
class_copro_budget.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Copyright 2010 De Bontridder Dany <dany@alchimerys.be>
4  * This file is part of NOALYSS.
5  *
6  * NOALYSS is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * NOALYSS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with NOALYSS; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20 ?>
21 <?php
22 
23 
25 {
26  function to_list()
27  {
28  global $cn;
29 
30  $array=$cn->get_array("select b_id, b_name,
31  b_exercice,
32  b_type,
33  case when b_type = 'OPER' then 'Opérationnel'
34  when b_type = 'PREV' then 'Prévisionnel' else 'inconnu' end as str_type,
35  b_amount
36  from coprop.budget
37  order by b_name
38  ");
39 
40  require_once 'template/budget_list.php';
41 
42  }
43  function load()
44  {
45  global $cn;
46  try
47  {
48  if ($this->b_id == '') throw new Exception("Aucun budget demandé");
49  $array=$cn->get_array("select b_id,b_name,b_amount,
50  b_type,b_exercice
51  from coprop.budget where b_id=$1",array($this->b_id));
52  if ($cn->count() == 1)
53  {
54  $this->b_name=$array[0]['b_name'];
55  $this->b_exercice=$array[0]['b_exercice'];
56  $this->b_type=$array[0]['b_type'];
57  $this->b_amount=$array[0]['b_amount'];
58  }
59  else
60  throw new Exception ('Aucun budget trouvé');
61  } catch (Exception $e)
62  {
63  echo $e->getTraceAsString();
64  throw $e;
65  }
66  }
67  /**
68  *Detail d'un budget avec les détails, pour mettre à jour
69  * @global type $cn
70  * @throws Exception
71  */
72  function detail()
73  {
74  global $cn,$g_copro_parameter;
75  try
76  {
77 
78  if ( ! isset ($this->b_id)|| trim($this->b_id)=='')
79  throw new Exception ("Aucun budget demandé");
80  $name=new IText('b_name');
81  $name->size=50;
82  if ($this->b_id <> 0)
83  {
84  $this->load();
85  $name->value=$this->b_name;
86  $exercice=new ISelect('b_exercice');
87  $exercice->value=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode
88  order by 1");
89  $exercice->selected=$this->b_exercice;
90 
91  $type=new ISelect('b_type');
92  $type->value=array(
93  array("value"=>"OPER","label"=>"Opérationnel"),
94  array("value"=>"PREV","label"=>"Prévisionnel")
95  );
96  $type->selected=$this->b_type;
97 
98  $amount=new INum('b_amount',round($this->b_amount,2));
99 
100  } else {
101  $exercice=new ISelect('b_exercice');
102  $exercice->value=$cn->make_array("select distinct p_exercice,p_exercice from parm_periode
103  order by 1");
104 
105  $type=new ISelect('b_type');
106  $type->value=array(
107  array("value"=>"OPER","label"=>"Opérationnel"),
108  array("value"=>"PREV","label"=>"Prévisionnel")
109  );
110  $amount=new INum('b_amount',0);
111 
112  }
113  $amount->javascript='onchange="format_number(this,2);compute_budget();"';
114  $bud_amount=$amount->value;
115 
116  echo HtmlInput::hidden("b_id",$this->b_id);
117  echo HtmlInput::request_to_hidden(array('gDossier','ac','plugin_code','sa'));
118  require_once 'template/budget.php';
119 
120  $array=$cn->get_array("select bt_label,
121  bt_id,bt_amount,f_id,vw_name,quick_code,cr_name,cr_id
122  from coprop.budget_detail
123  join coprop.clef_repartition using (cr_id)
124  join vw_fiche_attr using (f_id)
125  where b_id=$1",array($this->b_id));
126  $a_input=array();
127  $fiche_dep=$cn->make_list("select fd_id from fiche_def where fd_id=".$g_copro_parameter->categorie_charge);
128 
129  $a_key=$cn->make_array(" select cr_id,cr_name from coprop.clef_repartition order by cr_name");
130  $max=count($array);
131 
132  // Ajout bouton ajout charge
133  $f_add_button=new IButton('add_card');
134  $f_add_button->label=_('Créer une nouvelle fiche');
135  $f_add_button->set_attribute('ipopup','ipop_newcard');
136  $f_add_button->set_attribute('jrn',-1);
137  $filter=$cn->make_list("select fd_id from fiche_def where fd_id=".$g_copro_parameter->categorie_charge);
138  $f_add_button->javascript=" this.filter='$filter';this.jrn=-1;select_card_type(this);";
139  echo $f_add_button->input();
140  for ($i=0;$i<MAXROWBUD;$i++)
141  {
142  $label=new IText('bt_label[]');
143  $label->value=($i>=$max)?"":$array[$i]['bt_label'];
144 
145  $card=new ICard('f_id'.$i);
146  $card->value=($i>=$max)?"":$array[$i]['quick_code'];
147  $card->table=0;
148 
149  // name of the field to update with the name of the card
150  $card->set_attribute('label','w_card_label'.$i);
151 
152  // Type of card : deb, cred,
153  $card->set_attribute('typecard',$fiche_dep);
154 
155  $card->extra=$fiche_dep;
156 
157  // Add the callback function to filter the card on the jrn
158  $card->set_callback('filter_card');
159  $card->set_attribute('ipopup','ipopcard');
160  // when value selected in the autcomplete
161  $card->set_function('fill_data');
162 
163  // when the data change
164 
165  $card->javascript=sprintf(' onchange="fill_data_onchange(\'%s\');" ',
166  $card->name);
167  $card->set_dblclick("fill_ipopcard(this);");
168 
169  $card_label=new ISpan();
170  $card_label->table=0;
171  $f_card_label=$card_label->input("w_card_label".$i,"");
172 
173  // Search button for card
174  $f_card_bt=$card->search();
175 
176  $amount=new INum("bt_amount[]");
177  $amount->value=($i>=$max)?"":round($array[$i]['bt_amount'],2);
178  $amount->javascript='onchange="format_number(this,2);compute_budget();"';
179  $hidden=($i>=$max)?HtmlInput::hidden("bt_id[]",0):HtmlInput::hidden("bt_id[]",$array[$i]["bt_id"]);
180  echo $hidden;
181 
182  $ikey=new ISelect("key[]");
183  $ikey->value=$a_key;
184  $ikey->selected=($i>=$max)?0:$array[$i]['cr_id'];
185 
186  $a_input[$i]["amount"]=$amount->input();
187  $a_input[$i]["hidden"]=$hidden;
188  $a_input[$i]["card"]=$card->input().$f_card_bt;
189  $a_input[$i]["card_label"]=$label->input();
190 
191  $a_input[$i]['key']=$ikey->input();
192 
193  }
194  require_once 'template/bud_detail.php';
195  echo create_script("compute_budget()");
196  }
197  catch (Exception $e)
198  {
199  $e->getTraceAsString();
200  throw $e;
201  }
202  }
203  /**
204  *@brief insert or update a new budget
205  * @param $p_array
206  * - b_id
207  * - b_name
208  * - b_start
209  * - b_end
210  * - b_amount
211  * - f_idX -> qcode
212  * - key[X]
213  * - bt_amount[X]
214  * - p_jrn
215  * - bt_id[X]
216  */
217  function save($p_array)
218  {
219  try{
220  $this->b_id=$p_array['b_id'];
221  if ( $p_array['b_id'] == 0 )
222  {
223  $this->insert($p_array);
224  $this->save_detail($p_array);
225  } else {
226  $this->update($p_array);
227  $this->save_detail($p_array);
228  }
229  }
230  catch( Exception $e){
231  throw $e;
232  }
233  }
234  /**
235  *@brief update budget
236  */
237  function update($p_array)
238  {
239  global $cn;
240  try {
241  extract ($p_array);
242  // update coprop.budget
243  $cn->exec_sql("update coprop.budget set b_name=$1,
244  b_exercice=$2,
245  b_type=$3,
246  b_amount=$4
247  where b_id=$5
248  ",array(
249  strip_tags($b_name),
250  $b_exercice,
251  $b_type,
252  $b_amount,
253  $b_id
254  ));
255 
256 
257  }
258  catch (Exception $exc) {
259  echo $exc->getTraceAsString();
260  throw $exc;
261  }
262 
263  }
264  /**
265  *@brief insert budget
266  */
267  function insert($p_array)
268  {
269  global $cn;
270  try {
271  extract ($p_array);
272  // update coprop.budget
273  $this->b_id=$cn->get_value("insert into coprop.budget (b_name,b_exercice,b_type,b_amount)
274  values ($1,
275  $2,
276  $3,
277  $4) returning b_id
278  ",array(
279  strip_tags($b_name),
280  $b_exercice,
281  $b_type,
282  $b_amount
283  ));
284 
285 
286  }
287  catch (Exception $exc) {
288  echo $exc->getTraceAsString();
289  throw $exc;
290  }
291 
292  }
293  function save_detail($p_array)
294  {
295  extract($p_array);
296  global $cn;
297  try
298  {
299  $max=count($bt_id);
300  for ($i=0;$i<MAXROWBUD;$i++)
301  {
302 
303  if ( $bt_id[$i]== 0)
304  {
305  if ( strlen(trim(${'f_id'.$i})) != 0)
306  {
307  $f_id=$cn->get_value("select f_id from vw_fiche_attr where quick_code=upper(trim($1))",
308  array(${'f_id'.$i}));
309 
310  // insert into coprop.budget_detail
311  $cn->exec_sql("insert into coprop.budget_detail (bt_label,f_id,b_id,bt_amount,cr_id) ".
312  " values ($1,$2,$3,$4,$5)",
313  array(
314  strip_tags($bt_label[$i]),
315  $f_id,
316  $this->b_id,
317  $bt_amount[$i],
318  $key[$i]
319  )
320 
321  );
322  }
323  }
324  else
325  {
326  // update into coprop.budget_detail
327  if ( strlen(trim(${'f_id'.$i})) != 0)
328  {
329  $f_id=$cn->get_value("select f_id from vw_fiche_attr where quick_code=upper(trim($1))",
330  array(${'f_id'.$i}));
331 
332  $cn->exec_sql("update coprop.budget_detail set bt_label=$1,f_id=$2,bt_amount=$3,cr_id=$4 ".
333  " where bt_id=$5",
334  array(
335  strip_tags($bt_label[$i]),
336  $f_id,
337  $bt_amount[$i],
338  $key[$i],
339  $bt_id[$i]
340  )
341 
342  );
343 
344  } else {
345  $cn->exec_sql("delete from coprop.budget_detail where bt_id=$1",array($bt_id[$i]));
346  }
347 
348  }
349  }
350 
351 
352  }
353  catch (Exception $exc)
354  {
355  echo $exc->getTraceAsString();
356  throw $exc;
357  }
358 
359  }
360  function get_detail()
361  {
362  global $cn;
363  $array=$cn->get_array("select * from coprop.budget_detail where b_id=$1",
364  array($this->b_id));
365  return $array;
366  }
367 }
368 ?>
if(isset($_POST['save'])) $exercice
$type
Retrouve le type de row si == 3.
global $g_copro_parameter
$a_key
Definition: key.inc.php:59
detail()
Detail d'un budget avec les détails, pour mettre à jour type $cn.
$f_add_button
if(isset($_POST['remove'])) $array
$bud b_id
save($p_array)
insert or update a new budget
$key
update($p_array)
update budget
insert($p_array)
insert budget
const MAXROWBUD
global $cn
$name