Plugins  LAST
 All Data Structures Files Functions Variables Pages
Public Member Functions | Private Member Functions
Am_Generate Class Reference
Collaboration diagram for Am_Generate:
Collaboration graph

Public Member Functions

 input ($p_array)
 Show the form to generate the writing select ledger year date of operation list of material. More...
 
 propose_writing ($p_array)
 Propose to save the writing in the selected ledger. More...
 
 save ($p_array, $p_group)
 save into amortissement_histo More...
 

Private Member Functions

 save_separated ($p_array)
 save the amortized material into only one writing More...
 
 save_grouped ($p_array)
 save the amortized material into several writings More...
 

Detailed Description

Definition at line 30 of file class_am_generate.php.

Member Function Documentation

Am_Generate::input (   $p_array)

Show the form to generate the writing select ledger year date of operation list of material.

Definition at line 40 of file class_am_generate.php.

References $cn, $def, $ledger, $p_date, $periode, and $year.

41  {
42  global $cn, $g_user;
43  /*
44  * select ledger
45  */
46 
47  $ledger=new Acc_Ledger($cn, 0);
48  $sel_ledger=$ledger->select_ledger('ODS', 2);
49  $sel_ledger->selected=(isset($p_array['p_jrn']))?$p_array['p_jrn']:'';
50  /*
51  * Operation Date
52  */
53  $p_date=new IDate('p_date');
54  $p_date->value=(isset($p_array['p_date']))?$p_array['p_date']:date('d.m.Y');
55 
56  /*
57  * select year
58  */
59  $year=new INum('p_year');
60  $year->size=4;
61  $year->value=(isset($p_array['p_year']))?$p_array['p_year']:date('Y');
62 
63  /*
64  * PJ
65  */
66  $pj=new IText('p_pj');
67  $pj->size=10;
68  /*
69  * If we use the periode
70  */
71  if ($ledger->check_periode()==true)
72  {
73  $l_user_per=$g_user->get_periode();
74  $def=(isset($periode))?$periode:$l_user_per;
75  $period=new IPeriod("period");
76  $period->user=$g_user;
77  $period->cn=$cn;
78  $period->value=$def;
79  $period->type=OPEN;
80  try
81  {
82  $l_form_per=$period->input();
83  }
84  catch (Exception $e)
85  {
86  if ($e->getCode()==1)
87  {
88  echo _("Aucune période ouverte");
89  exit();
90  }
91  }
92  $label=HtmlInput::infobulle(3);
93  $f_periode=_("Période comptable")." $label ";
94  }
95  /*
96  * show all the visible material
97  */
98  require_once('template/util_generate.php');
99  }
$periode
global $cn
$def
Definition: am_print.php:40
Am_Generate::propose_writing (   $p_array)

Propose to save the writing in the selected ledger.

array
'plugin_code' => string 'AMORT' (length=5)
'sa' => string 'util' (length=4)
'gDossier' => string '48' (length=2)
'p_year' => string '' (length=0)
'p_jrn' => string '4' (length=1)
'p_date' => string '' (length=0)
'a_id' =>
array
0 => string '86' (length=2)
1 => string '85' (length=2)
'p_ck1' => string '' (length=0)

Definition at line 119 of file class_am_generate.php.

References $array, $cn, $fiche, $key, $ledger, $list, $mat, and $msg.

120  {
121  global $cn;
122  $msg='';
123  if (isNumber($p_array['p_year'])==0||$p_array['p_year']<1900||$p_array['p_year']>2100)
124  $msg="Année invalide\n";
125  if (isDate($p_array['p_date'])==null)
126  $msg.="Date invalide ";
127  if ($msg!='')
128  {
129  echo alert($msg);
130  return false;
131  }
132 
133  $array=array(
134  'p_jrn'=>$p_array['p_jrn'],
135  'e_date'=>$p_array['p_date'],
136  'periode'=>0,
137  'desc'=>'Amortissement '.$p_array['p_year'],
138  'e_pj'=>$p_array['p_pj'],
139  'e_pj_suggest'=>$p_array['p_pj'],
140  );
141  if (isset($p_array['period']))
142  {
143  $array['period']=$p_array['period'];
144  }
145  $idx=0;
146  $a_material=array();
147  for ($i=0; $i<count($p_array['a_id']); $i++)
148  {
149  if (isset($p_array['p_ck'.$i]))
150  {
151 
152  /*
153  * If selected the add it to array
154  */
155  $n=new Amortissement_Sql($cn, $p_array['a_id'][$i]);
156  $fiche=new Fiche($cn, $n->f_id);
157  $val=$cn->get_value("select ad_amount from amortissement.amortissement_detail ".
158  " where a_id = $1 and ad_year=$2", array($n->a_id, $p_array['p_year']));
159  $val=($val=='')?0:$val;
160  // retrieve quick code card deb
161  $card_deb="";
162  if ($n->card_deb!="")
163  {
164  $fiche_card_deb=new Fiche($cn, $n->card_deb);
165  $card_deb=$fiche_card_deb->get_quick_code();
166  }
167 
168  $card_cred="";
169  if ($n->card_cred!="")
170  {
171  // retrieve quick code card cred
172  $fiche_card_cred=new Fiche($cn, $n->card_cred);
173  $card_cred=$fiche_card_cred->get_quick_code();
174  }
175  $mat=array('poste'.$idx=>$n->account_deb,
176  'amount'.$idx=>$val,
177  'ld'.$idx=>'Dotation à '.$fiche->strAttribut(ATTR_DEF_QUICKCODE),
178  'ck'.$idx=>1,
179  'qc_'.$idx=>$card_deb);
180  $a_material+=array('request_a'.$i=>$idx);
181  $array+=$mat;
182  $idx++;
183  $mat=array('poste'.$idx=>$n->account_cred,
184  'amount'.$idx=>$val,
185  'ld'.$idx=>'Amortissement '.$fiche->strAttribut(ATTR_DEF_QUICKCODE),
186  'qc_'.$idx=>$card_cred);
187  $array+=$mat;
188  $idx++;
189  }
190  }
191  $array+=array('nb_item'=>$idx);
192  $ledger=new Acc_Ledger($cn, $p_array['p_jrn']);
193  $ledger->with_concerned=false;
194  $list=new ISelect('grouped');
195  $list->value=array(
196  array('label'=>_('En une opération'), 'value'=>1),
197  array('label'=>_('En plusieurs opérations'), 'value'=>0),
198  array('label'=>_('-- choix --'), 'value'=>-1)
199  );
200  $list->selected=-1;
201  echo '<div style="width:80%;margin-left:10%">';
202  echo '<form method="POST" style="display:inline">';
203  try
204  {
205  echo $ledger->input($array, true);
206  foreach ($a_material as $key=> $value)
207  echo HtmlInput::hidden($key, $value);
208  }
209  catch (Exception $e)
210  {
211  echo alert($e->getMessage());
212  return false;
213  }
214  echo $list->input();
215  echo HtmlInput::submit('save',_('Sauver'));
216  echo HtmlInput::hidden('sa', $p_array['sa']);
217  echo HtmlInput::hidden('sb', $p_array['sb']);
218  echo HtmlInput::hidden('p_year', $p_array['p_year']);
219  echo HtmlInput::hidden('p_date', $p_array['p_date']);
220  echo HtmlInput::hidden('p_jrn', $p_array['p_jrn']);
221  echo HtmlInput::hidden('plugin_code', $p_array['plugin_code']);
222  for ($i=0; $i<count($p_array['a_id']); $i++)
223  {
224  echo HtmlInput::hidden('a_id[]', $p_array['a_id'][$i]);
225  if (isset($p_array['p_ck'.$i]))
226  echo HtmlInput::hidden('p_ck'.$i, '1');
227  }
228 
229 
230  echo '</form>';
231  /*
232  * correct
233  */
234  echo '<form method="POST" style="display:inline">';
235  echo dossier::hidden();
236  echo HtmlInput::hidden('sa', $p_array['sa']);
237  echo HtmlInput::hidden('sb', $p_array['sb']);
238  echo HtmlInput::hidden('p_year', $p_array['p_year']);
239  echo HtmlInput::hidden('p_date', $p_array['p_date']);
240  echo HtmlInput::hidden('p_jrn', $p_array['p_jrn']);
241  echo HtmlInput::hidden('plugin_code', $p_array['plugin_code']);
242  for ($i=0; $i<count($p_array['a_id']); $i++)
243  {
244  echo HtmlInput::hidden('a_id[]', $p_array['a_id'][$i]);
245  if (isset($p_array['p_ck'.$i]))
246  echo HtmlInput::hidden('p_ck'.$i, '1');
247  }
248  echo HtmlInput::submit('correct', 'Corriger');
249  echo '</form>';
250  echo '</div>';
251  return true;
252  }
$msg
if(isset($_POST['remove'])) $array
$key
Manage the table amortissement.amortissement.
global $cn
Am_Generate::save (   $p_array,
  $p_group 
)

save into amortissement_histo

Parameters
$p_arraycontains the data to insert
$p_groupboolean Save in one operation if TRUE otherwise in several ones
array
'plugin_code' => string 'AMORT' (length=5)
'sa' => string 'util' (length=4)
'gDossier' => string '48' (length=2)
'p_year' => string '' (length=0)
'p_jrn' => string '4' (length=1)
'p_date' => string '' (length=0)
'a_id' =>
array
0 => string '86' (length=2)
1 => string '85' (length=2)
'p_ck1' => string '' (length=0)

Definition at line 275 of file class_am_generate.php.

References save_grouped(), and save_separated().

276  {
277  if ($p_group == true)
278  {
279  return $this->save_grouped($p_array);
280  }
281  else if ($p_group == false)
282  {
283  return $this->save_separated($p_array);
284  }
285  }
save_grouped($p_array)
save the amortized material into several writings
save_separated($p_array)
save the amortized material into only one writing
Am_Generate::save_grouped (   $p_array)
private

save the amortized material into several writings

Parameters
$p_arraycontains the data
See Also
save

Save into the ledger

Definition at line 377 of file class_am_generate.php.

References $cn, $ledger, $msg, and $oPeriode.

Referenced by save().

378  {
379  global $cn;
380  $ledger=new Acc_Ledger($cn, $p_array['p_jrn']);
381  $this->saved_operation=array();
382  /**
383  * Save into the ledger
384  */
385  $p_post=array();
386  $p_post['p_jrn']=$p_array['p_jrn'];
387  $p_post['jrn_type']=$p_array['jrn_type'];
388  $p_post['e_date']=$p_array['e_date'];
389  $p_post['e_pj']=$p_array['e_pj'];
390  $p_post['e_pj_suggest']=$p_array['e_pj_suggest'];
391  $p_post['desc']='Amortissement ';
392  $this->saved_operation['desc'][0]=$p_post['desc'];
393  $p_post['mt']=microtime(false);
394  $oPeriode = new Periode($cn);
395  $p_post['period']=$oPeriode->find_periode($p_array['e_date']);
396  $msg='';
397  for ($i=0; $i<count($p_array['a_id']); $i++)
398  {
399  if (isset($p_array['p_ck'.$i]))
400  {
401  /* * *
402  * corresponding
403  * if 'p_ck5' => '1',
404  * then
405  * if a_request5 = 4 operation 4 = deb 5 = cred
406  */
407  $idx=$p_array['request_a'.$i];
408  $cred=$idx+1;
409 
410 
411  $p_post['nb_item']=$cred*2;
412 
413  // Debit
414  if (isset($p_array['ck'.$idx]))
415  $p_post['ck'.$idx]=1;
416  if (isset($p_array['poste'.$idx]))
417  $p_post['poste'.$idx]=$p_array['poste'.$idx];
418  if (isset($p_array['qc_'.$idx]))
419  $p_post['qc_'.$idx]=$p_array['qc_'.$idx];
420  if (isset($p_array['ld'.$idx]))
421  $p_post['ld'.$idx]=$p_array['ld'.$idx];
422  $p_post['amount'.$idx]=$p_array['amount'.$idx];
423  // crédit
424  if (isset($p_array['poste'.$cred]))
425  $p_post['poste'.$cred]=$p_array['poste'.$cred];
426  if (isset($p_array['qc_'.$cred]))
427  $p_post['qc_'.$cred]=$p_array['qc_'.$cred];
428  if (isset($p_array['ld'.$cred]))
429  $p_post['ld'.$cred]=$p_array['ld'.$cred];
430  $p_post['amount'.$cred]=$p_array['amount'.$cred];
431  }
432  }
433  $ledger->save($p_post);
434  $this->saved_operation["internal"][0]=$ledger->internal;
435  $this->saved_operation["jr_id"][0]=$ledger->jr_id;
436  for ($i=0; $i<count($p_array['a_id']); $i++)
437  {
438  if (isset($p_array['p_ck'.$i]))
439  {
440  /*
441  * Do not exist we insert into amortissement.amortissement_histo
442  */
443  $n=new Amortissement_Histo_Sql($cn);
444  $val=$cn->get_value("select ad_amount from amortissement.amortissement_detail ".
445  " where a_id = $1 and ad_year=$2", array($p_array['a_id'][$i], $p_array['p_year']));
446  $val=($val=='')?0:$val;
447  $h=$cn->get_value('select ha_id from amortissement.amortissement_histo where a_id=$1 and h_year=$2', array($p_array['a_id'][$i], $p_array['p_year']));
448  if ($cn->count()==0)
449  continue;
450  $n->ha_id=$h;
451  $n->load();
452  $n->h_amount=$val;
453  $n->h_year=$p_array['p_year'];
454  $n->jr_internal=$ledger->internal;
455  $n->update();
456  }
457  }
458  return $msg;
459  }
$msg
if($cn->count()==0) $oPeriode
Manage the table amortissement.amortissement_histo.
global $cn
Am_Generate::save_separated (   $p_array)
private

save the amortized material into only one writing

Parameters
$p_arraycontains the data
See Also
save

Save into the ledger

Definition at line 293 of file class_am_generate.php.

References $cn, $ledger, $msg, and $oPeriode.

Referenced by save().

294  {
295  global $cn;
296  $ledger=new Acc_Ledger($cn, $p_array['p_jrn']);
297  $this->saved_operation=array();
298  $msg='';
299  $oPeriode = new Periode($cn);
300  $period=$oPeriode->find_periode($p_array['e_date']);
301  for ($i=0; $i<count($p_array['a_id']); $i++)
302  {
303  if (isset($p_array['p_ck'.$i]))
304  {
305  /* * *
306  * corresponding
307  * if 'p_ck5' => '1',
308  * then
309  * if a_request5 = 4 operation 4 = deb 5 = cred
310  */
311  $idx=$p_array['request_a'.$i];
312  $cred=$idx+1;
313 
314  /**
315  * Save into the ledger
316  */
317  $p_post=array();
318  $p_post['p_jrn']=$p_array['p_jrn'];
319  $p_post['jrn_type']=$p_array['jrn_type'];
320  $p_post['e_date']=$p_array['e_date'];
321  $p_post['e_pj']=$p_array['e_pj'];
322  $p_post['e_pj_suggest']=$p_array['e_pj_suggest'];
323  $msg_operation=$cn->get_value('select vw_name from vw_fiche_attr join amortissement.amortissement using (f_id) where a_id=$1', array($p_array['a_id'][$i]));
324  $p_post['desc']=$p_array['e_comm']."-".$msg_operation;
325  $p_post['period']=$period;
326  $this->saved_operation['desc'][]=$p_post['desc'];
327  $p_post['mt']=microtime(false);
328  $p_post['nb_item']=$cred*2;
329 
330  // Debit
331  if (isset($p_array['ck'.$idx]))
332  $p_post['ck'.$idx]=1;
333  if (isset($p_array['poste'.$idx]))
334  $p_post['poste'.$idx]=$p_array['poste'.$idx];
335  if (isset($p_array['qc_'.$idx]))
336  $p_post['qc_'.$idx]=$p_array['qc_'.$idx];
337  if (isset($p_array['ld'.$idx]))
338  $p_post['ld'.$idx]=$p_array['ld'.$idx];
339  $p_post['amount'.$idx]=$p_array['amount'.$idx];
340  // crédit
341  if (isset($p_array['poste'.$cred]))
342  $p_post['poste'.$cred]=$p_array['poste'.$cred];
343  if (isset($p_array['qc_'.$cred]))
344  $p_post['qc_'.$cred]=$p_array['qc_'.$cred];
345  if (isset($p_array['ld'.$cred]))
346  $p_post['ld'.$cred]=$p_array['ld'.$cred];
347  $p_post['amount'.$cred]=$p_array['amount'.$cred];
348  $ledger->save($p_post);
349  $this->saved_operation["internal"][]=$ledger->internal;
350  $this->saved_operation["jr_id"][]=$ledger->jr_id;
351  /*
352  * Do not exist we insert into amortissement.amortissement_histo
353  */
354  $n=new Amortissement_Histo_Sql($cn);
355  $val=$cn->get_value("select ad_amount from amortissement.amortissement_detail ".
356  " where a_id = $1 and ad_year=$2", array($p_array['a_id'][$i], $p_array['p_year']));
357  $val=($val=='')?0:$val;
358  $h=$cn->get_value('select ha_id from amortissement.amortissement_histo where a_id=$1 and h_year=$2', array($p_array['a_id'][$i], $p_array['p_year']));
359  if ($cn->count()==0)
360  continue;
361  $n->ha_id=$h;
362  $n->load();
363  $n->h_amount=$val;
364  $n->h_year=$p_array['p_year'];
365  $n->jr_internal=$ledger->internal;
366  $n->update();
367  }
368  }
369  return $msg;
370  }
$msg
if($cn->count()==0) $oPeriode
Manage the table amortissement.amortissement_histo.
global $cn

The documentation for this class was generated from the following file: