00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00028 class poste {
00029 var $db;
00030 var $id;
00031 var $row;
00032 function poste($p_cn,$p_id) {
00033 $this->db=$p_cn;
00034 $this->id=$p_id;
00035 }
00036
00046 function GetRow($p_from,$p_to)
00047 {
00048 if ( $p_from == $p_to )
00049 $periode=" jr_tech_per = $p_from ";
00050 else
00051 $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
00052
00053 $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,".
00054 "case when j_debit='t' then j_montant else 0 end as deb_montant,".
00055 "case when j_debit='f' then j_montant else 0 end as cred_montant,".
00056 " jr_comment as description,jrn_def_name as jrn_name,".
00057 "j_debit, jr_internal ".
00058 " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
00059 " left join jrn on jr_grpt_id=j_grpt".
00060 " where j_poste=".$this->id." and ".$periode.
00061 " order by j_date::date");
00062 $array=array();
00063 $tot_cred=0.0;
00064 $tot_deb=0.0;
00065 $Max=pg_NumRows($Res);
00066 if ( $Max == 0 ) return null;
00067 for ($i=0;$i<$Max;$i++) {
00068 $array[]=pg_fetch_array($Res,$i);
00069 if ($array[$i]['j_debit']=='t') {
00070 $tot_deb+=$array[$i]['deb_montant'] ;
00071 } else {
00072 $tot_cred+=$array[$i]['cred_montant'] ;
00073 }
00074 }
00075 $this->row=$array;
00076 return array($array,$tot_deb,$tot_cred);
00077 }
00080 function GetName() {
00081 $ret=pg_exec($this->db,
00082 "select pcm_lib from tmp_pcmn where
00083 pcm_val=".$this->id);
00084 if ( pg_NumRows($ret) != 0) {
00085 $r=pg_fetch_array($ret);
00086 $this->name=$r['pcm_lib'];
00087 } else {
00088 $this->name="Poste inconnu";
00089 }
00090 return $this->name;
00091 }
00099 function GetSolde($p_cond="") {
00100 $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from
00101 ( select j_poste,
00102 case when j_debit='t' then j_montant else 0 end as deb,
00103 case when j_debit='f' then j_montant else 0 end as cred
00104 from jrnx join tmp_pcmn on j_poste=pcm_val
00105 where
00106 j_poste like ('$this->id'::text) and
00107 $p_cond
00108 ) as m ");
00109 $Max=pg_NumRows($Res);
00110 if ($Max==0) return 0;
00111 $r=pg_fetch_array($Res,0);
00112
00113 return abs($r['sum_deb']-$r['sum_cred']);
00114 }
00121 function GetSoldeDetail($p_cond="") {
00122 if ( $p_cond != "") $p_cond=" and ".$p_cond;
00123 $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from
00124 ( select j_poste,
00125 case when j_debit='t' then j_montant else 0 end as deb,
00126 case when j_debit='f' then j_montant else 0 end as cred
00127 from jrnx join tmp_pcmn on j_poste=pcm_val
00128 where
00129 j_poste like ('$this->id'::text)
00130 $p_cond
00131 ) as m ");
00132 $Max=pg_NumRows($Res);
00133 if ($Max==0) return 0;
00134 $r=pg_fetch_array($Res,0);
00135
00136 return array('debit'=>$r['sum_deb'],
00137 'credit'=>$r['sum_cred'],
00138 'solde'=>abs($r['sum_deb']-$r['sum_cred']));
00139 }
00140 }