/*
* This file is part of WCOMPTA.
*
* WCOMPTA 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.
*
* WCOMPTA 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 WCOMPTA; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Auteur Dany De Bontridder ddebontridder@yahoo.fr
/* $Revision$ */
/* function RecordJrn
* Purpose : Record an entry in the selected journal
*
* parm :
* - p_dossier dossier id
* - p_user user id
* - p_jrn selected journal
* gen :
* - none
* return:
* - none
*
*/
function RecordJrn($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array = null,$p_update=0)
{
include_once("postgres.php");
include_once("preference.php");
echo_debug("RecordJrn($p_dossier,$p_user,$p_jrn,$p_MaxDeb,$p_MaxCred,$p_array,$p_update)");
for ( $i = 0; $i < $p_MaxDeb; $i++) {
${"e_class_deb$i"}=0;
${"e_mont_deb$i"}=0;
${"e_text_deb$i"}="";
}
for ( $i = 0; $i < $p_MaxCred; $i++) {
${"e_class_cred$i"}=0;
${"e_mont_cred$i"}=0;
${"e_text_cred$i"}="";
}
$l_dossier=sprintf("dossier%d",$p_dossier);
$cn=DbConnect($l_dossier);
if ( $p_array == null ) {
// userPref contient la periode par default
$userPref=GetUserPeriode($cn,$p_user);
list ($l_date_start,$l_date_end)=GetPeriode($cn,$userPref);
$e_op_date=$l_date_start;
$e_comment="";
$e_rapt="";
$e_ech="";
$e_sum_deb=0;
$e_sum_cred=0;
} else {
foreach ( $p_array as $n=>$e) {
${"e_$n"}= $e;
}
}
/* Get Jrn's properties */
$l_line=GetJrnProp($p_dossier,$p_jrn);
if ( $l_line == null ) return;
echo '
';
}
/* function GetJrnProp
* Purpose : Get the properties of a journal
*
* parm :
* - p_dossier the folder id
* - p_jrn the jrn id
* gen :
* - none
* return:
* - an array containing properties
*
*/
function GetJrnProp($p_dossier,$p_jrn)
{
$l_dossier=sprintf("dossier%d",$p_dossier);
$cn=DbConnect($l_dossier);
$Res=ExecSql($cn,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type,
jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code
from jrn_Def
where jrn_def_id=$p_jrn");
$Count=pg_NumRows($Res);
if ( $Count == 0 ) {
echo '
Paramètres journaux non trouvés
';
return null;
}
return pg_fetch_array($Res,0);
}
/* function
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
* -
*
*/
function GetNextId($p_cn,$p_name) {
include_once("postgres.php");
$Res=ExecSql($p_cn,"select max($p_name) as result from jrnx");
echo_debug("$Res=ExecSql($p_cn,"."select max($p_name) as result from jrnx");
if (pg_NumRows($Res) == 0 )
return 0;
$l_res=pg_fetch_array($Res,0);
return $l_res['result'];
}
/* function
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
* -
*
*/
function GetNextJrnId($p_cn,$p_name) {
include_once("postgres.php");
$Res=ExecSql($p_cn,"select max($p_name) as result from jrn ");
echo_debug("$Res=ExecSql($p_cn,"."select max($p_name) as result from jrn ");
if (pg_NumRows($Res) == 0 )
return 0;
$l_res=pg_fetch_array($Res,0);
return $l_res['result'];
}
/* function
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
* -
*
*/
function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) {
echo_debug("function ViewJrn($p_dossier,$p_user,$p_jrn,$p_array=null) ");
$db=sprintf("dossier%d",$p_dossier);
$l_prop=GetJrnProp($p_dossier,$p_jrn);
echo $l_prop['jrn_def_name']."( ".$l_prop['jrn_def_code'].")";
$cn=DbConnect($db);
if ( $p_array == null) {
include_once("preference.php");
$l_periode=GetUserPeriode($cn,$p_user);
$Res=ExecSql($cn,"select j_id,jr_internal,j_text,to_char(j_date,'DD.MM.YYYY') as j_date,
j_montant,j_poste,pcm_lib,j_grpt,j_rapt,j_debit,j_centralized,j_tech_per
from jrnx inner join tmp_pcmn on j_poste=pcm_val
inner join jrn on jr_grpt_id=j_grpt
where
j_jrn_def=$p_jrn and j_tech_per=$l_periode
order by j_id,j_grpt,j_debit desc");
} else {
// Construction Query
foreach ( $p_array as $key=>$element) {
${"l_$key"}=$element;
echo_debug ("l_$key $element");
}
$sql="select j_id,j_text,to_char(j_date,'DD.MM.YYYY') as j_date,j_montant,j_poste,pcm_lib,j_grpt,j_rapt,j_debit,j_centralized,j_tech_per,jr_internal
from jrnx inner join tmp_pcmn on j_poste=pcm_val
inner join jrn on jr_grpt_id=j_grpt
where
j_jrn_def=$p_jrn";
$l_and="and ";
if ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) ) {
$sql.=" and j_montant $l_mont_sel $l_s_montant";
}
if ( isDate($l_date_start) != null ) {
$sql.=$l_and." j_date >='".$l_date_start."'";
}
if ( isDate($l_date_end) != null ) {
$sql.=$l_and." j_date <='".$l_date_end."'";
}
$l_s_comment=FormatString($l_s_comment);
if ( $l_s_comment != null ) {
$sql.=$l_and." ( upper(jr_comment) like upper('%".$l_s_comment."%') or
upper(j_text) like upper('%".$l_s_comment."%'))";
}
$sql.=" order by j_id,j_grpt,j_debit desc";
echo_debug ("search query is $sql");
$Res=ExecSql($cn,$sql);
}
$MaxLine=pg_NumRows($Res);
if ( $MaxLine == 0 ) return;
$col_vide="
";
echo '
';
$l_id=0;
for ( $i=0; $i < $MaxLine; $i++) {
$l_line=pg_fetch_array($Res,$i);
if ( $l_line['j_debit'] == 't' ) {
echo '