/*
* 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 addFiche
* Purpose : ajoute une nouvelle fiche
*
* parm :
* - connexion
* - type de la fiche
* - tableau
* gen :
* - none
* return:
* - none
*
*/
function AddFiche($p_cn,$p_type,$p_array) {
echo_debug(" AddFiche($p_cn,$p_type,$p_array) ");
foreach ($p_array as $key=>$element){
${"p_$key"}=$element;
echo_debug("p_$key=$element;");
}
$base=GetBaseFiche($p_cn,$p_type);
$num=GetNextFiche($p_cn,$base);
$sql=sprintf("insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent)
values (%s,'%s',%d)",
$num,
$p_nom0,
$base);
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
$sql=sprintf("insert into fiche ( f_id,f_label,f_fd_id) values (%d,'%s',%d)",
$num,$p_nom0,$p_type);
$Res=ExecSql($p_cn,$sql);
for ( $i = 1; $i < $p_inc;$i++) {
$sql=sprintf("insert into isupp (is_f_id,is_isd_id,is_value) values (
%d,%d,'%s')",
$num, ${"p_isd_id$i"},${"p_nom$i"});
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
}
}
/* function EncodeFiche
* Purpose : Affiche les détails d'une fiche et propose
* de mettre à jour
* ou si array est a null, permet d'ajouter une
* fiche
*
* parm :
* - p_cn connexion
* - p_type id du modele fichedef(fd_id) de la fiche SI array est null
* sinon correspond au id d'une fiche fiche(f_id)
* gen :
* - none
* return:
* - none
*
*/
function EncodeFiche($p_cn,$p_type,$p_array=null) {
echo_debug("function EncodeFiche($p_cn,$p_type) ");
$ch_col="
";
$ch_li='
';
echo '';
}else {
$sql="select f_label,f_fd_id from fiche where f_id=".$p_type;
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
if ( $Max == 0 ) return;
$l_line=pg_fetch_array($Res,0);
echo '
'.getFicheName($p_cn,$l_line['f_fd_id']).'
';
printf(' ',
$l_line['f_label']);
echo '';
$sql="select isd_fd_id,isd_id,isd_label,is_value,is_id,is_f_id from isupp left join isupp_def on isd_id=is_isd_id where is_f_id=".$p_type;
$Res=ExecSql($p_cn,$sql);
$Max=pg_NumRows($Res);
echo_debug("Max ==== $Max");
echo '';
echo '';
for ($i=0;$i < $Max;$i++) {
$l_line=pg_fetch_array($Res,$i);
$Hid=sprintf('',
$i,$l_line['is_id']);
printf ('
%s
%s
',
$l_line['isd_label'], $i, $l_line['is_value'],$Hid);
}
echo '';
echo '';
echo '';
echo '';
}
}
/* function GetBaseFiche
* Purpose : donne la classe comptable de base d'une fiche
*
* parm :
* - p_cn connexion
* - p_type fiche id
* gen :
* - none
* return:
* - return la classe id ou rien
*
*/
function GetBaseFiche($p_cn,$p_type) {
$base=null;
$Res=ExecSql($p_cn,"select fd_class_base from fichedef where fd_id=".$p_type);
if ( pg_NumRows($Res) == 0 ) return;
$base=pg_fetch_array($Res,0);
return $base['fd_class_base'];
}
/* function ViewFiche
* Purpose : Montre les fiches d'une rubrique
*
* parm :
* - p_cn connexion
* - $p_type f_id
* gen :
* - none
* return:
* - none
*
*/
function ViewFiche($p_cn,$p_type) {
echo '
'.getFicheName($p_cn,$p_type).'
';
$Res=ExecSql($p_cn,"select f_id,f_label from fiche where f_fd_id='".$p_type."' order by f_id");
$Max=pg_NumRows($Res);
for ( $i = 0; $i < $Max; $i++) {
$l_line=pg_fetch_array($Res,$i);
$div="
";
}
echo '';
}
/* function GetNextFiche
* Purpose : Crée le poste suivant pour une fiche en fonction
* de la classe de base (fichedef(fd_class_base))
*
* parm :
* - p_cn connexion
* - p_base
* gen :
* -
* return:
* -
*
*/
function GetNextFiche($p_cn,$p_base) {
$Res=ExecSql($p_cn,"select max(pcm_val) as maxcode from tmp_pcmn where pcm_val_parent = $p_base");
$Max=pg_NumRows($Res);
echo_debug("$Max=pg_NumRows");
$l_line=pg_fetch_array($Res,0);
$ret=$l_line['maxcode'];
if ( $ret == "" ) {
$ret=sprintf("%d%04d",$p_base,0);
return $ret+1;
}
echo_debug("ret $ret");
return $ret+1;
}
/* function
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
* -
*
*/
function GetDataFiche($p_cn,$p_fiche_id) {
}
/* function ViewFicheDetail
* Purpose : Montre le detail d'une fiche
* et ajoute les lignes manquantes
* dans le cas où le modèle à changer
*
* parm :
* - p_cn
* - id de la fiche fiche(f_id)
* gen :
* -
* return:
* -
*
*/
function ViewFicheDetail($p_cn,$p_id) {
$sql="insert into isupp (is_f_id,is_isd_id) select".
" '".$p_id."',isd_id from isupp_def ".
" where isd_id not in ".
"(select is_isd_id from isupp where is_f_id=".$p_id.") ".
" and isd_fd_id=(select distinct f_fd_id from fiche ".
" where f_id=".$p_id.")";
$Res=ExecSql($p_cn,$sql);
EncodeFiche ($p_cn,$p_id,1);
}
/* function UpdateFiche
* Purpose : Met a jour une fiche
* change dans le plan comptable, fiche,et isupp
*
* parm :
* - p_cn
* - p_array
* gen :
* -
* return:
* -
*
*/
function UpdateFiche($p_cn,$p_array) {
foreach ( $p_array as $key=> $element) {
echo_debug("$key => $element");
${"$key"}=$element;
}
$sql=sprintf("update tmp_pcmn set pcm_lib='%s' where pcm_val=%s",
$f_label,
$f_id);
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
$sql=sprintf("update fiche set f_label='%s' where f_id=%s",
$f_label,
$f_id);
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
for ( $i =0 ; $i < $max ; $i++) {
$sql=sprintf("update isupp set is_value='%s' where is_id=%d",
${"nom$i"},
${"is_id$i"});
echo_debug($sql);
$Res=ExecSql($p_cn,$sql);
}
}
/* function EncodeModele
* Purpose :
*
* parm :
* -
* gen :
* -
* return:
* -
*
*/
function EncodeModele($p_js)
{
echo '