noalyss  Version-6.7.2
 All Data Structures Namespaces Files Functions Variables Enumerations
export_balance_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 /*! \file
00020  * \brief Print the balance in pdf format
00021  * \param received parameters
00022  * \param e_date element 01.01.2003
00023  * \param e_client element 3
00024  * \param nb_item element 2
00025  * \param e_march0 element 11
00026  * \param e_quant0 element 1
00027  * \param e_march1 element 6
00028  * \param e_quant1 element 2
00029  * \param e_comment  invoice number
00030  */
00031 // Copyright Author Dany De Bontridder danydb@aevalys.eu
00032 if ( ! defined ('ALLOWED') ) die('Appel direct ne sont pas permis');
00033 include_once("ac_common.php");
00034 require_once('class_database.php');
00035 include_once("class_acc_balance.php");
00036 require_once ('header_print.php');
00037 require_once('class_dossier.php');
00038 require_once('class_pdf.php');
00039 $gDossier=dossier::id();
00040 
00041 $cn=new Database($gDossier);
00042 $rep=new Database();
00043 require_once ('class_user.php');
00044 $g_user->Check();
00045 
00046 $bal=new Acc_Balance($cn);
00047 
00048 extract ($_GET);
00049 $bal->jrn=null;
00050 switch( $_GET['p_filter'])
00051 {
00052 case 0:
00053         $bal->jrn=null;
00054     break;
00055 case 1:
00056     if (  isset($_GET['r_jrn']))
00057     {
00058         $selected=$_GET['r_jrn'];
00059         $array_ledger=$g_user->get_ledger('ALL',3);
00060         $array=get_array_column($array_ledger,'jrn_def_id');
00061         for ($e=0;$e<count($selected);$e++)
00062         {
00063             if (isset ($selected[$e]) && in_array ($selected[$e],$array))
00064                 $bal->jrn[]=$selected[$e];
00065         }
00066     }
00067     break;
00068 case 2:
00069     if ( isset($_GET['r_cat']))   $bal->filter_cat($_GET['r_cat']);
00070     break;
00071 }
00072 
00073 $bal->from_poste=$_GET['from_poste'];
00074 $bal->to_poste=$_GET['to_poste'];
00075 if (isset($_GET['unsold'])) $bal->unsold=true;
00076 $previous=(isset($_GET['previous_exc']))?1:0;
00077   
00078 $array=$bal->get_row($from_periode,$to_periode,$previous);
00079 
00080 $previous= (isset ($array[0]['sum_cred_previous']))?1:0;
00081 
00082 
00083 if ( sizeof($array)  == 0 )
00084 {
00085     exit();
00086 
00087 }
00088 
00089 $pPeriode=new Periode($cn);
00090 $a=$pPeriode->get_date_limit($from_periode);
00091 $b=$pPeriode->get_date_limit($to_periode);
00092 $per_text="  du ".$a['p_start']." au ".$b['p_end'];
00093 if ($previous == 1 ) {
00094     $pdf=new PDFLand($cn);
00095 } else {
00096     $pdf= new PDF($cn);
00097 }
00098 $pdf->setDossierInfo(" Balance  ".$per_text);
00099 $pdf->AliasNbPages();
00100 $pdf->AddPage();
00101 $pdf->SetAuthor('NOALYSS');
00102 $pdf->SetFont('DejaVuCond','',7);
00103 $pdf->setTitle("Balance comptable",true);
00104 $pdf->Cell(30,6,'poste');
00105 $pdf->LongLine(60,6,'Libellé');
00106 if ($previous == 1 ){ 
00107     $pdf->Cell(20,6,'Débit N-1',0,0,'R');
00108     $pdf->Cell(20,6,'Crédit N-1',0,0,'R');
00109     $pdf->Cell(20,6,'Débiteur N-1',0,0,'R');
00110     $pdf->Cell(20,6,'Créditeur N-1',0,0,'R');
00111 }
00112 $pdf->Cell(25,6,'Total Débit',0,0,'R');
00113 $pdf->Cell(25,6,'Total Crédit',0,0,'R');
00114 $pdf->Cell(25,6,'Solde Débiteur',0,0,'R');
00115 $pdf->Cell(25,6,'Solde Créditeur',0,0,'R');
00116 $pdf->Ln();
00117 
00118 $pdf->SetFont('DejaVuCond','',8);
00119 $tp_deb=0;
00120 $tp_cred=0;
00121 $tp_sold=0;
00122 $tp_solc=0;
00123 $tp_deb_previous=0;
00124 $tp_cred_previous=0;
00125 $tp_sold_previous=0;
00126 $tp_solc_previous=0;
00127 if ( $previous == 1) {
00128     $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred','sum_cred_previous','sum_deb_previous','solde_deb_previous','solde_cred_previous');
00129 }
00130 else {
00131     $a_sum=array('sum_cred','sum_deb','solde_deb','solde_cred') ;
00132 }
00133 foreach($a_sum as $a)
00134   {
00135     $nlvl1[$a]=0;
00136     $nlvl2[$a]=0;
00137     $nlvl3[$a]=0;
00138   }
00139 $lvl1_old='';
00140 $lvl2_old='';
00141 $lvl3_old='';
00142 
00143 bcscale(2);
00144 if (! empty($array))
00145   {
00146     $i=0;
00147     foreach ($array as $key=>$value)
00148       {
00149         $i++;
00150         /*
00151          * level x
00152          */
00153         if ( $value['poste']=='') continue;
00154         foreach (array(3,2,1) as $ind)
00155           {
00156             $r=$value;
00157             if ( ! isset($_GET['lvl'.$ind]))continue;
00158 
00159             if (${'lvl'.$ind.'_old'} == '')       ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
00160             if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
00161               {
00162                 $pdf->SetFont('DejaVu','B',7);
00163                 $pdf->LongLine(30,6,"Totaux ".$ind);
00164                 $pdf->LongLine(60,6,${'lvl'.$ind.'_old'});
00165                 if ($previous == 1 ) {
00166                     $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
00167                     $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
00168                     $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
00169                     $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
00170                 }
00171                 $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
00172                 $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
00173                 $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
00174                 $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
00175                 $pdf->Ln();
00176                 $pdf->SetFont('DejaVuCond','',7);
00177                 ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
00178                 foreach($a_sum as $a)
00179                   {
00180                     ${'nlvl'.$ind}[$a]=0;
00181                   }
00182               }
00183           }
00184         foreach($a_sum as $a)
00185           {
00186             $nlvl1[$a]=bcadd($nlvl1[$a],$r[$a]);
00187             $nlvl2[$a]=bcadd($nlvl2[$a],$r[$a]);
00188             $nlvl3[$a]=bcadd($nlvl3[$a],$r[$a]);
00189           }
00190 
00191         if ( $i % 2 == 0 )
00192           {
00193             $pdf->SetFillColor(220,221,255);
00194             $fill=1;
00195           }
00196         else
00197           {
00198             $pdf->SetFillColor(0,0,0);
00199             $fill=0;
00200           }
00201 
00202         $pdf->LongLine(30,6,$value['poste'],0,'L',$fill);
00203         $pdf->LongLine(60,6,$value['label'],0,'L',$fill);
00204         if ($previous == 1 ) {
00205             $pdf->Cell(22,6,nbm($value['sum_deb_previous']),0,0,'R',$fill);
00206             $pdf->Cell(22,6,nbm($value['sum_cred_previous']),0,0,'R',$fill);
00207             $pdf->Cell(22,6,nbm($value['solde_deb_previous']),0,0,'R',$fill);
00208             $pdf->Cell(22,6,nbm($value['solde_cred_previous']),0,0,'R',$fill);
00209             $tp_deb_previous=bcadd($tp_deb_previous,$value['sum_deb_previous']);
00210             $tp_cred_previous=bcadd($tp_cred_previous,$value['sum_cred_previous']);
00211             $tp_sold_previous=bcadd($tp_sold_previous,$value['solde_deb_previous']);
00212             $tp_solc_previous=bcadd($tp_solc_previous,$value['solde_cred_previous']);
00213         }
00214         $pdf->Cell(25,6,nbm($value['sum_deb']),0,0,'R',$fill);
00215         $pdf->Cell(25,6,nbm($value['sum_cred']),0,0,'R',$fill);
00216         $pdf->Cell(25,6,nbm($value['solde_deb']),0,0,'R',$fill);
00217         $pdf->Cell(25,6,nbm($value['solde_cred']),0,0,'R',$fill);
00218         $pdf->Ln();
00219         $tp_deb=bcadd($tp_deb,$value['sum_deb']);
00220         $tp_cred=bcadd($tp_cred,$value['sum_cred']);
00221         $tp_sold=bcadd($tp_sold,$value['solde_deb']);
00222         $tp_solc=bcadd($tp_solc,$value['solde_cred']);
00223 
00224       }
00225     foreach (array(3,2,1) as $ind)
00226       {
00227         $r=$value;
00228         if ( ! isset($_GET['lvl'.$ind]))continue;
00229 
00230         if (${'lvl'.$ind.'_old'} == '')   ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
00231         if ( ${'lvl'.$ind.'_old'} != substr($r['poste'],0,$ind))
00232           {
00233             $pdf->SetFont('DejaVu','B',7);
00234             $pdf->Cell(30,6,"Totaux ".$ind);
00235             $pdf->Cell(60,6,${'lvl'.$ind.'_old'});
00236              if ($previous == 1 ) {
00237                 $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_deb_previous']),0,0,'R');
00238                 $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['sum_cred_previous']),0,0,'R');
00239                 $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_deb_previous']),0,0,'R');
00240                 $pdf->Cell(22,6,nbm(${'nlvl'.$ind}['solde_cred_previous']),0,0,'R');
00241              }
00242             $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_deb']),0,0,'R');
00243             $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['sum_cred']),0,0,'R');
00244             $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_deb']),0,0,'R');
00245             $pdf->Cell(25,6,nbm(${'nlvl'.$ind}['solde_cred']),0,0,'R');
00246             $pdf->Ln();
00247             $pdf->SetFont('DejaVuCond','',7);
00248             ${'lvl'.$ind.'_old'}=substr($r['poste'],0,$ind);
00249             foreach($a_sum as $a)
00250               {
00251                 ${'nlvl'.$ind}[$a]=0;
00252               }
00253           }
00254       }
00255 
00256     // Totaux
00257     $pdf->SetFont('DejaVuCond','B',8);
00258     $pdf->Cell(90,6,'Totaux');
00259      if ($previous == 1 ) {
00260         $pdf->Cell(22,6,nbm($tp_deb_previous),'T',0,'R',0);
00261         $pdf->Cell(22,6,nbm($tp_cred_previous),'T',0,'R',0);
00262         $pdf->Cell(22,6,nbm($tp_sold_previous),'T',0,'R',0);
00263         $pdf->Cell(22,6,nbm($tp_solc_previous),'T',0,'R',0);
00264     }
00265     $pdf->Cell(25,6,nbm($tp_deb),'T',0,'R',0);
00266     $pdf->Cell(25,6,nbm($tp_cred),'T',0,'R',0);
00267     $pdf->Cell(25,6,nbm($tp_sold),'T',0,'R',0);
00268     $pdf->Cell(25,6,nbm($tp_solc),'T',0,'R',0);
00269     $pdf->Ln();
00270   } /** empty */
00271 
00272 $fDate=date('dmy-Hi');
00273 $pdf->Output('balance-'.$fDate.'.pdf','D');
00274 
00275 
00276 
00277 ?>
 All Data Structures Namespaces Files Functions Variables Enumerations