class_print_ledger_simple.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta 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  *   PhpCompta 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 PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  */
00019 /* $Revision: 4872 $ */
00020 
00021 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00022 
00023 /*!\file
00024  * \brief this class extends PDF and let you export the detailled printing
00025  *  of any ledgers
00026  *\todo Must add the third part
00027  */
00028 require_once('class_pdf.php');
00029 
00030 class Print_Ledger_Simple extends PDF
00031 {
00032     public function __construct ($p_cn,$p_jrn)
00033     {
00034 
00035         if($p_cn == null) die("No database connection. Abort.");
00036 
00037         parent::__construct($p_cn,'L', 'mm', 'A4');
00038         $this->ledger=$p_jrn;
00039         $this->a_Tva=$this->ledger->existing_vat();
00040         foreach($this->a_Tva as $line_tva)
00041         {
00042             //initialize Amount TVA
00043             $tmp1=$line_tva['tva_id'];
00044             $this->rap_tva[$tmp1]=0;
00045         }
00046         $this->jrn_type=$p_jrn->get_type();
00047         //----------------------------------------------------------------------
00048         /* report
00049          *
00050          * get rappel to initialize amount rap_xx
00051          *the easiest way is to compute sum from quant_
00052          */
00053         $this->previous=$this->ledger->previous_amount($_GET['from_periode']);
00054 
00055         /* initialize the amount to report */
00056         foreach($this->previous['tva'] as $line_tva)
00057         {
00058             //initialize Amount TVA
00059             $tmp1=$line_tva['tva_id'];
00060             $this->rap_tva[$tmp1]=$line_tva['sum_vat'];
00061         }
00062 
00063         $this->rap_htva=$this->previous['price'];
00064         $this->rap_tvac=$this->previous['price']+$this->previous['vat'];
00065         $this->rap_priv=$this->previous['priv'];
00066         $this->rap_nd=$this->previous['tva_nd'];
00067     }
00068 
00069     function setDossierInfo($dossier = "n/a")
00070     {
00071         $this->dossier = dossier::name()." ".$dossier;
00072     }
00073     /**
00074      *@brief write the header of each page
00075      */
00076     function Header()
00077     {
00078         //Arial bold 12
00079         $this->SetFont('DejaVu', 'B', 12);
00080         //Title
00081         $this->Cell(0,10,$this->dossier, 'B', 0, 'C');
00082         //Line break
00083         $this->Ln(20);
00084         $this->SetFont('DejaVu', 'B', 8);
00085         /* column header */
00086         //----------------------------------------------------------------------
00087         // Show column header, if $flag_tva is false then display vat as column
00088         foreach($this->a_Tva as $line_tva)
00089         {
00090             //initialize Amount TVA
00091             $tmp1=$line_tva['tva_id'];
00092             $this->rap_tva[$tmp1]=(isset($this->rap_tva[$tmp1]))?$this->rap_tva[$tmp1]:0;
00093         }
00094         $this->Cell(15,6,'Pièce');
00095         $this->Cell(10,6,'Date');
00096         $this->Cell(13,6,'ref');
00097         if ( $this->jrn_type=='ACH')
00098             $this->Cell(40,6,'Client');
00099         else
00100             $this->Cell(40,6,'Fournisseur');
00101 
00102         $flag_tva=(count($this->a_Tva) > 4)?true:false;
00103         if ( !$flag_tva )      $this->Cell(65,6,'Description');
00104 
00105         $this->Cell(15,6,'HTVA',0,0,'R');
00106         if ( $this->jrn_type=='ACH')
00107         {
00108             $this->Cell(15,6,'Privé',0,0,'R');
00109             $this->Cell(15,6,'TVA ND',0,0,'R');
00110         }
00111         foreach($this->a_Tva as $line_tva)
00112         {
00113             $this->Cell(15,6,$line_tva['tva_label'],0,0,'R');
00114         }
00115         $this->Cell(15,6,'TVAC',0,0,'R');
00116         $this->Ln(5);
00117 
00118         $this->SetFont('DejaVu','',6);
00119         // page Header
00120         $this->Cell(143,6,'report',0,0,'R');
00121         $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
00122         if ( $this->jrn_type != 'VEN')
00123         {
00124             $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
00125             $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
00126         }
00127         foreach($this->rap_tva as $line_tva)
00128         $this->Cell(15,6,nbm($line_tva),0,0,'R');
00129         $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
00130 
00131         $this->Ln(6);
00132         //total page
00133         $this->tp_htva=0.0;
00134         $this->tp_tvac=0.0;
00135         $this->tp_priv=0;
00136         $this->tp_nd=0;
00137         foreach($this->a_Tva as $line_tva)
00138         {
00139             //initialize Amount TVA
00140             $tmp1=$line_tva['tva_id'];
00141             $this->tp_tva[$tmp1]=0.0;
00142         }
00143     }
00144     /**
00145      *@brief write the Footer
00146      */
00147     function Footer()
00148     {
00149         //Position at 3 cm from bottom
00150         $this->SetY(-20);
00151         /* write reporting  */
00152         $this->Cell(143,6,'Total page ','T',0,'R'); /* HTVA */
00153         $this->Cell(15,6,nbm($this->tp_htva),'T',0,'R'); /* HTVA */
00154         if ( $this->jrn_type !='VEN')
00155         {
00156             $this->Cell(15,6,nbm($this->tp_priv),'T',0,'R');  /* prive */
00157             $this->Cell(15,6,nbm($this->tp_nd),'T',0,'R');  /* Tva ND */
00158         }
00159         foreach($this->a_Tva as $line_tva)
00160         {
00161             $l=$line_tva['tva_id'];
00162             $this->Cell(15,6,nbm($this->tp_tva[$l]),'T',0,'R');
00163         }
00164         $this->Cell(15,6,nbm($this->tp_tvac),'T',0,'R'); /* Tvac */
00165         $this->Ln(2);
00166 
00167         $this->Cell(143,6,'report',0,0,'R'); /* HTVA */
00168         $this->Cell(15,6,nbm($this->rap_htva),0,0,'R'); /* HTVA */
00169         if ( $this->jrn_type !='VEN')
00170         {
00171             $this->Cell(15,6,nbm($this->rap_priv),0,0,'R');  /* prive */
00172             $this->Cell(15,6,nbm($this->rap_nd),0,0,'R');  /* Tva ND */
00173         }
00174         foreach($this->a_Tva as $line_tva)
00175         {
00176             $l=$line_tva['tva_id'];
00177             $this->Cell(15,6,nbm($this->rap_tva[$l]),0,0,'R');
00178         }
00179         $this->Cell(15,6,nbm($this->rap_tvac),0,0,'R'); /* Tvac */
00180         $this->Ln(2);
00181 
00182         //Arial italic 8
00183         $this->SetFont('Arial', 'I', 8);
00184         //Page number
00185         $this->Cell(0,8,'Date '.$this->date." - Page ".$this->PageNo().'/{nb}',0,0,'C');
00186         $this->Ln(3);
00187         // Created by PhpCompta
00188         $this->Cell(0,8,'Created by Phpcompta, online on http://www.aevalys.eu',0,0,'C',false,'http://www.aevalys.eu');
00189     }
00190 
00191     function Cell ($w, $h=0, $txt='', $border=0, $ln=0, $align='', $fill=false, $link='')
00192     {
00193         $txt = str_replace("\\", "", $txt);
00194         return parent::Cell($w, $h, $txt, $border, $ln, $align, $fill, $link);
00195     }
00196     /**
00197      *@brief export the ledger in  PDF
00198      */
00199     function export()
00200     {
00201       bcscale(2);
00202         $a_jrn=$this->ledger->get_operation($_GET['from_periode'],
00203                                             $_GET['to_periode']);
00204 
00205         if ( $a_jrn == null ) return;
00206         for ( $i=0;$i<count($a_jrn);$i++)
00207         {
00208             /* initialize tva */
00209             for ($f=0;$f<count($this->a_Tva);$f++)
00210             {
00211                 $l=$this->a_Tva[$f]['tva_id'];
00212                 $atva_amount[$l]=0;
00213             }
00214 
00215             // retrieve info from ledger
00216             $aAmountVat=$this->ledger->vat_operation($a_jrn[$i]['jr_grpt_id']);
00217 
00218             // put vat into array
00219             for ($f=0;$f<count($aAmountVat);$f++)
00220             {
00221                 $l=$aAmountVat[$f]['tva_id'];
00222                 $atva_amount[$l]=bcadd($atva_amount[$l],$aAmountVat[$f]['sum_vat']);
00223                 $this->tp_tva[$l]=bcadd($this->tp_tva[$l],$aAmountVat[$f]['sum_vat']);
00224                 $this->rap_tva[$l]=bcadd($this->rap_tva[$l],$aAmountVat[$f]['sum_vat']);
00225             }
00226 
00227             $row=$a_jrn[$i];
00228             $this->Cell(15,5,($row['pj']),0,0);
00229             $this->Cell(10,5,$row['date_fmt'],0,0);
00230             $this->Cell(13,5,$row['internal'],0,0);
00231             list($qc,$name)=$this->get_tiers($row['id'],$this->jrn_type);
00232             $this->LongLine(40,5,"[".$qc."]".$name,0,'L');
00233 
00234             $this->LongLine(65,5,mb_substr($row['comment'],0,150),0,'L');
00235 
00236             /* get other amount (without vat, total vat included, private, ND */
00237             $other=$this->ledger->get_other_amount($a_jrn[$i]['jr_grpt_id']);
00238             $this->tp_htva=bcadd($this->tp_htva,$other['price']);
00239             $this->tp_tvac=bcadd($this->tp_tvac,$other['price']+$other['vat']);
00240             $this->tp_priv=bcadd($this->tp_priv,$other['priv']);
00241             $this->tp_nd=bcadd($this->tp_nd,$other['tva_nd']);
00242             $this->rap_htva=bcadd($this->rap_htva,$other['price']);
00243             $this->rap_tvac=bcadd($this->rap_tvac,$other['price']+$other['vat']);
00244             $this->rap_priv=bcadd($this->rap_priv,$other['priv']);
00245             $this->rap_nd=bcadd($this->rap_nd,$other['tva_nd']);
00246 
00247 
00248             $this->Cell(15,5,nbm($other['price']),0,0,'R');
00249             if ( $this->jrn_type !='VEN')
00250             {
00251               $this->Cell(15,5,nbm($other['priv']),0,0,'R');
00252               $this->Cell(15,5,nbm($other['tva_nd']),0,0,'R');
00253             }
00254                                 foreach ($atva_amount as $row_atva_amount)
00255                         {
00256                                 $this->Cell(15, 5, nbm($row_atva_amount), 0, 0, 'R');
00257                         }
00258 
00259             $l_tvac=bcadd($other['price'],$other['vat']);
00260             $l_tvac=bcadd($l_tvac,$other['tva_nd']);
00261             $this->Cell(15,5,nbm($l_tvac),0,0,'R');
00262             $this->Ln(5);
00263         }
00264     }
00265 
00266 }