diff --git a/html/js/anc_script.js b/html/js/anc_script.js index 1d65ca64b..d75d48eb9 100644 --- a/html/js/anc_script.js +++ b/html/js/anc_script.js @@ -410,6 +410,7 @@ function anc_key_compute(p_dossier, p_table, p_amount, p_key_id) code_html = unescape_xml(code_html); console.log(code_html); $(name_ctl).innerHTML = code_html; + removeDiv('div_anc_key_choice'); } catch (e) { error_message(e.message); @@ -493,28 +494,31 @@ function add_row_key(p_table) { return; } - if (mytable.rows.length > 15) + var table_length=mytable.rows.length ; + if ( table_length > 15) { alert("Maximum 15 lignes "); return; } var rowToCopy = mytable.rows[1]; - var row = mytable.insertRow(mytable.rows.length); - + var row = mytable.insertRow(table_length); + var nb=mytable.rows.length -2; for (var i = 0; i < rowToCopy.cells.length; i++) { var cell = row.insertCell(i); cell.className=rowToCopy.cells[i].className; var txt = rowToCopy.cells[i].innerHTML; -// txt=txt.replace(/row_1/g,"row_"+new_value); if ( i == 0 ) { - cell.innerHTML =mytable.rows.length-1 ; + var change=nb+1; + cell.innerHTML =change+''; } else { if (i == rowToCopy.cells.length -1 ) { txt=txt.replace(/value="[0-9]*.{1}[0-9]*"/,'value="0"') + } else { + txt=txt.replace(/po_id\[0\]/g,'po_id['+nb+']'); } cell.innerHTML = txt; } diff --git a/include/anc_key.inc.php b/include/anc_key.inc.php index 25279341d..fbbfaec69 100644 --- a/include/anc_key.inc.php +++ b/include/anc_key.inc.php @@ -26,7 +26,6 @@ * @see do.php * */ -var_dump($_POST); if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); global $cn, $g_user; @@ -63,5 +62,11 @@ switch ($op) } $key->input(); break; + case 'delete_key': + $id=HtmlInput::default_value_request("key", "0"); + $key=new Anc_Key($id); + $key->delete(); + Anc_Key::display_list(); + Anc_Key::key_add(); } ?> diff --git a/include/class_anc_key.php b/include/class_anc_key.php index c277a527e..7e70baa0c 100644 --- a/include/class_anc_key.php +++ b/include/class_anc_key.php @@ -75,9 +75,9 @@ class Anc_Key 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); + $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'); @@ -127,7 +127,7 @@ class Anc_Key { $tot_percent=bcadd($tot_percent, $a_percent[$i]); } - if ($tot_percent<>100) + if ($tot_percent >100) { throw new Exception(_('Le total ne vaut pas 100, total calculé = ').$tot_percent); } @@ -195,7 +195,7 @@ class Anc_Key $cn->start(); // for each row $a_row=$p_array['row']; - $a_ledger=$p_array['jrn']; + $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']; @@ -226,7 +226,7 @@ class Anc_Key for ($j=0; $jsetp('detail', $key_row->getp('id')); + $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]); @@ -243,12 +243,13 @@ class Anc_Key $ledger->save(); } + $cn->commit(); } catch (Exception $e) { - echo $e->getTraceAsString(); + if ( DEBUG ) { echo $e->getTraceAsString(); var_dump($_POST);} else { echo _('erreur');} + $cn->rollback(); } - $cn->commit(); } /** * @brief Call the Anc_Operation::display_form_plan with the right amounts. @@ -263,6 +264,7 @@ class Anc_Key { global $cn; $number=str_replace('t', '', $p_target); + $number=str_replace('popup', '', $number); $op[$number]=$p_amount; $array['op']=$op; @@ -302,10 +304,13 @@ class Anc_Key $array['val']=$val; $anc_operation=new Anc_Operation($cn); - echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount); + echo $anc_operation->display_form_plan($array, 1, 1, $number, $p_amount,'',false); } - + /** + *@brief show a form for adding a key + button to display it + * + */ static function key_add() { $key=new Anc_Key(); @@ -319,4 +324,11 @@ class Anc_Key echo ''; } + /** + *@brief delete the distribution key + */ + function delete () + { + $this->key->delete(); + } } diff --git a/include/template/anc_key_display_list.php b/include/template/anc_key_display_list.php index 8ea60acf7..9a57108b2 100644 --- a/include/template/anc_key_display_list.php +++ b/include/template/anc_key_display_list.php @@ -21,19 +21,21 @@ * @brief display a table with the list of available keys for all ledgers * @see Anc_Key::display_list */ - +global $g_succeed,$g_failed; ?> +
- Dossier::id(), 'ac'=>$_REQUEST['ac'], 'op'=>'consult', 'key'=>$a_key[$i]['kd_id'] )); + $class=($i%2==0)?'class="even"':'class="odd"'; ?> - + > - + + -
@@ -42,7 +44,14 @@ + % + +
\ No newline at end of file + +
\ No newline at end of file diff --git a/include/template/anc_key_input.php b/include/template/anc_key_input.php index 8597306fe..305234105 100644 --- a/include/template/anc_key_input.php +++ b/include/template/anc_key_input.php @@ -22,7 +22,7 @@ * all the pa_id and analytic plan */ ?> -
+ +
+
+ key->getp('id')); + if ($this->key->getp('id') != -1) echo HtmlInput::submit('delete_key', _('Effacer'),'onclick="return confirm(\''._('Confirmer effacement?').'\')"'); ?>
\ No newline at end of file