diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 2ff71350e..57119fb76 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -632,6 +632,19 @@ EOF; } exit(); break; + + case 'anc_key_choice': + /* + * Show the available distribution keys for analytic + */ + require_once 'ajax_anc_key_choice.php'; + break; + case 'anc_key_compute': + /* + * Show the activities computed with the selected distribution key + */ + require_once 'ajax_anc_key_compute.php'; + break; default: var_dump($_GET); } diff --git a/html/js/anc_script.js b/html/js/anc_script.js index 3186a7955..87433f1b3 100644 --- a/html/js/anc_script.js +++ b/html/js/anc_script.js @@ -375,32 +375,51 @@ function filter_anc(obj, queryString) return queryString; } /** - * @brief use a distribution key + * @brief compute and display Analytic activity, related to the choosen distribution key * @param p_dossier is the dossier id * @param p_table is table id to replace * @param p_amount is the amount to distribute + * @param p_key_id is the choosen key * */ -function anc_key_compute(p_dossier, p_table, p_amount) +function anc_key_compute(p_dossier, p_table, p_amount, p_key_id) { waiting_box(); var op = "op=anc_key_compute"; - var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount; + var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount + '&key=' + p_key_id; try { var action = new Ajax.Request( "ajax_misc.php", { method: 'get', parameters: queryString, - onFailure: error_box('Ajax failure'), - onSuccess: function(req) { + onFailure: error_box, + onSuccess: function(req, json) { + try + { + var name_ctl = p_table; + var answer = req.responseXML; + remove_waiting_box(); + var html = answer.getElementsByTagName('code'); + if (html.length == 0) { + var rec = req.responseText; + alert('erreur :' + rec); + } + var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car. + code_html = unescape_xml(code_html); + console.log(code_html); + $(name_ctl).innerHTML = code_html; + } catch (e) + { + error_message(e.message); + } } } ); } catch (e) { - error_box(e.message); + error_message(e.message); } } /** @@ -408,11 +427,57 @@ function anc_key_compute(p_dossier, p_table, p_amount) * in ajax, a window let you choose what key you want to use * * @param p_dossier is the dossier - * @param p_key_id is the choosen key * @param p_table the table id of the target * @param p_amount amount to distribute + * @param p_ledger */ -function anc_key_choice(p_dossier, p_key_id, p_table, p_amount) +function anc_key_choice(p_dossier, p_table, p_amount) { + waiting_box(); + var op = 'op=anc_key_choice'; + var queryString = op + "&gDossier=" + p_dossier + "&t=" + p_table + "&amount=" + p_amount; + try { + var ledger=$('p_jrn'); + if (ledger == null ) { + error_message('error : ledger is null '); + return; + } + + queryString+='&led='+ledger.value; + var action = new Ajax.Request( + "ajax_misc.php", + { + method: 'get', + parameters: queryString, + onFailure: error_box, + onSuccess: function(req, json) { + try + { + var name_ctl = 'div_anc_key_choice'; + var answer = req.responseXML; + remove_waiting_box(); + var html = answer.getElementsByTagName('code'); + if (html.length == 0) { + var rec = req.responseText; + alert('erreur :' + rec); + } + console.log('Received ajax_call'); + var code_html = getNodeText(html[0]); // Firefox ne prend que les 4096 car. + code_html = unescape_xml(code_html); + console.log(code_html); + add_div({id: name_ctl, cssclass: 'inner_box', style: 'top:30%;right:35%;position:absolute', drag: 1}); + $(name_ctl).innerHTML = code_html; + } catch (e) + { + error_message(e.message); + } + } + } + + ); + + } catch (e) { + error_message(e.message); + } } \ No newline at end of file diff --git a/html/js/infobulle.js b/html/js/infobulle.js index 77bd8bbaf..de8ac1851 100644 --- a/html/js/infobulle.js +++ b/html/js/infobulle.js @@ -68,6 +68,7 @@ content[37]='Les dates sont en format DD.MM.YYYY'; content[38]='La numérotation est propre à chaque journal. Laissez à 0 pour ne pas changer le numéro'; content[39]='Le préfixe des pièces doit être différent pour chaque journal, on peut aussi utiliser l\'année'; content[40]='Laissez à 0 pour ne pas changer le numéro'; +content[41]='Mettez le pourcentage à zéro pour effacer la ligne'; function showBulle(p_ctl){ d=document.getElementById('bulle'); diff --git a/include/ajax_anc_key_choice.php b/include/ajax_anc_key_choice.php new file mode 100644 index 000000000..d2d38ee29 --- /dev/null +++ b/include/ajax_anc_key_choice.php @@ -0,0 +1,53 @@ + + + +$html + +EOF; +?> \ No newline at end of file diff --git a/include/ajax_anc_key_compute.php b/include/ajax_anc_key_compute.php new file mode 100644 index 000000000..8d375fedc --- /dev/null +++ b/include/ajax_anc_key_compute.php @@ -0,0 +1,61 @@ +fill_table($target,$amount); + +//// +$response = ob_get_clean(); +$html = escape_xml($response); +header('Content-type: text/xml; charset=UTF-8'); +echo << + + +$html + +EOF; +?> \ No newline at end of file diff --git a/include/anc_key.inc.php b/include/anc_key.inc.php new file mode 100644 index 000000000..0365faea8 --- /dev/null +++ b/include/anc_key.inc.php @@ -0,0 +1,64 @@ +save($_POST); + Anc_Key::display_list(); + break; + } + catch (Exception $e) + { + echo span($e->getMessage(),' class="notice"'); + } + } + $key->input(); + break; +} +?> diff --git a/include/class_anc_key.php b/include/class_anc_key.php new file mode 100644 index 000000000..0cdfecf17 --- /dev/null +++ b/include/class_anc_key.php @@ -0,0 +1,296 @@ +key=new Anc_Key_SQL($cn, $p_id); + $this->a_ledger=null; + $this->a_activity=null; + $this->a_row=null; + } + + /** + * @brief display list of available keys + * @param $p_amount amount to distribute + * @param $p_target target to update + * @param $p_ledger is the jrn_def_id + */ + static function display_choice($p_amount, $p_target,$p_ledger) + { + 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'); + } + include 'template/anc_key_display_choice.php'; + } + + /** + * @brief display a list of keys, choose one to modify it + * + */ + static function display_list() + { + global $cn; + $keysql=new Anc_Key_SQL($cn); + $rkey=$keysql->seek(' order by kd_name'); + $a_key=$cn->fetch_all($rkey); + if (empty($a_key)) + { + echo _('Aucune clef disponible'); + } + include 'template/anc_key_display_list.php'; + } + + /** + * @brief Show the detail for a key distribution and let you change it + * for adding or update + */ + function input() + { + 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'; + } + + /** + * @brief verify that data are ok + * @param type $p_array + */ + function verify($p_array) + { + $a_percent=$p_array['percent']; + if (count($a_percent)==0) + { + throw Exception(_('Aucune répartition')); + } + $tot_percent=0; + bcscale(4); + for ($i=0; $i100) + { + throw new Exception(_('Le total ne vaut pas 100, total calculé = ').$tot_percent); + } + } + + /** + * @brief save the data of a repartition key. + * @param received an 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 + * @verbatim + + '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) + @endverbatim + * + */ + function save($p_array) + { + global $cn; + $this->verify($p_array); + $cn->start(); + // for each row + $a_row=$p_array['row']; + $a_ledger=$p_array['jrn']; + $a_percent=$p_array['percent']; + $a_po_id=$p_array['po_id']; + $a_plan=$p_array['pa']; + try + { + for ($i=0; $isetp('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; $jsetp('detail', $key_row->getp('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; $kkd_id=$this->key->getp('id'); + $ledger->jrn_def_id=$a_ledger[$k]; + $ledger->save(); + } + } + catch (Exception $e) + { + echo $e->getTraceAsString(); + } + $cn->commit(); + } + function fill_table($p_target,$p_amount) + { + global $cn; + $number=str_replace('t', '', $p_target); + + $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); + + } + +} diff --git a/include/class_anc_key_sql.php b/include/class_anc_key_sql.php new file mode 100644 index 000000000..ffb6577fe --- /dev/null +++ b/include/class_anc_key_sql.php @@ -0,0 +1,155 @@ + + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +/** + * @file + * @brief Class to manage distribution keys for SQL. + * + */ +require_once 'class_noalyss_sql.php'; + + +/** + * @brief Manage the table key_distribution. + */ +class Anc_Key_SQL extends Noalyss_SQL +{ + + function __construct($cn, $p_id = -1) + { + $this->table = "public.key_distribution"; + $this->primary_key = "kd_id"; + + $this->name = array( + "id" => "kd_id", + "name"=>"kd_name", + "description"=>"kd_description" + ); + + $this->type = array( + "kd_id" => "numeric", + "kd_name" => "text", + "kd_description" => "text" + ); + + $this->default = array( + "kd_id" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } + +} +/** + * @brief manage table key_distribution_ledger + */ +class Anc_Key_Ledger_SQL extends Noalyss_SQL +{ + function __construct($cn, $p_id = -1) + { + $this->table = "public.key_distribution_ledger"; + $this->primary_key = "kl_id"; + + $this->name = array( + "id" => "kl_id", + "key"=>"kd_id", + "ledger"=>"jrn_def_id" + ); + + $this->type = array( + "kl_id" => "numeric", + "kd_id" => "numeric", + "jrn_def_id" => "numeric" + ); + + $this->default = array( + "kl_id" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } +} +/** + * @brief manage table key_distribution_detail + */ +class Anc_Key_Detail_SQL extends Noalyss_SQL +{ + function __construct($cn, $p_id = -1) + { + $this->table = "public.key_distribution_detail"; + $this->primary_key = "ke_id"; + + $this->name = array( + "id" => "ke_id", + "key"=>"kd_id", + "row"=>"ke_row", + "percent"=>"ke_percent" + ); + + $this->type = array( + "ke_id" => "numeric", + "kd_id" => "numeric", + "ke_row" => "numeric", + "ke_percent" => "numeric" + ); + + $this->default = array( + "ke_id" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } +} +/** + * @brief manage table key_distribution_activity + */ +class Anc_Key_Activity_SQL extends Noalyss_SQL +{ + function __construct($cn, $p_id = -1) + { + $this->table = "public.key_distribution_activity"; + $this->primary_key = "ka_id"; + + $this->name = array( + "id" => "ka_id", + "detail"=>"ke_id", + "activity"=>"po_id", + "plan"=>"pa_id" + ); + + $this->type = array( + "ka_id" => "numeric", + "ke_id" => "numeric", + "po_id" => "numeric", + "pa_id" => "numeric" + + ); + + $this->default = array( + "ka_id" => "auto" + ); + global $cn; + + parent::__construct($cn, $p_id); + } +} \ No newline at end of file diff --git a/include/template/anc_key_display_choice.php b/include/template/anc_key_display_choice.php new file mode 100644 index 000000000..c361b6648 --- /dev/null +++ b/include/template/anc_key_display_choice.php @@ -0,0 +1,47 @@ + + + + + + + + + +
+ > + + + + +
\ No newline at end of file diff --git a/include/template/anc_key_display_list.php b/include/template/anc_key_display_list.php new file mode 100644 index 000000000..a2dff1971 --- /dev/null +++ b/include/template/anc_key_display_list.php @@ -0,0 +1,54 @@ + + + Dossier::id(), + 'ac'=>$_REQUEST['ac'], + 'op'=>'consult', + 'key'=>$a_key[$i]['kd_id'] + )); + + /*sprintf(' onclick="anc_key_compute(%s,\'%s\',%s,%s)"', + Dossier::id(), + $p_target, + $p_amount, + $a_key[$i]['kd_id']);*/ + ?> + + + + + + +
+ + + + + +
\ No newline at end of file diff --git a/include/template/anc_key_input.php b/include/template/anc_key_input.php new file mode 100644 index 000000000..caa6180bf --- /dev/null +++ b/include/template/anc_key_input.php @@ -0,0 +1,165 @@ + +
+ key->getp('id')); + ?> +
+
+

+ key->getp('name'); ?> +

+
+
+

+ key->getp('description'); ?> +

+ +
+

+ +

+ + + + + + + + + + + + make_array("select po_id,po_name from poste_analytique where pa_id=$1", 1, array($plan[$i]['pa_id'])); + $select=new ISelect('po_id['.$j.'][]'); + $select->value=$a_poste; + $value=$cn->get_array('select po_id,ke_percent + from key_distribution_activity as ka + join key_distribution_detail using (ke_id) + join key_distribution using (kd_id) + left join poste_analytique using(po_id) + + where ke_id=$1 and ka.pa_id=$2 ', array($a_row[$j]['ke_row'],$plan[$i]['pa_id'])); + $selected=-1; + if (sizeof($value)==1) + { + $selected=$value[0]['po_id']; + + } + if (isset($_POST['po_id'])) + { + $a_po_id=HtmlInput::default_value_post('po_id', array()); + $selected=$a_po_id[$j][$i]; + $a_percent=HtmlInput::default_value_post('percent', array()); + $percent=$a_percent[$j]; + } + $select->selected=$selected; + ?> + + + + + + + + +
+ + + + +
+ + + + input(); + ?> + + value=$percent; + echo $inum_percent->input(); + ?> +
+ + +
+
+

+ +

+
+
+ + get_array('select kl_id,jrn_def_id,jrn_def_name,jrn_def_description from jrn_def + left join key_distribution_ledger using (jrn_def_id) + where kd_id=$1 or kd_id is null + order by jrn_def_name ', array($this->key->getp('id'))); + ?> + + + + + + + + +
+ + value=$jrn[$i]['jrn_def_id']; ?> + selected=($jrn[$i]['kl_id']=="")?false:true; ?> + input(); ?> + + + + +
+
+
+ + +
+ +
\ No newline at end of file