From 4f64bcf72e626509af96bd5b7b1f75809e72b1a5 Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Tue, 18 Nov 2014 17:58:07 +0100 Subject: [PATCH] =?UTF-8?q?Task=20#1050=20-=20Am=C3=A9lioration=20PCMN=20*?= =?UTF-8?q?=20Add=20Ajax=20for=20update,inserting=20and=20deleting=20accou?= =?UTF-8?q?nt=20*=20Add=20Filter=20table=20*=20improve=20appearance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/ajax_misc.php | 6 + html/js/accounting_item.js | 119 +++++++++++++++++- include/ajax_account_update.php | 210 ++++++++++++++++++++++++++++++++ include/param_pcmn.inc.php | 210 +++++--------------------------- 4 files changed, 362 insertions(+), 183 deletions(-) create mode 100644 include/ajax_account_update.php diff --git a/html/ajax_misc.php b/html/ajax_misc.php index 490e4d066..4be9f87c6 100644 --- a/html/ajax_misc.php +++ b/html/ajax_misc.php @@ -664,6 +664,12 @@ EOF; */ require_once 'ajax_anc_key_compute.php'; break; + case 'account_update': + /** + * update an accounting (from CFGPCMN) + */ + require_once 'ajax_account_update.php'; + break; default: var_dump($_GET); } diff --git a/html/js/accounting_item.js b/html/js/accounting_item.js index 39c6c5340..ce5af71c7 100644 --- a/html/js/accounting_item.js +++ b/html/js/accounting_item.js @@ -39,17 +39,37 @@ function set_jrn_parent(p_ctl,p_value) f.value+=p_value; } } +/** + * Display a box with accounting detail for update, delete or add + * @param {type} p_value pcmn_val + * @param {type} p_lib pcmn_lib + * @param {type} p_parent pcmn_val_parent + * @param {type} p_type pcmn_val_type + * @param {type} p_dossier gDossier + * @param {type} p_top position of the box + * @param {type} p_action = new | update | delete + * @returns {undefined} + */ - -function PcmnUpdate(p_value,p_lib,p_parent,p_type,p_dossier) +function PcmnUpdate(p_value,p_lib,p_parent,p_type,p_dossier,p_top,p_action) { + console.log(p_type); $('p_valu').value=p_value; $('p_oldu').value=p_value; $('p_libu').value=p_lib; $('p_parentu').value=p_parent; $('p_typeu').value=p_type; - $('acc_update').style.top=posY+offsetY+"px"; - $('acc_update').style.left=posX+offsetX+"px"; + var i=0; + for (i=0;i < $('p_typeu').options.length;i++) { + if ($('p_typeu').options[i].value== p_type) {$('p_typeu').options.selectedIndex= i; break; } + } + $('p_typeu').options.selectedIndex=p_type; + $('acc_update').style.top=(posY+offsetY+p_top)+"px"; + $('acc_update').style.left="10%"; + $('acc_update').style.width="80%"; + $('acc_update_info').innerHTML=""; + $('p_action').value=p_action; + $('delete_acc').checked=false; $('acc_update').show(); } /** @@ -248,3 +268,94 @@ function errorPoste() { alert('Ajax failed'); } +function pausecomp(millis) + { + var date = new Date(); + var curDate = null; + do { curDate = new Date(); } + while(curDate-date < millis); +} +/** + * + * @param {type} p_obj_id id of the form + * @returns false + */ +function account_update(p_obj_id) +{ + try { + waiting_box(); + console.log('call account_update'); + // initialize variables + var gDossier=0; + var p_action=""; + var p_oldu=-1; + var p_valu=""; + var p_libu=""; + var p_parentu=""; + var form=$('acc_update_frm_id'); + var notfound="not found:"; + var p_typeu=-1; + // get them + if ( form['gDossier']) { gDossier=form['gDossier'].value;}else { notfound+='gDossier';} + if ( form['p_action']) { action=form['p_action'].value;}else { notfound+=', p_action ';} + if ( form['p_oldu']) { p_oldu=form['p_oldu'].value;}else { notfound+=', p_oldu';} + if ( form['p_valu']) { p_valu=form['p_valu'].value;}else { notfound+=', p_valu';} + if ( form['p_libu']) { p_libu=form['p_libu'].value;}else { notfound+=', p_libu ';} + if ( form['p_parentu']) { p_parentu=form['p_parentu'].value;}else { notfound+='p_parentu';} + if ( form['delete_acc']) { + if (form['delete_acc'].checked) { acc_delete=1;} else {acc_delete=0} } + else { + notfound += ', delete_acc'; + } + if ( form['p_typeu']) { p_typeu=form['p_typeu'].value;} else { notfound+=", p_typeu";} + + console.log (notfound); + + if ( notfound != "not found:") throw notfound; + + var queryString = "op=account_update" + "&gDossier=" + gDossier+ "&action=" + action + "&p_oldu=" + p_oldu+"&p_valu="+p_valu+"&p_libu="+p_libu+"&p_parentu="+p_parentu+"&acc_delete="+acc_delete+"&p_typeu="+p_typeu; + var ajax_action = new Ajax.Request( + "ajax_misc.php", + { + method: 'get', + parameters: queryString, + onFailure: error_box, + onSuccess: function(req, json) { + try + { + var name_ctl = 'acc_update_info'; + var answer = req.responseXML; + remove_waiting_box(); + var html = answer.getElementsByTagName('code'); + var ctl = answer.getElementsByTagName('ctl')[0].textContent; + if (html.length == 0) { + var rec = req.responseText; + alert('erreur :' + rec); + } + console.log("ctl ");console.log(ctl); + 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); + + $(name_ctl).innerHTML = code_html; + if ( ctl == 'ok') { + window.location.reload(); + } + } catch (e) + { + error_message(e.message); + return false; + } + } + } + + ); + + }catch (e) { + if (console) { console.log('Account update'); } + return false; + } + return false; +} + \ No newline at end of file diff --git a/include/ajax_account_update.php b/include/ajax_account_update.php new file mode 100644 index 000000000..d5b500c15 --- /dev/null +++ b/include/ajax_account_update.php @@ -0,0 +1,210 @@ + + +if (!defined('ALLOWED')) die('Appel direct ne sont pas permis'); + +/** + * @file + * @brief delete insert or update data from account_update (need right CFGPCMN) + * called from ajax_misc.php + * @param array + * @code + * 'op' => string 'account_update' (length=14) + 'gDossier' => string '44' (length=2) + 'action' => string 'update' (length=6) + 'p_oldu' => string '4124' (length=4) + 'p_valu' => string '4124' (length=4) + 'p_libu' => string 'Impôt belge sur le résultat' (length=29) + 'p_parentu' => string '412' (length=3) + 'acc_delete' => string '0' (length=1) + 'p_typeu' => string '0' (length=1) + * @endcode + */ +$var=array('action', 'p_oldu', 'p_valu', 'p_libu', 'p_parentu', 'acc_delete', 'p_typeu'); +for ($i=0; $iset_parameter('libelle', $p_lib); + $acc->set_parameter('value', $p_val); + $acc->set_parameter('parent', $p_parent); + $acc->set_parameter('type', $p_type); + $acc->check(); + } + catch (Exception $e) + { + $message=_("Valeurs invalides, pas de changement")." \n ". + $e->getMessage(); + $ctl='nok'; + } + if (strlen($p_val)!=0&&strlen($p_lib)!=0&&strlen($old_line)!=0) + { + if (strlen($p_val)==1) + { + $p_parent=0; + } + else + { + if (strlen($p_parent)==0) + { + $p_parent=substr($p_val, 0, strlen($p_val)-1); + } + } + /* Parent existe */ + $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parent)); + if (($p_parent!=0&&Database::num_row($Ret)==0)||$p_parent==$old_line) + { + $message=_("Ne peut pas modifier; aucun poste parent"); + $ctl='nok'; + } + else + { + try + { + $acc->update($old_line); + } + catch (Exception $e) + { + $message=$e->getMessage(); + $ctl='nok'; + } + } + } + else + { + $message=_('Update Valeurs invalides'); + $ctl='nok'; + } +} +//----------------------------------------------------- +/* Ajout d'une ligne */ +if ($action=="new") +{ + $p_val=trim($p_valu); + $p_parent=trim($p_parentu); + + if (isset($p_valu)&&isset($p_libu)) + { + $p_val=trim($p_valu); + + if (strlen($p_valu)!=0&&strlen($p_libu)!=0) + { + if (strlen($p_valu)==1) + { + $p_parentu=0; + } + else + { + if (strlen(trim($p_parentu))==0&& + (string) $p_parentu!=(string) (int) $p_parentu) + { + $p_parentu=substr($p_val, 0, strlen($p_valu)-1); + } + } + /* Parent existe */ + $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1", array($p_parentu)); + if ($p_parent!=0&&Database::num_row($Ret)==0) + { + $message=_(" Ne peut pas modifier; aucun poste parent"); + $ctl='nok'; + } + else + { + // Check if the account already exists + + $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1", array($p_val)); + if ($Count!=0) + { + // Alert message account already exists + $message=_("Ce poste existe déjà "); + $ctl='nok'; + } + else + { + $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)", array($p_val, $p_libu, $p_parent, $p_typeu)); + } + } + } + else + { + $message=_("Valeurs invalides "); + $ctl='nok'; + } + } +} + +//----------------------------------------------------- +// Action == remove a line +if ($action=="update"&&$acc_delete==1) +{ + /* Ligne a enfant */ + $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1", array($p_valu)); + if (Database::num_row($R)!=0) + { + $message=_("Ne peut pas effacer le poste: d'autres postes en dépendent"); + $ctl='nok'; + } + else + { + /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */ + $Res=$cn->exec_sql("select * from jrnx where j_poste=$1", array($p_valu)); + if (Database::num_row($Res)!=0) + { + $message=_("Ne peut pas effacer le poste: il est utilisé dans les journaux"); + $ctl='nok'; + } + else + { + $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1", array($p_valu)); + } // if Database::num_row + } // if Database::num_row +} //$action == del +$message=escape_xml($message); + if ( ! headers_sent()) { header('Content-type: text/xml; charset=UTF-8');} else { echo "HTML".unescape_xml($html);} + + echo << + +$ctl +$message + +EOF; +?> diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php index 12bc889ea..0129f3fab 100644 --- a/include/param_pcmn.inc.php +++ b/include/param_pcmn.inc.php @@ -38,9 +38,10 @@ include_once ("class_user.php"); include_once ("user_menu.php"); -echo ''; echo ''; +if ($g_start == -1) return; echo '
'; -/* Analyse ce qui est demandé */ -/* Effacement d'une ligne */ -if (isset ($_GET['action'])) -{ -//----------------------------------------------------- -// Action == remove a line - if ( $_GET['action']=="del" ) - { - if ( isset ($_GET['l']) ) - { - /* Ligne a enfant*/ - $R=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val_parent=$1",array($_GET['l'])); - if ( Database::num_row($R) != 0 ) - { - alert("Ne peut pas effacer le poste: d'autres postes en dépendent"); - } - else - { - /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */ - $Res=$cn->exec_sql("select * from jrnx where j_poste=$1",array($_GET['l'])); - if ( Database::num_row($Res) != 0 ) - { - alert("Ne peut pas effacer le poste: il est utilisé dans les journaux"); - } - else - { - $Del=$cn->exec_sql("delete from tmp_pcmn where pcm_val=$1",array($_GET['l'])); - } // if Database::num_row - } // if Database::num_row - } // isset ($l) - } //$action == del -} // isset action -//---------------------------------------------------------------------- -// Modification -//---------------------------------------------------------------------- -if ( isset ($_POST['update'])) -{ - $p_val=trim($_POST["p_valu"]); - $p_lib=trim($_POST["p_libu"]); - $p_parent=trim($_POST["p_parentu"]); - $old_line=trim($_POST["p_oldu"]); - $p_type=htmlentities($_POST['p_typeu']); - $acc=new Acc_Account($cn); - $acc->set_parameter('libelle',$p_lib); - $acc->set_parameter('value',$p_val); - $acc->set_parameter('parent',$p_parent); - $acc->set_parameter('type',$p_type); - // Check if the data are correct - try - { - $acc->check() ; - } - catch (Exception $e) - { - $message="Valeurs invalides, pas de changement \n ". - $e->getMessage(); - echo ''; - } - if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 && strlen($old_line)!=0 ) - { - if (strlen ($p_val) == 1 ) - { - $p_parent=0; - } - else - { - if ( strlen($p_parent)==0 ) - { - $p_parent=substr($p_val,0,strlen($p_val)-1); - } - } - /* Parent existe */ - $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent)); - if ( ($p_parent != 0 && Database::num_row($Ret) == 0) || $p_parent==$old_line ) - { - echo ''; - } - else - { - try - { - $acc->update($old_line); - } - catch(Exception $e) - { - alert($e->getMessage()); - } - } - } - else - { - echo ''; - } -} -//----------------------------------------------------- -/* Ajout d'une ligne */ -if ( isset ( $_POST["Ajout"] ) ) -{ - extract ($_POST); - $p_val=trim($p_val); - $p_parent=trim($p_parent); - - if ( isset ( $p_val) && isset ( $p_lib ) ) - { - $p_val=trim($p_val); - $p_parent=$_POST["p_parent"]; - if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 ) - { - if (strlen ($p_val) == 1 ) - { - $p_parent=0; - } - else - { - if ( strlen(trim($p_parent))==0 && - (string) $p_parent != (string)(int) $p_parent) - { - $p_parent=substr($p_val,0,strlen($p_val)-1); - } - } - /* Parent existe */ - $Ret=$cn->exec_sql("select pcm_val from tmp_pcmn where pcm_val=$1",array($p_parent)); - if ( $p_parent != 0 && Database::num_row($Ret) == 0 ) - { - alert(" Ne peut pas modifier; aucun poste parent"); - } - else - { - // Check if the account already exists - - $Count=$cn->get_value("select count(*) from tmp_pcmn where pcm_val=$1",array($p_val)); - if ( $Count != 0 ) - { - // Alert message account already exists - alert(" Ce poste existe déjà "); - - } - else - { - $Ret=$cn->exec_sql("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ($1,$2,$3,$4)",array($p_val,$p_lib,$p_parent,$p_type)); - } - } - } - else - { - echo '

Valeurs invalides

'; - } - } -} $Ret=$cn->exec_sql("select pcm_val,pcm_lib,pcm_val_parent,pcm_type,array_to_string(array_agg(j_qcode) , ',') as acode - from tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."'". + from tmp_pcmn left join vw_poste_qcode on (j_poste=pcm_val) where substr(pcm_val::text,1,1)='".$g_start."'". " group by pcm_val,pcm_lib,pcm_val_parent, pcm_type order by pcm_val::text"); $MaxRow=Database::num_row($Ret); ?> - + + + +
- +
@@ -262,14 +111,14 @@ $limite=MAX_QCODE; form(false); +//$line=new Acc_Account($cn); +//echo $line->form(false); ?> - +'; echo "$td"; - printf ("", - $A['pcm_val'], - str_replace("'","\'",$A['pcm_lib']), - $A['pcm_val_parent'], - $A['pcm_type'], + printf ("", + str_replace("'","\'",$A['pcm_val']), + str_replace("'","\'",$A['pcm_lib']), + str_replace("'","\'",$A['pcm_val_parent']), + str_replace("'","\'",$A['pcm_type']), dossier::id()); echo h($A['pcm_lib']); @@ -325,15 +174,18 @@ for ($i=0; $i <$MaxRow; $i++) } echo ''; - echo $td; - printf ('Efface',$A['pcm_val'],$str_dossier); - echo ""; + //echo $td; + //printf ('Efface',$A['pcm_val'],$str_dossier); + //echo ""; echo ""; } echo "
Poste comptable Libellé Fiche
"; echo "
"; +?> + +"; html_page_stop(); ?>