00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00036 function GetPosteLibelle($p_dossier,$p_id,$is_cn=0)
00037 {
00038 include_once("postgres.php");
00039 if ( ! isset($is_cn) ) $is_cn=0;
00040 if ( $is_cn == 0) {
00041 $cn=DbConnect($p_dossier);
00042 } else {
00043 $cn=$p_dossier;
00044 }
00045 $Res=ExecSql($cn,"select pcm_lib from tmp_pcmn where pcm_val=$p_id");
00046 if ( pg_NumRows($Res) == 0) { return "non existing poste";}
00047 $l_poste=pg_fetch_row($Res,0);
00048 return $l_poste[0];
00049 }
00062 function GetNumberLine($p_dossier,$p_jrn)
00063 {
00064 $cn=DbConnect($p_dossier);
00065 $Res=ExecSql($cn,"select jrn_deb_max_line,jrn_cred_max_line from jrn_def where jrn_def_id=$p_jrn");
00066 if ( pg_NumRows($Res) == 0 ) {
00067 echo "<H2 class=\"warning\"> Journal non trouvé </H2>";
00068
00069 }
00070 $l_line=pg_fetch_array($Res,0);
00071 $l_deb=$l_line['jrn_deb_max_line'];
00072 $l_cred=$l_line['jrn_cred_max_line'];
00073 return array ($l_deb,$l_cred);
00074
00075 }
00087 function PosteForm($p_cn) {
00088 $Res=ExecSql($p_cn,"select pcm_val,pcm_lib from tmp_pcmn
00089 where pcm_val = any (select j_poste from jrnx) order by pcm_val::text");
00090 $Max=pg_NumRows($Res);
00091 if ($Max==0) return null;
00092 $ret='<SELECT NAME="poste[]" SIZE="15" MULTIPLE>';
00093 for ( $i = 0;$i< $Max;$i++) {
00094 $line=pg_fetch_array($Res,$i);
00095 $ret.=sprintf('<OPTION VALUE="%s" > %s - %s',
00096 $line['pcm_val'],
00097 $line['pcm_val'],
00098 $line['pcm_lib']);
00099 }
00100 $ret.="</SELECT>";
00101 return $ret;
00102 }
00114 function GetSolde($p_cn,$p_account,$p_cond="") {
00115 $Res=ExecSql($p_cn,"select j_poste,sum(deb) as sum_deb, sum(cred) as sum_cred from
00116 ( select j_poste,
00117 case when j_debit='t' then j_montant else 0 end as deb,
00118 case when j_debit='f' then j_montant else 0 end as cred
00119 from jrnx join tmp_pcmn on j_poste=pcm_val
00120 where
00121 j_poste=$p_account
00122 ) as m group by j_poste ");
00123 $Max=pg_NumRows($Res);
00124 if ($Max==0) return 0;
00125 $r=pg_fetch_array($Res,0);
00126
00127 return $r['sum_deb']-$r['sum_cred'];
00128 }
00129 ?>