noalyss
Version-6.7.2
|
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. | |
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. | |
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_avaiable ($p_jrn) |
Return the number of keys available. | |
Private Attributes | |
$key |
Definition at line 30 of file class_anc_key.php.
Anc_Key::__construct | ( | $ | p_id = -1 | ) |
Definition at line 52 of file class_anc_key.php.
References $cn.
{ global $cn; $this->key=new Anc_Key_SQL($cn, $p_id); $this->a_ledger=null; $this->a_activity=null; $this->a_row=null; }
Anc_Key::delete | ( | ) |
delete the distribution key
Definition at line 350 of file class_anc_key.php.
{ $this->key->delete(); }
static Anc_Key::display_choice | ( | $ | p_amount, |
$ | p_target, | ||
$ | p_ledger | ||
) | [static] |
display list of available keys
$p_amount | amount to distribute |
$p_target | target to update |
$p_ledger | is the jrn_def_id |
Definition at line 67 of file class_anc_key.php.
{ global $cn; $a_key=$cn->get_array(' select kd_id, kd_name, kd_description from key_distribution join key_distribution_ledger using (kd_id) where jrn_def_id=$1', array( $p_ledger )); if (empty($a_key)) { echo _('Aucune clef disponible'); echo _('Allez dans ANCKEY pour en ajouter pour ce journal'); } include 'template/anc_key_display_choice.php'; }
static Anc_Key::display_list | ( | ) | [static] |
display a list of keys, choose one to modify it
Definition at line 93 of file class_anc_key.php.
{ global $cn; $a_key=$cn->get_array('select b.kd_id,b.kd_name,b.kd_description, (select sum(ke_percent) from key_distribution_detail as a where a.kd_id=b.kd_id) as distrib from key_distribution as b order by b.kd_name'); if (empty($a_key)) { echo _('Aucune clef disponible'); } include 'template/anc_key_display_list.php'; }
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.
$cn database connection
$p_target | Table to be replaced |
$p_amount | amount to distribute among activities |
Definition at line 281 of file class_anc_key.php.
References $a_poste, $array, $cn, $op, $val, and echo.
{ global $cn; /* number is the index of the plan, he's computed from p_target */ $number=preg_replace('/det[0-9]/', '', $p_target); $number=str_replace('t', '', $number); $number=str_replace('popup', '', $number); $op[$number]=$p_amount; $array['op']=$op; $a_plan=$cn->get_array('select pa_id from plan_analytique order by pa_id'); for ($i=0;$i < count($a_plan);$i++) { $array['pa_id'][$i]=$a_plan[$i]['pa_id']; } $a_poste=$cn->get_array('select po_id,ke_percent,pa_id,ke_row from key_distribution_activity join key_distribution_detail using (ke_id) where kd_id=$1 order by ke_row,pa_id', array($this->key->getp('id'))); for ($i=0;$i< count($a_poste);$i++) { $hplan[$number][$i]=($a_poste[$i]['po_id']==null)?-1:$a_poste[$i]['po_id']; } $array['hplan']=$hplan; $a_amount=$cn->get_array("select distinct ke_row,ke_percent from key_distribution_activity join key_distribution_detail using (ke_id) where kd_id=$1 and pa_id=$2 order by ke_row", array($this->key->getp('id'),$a_plan[0]['pa_id'])); bcscale(2); for ($i=0;$i< count($a_amount);$i++) { $val[$number][$i]=bcmul($p_amount,$a_amount[$i]['ke_percent'])/100; } $array['val']=$val; $anc_operation=new Anc_Operation($cn); echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount,'',false); }
Anc_Key::input | ( | ) |
Show the detail for a key distribution and let you change it for adding or update.
Definition at line 110 of file class_anc_key.php.
References $cn.
Referenced by key_add().
{ global $cn; $plan=$cn->get_array(' select pa_id, pa_name , pa_description from plan_analytique order by pa_name'); $count_max=count($plan); $a_row=$cn->get_array('select ke_id,ke_row,ke_percent from key_distribution_detail where kd_id=$1 order by ke_row', array($this->key->getp('id'))); require_once 'template/anc_key_input.php'; }
static Anc_Key::key_add | ( | ) | [static] |
show a form for adding a key + button to display it
Definition at line 334 of file class_anc_key.php.
References $key, echo, input(), onclick, style, type, and value.
{ $key=new Anc_Key(); $key->key->setp('name',_('Nouvelle clef')); $key->key->setp('description',_('Description de la nouvelle clef')); ?> <input type="button" class="smallbutton" value="<?php echo _('Ajout')?>" onclick="$('key_add_div_id').show()"> <div id="key_add_div_id" style="display: none"> <?php $key->input(); echo '</div>'; }
static Anc_Key::key_avaiable | ( | $ | p_jrn | ) | [static] |
Return the number of keys available.
Return the number of keys available for the ledger given in parameter
$cn database connection
$p_jrn | number of the ledger (jrn_def.jrn_def_id |
Definition at line 42 of file class_anc_key.php.
Anc_Key::save | ( | $ | p_array | ) |
save the data of a repartition key.
received | an array index :
|
'key_id' => string '1' (length=1) '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 209 of file class_anc_key.php.
References $cn, $e, $ledger, $p_array, $value, HtmlInput\default_value(), echo, and verify().
{ global $cn; $this->verify($p_array); $cn->start(); // for each row $a_row=$p_array['row']; $a_ledger=HtmlInput::default_value("jrn",array(),$p_array); $a_percent=$p_array['percent']; $a_po_id=$p_array['po_id']; $a_plan=$p_array['pa']; try { $this->key->setp('name',$p_array['name_key']); $this->key->setp('description',$p_array['description_key']); $this->key->save(); for ($i=0; $i<count($a_row); $i++) { //save key_distribution_row $key_row=new Anc_Key_Detail_SQL($cn); $key_row->setp('id', $a_row[$i]); $key_row->setp('key', $this->key->getp('id')); $key_row->setp('row', $i+1); $key_row->setp('percent', $a_percent[$i]); $key_row->save(); // // Save each activity + percent $cn->exec_sql('delete from key_distribution_activity where ke_id=$1', array($key_row->getp('id'))); // Don't save row with 0 % if ($a_percent[$i]==0) { $key_row->delete(); continue; } for ($j=0; $j<count($a_po_id[$i]); $j++) { $activity=new Anc_Key_Activity_SQL($cn); $activity->setp('detail', $key_row->ke_id); $value=($a_po_id[$i][$j]==-1)?null:$a_po_id[$i][$j]; $activity->setp('activity', $value); $activity->setp('plan',$a_plan[$j]); $activity->save(); } } // delete all from key_distribution_ledger $cn->exec_sql('delete from key_distribution_ledger where kd_id=$1', array($this->key->getp('id'))); for ($k=0; $k<count($a_ledger); $k++) { $ledger=new Anc_Key_Ledger_SQL($cn); $ledger->kd_id=$this->key->getp('id'); $ledger->jrn_def_id=$a_ledger[$k]; $ledger->save(); } $cn->commit(); } catch (Exception $e) { if ( DEBUG ) { echo $e->getTraceAsString(); var_dump($_POST);} else { echo _('erreur');} $cn->rollback(); } }
Anc_Key::verify | ( | $ | p_array | ) |
verify that data are ok
type | $p_array |
Definition at line 135 of file class_anc_key.php.
References $p_array.
Referenced by save().
{ $a_percent=$p_array['percent']; if (count($a_percent)==0) { throw Exception(_('Aucune répartition')); } $tot_percent=0; bcscale(4); for ($i=0; $i<count($a_percent); $i++) { $tot_percent=bcadd($tot_percent, $a_percent[$i]); } if ($tot_percent >100) { throw new Exception(_('Le total ne vaut pas 100, total calculé = ').$tot_percent); } if ($p_array['name_key']=='') { throw new Exception (_('Le nom ne peut être vide')); } }
Anc_Key::$key [private] |
Definition at line 33 of file class_anc_key.php.
Referenced by key_add().