noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_poste_detail_csv.php
Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of NOALYSS.
00004  *
00005  *   NOALYSS 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  *   NOALYSS 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 NOALYSS; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00020 /*! \file
00021  * \brief Send the poste list in csv
00022  */
00023 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00024 include_once("ac_common.php");
00025 require_once('class_database.php');
00026 require_once("class_acc_account_ledger.php");
00027 require_once ('class_acc_operation.php');
00028 $fDate=date('dmy-Hi');
00029 header('Pragma: public');
00030 header('Content-type: application/csv');
00031 header('Content-Disposition: attachment;filename="poste-'.$fDate.'-'.$_REQUEST['poste_id'].'.csv"',FALSE);
00032 require_once('class_dossier.php');
00033 $gDossier=dossier::id();
00034 
00035 /* Admin. Dossier */
00036 $cn=new Database($gDossier);
00037 
00038 if ( isset ( $_REQUEST['poste_fille']) )
00039 { //choisit de voir tous les postes
00040   $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like $1||'%'",array($_REQUEST["poste_id"]));
00041 }
00042 else
00043 {
00044   $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val = $1",array($_REQUEST['poste_id']));
00045 }
00046 
00047 if ( ! isset ($_REQUEST['oper_detail']))
00048 {
00049     if ( count($a_poste) == 0 )
00050         exit;
00051 
00052     foreach ($a_poste as $pos)
00053     {
00054         $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
00055         $name=$Poste->get_name();
00056         list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
00057                                                               $_REQUEST['to_periode'],
00058                                                               $_GET['ople']
00059                                                               );
00060         if ( count($Poste->row ) == 0 )
00061             continue;
00062 
00063         echo '"Poste";'.
00064           '"n° pièce";'.
00065           '"Lib.";'.
00066         "\"Code interne\";".
00067         "\"Date\";".
00068         "\"Description\";".
00069         "\"Débit\";".
00070         "\"Crédit\";".
00071         "\"Prog.\";".
00072                 "\"Let.\"";
00073         printf("\n");
00074 
00075         $prog=0;
00076         foreach ( $Poste->row as $op )
00077         {
00078           $diff=bcsub($op['deb_montant'],$op['cred_montant']);
00079           $prog=bcadd($prog,$diff);
00080           echo '"'.$pos['pcm_val'].'";'.
00081             '"'.$op['jr_pj_number'].'"'.";".
00082             '"'.$name.'";'.
00083             '"'.$op['jr_internal'].'"'.";".
00084             '"'.$op['j_date_fmt'].'"'.";".
00085             '"'.$op['description'].'";'.
00086             nb($op['deb_montant']).";".
00087             nb($op['cred_montant']).";".
00088             nb(abs($prog)).";".
00089                         (($op['letter']!=-1)?strtoupper(base_convert($op['letter'],10,36)):"");
00090             printf("\n");
00091 
00092 
00093         }
00094         $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
00095         $diff=abs($tot_deb-$tot_cred);
00096         printf(
00097             '"'."$solde_type".'"'.";".
00098             nb($diff).";".
00099             nb($tot_deb).";".
00100             nb($tot_cred)."\n");
00101     }
00102 }
00103 else
00104 {
00105     /* detail of all operation */
00106     if ( count($a_poste) == 0 )
00107         exit;
00108 
00109     foreach ($a_poste as $pos)
00110     {
00111         $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
00112         $Poste->get_name();
00113         list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
00114                                         $_REQUEST['to_periode'],
00115                                                                               $_GET['ople']
00116                                                             );
00117         if ( count($Poste->row ) == 0 )
00118             continue;
00119 
00120         echo '"Poste";'.
00121         '"Lib.";'.
00122         '"QuickCode";'.
00123         "\"Code interne\";".
00124         "\"Date\";".
00125         "\"Description\";".
00126         "\"Montant\";".
00127         "\"D/C\"";
00128         printf("\n");
00129 
00130 
00131         foreach ( $Poste->row as $a )
00132         {
00133             $op=new Acc_Operation($cn);
00134             $op->jr_id=$a['jr_id'];
00135             $result=$op->get_jrnx_detail();
00136             foreach ( $result as $r)
00137             {
00138                 printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
00139                        $r['j_poste'],
00140                        $r['pcm_lib'],
00141                        $r['j_qcode'],
00142                        $r['jr_internal'],
00143                        $r['jr_date'],
00144                        $a['description'],
00145                        $a['jr_pj_number'],
00146                        nb($r['j_montant']),
00147                        $r['debit']);
00148                 printf("\r\n");
00149 
00150             }
00151 
00152 
00153 
00154         }
00155     }
00156     exit;
00157 }
00158 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations