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 bcscale(2);
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           '"Code journal";'.
00066           '"Nom journal";'.
00067           '"Lib.";'.
00068         "\"Code interne\";".
00069         "\"Date\";".
00070         "\"Description\";".
00071         "\"Débit\";".
00072         "\"Crédit\";".
00073         "\"Prog.\";".
00074                 "\"Let.\"";
00075         printf("\n");
00076 
00077         $prog=0;
00078         $current_exercice="";
00079         $tot_cred=0;
00080         $tot_deb=0;
00081         $diff=0;
00082         foreach ( $Poste->row as $op )
00083         {
00084            /*
00085              * separation per exercice
00086              */
00087             if ( $current_exercice == "") $current_exercice=$op['p_exercice'];
00088             
00089             if ( $current_exercice != $op['p_exercice']) {
00090                 $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
00091                 $diff=abs($tot_deb-$tot_cred);
00092                 printf(
00093                      ";;;".
00094                      '"'._('total').'";'.
00095                      '"'.$current_exercice.'";'.
00096                 '"'."$solde_type".'"'.";".
00097                 nb($tot_deb).";".
00098                 nb($tot_cred).";".
00099                 nb($diff).";"."\n");
00100                 /*
00101                 * reset total and current_exercice
00102                 */
00103                 $prog=0;
00104                 $current_exercice=$op['p_exercice'];
00105                 $tot_deb=0;$tot_cred=0;    
00106             }
00107           $tot_deb=bcadd($tot_deb,$op['deb_montant']);
00108           $tot_cred=bcadd($tot_cred,$op['cred_montant']);
00109           $diff=bcsub($op['deb_montant'],$op['cred_montant']);
00110           $prog=bcadd($prog,$diff);
00111           echo '"'.$pos['pcm_val'].'";'.
00112             '"'.$op['jr_pj_number'].'"'.";".
00113             '"'.$op['jrn_def_code'].'"'.";".
00114             '"'.$op['jrn_def_name'].'"'.";".
00115             '"'.$name.'";'.
00116             '"'.$op['jr_internal'].'"'.";".
00117             '"'.$op['j_date_fmt'].'"'.";".
00118             '"'.$op['description'].'";'.
00119             nb($op['deb_montant']).";".
00120             nb($op['cred_montant']).";".
00121             nb(abs($prog)).";".
00122                         (($op['letter']!=-1)?strtoupper(base_convert($op['letter'],10,36)):"");
00123             printf("\n");
00124 
00125 
00126         }
00127         $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur";
00128         $diff=abs($tot_deb-$tot_cred);
00129        printf(
00130                          ";;;".
00131                          '"'._('total').'";'.
00132                          '"'.$current_exercice.'";'.
00133             '"'."$solde_type".'"'.";".
00134             nb($tot_deb).";".
00135             nb($tot_cred).";".
00136             nb($diff).";"."\n");
00137     }
00138 }
00139 else
00140 {
00141     /* detail of all operation */
00142     if ( count($a_poste) == 0 )
00143         exit;
00144 
00145     foreach ($a_poste as $pos)
00146     {
00147         $Poste=new Acc_Account_Ledger($cn,$pos['pcm_val']);
00148         $Poste->get_name();
00149         list($array,$tot_deb,$tot_cred)=$Poste->get_row_date( $_REQUEST['from_periode'],
00150                                         $_REQUEST['to_periode'],
00151                                                                               $_GET['ople']
00152                                                             );
00153         if ( count($Poste->row ) == 0 )
00154             continue;
00155 
00156         echo '"Poste";'.
00157         '"Lib.";'.
00158         '"QuickCode";'.
00159         "\"Code interne\";".
00160         "\"Date\";".
00161         "\"Description\";".
00162         "\"Montant\";".
00163         "\"D/C\"";
00164         printf("\n");
00165 
00166 
00167         foreach ( $Poste->row as $a )
00168         {
00169             $op=new Acc_Operation($cn);
00170             $op->jr_id=$a['jr_id'];
00171             $result=$op->get_jrnx_detail();
00172             foreach ( $result as $r)
00173             {
00174                 printf('"%s";"%s";"%s";"%s";"%s";"%s";"%s";%12.2f;"%s"',
00175                        $r['j_poste'],
00176                        $r['pcm_lib'],
00177                        $r['j_qcode'],
00178                        $r['jr_internal'],
00179                        $r['jr_date'],
00180                        $a['description'],
00181                        $a['jr_pj_number'],
00182                        nb($r['j_montant']),
00183                        $r['debit']);
00184                 printf("\r\n");
00185 
00186             }
00187 
00188 
00189 
00190         }
00191     }
00192     exit;
00193 }
00194 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations