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

@ -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();
?>