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