Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

print_invoice.php

Go to the documentation of this file.
00001 <?
00002 
00003 /*
00004  *   This file is part of PhpCompta.
00005  *
00006  *   PhpCompta is free software; you can redistribute it and/or modify
00007  *   it under the terms of the GNU General Public License as published by
00008  *   the Free Software Foundation; either version 2 of the License, or
00009  *   (at your option) any later version.
00010  *
00011  *   PhpCompta is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *   GNU General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU General Public License
00017  *   along with PhpCompta; if not, write to the Free Software
00018  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00034 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00035 // $Revision$
00036 
00037 include_once("jrn.php");
00038 include_once("ac_common.php");
00039 include_once("postgres.php");
00040 include_once("class.ezpdf.php");
00041 include_once("impress_inc.php");
00042 include_once("fiche_inc.php");
00043 include_once("user_common.php");
00044 echo_debug('print_invoice.php',__LINE__,"imp pdf journaux");
00045 $cn=DbConnect($g_dossier);
00046 foreach ($HTTP_POST_VARS as $key=>$element) {
00047   ${"$key"}=$element;
00048   echo_debug('print_invoice.php',__LINE__,"key => $key element $element");
00049 }
00050 
00051 $amount=0.0;
00052 for ($i=0;$i<$nb_item;$i++) {
00053   // store quantity & goods in array
00054   $a_good[$i]=${"e_march$i"};
00055   $a_quant[$i]=${"e_quant$i"};
00056   $a_vat[$i]=${"e_march$i"."_tva_id"};
00057  if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
00058       // If the price is not set we have to find it from the database
00059       $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE);
00060     } else {
00061       // The price is valid
00062       $a_price[$i]=${"e_march$i"."_sell"};
00063  }
00064 
00065   $a_amount[$i]=$a_price[$i]*$a_quant[$i];
00066   $amount+=$a_amount[$i];
00067   $tva=GetTvaRate($cn,GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_TVA));
00068   // Prepare the array to print
00069   $a_good_detail[]=array('id'=>$i+1,
00070                          'name'=>GetFicheAttribut($cn,$a_good[$i],ATTR_DEF_NAME),
00071                          'quantity'=>$a_quant[$i],
00072                          'Unit'        =>$a_price[$i],
00073                          'Total HTVA' => $a_amount[$i],
00074                          'tva'=>$tva['tva_label'],
00075                          'Total' => $a_amount[$i]+$a_amount[$i]*$a_quant[$i]*$tva['tva_rate']);
00076 }
00077 
00078 $a_vat=ComputeVat($cn,  $a_good,$a_quant,$a_price,$a_vat);
00079 $sum_vat=0.0;
00080 foreach ( $a_vat as $element => $t) {
00081   echo_debug('print_invoice.php',__LINE__," a_vat element $element t $t");
00082   $sum_vat+=$t;
00083   echo_debug('print_invoice.php',__LINE__,"sum_vat = $sum_vat");
00084 }
00085 
00086 $ret="";
00087 $pdf=& new Cezpdf('a4');
00088 $pdf->selectFont('./addon/fonts/Helvetica.afm');
00089 $pdf->ezSetCmMargins(2,2,2,2);
00090 // Write the date
00091 $pdf->ezText("Date : ".$e_date,10,array('justification'=>'right'));
00092          
00093 // write the customer data
00094 $info[0]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_NAME));
00095 $info[1]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_ADRESS));
00096 $info[2]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_CP));
00097 $info[3]=array('info'=>GetFicheAttribut($cn,$e_client,ATTR_DEF_PAYS));
00098 $pdf->ezSetDy(-50);
00099 $pdf->ezTable($info, null, "Informations"
00100               , array('width'=>200,'fontSize'=>12,'shaded'=>0,'xOrientation'=>'left','xPos'=>'right','showHeadings'=>0));       
00101         
00102 // Write the invoice number
00103 $pdf->ezSetDy(-50);
00104 $pdf->ezText ($e_comment,14,array('justification'=>'center'));
00105         
00106 // Write the goods details                                              
00107 $pdf->ezSetDy(-50);
00108 $pdf->ezTable($a_good_detail,null,'Detail invoice',
00109               array('width'=>400,'cols'=>array(
00110                                                'quantity'=>array('justification'=>'right'),
00111                                                'Unit'=>array('justification'=>'right'),
00112                                                'Total HTVA'=>array('justification'=>'right'),
00113                                                'tva'=>array('justification'=>'right'),
00114                                                'Total'=>array('justification'=>'right')
00115                                                )));
00116         
00117         
00118 // Write the sum detail 
00119 $sum_detail[0] = array ('label'=>'Total HTVA ','amount'=>$amount);
00120 $index=1;
00121 foreach ( $a_vat as $element => $t) {
00122   echo_debug('print_invoice.php',__LINE__," a_vat element $element t $t");
00123   $a_tva_sum=GetTvaRate($cn,$element);
00124   $sum_detail[++$index]=array('label'=>"tva ". $a_tva_sum['tva_label'],'amount'=>$t);
00125 }
00126 $total=$amount+$sum_vat;
00127 $sum_detail[++$index]=array('label'=>"Total", 'amount'=>$total);
00128 $pdf->ezSetDy(-50);
00129 $pdf->ezTable($sum_detail,null,'',
00130               array('width'=>200,'showHeadings'=>0,'shaded'=>0,'cols'=>array('amount'=>array('justification'=>'right'))));
00131 
00132 
00133 // WRITE THE DATE LIMIT
00134 $pdf->ezSetDy(-50);
00135 $pdf->ezText(" Limit date : ".$e_ech);
00136 
00137 
00138 
00139 // Make a file of it
00140 //$pdfcode=" I don't know whether the prob comes from the ezPdf or from Apache or from Mysql";
00141 //$pdfcode=$pdf->ezOutput();
00142 //$fp=fopen("invoice.pdf","wb+");
00143 //fwrite($fp,$pdfcode);
00144 //fclose ($fp);
00145 
00146 $pdf->ezStream();
00147 
00148 
00149 ?>

Generated on Fri Jun 23 00:12:45 2006 for phpcompta by  doxygen 1.4.4