Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

class_poste.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision: 1.7 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00028 class poste {
00029   var $db;          
00030   var $id;          
00031   var $label;       
00032   var $parent;      
00033   var $row;         
00034   function poste($p_cn,$p_id) {
00035     $this->db=$p_cn;
00036     $this->id=$p_id;
00037   }
00038 
00048   function GetRow($p_from,$p_to)
00049     {
00050       if ( $p_from == $p_to ) 
00051         $periode=" jr_tech_per = $p_from ";
00052       else
00053         $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
00054       
00055       $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,".
00056                "case when j_debit='t' then j_montant else 0 end as deb_montant,".
00057                "case when j_debit='f' then j_montant else 0 end as cred_montant,".
00058                " jr_comment as description,jrn_def_name as jrn_name,".
00059                "j_debit, jr_internal ".
00060                " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ".
00061                " left join jrn on jr_grpt_id=j_grpt".
00062                " where j_poste=".$this->id." and ".$periode.
00063                " order by j_date::date");
00064       $array=array();
00065       $tot_cred=0.0;
00066       $tot_deb=0.0;
00067       $Max=pg_NumRows($Res);
00068       if ( $Max == 0 ) return null;
00069       for ($i=0;$i<$Max;$i++) {
00070         $array[]=pg_fetch_array($Res,$i);
00071         if ($array[$i]['j_debit']=='t') {
00072           $tot_deb+=$array[$i]['deb_montant'] ;
00073         } else {
00074           $tot_cred+=$array[$i]['cred_montant'] ;
00075         }
00076       }
00077       $this->row=$array;
00078   return array($array,$tot_deb,$tot_cred);
00079 }
00084   function GetName() {
00085     $ret=pg_exec($this->db,
00086                  "select pcm_lib from tmp_pcmn where
00087                   pcm_val=".$this->id);
00088       if ( pg_NumRows($ret) != 0) {
00089         $r=pg_fetch_array($ret);
00090         $this->name=$r['pcm_lib'];
00091       } else {
00092         $this->name="Poste inconnu";
00093       }
00094     return $this->name;
00095   }
00100   function get()
00101     {
00102       $ret=ExecSql($this->db,"select pcm_lib,pcm_val_parent from 
00103                               tmp_pcmn where pcm_val=".$this->id);
00104       $r=pg_fetch_all($ret);
00105 
00106       if ( ! $r ) return false;
00107       $this->label=$r[0]['pcm_lib'];
00108       $this->parent=$r[0]['pcm_val_parent'];
00109       return true;
00110     }
00111          
00119 function GetSolde($p_cond="") {
00120   $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from 
00121           ( select j_poste, 
00122              case when j_debit='t' then j_montant else 0 end as deb, 
00123              case when j_debit='f' then j_montant else 0 end as cred 
00124           from jrnx join tmp_pcmn on j_poste=pcm_val 
00125               where  
00126             j_poste like ('$this->id'::text) and
00127             $p_cond
00128           ) as m  ");
00129   $Max=pg_NumRows($Res);
00130   if ($Max==0) return 0;
00131   $r=pg_fetch_array($Res,0);
00132   
00133   return abs($r['sum_deb']-$r['sum_cred']);
00134 }
00141 function GetSoldeDetail($p_cond="") {
00142         if ( $p_cond != "") $p_cond=" and ".$p_cond;
00143   $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from 
00144           ( select j_poste, 
00145              case when j_debit='t' then j_montant else 0 end as deb, 
00146              case when j_debit='f' then j_montant else 0 end as cred 
00147           from jrnx join tmp_pcmn on j_poste=pcm_val 
00148               where  
00149             j_poste like ('$this->id'::text)
00150             $p_cond
00151           ) as m  ");
00152   $Max=pg_NumRows($Res);
00153   if ($Max==0) return 0;
00154   $r=pg_fetch_array($Res,0);
00155   
00156   return array('debit'=>$r['sum_deb'],
00157                'credit'=>$r['sum_cred'],
00158                'solde'=>abs($r['sum_deb']-$r['sum_cred']));
00159 }
00160 }