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

class_jrn.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.8 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00024 class jrn {
00025   var $id;
00026   var $name;
00027   var $db;
00028   var $row;
00029   function jrn ($p_cn,$p_id){
00030     $this->id=$p_id;
00031     $this->db=$p_cn;
00032     $this->row=null;
00033   }
00034   function GetName() {
00035     if ( $this->id==0 ) {
00036       $this->name=" Grand Livre ";
00037       return $this->name;
00038     }
00039 
00040     $Res=ExecSql($this->db,"select jrn_def_name from ".
00041                " jrn_def where jrn_def_id=".
00042                $this->id);
00043     $Max=pg_NumRows($Res);
00044     if ($Max==0) return null;
00045     $ret=pg_fetch_array($Res,0);
00046     $this->name=$ret['jrn_def_name'];
00047     return $ret['jrn_def_name'];
00048   }
00049 
00065   function GetRow($p_from,$p_to,$cent='off',$p_limit=-1,$p_offset=-1) {
00066 
00067   echo_debug('class_jrn.php',__LINE__,"GetRow ( $p_from,$p_to,$cent,$p_limit,$p_offset)");
00068 
00069     if ( $p_from == $p_to ) 
00070       $periode=" jr_tech_per = $p_from ";
00071     else
00072       $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
00073     $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
00074 
00075     // Grand livre == 0
00076     if ( $this->id != 0 ) {
00077 
00078       if ( $cent=='off' ) {
00079         echo_debug('class_jrn.php',__LINE__,"journaux non  centralisé");
00080         // Journaux non centralisés
00081         $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
00082                       jr_internal,
00083                 case j_debit when 't' then j_montant::text else '   ' end as deb_montant,
00084                 case j_debit when 'f' then j_montant::text else '   ' end as cred_montant,
00085                 j_debit as debit,j_poste as poste,jr_montant , ".
00086                "pcm_lib as description,j_grpt as grp,jr_comment||' ('||jr_internal||')' as jr_comment ,
00087                 jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ".
00088                  "jr_grpt_id=j_grpt ".
00089                  " left join tmp_pcmn on pcm_val=j_poste ".
00090                  " where j_jrn_def=".$this->id.
00091                " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ".
00092                  $cond_limite);
00093     }else {
00094       // Journaux centralisés
00095       echo_debug('class_jrn.php',__LINE__,"journaux centralisé");
00096       $Sql="select jr_opid as j_id,
00097                     c_order as int_j_id,
00098             to_char (c_date,'DD.MM.YYYY') as j_date ,
00099             c_internal as jr_internal,
00100             case c_debit when 't' then c_montant::text else '   ' end as deb_montant,
00101             case c_debit when 'f' then c_montant::text else '   ' end as cred_montant,
00102             c_debit as j_debit,
00103             c_poste as poste,
00104             pcm_lib as description,
00105             jr_comment||' ('||c_internal||')' as jr_comment,
00106             jr_montant,
00107             c_grp as grp,
00108             c_comment as comment,
00109             c_rapt as oc,
00110             c_periode as periode 
00111             from centralized left join jrn on ".
00112                 "jr_grpt_id=c_grp left join tmp_pcmn on pcm_val=c_poste where ".
00113                 " c_jrn_def=".$this->id." and ".
00114                 $periode." order by c_order ";
00115       $Res=ExecSql($this->db,$Sql.$cond_limite);
00116 
00117     }
00118   } else {
00119     // Grand Livre
00120     if ( $cent == 'off') {
00121       echo_debug('class_jrn.php',__LINE__,"Grand livre non centralisé");
00122       // Non centralisé
00123       $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date,
00124                       jr_internal,
00125                 case j_debit when 't' then j_montant::text else '   ' end as deb_montant,
00126                 case j_debit when 'f' then j_montant::text else '   ' end as cred_montant,
00127                 j_debit as debit,j_poste as poste,".
00128                "pcm_lib as description,j_grpt as grp,
00129                 jr_comment||' ('||jr_internal||')' as jr_comment,
00130                 jr_montant,
00131                 jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ".
00132                  "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ".
00133                "  ".$periode." order by j_date::date,j_grpt,j_debit desc   ".
00134                $cond_limite);
00135 
00136     } else {
00137       echo_debug('class_jrn.php',__LINE__,"Grand livre  centralisé");
00138       // Centralisé
00139       $Sql="select jr_c_opid as j_id,
00140                    c_order as int_j_id,
00141 
00142             c_j_id,
00143             to_char (c_date,'DD.MM.YYYY') as j_date ,
00144             c_internal as jr_internal,
00145             case c_debit when 't' then c_montant::text else '   ' end as deb_montant,
00146             case c_debit when 'f' then c_montant::text else '   ' end as cred_montant,
00147             c_debit as j_debit,
00148             c_poste as poste,
00149             pcm_lib as description,
00150             jr_comment||' ('||c_internal||')' as jr_comment,
00151             jr_montant,
00152             c_grp as grp,
00153             c_comment||' ('||c_internal||')' as comment,
00154             c_rapt as oc,
00155             c_periode as periode 
00156             from centralized left join jrn on ".
00157                 "jr_grpt_id=c_grp left join tmp_pcmn on pcm_val=c_poste where ".
00158                 $periode." order by c_order ";
00159     $Res=ExecSql($this->db,$Sql.$cond_limite);
00160     } // Grand Livre
00161   }
00162 
00163 
00164   $array=array();
00165   $Max=pg_NumRows($Res);
00166   if ($Max==0) return null;
00167   $case="";
00168   $tot_deb=0;
00169   $tot_cred=0;
00170   for ($i=0;$i<$Max;$i++) {
00171     $line=pg_fetch_array($Res,$i);
00172     $mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):"";
00173     $mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):"";
00174     $jr_montant=($line['jr_montant']!=0)?sprintf("% 8.2f",$line['jr_montant']):"";
00175     $tot_deb+=$line['deb_montant'];
00176     $tot_cred+=$line['cred_montant'];
00177     echo_debug('class_jrn.php',__LINE__," GetRow : mont_Deb ".$mont_deb);
00178     echo_debug('class_jrn.php',__LINE__," GetRow : mont_cred ".$mont_cred);
00179 
00180     if ( $case != $line['grp'] ) {
00181       $case=$line['grp'];
00182       $array[]=array (
00183                       'int_j_id' => $line['int_j_id'],
00184                       'j_id'=>$line['j_id'],
00185                       'j_date' => $line['j_date'],
00186                       'internal'=>$line['jr_internal'],
00187                       'deb_montant'=>'',
00188                       'cred_montant'=>'<b><i>'.$jr_montant.'</i></b>',
00189                       'description'=>'<b><i>'.$line['jr_comment'].'</i></b>',
00190                       'poste' => $line['oc'],
00191                       'periode' =>$line['periode'] );
00192 
00193       $array[]=array (
00194                       'int_j_id' => $line['int_j_id'],
00195                       'j_id'=>'', 
00196                       'j_date' => '',
00197                       'internal'=>'',
00198                       'deb_montant'=>$mont_deb,
00199                       'cred_montant'=>$mont_cred,
00200                       'description'=>$line['description'],
00201                       'poste' => $line['poste'],
00202                       'periode' => $line['periode']
00203                       );
00204     
00205     }else {
00206       $array[]=array (
00207                       'int_j_id' => $line['int_j_id'],
00208                       'j_id'=>'',
00209                       'j_date' => '',
00210                       'internal'=>'',
00211                       'deb_montant'=>$mont_deb,
00212                       'cred_montant'=>$mont_cred,
00213                       'description'=>$line['description'],
00214                       'poste' => $line['poste'],
00215                       'periode' => $line['periode']);
00216 
00217     }
00218       
00219 
00220   }
00221   echo_debug('class_jrn.php',__LINE__,"Total debit $tot_deb,credit $tot_cred");
00222   $this->row=$array;
00223   $a=array($array,$tot_deb,$tot_cred);
00224   return $a;
00225   }
00243   function GetRowSimple($p_from,$p_to,$cent='off',$p_limit=-1,$p_offset=-1) 
00244   {
00245     
00246     echo_debug('class_jrn.php',__LINE__,"GetRowSimple ( $p_from,$p_to,$cent,$p_limit,$p_offset)");
00247     // Periode check
00248     //---
00249     if ( $p_from == $p_to ) 
00250       $periode=" jr_tech_per = $p_from ";
00251     else
00252       $periode = "(jr_tech_per >= $p_from and jr_tech_per <= $p_to) ";
00253     $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:"";
00254     // Grand-livre : id= 0
00255     //---
00256     $jrn=($this->id == 0 )?"":"and jrn_def_id = ".$this->id;
00257     // Non Centralise si cent=off
00258     //--
00259     if ($cent=='off') 
00260       {// Non centralisé
00261         //---
00262         $sql=" 
00263     SELECT jrn.jr_id as jr_id ,
00264            jrn.jr_id as num , 
00265            jrn.jr_def_id as jr_def_id, 
00266            jrn.jr_montant as montant, 
00267            jrn.jr_comment as comment, 
00268            to_char(jrn.jr_date,'DD-MM-YYYY') as date, 
00269            jr_internal,
00270            jrn.jr_grpt_id as grpt_id, 
00271            jrn.jr_pj_name as pj,
00272             jrn_def_type
00273    FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
00274 where $periode $jrn order by jr_date";
00275 
00276 
00277         
00278       } 
00279     else 
00280       {
00281         //Centralisé
00282         //---
00283         $id=($this->id == 0 ) ?"jr_c_opid as num":"jr_opid as num";
00284         $sql="
00285     SELECT jrn.jr_id as jr_id ,
00286            $id , 
00287            jrn.jr_def_id as jr_def_id, 
00288            jrn.jr_montant as montant, 
00289            jrn.jr_comment as comment, 
00290            to_char(jrn.jr_date,'DD-MM-YYYY') as date, 
00291            jr_internal,
00292            jrn.jr_grpt_id as grpt_id, 
00293            jrn.jr_pj_name as pj,
00294             jrn_def_type
00295    FROM jrn join jrn_def on (jrn_def_id=jr_def_id)
00296        where 
00297          $periode $jrn and 
00298          jr_opid is not null
00299          order by jr_date";
00300       }// end else $cent=='off'
00301     //load all data into an array
00302     //---
00303     $Res=ExecSql($this->db,$sql);
00304     if ( pg_NumRows($Res) == 0 ) 
00305       {
00306         return null;
00307       } 
00308 
00309 
00310     $array=pg_fetch_all($Res); 
00311 
00312     return $array;  
00313   }// end function GetRowSimple
00314 
00321 function GetDefLine() 
00322 {
00323         $sql_cred='jrn_deb_max_line';
00324         $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=".$this->id;
00325         $r=ExecSql($this->db,$sql);
00326         $Res=pg_fetch_all($r);
00327         echo_debug('class_jrn',__LINE__,$Res);
00328         if ( sizeof($Res) == 0 ) return 1;
00329         return $Res[0]['value'];
00330 }
00331 }