Task #1050 - Amélioration PCMN

* Add Ajax for update,inserting and deleting account
* Add Filter table
* improve appearance
This commit is contained in:
Dany De Bontridder 2014-11-18 17:58:07 +01:00
parent 4a3e79e0dd
commit 4f64bcf72e
4 changed files with 362 additions and 183 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -0,0 +1,210 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta 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.
*
* PhpCompta 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 PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Copyright (2014) Author Dany De Bontridder <dany@alchimerys.be>
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; $i<count($var); $i++)
{
$name=$var[$i];
if (!isset($$name))
throw new Exception($name." is not set");
}
$ctl='ok';
extract($_GET);
//----------------------------------------------------------------------
// Modification
//----------------------------------------------------------------------
$message=_("opération réussie");
if ($action=="update" &&$acc_delete==0)
{
// Check if the data are correct
try
{
$p_val=trim($p_valu);
$p_lib=trim($p_libu);
$p_parent=trim($p_parentu);
$old_line=trim($p_oldu);
$p_type=htmlentities($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);
$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 <<<EOF
<?xml version="1.0" encoding="UTF-8"?>
<data>
<ctl>$ctl</ctl>
<code>$message</code>
</data>
EOF;
?>

View file

@ -38,9 +38,10 @@ include_once ("class_user.php");
include_once ("user_menu.php");
echo '<div id="acc_update" style="border:1px solid blue;width:40%;display:none;background-color:lightgrey;padding:0;position:absolute;text-align:left;z-index:1">';
echo '<div id="acc_update" class="inner_box" style="display:none;position:absolute;text-align:left;z-index:1">';
echo HtmlInput::title_box("Poste comptable", "acc_update", "hide");
echo '<form method="post">';
echo '<span id="acc_update_info" class="notice"></span>';
echo '<form method="post" id="acc_update_frm_id" onsubmit="account_update(\'acc_update_frm_id\');return false;">';
$val=new IText('p_valu');
$parent=new IText('p_parentu');
$lib=new IText('p_libu');
@ -58,7 +59,11 @@ $r= td(_('Type ')).td($type->input());
echo tr($r);
echo '</table>';
echo HtmlInput::hidden('p_oldu','');
echo HtmlInput::hidden('p_action','');
echo dossier::hidden();
$checkbox=new ICheckBox("delete_acc");
echo _('Cocher pour effacer')." ".$checkbox->input();
echo '<hr>';
echo HtmlInput::submit('update',_('Sauve'));
echo HtmlInput::button('hide',_('Annuler'),'onClick="$(\'acc_update\').hide();return true;"');
echo '</form>';
@ -67,18 +72,8 @@ echo '</div>';
/* Store the p_start parameter */
if ( ! isset ( $_SESSION['g_start']) )
{
$_SESSION['g_start']="";
}
if ( isset ($_GET['p_start']))
{
$g_start=$_GET['p_start'];
$_SESSION["g_start"]=$g_start;
}
$g_start=HtmlInput::default_value_get('p_start',-1);
echo '<div class="u_subtmenu">';
echo '</div>';
@ -87,165 +82,19 @@ echo '</div>';
echo '<div class="lmenu">';
menu_acc_plan($_SESSION['g_start']);
echo '</div>';
if ($g_start == -1) return;
echo '<DIV CLASS="redcontent">';
/* 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 '<script> alert(\''.$message.'\');
</script>';
}
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 '<SCRIPT> alert(" Ne peut pas modifier; aucun poste parent"); </SCRIPT>';
}
else
{
try
{
$acc->update($old_line);
}
catch(Exception $e)
{
alert($e->getMessage());
}
}
}
else
{
echo '<script> alert(\'Update Valeurs invalides\'); </script>';
}
}
//-----------------------------------------------------
/* 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 '<H2 class="error"> Valeurs invalides </H3>';
}
}
}
$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);
?>
<span style="display:block">
<input type="button" class="smallbutton" onclick="PcmnUpdate('','','','',0,0,'new')" value="<?php echo _('Ajout'); ?>">
</span>
<?php echo _('Filtre')." ".HtmlInput::filter_table("account_tbl_id", "0,1,2,3,4", 1);?>
<FORM METHOD="POST">
<?php
echo HtmlInput::hidden('p_action','pcmn');
@ -253,7 +102,7 @@ $MaxRow=Database::num_row($Ret);
echo dossier::hidden();
$limite=MAX_QCODE;
?>
<TABLE class="result">
<TABLE id="account_tbl_id" class="result">
<TR>
<TH> Poste comptable </TH>
<TH> Libellé </TH>
@ -262,14 +111,14 @@ $limite=MAX_QCODE;
<TH> Fiche</TH>
</TR>
<?php
$line=new Acc_Account($cn);
echo $line->form(false);
//$line=new Acc_Account($cn);
//echo $line->form(false);
?>
<td></td>
<!-- <td></td>
<TD>
<INPUT TYPE="SUBMIT" class="button" Value="Ajout" Name="Ajout">
</TD>
</TR>
</TR>-->
<?php
$str_dossier=dossier::get();
for ($i=0; $i <$MaxRow; $i++)
@ -288,14 +137,14 @@ for ($i=0; $i <$MaxRow; $i++)
}
echo $tr;
echo "$td";
echo $A['pcm_val'];
echo HtmlInput::history_account($A['pcm_val'], $A['pcm_val']);
echo '</td>';
echo "$td";
printf ("<A HREF=\"javascript:void(0)\" onclick=\"PcmnUpdate('%s','%s','%s','%s',%d)\">",
$A['pcm_val'],
str_replace("'","\'",$A['pcm_lib']),
$A['pcm_val_parent'],
$A['pcm_type'],
printf ("<A style=\"text-decoration:underline\" HREF=\"javascript:void(0)\" onclick=\"PcmnUpdate('%s','%s','%s','%s',%d,0,'update')\">",
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 '</td>';
echo $td;
printf ('<A class="input_text" href="?ac='.$_REQUEST['ac'].'&l=%s&action=del&%s">Efface</A>',$A['pcm_val'],$str_dossier);
echo "</TD>";
//echo $td;
//printf ('<A class="input_text" href="?ac='.$_REQUEST['ac'].'&l=%s&action=del&%s">Efface</A>',$A['pcm_val'],$str_dossier);
//echo "</TD>";
echo "</TR>";
}
echo "</TABLE>";
echo "</FORM>";
?>
<input type="button" class="smallbutton" onclick="PcmnUpdate('','','','',0,-230,'new')" value="<?php echo _('Ajout'); ?>">
<?php
echo "</DIV>";
html_page_stop();
?>