noalyss Version-10
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
Anc_Key Class Reference

Class to manage distribution keys for Analytic accountancy. More...

+ Collaboration diagram for Anc_Key:

Public Member Functions

 __construct ($p_id=-1)
 
 delete ()
 delete the distribution key
 
 fill_table ($p_target, $p_amount)
 Call the Anc_Operation\display_form_plan with the right amounts.
 
 get_key ()
 
 input ()
 Show the detail for a key distribution and let you change it for adding or update.
 
 save ($p_array)
 save the data of a repartition key.
 
 set_key ($key)
 
 verify ($p_array)
 verify that data are ok
 

Static Public Member Functions

static display_choice ($p_amount, $p_target, $p_ledger)
 display list of available keys
 
static display_list ()
 display a list of keys, choose one to modify it
 
static key_add ()
 show a form for adding a key + button to display it
 
static key_available ($p_jrn)
 Return the number of keys available.
 

Protected Attributes

 $a_activity
 
 $a_ledger
 
 $a_row
 

Private Attributes

 $key
 

Detailed Description

Class to manage distribution keys for Analytic accountancy.

Definition at line 38 of file anc_key.class.php.

Constructor & Destructor Documentation

◆ __construct()

Anc_Key::__construct ( $p_id = -1)

Definition at line 67 of file anc_key.class.php.

68 {
69 global $cn;
70 $this->key=new Anc_Key_SQL($cn, $p_id);
71 $this->a_ledger=null;
72 $this->a_activity=null;
73 $this->a_row=null;
74 }

References $cn, and $p_id.

Member Function Documentation

◆ delete()

Anc_Key::delete ( )

delete the distribution key

Definition at line 397 of file anc_key.class.php.

398 {
399 $this->key->delete();
400 }

◆ display_choice()

static Anc_Key::display_choice ( $p_amount,
$p_target,
$p_ledger )
static

display list of available keys

Parameters
$p_amountamount to distribute
$p_targettarget to update
$p_ledgeris the jrn_def_id

Definition at line 92 of file anc_key.class.php.

93 {
94 global $cn;
95 $a_key=$cn->get_array(' select kd_id,
96 kd_name,
97 kd_description
98 from
99 key_distribution
100 join key_distribution_ledger using (kd_id)
101 where
102 jrn_def_id=$1',
103 array(
104 $p_ledger
105 ));
106 if (empty($a_key))
107 {
108 echo _('Aucune clef disponible');
109 echo _('Allez dans ANCKEY pour en ajouter pour ce journal');
110 }
111 include NOALYSS_TEMPLATE.'/anc_key_display_choice.php';
112 }
_("actif, passif,charge,...")

References $cn, and _.

◆ display_list()

static Anc_Key::display_list ( )
static

display a list of keys, choose one to modify it

Definition at line 118 of file anc_key.class.php.

119 {
120 global $cn;
121 $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description,
122 (select sum(ke_percent) from key_distribution_detail as a where a.kd_id=b.kd_id) as distrib
123 from key_distribution as b order by b.kd_name');
124 if (empty($a_key))
125 {
126 echo _('Aucune clef disponible');
127 }
128 include NOALYSS_TEMPLATE.'/anc_key_display_list.php';
129 }

References $cn, and _.

◆ fill_table()

Anc_Key::fill_table ( $p_target,
$p_amount )

Call the Anc_Operation\display_form_plan with the right amounts.

This function compute the array and amount to pass to the Anc_Operation\display_form_plan and replace the current table of activity with the value computed from the key.

@global $cn database connection

Parameters
$p_targetTable to be replaced
$p_amountamount to distribute among activities

Definition at line 318 of file anc_key.class.php.

319 {
320 global $cn;
321 /* number is the index of the plan, he's computed from p_target */
322 $number=preg_replace('/det[0-9]*/', '', $p_target);
323 $number=noalyss_str_replace('t', '', $number);
324 $number=noalyss_str_replace('popup', '', $number);
325
326 $op[$number]=$p_amount;
327 $array['op']=$op;
328 $a_plan=$cn->get_array('select pa_id from plan_analytique order by pa_id');
329 for ($i=0;$i < count($a_plan);$i++)
330 {
331 $array['pa_id'][$i]=$a_plan[$i]['pa_id'];
332 }
333
334 $a_poste=$cn->get_array('select po_id,ke_percent,pa_id,ke_row
335 from key_distribution_activity
336 join key_distribution_detail using (ke_id)
337 where
338 kd_id=$1
339 order by ke_row,pa_id',
340 array($this->key->getp('id')));
341
342 for ($i=0;$i< count($a_poste);$i++)
343 {
344 $hplan[$number][$i]=($a_poste[$i]['po_id']==null)?-1:$a_poste[$i]['po_id'];
345 }
346 $array['hplan']=$hplan;
347
348 $a_amount=$cn->get_array("select distinct ke_row,ke_percent
349 from key_distribution_activity
350 join key_distribution_detail using (ke_id)
351 where
352 kd_id=$1
353 and pa_id=$2
354 order by ke_row",
355 array($this->key->getp('id'),$a_plan[0]['pa_id']));
356 bcscale(2);
357 for ($i=0;$i< count($a_amount);$i++)
358 {
359 $val[$number][$i]=bcmul($p_amount,$a_amount[$i]['ke_percent']);
360 $val[$number][$i]=bcdiv($val[$number][$i],100);
361 $val[$number][$i]=abs($val[$number][$i]);
362 }
363 $array['val']=$val;
364
365 $anc_operation=new Anc_Operation($cn);
366 // find the div thanks the target which looks like "det4t0"
367 // det4 is the div id and t0 is the row
368 if (strpos($p_target, "et")){
369 // cut off t[0-9]
370 $pos=strrpos($p_target,"t");
371 $anc_operation->in_div=substr($p_target,0,$pos);
372
373 }
374 echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount,'',false);
375
376 }
noalyss_str_replace($search, $replace, $string)
$op
for($i=0; $i< count($plan); $i++)( $j==0) $a_poste

References $a_plan, $a_poste, $array, $cn, $i, $op, $pos, and noalyss_str_replace().

+ Here is the call graph for this function:

◆ get_key()

Anc_Key::get_key ( )

Definition at line 75 of file anc_key.class.php.

76 {
77 return $this->key;
78 }

References $key.

◆ input()

Anc_Key::input ( )

Show the detail for a key distribution and let you change it for adding or update.

Definition at line 135 of file anc_key.class.php.

136 {
137 global $cn;
138
139 $plan=$cn->get_array('
140 select
141 pa_id,
142 pa_name ,
143 pa_description
144 from
145 plan_analytique
146 order by pa_name');
147 $count_max=count($plan);
148
149 $a_row=$cn->get_array('select ke_id,ke_row,ke_percent from key_distribution_detail
150 where
151 kd_id=$1 order by ke_row', array($this->key->getp('id')));
152
153 require_once NOALYSS_TEMPLATE.'/anc_key_input.php';
154 }

References $a_row, and $cn.

Referenced by key_add().

◆ key_add()

static Anc_Key::key_add ( )
static

show a form for adding a key + button to display it

Definition at line 381 of file anc_key.class.php.

382 {
383 $key=new Anc_Key();
384 $key->key->setp('name',_('Nouvelle clef'));
385 $key->key->setp('description',_('Description de la nouvelle clef'));
386 ?>
387<input type="button" class="smallbutton" value="<?php echo _('Ajout')?>" onclick="$('key_add_div_id').show()">
388<div id="key_add_div_id" style="display: none">
389<?php
390 $key->input();
391 echo '</div>';
392
393 }
$opd_description style
$input_from type
input()
Show the detail for a key distribution and let you change it for adding or update.

References $key, _, input(), style, type, and value.

+ Here is the call graph for this function:

◆ key_available()

static Anc_Key::key_available ( $p_jrn)
static

Return the number of keys available.

Return the number of keys available for the ledger given in parameter

@global $cn database connection

Parameters
$p_jrnnumber of the ledger (jrn_def.jrn_def_id
Returns
number of available keys

Definition at line 57 of file anc_key.class.php.

58 {
59 global $cn;
60 $count=$cn->get_value (' select count(*)
61 from key_distribution_ledger
62 join key_distribution using (kd_id)
63 where
64 jrn_def_id=$1', array($p_jrn));
65 return $count;
66 }
$count

References $cn, $count, and $p_jrn.

◆ save()

Anc_Key::save ( $p_array)

save the data of a repartition key.

Parameters
receivedan array index :
  • key_id : key_distribution.kd_id
  • row : array of key_distribution.ke_id (row
  • pa : array of plan_analytic.pa_id (column)
  • po_id : double array, first index is the row second index is the first plan, the second the second plan...(column)
  • percent array, one per row
  • jrn : array of available ledgers
Note
if po_id == -1 then it is replaced by null, this why the pa_id is needed : to identify the column
  'key_id' => string '1' (length=1)
  "name_key" => "name"
  "description_key" => "description"
  'row' => 
    array
      0 => string '1' (length=1)
      1 => string '2' (length=1)
      2 => string '3' (length=1)
  'pa' => 
    array
      0 => string '1' (length=1)
      1 => string '2' (length=1)
  'po_id' => 
    array
      0 => 
        array
          0 => string '1' (length=1)
          1 => string '8' (length=1)
      1 => 
        array
          0 => string '2' (length=1)
          1 => string '-1' (length=2)
      2 => 
        array
          0 => string '3' (length=1)
          1 => string '8' (length=1)
  'percent' => 
    array
      0 => string '50.0000' (length=7)
      1 => string '20.0000' (length=7)
      2 => string '30.0000' (length=7)
  'jrn' => 
    array
      0 => string '3' (length=1)
      1 => string '2' (length=1)

Definition at line 241 of file anc_key.class.php.

242 {
243 global $cn;
244 $this->verify($p_array);
245 $cn->start();
246 // for each row
247 $http=new HttpInput();
248 $http->set_array($p_array);
249
250 $a_row=$http->extract('row',"array");
251 $a_ledger=$http->extract("jrn","string",array());
252 $a_percent=$http->extract('percent',"array",[]);
253 $a_po_id=$http->extract('po_id',"array",[]);
254 $a_plan=$http->extract('pa',"array",[]);
255 try
256 {
257 $this->key->setp('name',$http->extract('name_key'));
258 $this->key->setp('description',$http->extract('description_key'));
259 $this->key->save();
260 for ($i=0; $i<count($a_row); $i++)
261 {
262 //save key_distribution_row
263 $key_row=new Anc_Key_Detail_SQL($cn);
264 $key_row->setp('id', $a_row[$i]);
265 $key_row->setp('key', $this->key->getp('id'));
266 $key_row->setp('row', $i+1);
267 $key_row->setp('percent', $a_percent[$i]);
268 $key_row->save();
269 //
270 // Save each activity + percent
271 $cn->exec_sql('delete from key_distribution_activity where ke_id=$1', array($key_row->getp('id')));
272
273 // Don't save row with 0 %
274 if ($a_percent[$i]==0)
275 {
276 $key_row->delete();
277 continue;
278 }
279 for ($j=0; $j<count($a_po_id[$i]); $j++)
280 {
281 $activity=new Anc_Key_Activity_SQL($cn);
282 $activity->setp('detail', $key_row->ke_id);
283 $value=($a_po_id[$i][$j]==-1)?null:$a_po_id[$i][$j];
284 $activity->setp('activity', $value);
285 $activity->setp('plan',$a_plan[$j]);
286 $activity->save();
287 }
288 }
289 // delete all from key_distribution_ledger
290 $cn->exec_sql('delete from key_distribution_ledger where kd_id=$1', array($this->key->getp('id')));
291 for ($k=0; $k<count($a_ledger); $k++)
292 {
293 $ledger=new Anc_Key_Ledger_SQL($cn);
294 $ledger->kd_id=$this->key->getp('id');
295 $ledger->jrn_def_id=$a_ledger[$k];
296 $ledger->save();
297 }
298
299 $cn->commit();
300 }
301 catch (Exception $e)
302 {
303
304 if ( DEBUGNOALYSS > 0 ) { echo $e->getTraceAsString(); } else { echo _('erreur').$e->getMessage();}
305 record_log($e);
306 $cn->rollback();
307 }
308 }
record_log($p_message)
Record an error message into the log file of the server or in the log folder of NOALYSS Record also t...
verify($p_array)
verify that data are ok

References $a_ledger, $a_plan, $a_row, $cn, $e, $http, $i, $ledger, $p_array, $value, _, record_log(), and verify().

+ Here is the call graph for this function:

◆ set_key()

Anc_Key::set_key ( $key)

Definition at line 80 of file anc_key.class.php.

81 {
82 $this->key=$key;
83 return $this;
84 }

References $key.

◆ verify()

Anc_Key::verify ( $p_array)

verify that data are ok

Parameters
type$p_array

Definition at line 160 of file anc_key.class.php.

161 {
162 $http=new HttpInput();
163 $http->set_array($p_array);
164
165 $a_percent=$http->extract('percent',"array");
166
167 if (count($a_percent)==0)
168 {
169 throw new Exception(_('Aucune répartition'));
170 }
171 $tot_percent=0;
172 bcscale(4);
173 for ($i=0; $i<count($a_percent); $i++)
174 {
175 $tot_percent=bcadd($tot_percent, $a_percent[$i]);
176 }
177 if ($tot_percent >100)
178 {
179 throw new Exception(_('Le total ne vaut pas 100, total calculé = ').$tot_percent);
180 }
181
182 if (trim($http->extract('name_key'))=='') {
183 throw new Exception (_('Le nom ne peut être vide'));
184 }
185 }

References $http, $i, $p_array, and _.

Referenced by save().

Field Documentation

◆ $a_activity

Anc_Key::$a_activity
protected

array of activity for which the key is available

Definition at line 44 of file anc_key.class.php.

◆ $a_ledger

Anc_Key::$a_ledger
protected

the distribution key array of ledger (JRN_DEF.JRN_DEF_ID) for which the key is available

Definition at line 42 of file anc_key.class.php.

Referenced by save().

◆ $a_row

Anc_Key::$a_row
protected

array of row from key_distribution_detail , detail of the key

Definition at line 46 of file anc_key.class.php.

Referenced by input(), and save().

◆ $key

Anc_Key::$key
private

Definition at line 41 of file anc_key.class.php.

Referenced by get_key(), key_add(), and set_key().


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