noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_gl_pdf.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 require_once('class_pdf.php');
00034 
00035 
00036 $gDossier=dossier::id();
00037 
00038 /* Security */
00039 $cn=new Database($gDossier);
00040 $g_user->Check();
00041 $g_user->check_dossier($gDossier);
00042 
00043 $sql="select pcm_val from tmp_pcmn ";
00044 
00045 extract($_GET);
00046 $cond_poste="";
00047 if ($from_poste != '')
00048   {
00049     $cond_poste = '  where ';
00050     $cond_poste .=' pcm_val >= upper (\''.Database::escape_string($from_poste).'\')';
00051   }
00052 
00053 if ( $to_poste != '')
00054   {
00055     if  ( $cond_poste == '')
00056       {
00057         $cond_poste =  ' where pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
00058       }
00059     else
00060       {
00061         $cond_poste.=' and pcm_val <= upper (\''.Database::escape_string($to_poste).'\')';
00062       }
00063   }
00064 
00065 $sql=$sql.$cond_poste.'  order by pcm_val::text';
00066 $a_poste=$cn->get_array($sql);
00067 
00068 $pdf = new PDF($cn);
00069 $pdf->setDossierInfo("  Periode : ".$from_periode." - ".$to_periode);
00070 $pdf->AliasNbPages();
00071 $pdf->AddPage();
00072 $pdf->setTitle("Grand Livre",true);
00073 $pdf->SetAuthor('NOALYSS');
00074 
00075 if ( count($a_poste) == 0 )
00076 {
00077     $pdf->Output();
00078     return;
00079 }
00080 
00081 // Header
00082 $header = array( "Date", "Référence", "Libellé", "Pièce","Let", "Débit", "Crédit", "Solde" );
00083 // Left or Right aligned
00084 $lor    = array( "L"   , "L"        , "L"      , "L"    , "R",   "R"    , "R"     , "R"     );
00085 // Column widths (in mm)
00086 $width  = array( 13    , 20         , 60       , 15     ,  12     , 20     , 20      , 20      );
00087 $l=(isset($_REQUEST['letter']))?2:0;
00088 $s=(isset($_REQUEST['solded']))?1:0;
00089 
00090 foreach ($a_poste as $poste)
00091 {
00092 
00093   $Poste=new Acc_Account_Ledger($cn,$poste['pcm_val']);
00094 
00095 
00096   $array1=$Poste->get_row_date($from_periode,$to_periode,$l,$s);
00097   // don't print empty account
00098   if ( count($array1) == 0 )
00099     {
00100         continue;
00101     }
00102   $array=$array1[0];
00103   $tot_deb=$array1[1];
00104   $tot_cred=$array1[2];
00105 
00106     $pdf->SetFont('DejaVuCond','',10);
00107     $Libelle=sprintf("%s - %s ",$Poste->id,$Poste->get_name());
00108     $pdf->Cell(0, 7, $Libelle, 1, 1, 'C');
00109 
00110     $pdf->SetFont('DejaVuCond','',6);
00111     for($i=0;$i<count($header);$i++)
00112         $pdf->Cell($width[$i], 4, $header[$i], 0, 0, $lor[$i]);
00113     $pdf->Ln();
00114 
00115     $pdf->SetFont('DejaVuCond','',7);
00116 
00117 
00118     $solde = 0.0;
00119     $solde_d = 0.0;
00120     $solde_c = 0.0;
00121 
00122     foreach ($Poste->row as $detail)
00123     {
00124 
00125         /*
00126                [0] => 1 [jr_id] => 1
00127                [1] => 01.02.2009 [j_date_fmt] => 01.02.2009
00128                [2] => 2009-02-01 [j_date] => 2009-02-01
00129                [3] => 0 [deb_montant] => 0
00130                [4] => 12211.9100 [cred_montant] => 12211.9100
00131                [5] => Ecriture douverture [description] => Ecriture douverture
00132                [6] => Opération Diverses [jrn_name] => Opération Diverses
00133                [7] => f [j_debit] => f
00134                [8] => 17OD-01-1 [jr_internal] => 17OD-01-1
00135                [9] => ODS1 [jr_pj_number] => ODS1 ) 1
00136          */
00137 
00138         if ($detail['cred_montant'] > 0)
00139         {
00140             $solde   -= $detail['cred_montant'];
00141             $solde_c += $detail['cred_montant'];
00142         }
00143         if ($detail['deb_montant'] > 0)
00144         {
00145             $solde   += $detail['deb_montant'];
00146             $solde_d += $detail['deb_montant'];
00147         }
00148 
00149         $i = 0;
00150                 $side=" ".$Poste->get_amount_side($solde);
00151         $pdf->LongLine($width[$i], 6, shrink_date($detail['j_date_fmt']), 0, $lor[$i]);
00152         $i++;
00153         $pdf->LongLine($width[$i], 6, $detail['jr_internal'], 0, $lor[$i] );
00154         $i++;
00155         /* limit set to 20 for the substring */
00156         $pdf->LongLine($width[$i], 6, mb_substr($detail['description'],0,120), 0,$lor[$i]);
00157         $i++;
00158         $pdf->Cell($width[$i], 6, $detail['jr_pj_number'], 0, 0, $lor[$i]);
00159         $i++;
00160         $pdf->Cell($width[$i], 6, ($detail['letter']!=-1)?$detail['letter']:'', 0, 0, $lor[$i]);
00161         $i++;
00162         $pdf->Cell($width[$i], 6, ($detail['deb_montant']  > 0 ? nbm( $detail['deb_montant'])  : ''), 0, 0, $lor[$i]);
00163         $i++;
00164         $pdf->Cell($width[$i], 6, ($detail['cred_montant'] > 0 ? nbm( $detail['cred_montant']) : ''), 0, 0, $lor[$i]);
00165         $i++;
00166         $pdf->Cell($width[$i], 6, nbm(abs( $solde)).$side, 0, 0, $lor[$i]);
00167         $i++;
00168         $pdf->Ln();
00169 
00170     }
00171 
00172 
00173     $pdf->SetFont('DejaVuCond','B',8);
00174 
00175     $i = 0;
00176     $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00177     $i++;
00178     $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00179     $i++;
00180     $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00181     $i++;
00182     $pdf->Cell($width[$i], 6, '', 0, 0, $lor[$i]);
00183     $i++;
00184     $pdf->Cell($width[$i], 6, 'Total du compte '.$Poste->id, 0, 0, 'R');
00185     $i++;
00186     $pdf->Cell($width[$i], 6, ($solde_d  > 0 ? nbm($solde_d)  : ''), 0, 0, $lor[$i]);
00187     $i++;
00188     $pdf->Cell($width[$i], 6, ($solde_c  > 0 ? nbm( $solde_c)  : ''), 0, 0, $lor[$i]);
00189     $i++;
00190     $pdf->Cell($width[$i], 6, nbm(abs($solde_c-$solde_d)), 0, 0, $lor[$i]);
00191     $i++;
00192     $pdf->Cell(5, 6, ($solde_c > $solde_d ? 'C' : 'D'), 0, 0, 'L');
00193 
00194     $pdf->Ln();
00195     $pdf->Ln();
00196 
00197 }
00198 //Save PDF to file
00199 $pdf->Output("gl_comptes.pdf", 'D');
00200 exit;
00201 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations