noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_gl_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 
00020 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00021 
00022 /*! \file
00023  * \brief create GL comptes as PDF
00024  */
00025 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00026 include_once('class_acc_account_ledger.php');
00027 include_once('ac_common.php');
00028 require_once('class_database.php');
00029 include_once('class_impress.php');
00030 require_once('class_own.php');
00031 require_once('class_dossier.php');
00032 require_once('class_user.php');
00033 
00034 header('Content-type: application/csv');
00035 header('Content-Disposition: attachment;filename="gl_comptes.csv"',FALSE);
00036 header('Pragma: public');
00037 
00038 
00039 $gDossier=dossier::id();
00040 
00041 /* Security */
00042 $cn=new Database($gDossier);
00043 
00044 
00045 extract($_GET);
00046 
00047 if ( isset($poste_id) && strlen(trim($poste_id)) != 0 && isNumber($poste_id) )
00048 {
00049     if ( isset ($poste_fille) )
00050     {
00051         $parent=$poste_id;
00052         $a_poste=$cn->get_array("select pcm_val from tmp_pcmn where pcm_val::text like '$parent%' order by pcm_val::text");
00053     }
00054     elseif ( $cn->count_sql('select * from tmp_pcmn where pcm_val='.sql_string($poste_id)) != 0 )
00055     {
00056         $a_poste=array('pcm_val' => $poste_id);
00057     }
00058 }
00059 else
00060 {
00061   $cond_poste='';
00062   $sql="select pcm_val from tmp_pcmn ";
00063     if ($from_poste != '')
00064       {
00065         $cond_poste = '  where ';
00066         $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')';
00067       }
00068 
00069     if ( $to_poste != '')
00070       {
00071         if  ( $cond_poste == '')
00072           {
00073             $cond_poste =  " where pcm_val <= upper (''".Database::escape_string($to_poste)."'')";
00074           }
00075         else
00076           {
00077             $cond_poste.=" and pcm_val <= upper (''".Database::escape_string($to_poste)."'')";
00078           }
00079       }
00080 
00081     $sql=$sql.$cond_poste.'  order by pcm_val::text';
00082 
00083     $a_poste=$cn->get_array($sql);
00084 
00085 }
00086 
00087 if ( count($a_poste) == 0 )
00088 {
00089     echo 'Rien à rapporter.';
00090     printf("\n");
00091     exit;
00092 }
00093 
00094 // Header
00095 $header = array( "Date", "Référence", "Libellé", "Pièce","Lettrage", "Débit", "Crédit", "Solde" );
00096 
00097 $l=(isset($_GET['letter']))?2:0;
00098 $s=(isset($_REQUEST['solded']))?1:0;
00099 
00100 foreach ($a_poste as $poste)
00101 {
00102 
00103 
00104   $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
00105 
00106   $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
00107   // don't print empty account
00108   if ( count($array1) == 0 )
00109     {
00110       continue;
00111     }
00112   $array=$array1[0];
00113   $tot_deb=$array1[1];
00114   $tot_cred=$array1[2];
00115 
00116     // don't print empty account
00117     if ( count($array) == 0 )
00118     {
00119         continue;
00120     }
00121 
00122     echo sprintf("%s - %s ",$Poste->id,$Poste->get_name());
00123     printf("\n");
00124 
00125     for($i=0;$i<count($header);$i++)
00126         echo $header[$i].";";
00127     printf("\n");
00128 
00129     $solde = 0.0;
00130     $solde_d = 0.0;
00131     $solde_c = 0.0;
00132 
00133     foreach ($Poste->row as $detail)
00134     {
00135 
00136         /*
00137                [0] => 1 [jr_id] => 1
00138                [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
00139                [2] => 2009-02-01 [j_date] => 2009-02-01
00140                [3] => 0 [deb_montant] => 0
00141                [4] => 12211.9100 [cred_montant] => 12211.9100
00142                [5] => Ecriture douverture [description] => Ecriture douverture
00143                [6] => Opération Diverses [jrn_name] => Opération Diverses
00144                [7] => f [j_debit] => f
00145                [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
00146                [9] => ODS1 [jr_pj_number] => ODS1 ) 1
00147          */
00148 
00149         if ($detail['cred_montant'] > 0)
00150         {
00151             $solde   -= $detail['cred_montant'];
00152             $solde_c += $detail['cred_montant'];
00153         }
00154         if ($detail['deb_montant'] > 0)
00155         {
00156             $solde   += $detail['deb_montant'];
00157             $solde_d += $detail['deb_montant'];
00158         }
00159 
00160         echo $detail['j_date_fmt'].";";
00161         echo $detail['jr_internal'].";";
00162         echo $detail['description'].";";
00163         echo $detail['jr_pj_number'].";";
00164         if ($detail['letter'] == -1) { echo ';'; } else { echo $detail['letter'].";";}
00165         echo ($detail['deb_montant']  > 0 ? nb($detail['deb_montant'])  : '').";";
00166         echo ($detail['cred_montant'] > 0 ? nb($detail['cred_montant']) : '').";";
00167         echo nb(abs($solde)).";";
00168                 echo $Poste->get_amount_side($solde);
00169         printf("\n");
00170 
00171     }
00172 
00173 
00174     echo ";";
00175     echo ";";
00176     echo ";";
00177     echo ";";
00178     echo 'Total du compte '.$Poste->id.";";
00179     echo ($solde_d  > 0 ? nb($solde_d)  : '').";";
00180     echo ($solde_c  > 0 ? nb( $solde_c)  : '').";";
00181     echo nb(abs($solde_c-$solde_d)).";";
00182     echo ($solde_c > $solde_d ? 'C' : 'D').";";
00183     printf("\n");
00184     printf("\n");
00185 }
00186 
00187 exit;
00188 
00189 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations