noalyss Version-9
Public Member Functions | Static Public Member Functions | Private Attributes
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 More...
 
 fill_table ($p_target, $p_amount)
 Call the Anc_Operation::display_form_plan with the right amounts. More...
 
 get_key ()
 
 input ()
 Show the detail for a key distribution and let you change it for adding or update. More...
 
 save ($p_array)
 save the data of a repartition key. More...
 
 set_key ($key)
 
 verify ($p_array)
 verify that data are ok More...
 

Static Public Member Functions

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

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 60 of file anc_key.class.php.

61 {
62 global $cn;
63 $this->key=new Anc_Key_SQL($cn, $p_id);
64 $this->a_ledger=null;
65 $this->a_activity=null;
66 $this->a_row=null;
67 }
Manage the table key_distribution.

References $cn, and $p_id.

Member Function Documentation

◆ delete()

Anc_Key::delete ( )

delete the distribution key

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

391 {
392 $this->key->delete();
393 }

◆ 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 85 of file anc_key.class.php.

86 {
87 global $cn;
88 $a_key=$cn->get_array(' select kd_id,
89 kd_name,
90 kd_description
91 from
92 key_distribution
93 join key_distribution_ledger using (kd_id)
94 where
95 jrn_def_id=$1',
96 array(
97 $p_ledger
98 ));
99 if (empty($a_key))
100 {
101 echo _('Aucune clef disponible');
102 echo _('Allez dans ANCKEY pour en ajouter pour ce journal');
103 }
104 include NOALYSS_TEMPLATE.'/anc_key_display_choice.php';
105 }

References $cn.

◆ display_list()

static Anc_Key::display_list ( )
static

display a list of keys, choose one to modify it

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

112 {
113 global $cn;
114 $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description,
115 (select sum(ke_percent) from key_distribution_detail as a where a.kd_id=b.kd_id) as distrib
116 from key_distribution as b order by b.kd_name');
117 if (empty($a_key))
118 {
119 echo _('Aucune clef disponible');
120 }
121 include NOALYSS_TEMPLATE.'/anc_key_display_list.php';
122 }

References $cn.

◆ 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 311 of file anc_key.class.php.

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

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

+ Here is the call graph for this function:

◆ get_key()

Anc_Key::get_key ( )

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

69 {
70 return $this->key;
71 }

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 128 of file anc_key.class.php.

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

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 374 of file anc_key.class.php.

375 {
376 $key=new Anc_Key();
377 $key->key->setp('name',_('Nouvelle clef'));
378 $key->key->setp('description',_('Description de la nouvelle clef'));
379 ?>
380<input type="button" class="smallbutton" value="<?php echo _('Ajout')?>" onclick="$('key_add_div_id').show()">
381<div id="key_add_div_id" style="display: none">
382<?php
383 $key->input();
384 echo '</div>';
385
386 }
$opd_description style
$input_from type
Definition: balance.inc.php:65
Class to manage distribution keys for Analytic accountancy.
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.

the distribution key 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 50 of file anc_key.class.php.

51 {
52 global $cn;
53 $count=$cn->get_value (' select count(*)
54 from key_distribution_ledger
55 join key_distribution using (kd_id)
56 where
57 jrn_def_id=$1', array($p_jrn));
58 return $count;
59 }
$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 234 of file anc_key.class.php.

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

References $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 73 of file anc_key.class.php.

74 {
75 $this->key=$key;
76 return $this;
77 }

References $key.

◆ verify()

Anc_Key::verify (   $p_array)

verify that data are ok

Parameters
type$p_array

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

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

References $http, $i, and $p_array.

Referenced by save().

Field Documentation

◆ $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: