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

jrn_csv.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.12 $ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00025 header('Content-type: application/csv');
00026 header('Content-Disposition: attachment;filename="jrn.csv"',FALSE);
00027 include_once ("ac_common.php");
00028 
00029 include_once ("postgres.php");
00030 include_once("check_priv.php");
00031 include("class_jrn.php");
00032 $cn=DbConnect($_SESSION['g_dossier']);
00033 $rep=DbConnect();
00034 
00035 include ('class_user.php');
00036 $User=new cl_user($rep);
00037 $User->Check();
00038 if ( $User->CheckAction($cn,IMP) == 0 ||
00039      $User->AccessJrn($cn,$_GET['jrn_id']) == false){
00040     /* Cannot Access */
00041     NoAccess();
00042   }
00043 
00044 
00045  $p_cent=( isset ( $_GET['central']) )?$_GET['central']:'off';
00046 
00047 $Jrn=new jrn($cn,$_GET['jrn_id']);
00048 
00049 $Jrn->GetName();
00050 // Detailled printing
00051 //---
00052 if  ( $_GET['p_simple'] == 0 ) 
00053   {
00054     $Jrn->GetRow( $_GET['from_periode'],
00055                   $_GET['to_periode'],
00056                   $p_cent);
00057 
00058     if ( count($Jrn->row) == 0) 
00059       exit;
00060     foreach ( $Jrn->row as $op ) { 
00061       // should clean description : remove <b><i> tag and '; char
00062       $desc=$op['description'];
00063       $desc=str_replace("<b>","",$desc);
00064       $desc=str_replace("</b>","",$desc);
00065       $desc=str_replace("<i>","",$desc);
00066       $desc=str_replace("</i>","",$desc);
00067       $desc=str_replace('"',"'",$desc);
00068 
00069       printf("\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t\"%s\"\t%8.4f\t%8.4f\n",
00070              $op['j_id'],
00071              $op['internal'],
00072              $op['j_date'],
00073              $op['poste'],
00074              $desc,
00075              $op['cred_montant'],
00076              $op['deb_montant']
00077              );
00078         
00079     }
00080     exit;
00081   }
00082  else 
00083    {
00084      $Row=$Jrn->GetRowSimple($_GET['from_periode'],
00085                              $_GET['to_periode'],
00086                              $p_cent);
00087 //-----------------------------------------------------
00088      printf ('" operation "'.
00089              '"Date"'.
00090              '"commentaire"'.
00091              '"internal"'.
00092              '"montant"');
00093 
00094       foreach ($Row as $line)
00095         {
00096           echo $line['num'].";";
00097           echo $line['date'].";";
00098           echo $line['comment'].";";
00099           echo $line['jr_internal'].";";
00100           //      echo "<TD>".$line['pj'].";";
00101         // If the ledger is financial :
00102         // the credit must be negative and written in red
00103         // Get the jrn type
00104         if ( $line['jrn_def_type'] == 'FIN' ) {
00105           $positive = CountSql($cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
00106                    " where jr_id=".$line['jr_id']." and (j_poste like '55%' or j_poste like '57%' )".
00107                                " and j_debit='f'");
00108         
00109 
00110         echo ( $positive != 0 )?sprintf("-%8.2f",$line['montant']):sprintf("%8.2f",$line['montant']);
00111         echo ";";
00112         }
00113         else 
00114           {
00115             printf("% 8.2f",$line['montant']).";";
00116           }
00117 
00118         printf("\r\n");
00119         }
00120       
00121 //-----------------------------------------------------
00122    }
00123 ?>