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

export_ouv.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.6 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00025 include_once ("ac_common.php");
00026 require_once("class_poste.php");
00027 header('Content-type: application/csv');
00028 header('Content-Disposition: attachment;filename="export_ouv.csv"',FALSE);
00029 if ( ! isset ( $_SESSION['g_dossier'] ) ) {
00030   echo "You must choose a Dossier ";
00031   exit -2;
00032 }
00033 include_once ("postgres.php");
00034 /* Admin. Dossier */
00035 $rep=DbConnect();
00036 include_once ("class_user.php");
00037 $User=new cl_user($rep);
00038 $User->Check();
00039 
00040 include_once ("check_priv.php");
00041 
00042 include_once ("user_menu.php");
00043 
00044 $cn=DbConnect($_SESSION['g_dossier']);
00045 // TODO : add a check for permission
00046 if ( $User->CheckAction($cn,EXP_IMP_ECR) == 0 ) {
00047   /* Cannot Access */
00048   NoAccess();
00049   exit -1;                      
00050  }
00051 if ( !isset ($_GET['p_periode'])) {
00052         echo 'Erreur : aucune periode demandée';
00053         exit(0);
00054 }
00055 $sql_from=GetArray($cn,"select min(p_id) from parm_periode where p_exercice=".$_GET['p_periode']);
00056 
00057 $sql_to=GetArray($cn,"select max(p_id) from parm_periode where p_exercice=".$_GET['p_periode']);
00058 
00059 $ret=GetArray($cn,"select distinct j_poste::text 
00060                 from jrnx inner join tmp_pcmn on (pcm_val=j_poste)
00061                 where 
00062                 j_tech_per >= ".$sql_from[0]['min']." and 
00063                 j_tech_per <= ".$sql_to[0]['max']." and j_poste not like '7%'
00064                 and j_poste not like '6%'
00065                  order by j_poste::text");
00066 if ( $ret == null ) {echo 'Rien à exporter'; exit();}
00067 printf ("OUVERTURE\n");
00068 // check if the account are balanced 
00069 $sum=0;
00070 foreach ($ret as $poste_id) {
00071 
00072         $Poste=new poste($cn,$poste_id['j_poste']);
00073         // fill the object
00074         $Poste->get();
00075         // build sql stmt
00076         $sql="j_tech_per >=". $sql_from[0]['min']." and j_tech_per <=".$sql_to[0]['max'];
00077         $result=$Poste->GetSoldeDetail($sql );
00078         $Poste->label=str_replace(';','',$Poste->label);
00079         
00080         if ( $result['solde'] == 0 ) continue;
00081         if ( $result['debit'] > $result ['credit'] ) {
00082                 printf ("d;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
00083                 $sum+=$result['solde'];
00084         } else {
00085                 printf ("c;%d;%s;%12.4f\n",$Poste->id,$Poste->label,$result['solde']);
00086                 $sum-=$result['solde'];
00087         }
00088 }
00089 // $sum must be equal to 0 
00090 // $sum > 0 then deb is too big
00091 // $sum < 0 then cred is too big
00092 if ( $sum != 0) 
00093 {
00094   printf("ATTENTION : COMPTE NON EQUILIBRE\n ");
00095   $msg = ($sum > 0)?" Debit plus grand de $sum":"Credit plus grand de $sum";
00096   printf ("DIFFERENCE = $msg \n");
00097  
00098 }
00099 ?>