Codice PHP:
<?php
session_start();
require('../fpdf/fpdf.php');
require('ddt_pdf.inc.php');
define('EURO', chr(128) );
define('EURO_VAL', 6.55957 );
define('X_VAT_COL_FIRST', 10 );
define('X_VAT_COL_1' , 20 );
define('X_VAT_COL_2' , 50 );
define('X_VAT_COL_3' , 65 );
define('X_VAT_COL_4' , 105 );
//define('X_VAT_COL_5' , 130);
define('X_VAT_COL_LAST' , 180 );
class INVOICE extends FPDF
{
var $colonnes;
var $format;
var $angle=0;
var $logo="";
var $footerMsg="";
var $formatoInv;
function SetLogo($path,$pfInv=0)
{
global $logo,$formatoInv;
$logo=$path;
$formatoInv=$pfInv;
}
function SetFooterMsg($msg)
{
global $footerMsg;
$footerMsg=$msg;
}
function RoundedRect($x, $y, $w, $h, $r, $style = '')
{
$k = $this->k;
$hp = $this->h;
if($style=='F')
$op='f';
elseif($style=='FD' or $style=='DF')
$op='B';
else
$op='S';
$MyArc = 4/3 * (sqrt(2) - 1);
$this->_out(sprintf('%.2f %.2f m',($x+$r)*$k,($hp-$y)*$k ));
$xc = $x+$w-$r ;
$yc = $y+$r;
$this->_out(sprintf('%.2f %.2f l', $xc*$k,($hp-$y)*$k ));
$this->_Arc($xc + $r*$MyArc, $yc - $r, $xc + $r, $yc - $r*$MyArc, $xc + $r, $yc);
$xc = $x+$w-$r ;
$yc = $y+$h-$r;
$this->_out(sprintf('%.2f %.2f l',($x+$w)*$k,($hp-$yc)*$k));
$this->_Arc($xc + $r, $yc + $r*$MyArc, $xc + $r*$MyArc, $yc + $r, $xc, $yc + $r);
$xc = $x+$r ;
$yc = $y+$h-$r;
$this->_out(sprintf('%.2f %.2f l',$xc*$k,($hp-($y+$h))*$k));
$this->_Arc($xc - $r*$MyArc, $yc + $r, $xc - $r, $yc + $r*$MyArc, $xc - $r, $yc);
$xc = $x+$r ;
$yc = $y+$r;
$this->_out(sprintf('%.2f %.2f l',($x)*$k,($hp-$yc)*$k ));
$this->_Arc($xc - $r, $yc - $r*$MyArc, $xc - $r*$MyArc, $yc - $r, $xc, $yc - $r);
$this->_out($op);
}
function _Arc($x1, $y1, $x2, $y2, $x3, $y3)
{
$h = $this->h;
$this->_out(sprintf('%.2f %.2f %.2f %.2f %.2f %.2f c ', $x1*$this->k, ($h-$y1)*$this->k,
$x2*$this->k, ($h-$y2)*$this->k, $x3*$this->k, ($h-$y3)*$this->k));
}
function Rotate($angle,$x=-1,$y=-1)
{
if($x==-1)
$x=$this->x;
if($y==-1)
$y=$this->y;
if($this->angle!=0)
$this->_out('Q');
$this->angle=$angle;
if($angle!=0)
{
$angle*=M_PI/180;
$c=cos($angle);
$s=sin($angle);
$cx=$x*$this->k;
$cy=($this->h-$y)*$this->k;
$this->_out(sprintf('q %.5f %.5f %.5f %.5f %.2f %.2f cm 1 0 0 1 %.2f %.2f cm',$c,$s,-$s,$c,$cx,$cy,-$cx,-$cy));
}
}
function _endpage()
{
if($this->angle!=0)
{
$this->angle=0;
$this->_out('Q');
}
parent::_endpage();
}
function sizeOfText( $texte, $largeur )
{
$index = 0;
$nb_lines = 0;
$loop = TRUE;
while ( $loop )
{
$pos = strpos($texte, "\n");
if (!$pos)
{
$loop = FALSE;
$ligne = $texte;
}
else
{
$ligne = substr( $texte, $index, $pos);
$texte = substr( $texte, $pos+1 );
}
$length = floor( $this->GetStringWidth( $ligne ) );
$res = 1 + floor ;
$nb_lines += $res;
}
return $nb_lines;
}
function addSociete( $nom, $adresse )
{
global $logo,$formatoInv;
$x1 = 10;
$y1 = 6;
if ($formatoInv==1 && !empty($logo)) {
$this->Image($logo,$x1,$y1,100,60);
return;
}
if (!empty($logo)) {
$this->Image($logo,$x1,$y1,60,20);
$x1 = 10;
$y1 = 29;
}
$this->SetXY( $x1, $y1+3 );
$this->SetFont('Helvetica','IB',10);
$length = $this->GetStringWidth( $nom );
$this->Cell( $length, 2, $nom);
$this->SetXY( $x1, $y1 + 6 );
$this->SetFont('Helvetica','I',10);
$length = $this->GetStringWidth( $adresse );
$lignes = $this->sizeOfText( $adresse, $length) ;
$this->MultiCell($length, 4, $adresse);
}
function fact_dev( $libelle, $anno, $numero )
{
$r1 = $this->w - 80;
$r2 = $r1 + 68;
$y1 = 6;
$y2 = $y1 + 2;
$mid = ($r1 + $r2 ) / 2;
$texte = $libelle. " N° " . $anno. "/" . $numero;
$szfont = 12;
$loop = 0;
while ( $loop == 0 )
{
$this->SetFont( "Helvetica", "B", $szfont );
$sz = $this->GetStringWidth( $texte );
if ( ($r1+$sz) > $r2 )
$szfont --;
else
$loop ++;
}
$this->SetLineWidth(0.1);
$this->SetFillColor(255);
$this->RoundedRect($r1, $y1, ($r2 - $r1), $y2, 2.5, 'DF');
$this->SetXY( $r1+1, $y1+2);
$this->Cell($r2-$r1 -1,5, $texte, 0, 0, "C" );
}
function addDevis( $numdev )
{
$string = sprintf("DEV%04d",$numdev);
$this->fact_dev( "Devis", $string );
}
function addFacture( $numfact )
{
$string = sprintf("FA%04d",$numfact);
$this->fact_dev( "Fattura", $string );
}
function addDate( $date )
{
$r1 = $this->w - 42;
$r2 = $r1 + 30;
$y1 = 17;
$y2 = $y1+10;
$mid = $y1 + (($y2-$y1) / 2);
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
$this->Line( $r1, $mid, $r2, $mid);
$this->SetXY( $r1 + ($r2 - $r1)/2 - 5 , $y1+1 );
$this->SetFont( "Helvetica", "B", 10);
$this->Cell(10,4, "Data", 0, 0, "C");
$this->SetXY( $r1 + ($r2-$r1)/2 - 5 , $y1 + 5 );
$this->SetFont( "Helvetica", "", 10);
$this->Cell(10,5,$date, 0,0, "C");
}
function addPageNumber( $page )
{
$r1 = $this->w - 80;
$r2 = $r1 + 30;
$y1 = 17;
$y2 = $y1+10;
$mid = $y1 + (($y2-$y1) / 2);
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
$this->Line( $r1, $mid, $r2, $mid);
$this->SetXY( $r1 + ($r2 - $r1)/2 - 5 , $y1+1 );
$this->SetFont( "Helvetica", "B", 10);
$this->Cell(10,4, "Pagina", 0, 0, "C");
$this->SetXY( $r1 + ($r2-$r1)/2 - 5 , $y1 + 5 );
$this->SetFont( "Helvetica", "", 10);
$this->Cell(10,5,$page, 0,0, "C");
}
function addClient( $ref )
{
$r1 = $this->w - 80;
$r2 = $r1 + 68;
$y1 = 30;
$y2 = $y1+8;
$mid = $y1 + (($y2-$y1) / 2);
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'DF');
$this->SetXY( $r1+1, $y1+2);
$this->Cell($r2-$r1 -1,5, "Destinatario", 0, 0, "C" );
}
function addClientAdresse( $adresse )
{
$r1 = $this->w - 80;
$r2 = $r1 + 68;
$y1 = 40;
$this->SetXY( $r1, $y1);
$this->MultiCell( 60, 4, $adresse);
}
function addClientDest( $ref1 )
{
$r1 = $this->w - 80;
$r2 = $r1 + 68;
$y1 = 58;
$y2 = $y1+8;
$mid = $y1 + (($y2-$y1) / 2);
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'DF');
$this->SetXY( $r1+1, $y1+2);
$this->Cell($r2-$r1 -1,5, "Destinazione", 0, 0, "C" );
}
function addClientAdresseDest( $adresse1 )
{
$r1 = $this->w - 80;
$r2 = $r1 + 68;
$y1 = 68;
$this->SetXY( $r1, $y1);
$this->MultiCell( 60, 4, $adresse1);
}
function addReglement($causale)
{
$r1 = 10;
$r2 = $r1 + 60;
$y1 = 71;
$y2 = $y1+10;
$mid = $y1 + (($y2-$y1) / 2);
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2+5-$y1), 2.5, 'D');
$this->Line( $r1, $mid, $r2, $mid);
$this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1+1 );
$this->SetFont( "Helvetica", "B", 10);
$this->Cell(10,4, "Causale Trasporto", 0, 0, "C");
$this->SetXY( $r1 + ($r2-$r1)/2 -5 , $y1 + 5 );
$this->SetFont( "Helvetica", "", 10);
$this->Cell(10,5,$_SESSION['causale'], 0,0, "C");
}
function addReference($ref,$r1=10,$y1=92,$pf=10)
{
$this->SetFont( "Helvetica", "", $pf);
$length = $this->GetStringWidth( "" . $ref );
$this->SetXY( $r1 , $y1 );
$this->Cell($length,4, "" . $ref);
}
function addCols( $tab )
{
global $colonnes;
$r1 = 10;
$r2 = $this->w - ($r1 * 2) ;
$y1 = 90;
$y2 = $this->h - 50 - $y1;
$this->SetXY( $r1, $y1 );
$this->Rect( $r1, $y1, $r2, $y2, "D");
$this->Line( $r1, $y1+6, $r1+$r2, $y1+6);
$colX = $r1;
$colonnes = $tab;
while ( list( $lib, $pos ) = each ($tab) )
{
$this->SetXY( $colX, $y1+2 );
$this->Cell( $pos, 1, $lib, 0, 0, "C");
$colX += $pos;
$this->Line( $colX, $y1, $colX, $y1+$y2);
}
}
function addLineFormat( $tab )
{
global $format, $colonnes;
while ( list( $lib, $pos ) = each ($colonnes) )
{
if ( isset( $tab["$lib"] ) )
$format[ $lib ] = $tab["$lib"];
}
}
function lineVert( $tab )
{
global $colonnes;
reset( $colonnes );
$maxSize=0;
while ( list( $lib, $pos ) = each ($colonnes) )
{
$texte = $tab[ $lib ];
$longCell = $pos -2;
$size = $this->sizeOfText( $texte, $longCell );
if ($size > $maxSize)
$maxSize = $size;
}
return $maxSize;
}
function addLine( $ligne, $tab )
{
global $colonnes, $format;
$ordonnee = 10;
$maxSize = $ligne;
reset( $colonnes );
while ( list( $lib, $pos ) = each ($colonnes) )
{
$longCell = $pos -2;
$texte = $tab[ $lib ];
$length = $this->GetStringWidth( $texte );
$tailleTexte = $this->sizeOfText( $texte, $length );
$formText = $format[ $lib ];
$this->SetXY( $ordonnee, $ligne-1);
$this->MultiCell( $longCell, 4 , $texte, 0, $formText);
if ( $maxSize < ($this->GetY() ) )
$maxSize = $this->GetY() ;
$ordonnee += $pos;
}
return ( $maxSize - $ligne );
}
function addRemarque($remarque)
{
$this->SetFont( "Helvetica", "", 10);
$length = $this->GetStringWidth( "Remarque : " . $remarque );
$r1 = 10;
$r2 = $r1 + $length;
$y1 = $this->h - 45.5;
$y2 = $y1+5;
$this->SetXY( $r1 , $y1 );
$this->Cell($length,4, "Remarque : " . $remarque);
}
function addCadreTVAs()
{
$this->SetFont( "Helvetica", "B", 10);
$r1 = 10;
$r2 = $r1 + 120;
$y1 = $this->h - 40;
$y2 = $y1+29;
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
$this->Line( $r1, $y1+5, $r2, $y1+5);
$this->Line( $r1, $y1+5, $r2, $y1+5); // avant BASES HT
$this->Line( $r1+27, $y1, $r1+27, $y2-5); // avant REMISE
$this->Line( $r1+52, $y1, $r1+52, $y2-5); // avant MT TVA
$this->Line( $r1, $y1+24, $r2, $y1+24);
$this->SetFont( "Helvetica", "", 10);
$this->SetXY( $r1+7, $y1);
$this->Cell(10,4, BASES_HT);
$this->SetXY( $r1+11, $y1);
$this->SetFont( "Helvetica", "", 10);
$this->Cell(2,15,$_SESSION['colli'], 0,0, "C");
$this->SetX( $r1+32 );
$this->Cell(10,4, REMISE);
$this->SetX( $r1+39 );
$this->SetFont( "Helvetica", "", 10);
$this->Cell(1,15,$_SESSION['porto'], 0,0, "C");
$this->SetX( $r1+72 );
$this->Cell(10,4, MT_TVA);
$this->SetX( $r1+75 );
$this->SetFont( "Helvetica", "", 10);
$this->Cell(2,15,$_SESSION['vettore'], 0,0, "C");
}
function addCadreEurosFrancs()
{
$r1 = $this->w - 55;
$r2 = $r1 + 45;
$y1 = $this->h - 40;
$y2 = $y1+29;
$this->RoundedRect($r1, $y1, ($r2 - $r1), ($y2-$y1), 2.5, 'D');
$this->Line( $r1, $y1+14.5, $r2, $y1+14.5);
$this->SetFont( "Helvetica", "", 6);
$this->SetFont( "Helvetica", "", 6);
$this->SetFont( "Helvetica", "", 6);
$this->SetXY( $r1+13, $y1 );
$this->Cell(22,4, TOTAUX, 0, 0, "C");
$this->SetXY( $r1+13, $y1+2 );
$this->Cell(22,4, ACOMPTE, 0, 0, "C");
$this->SetFont( "Helvetica", "", 6);
$this->SetXY( $r1+13, $y1+14.5 );
$this->Cell(22,4, NET, 0, 0, "C");
$this->SetXY( $r1+13, $y1+18);
$this->Cell(22,1, A_PAYER, 0, 0,'C');
}
function addTVAs( $params, $tab_tva, $invoice )
{
$this->SetFont('Helvetica','',8);
reset ($invoice);
$px = array();
while ( list( $k, $prod) = each( $invoice ) )
{
$tva = $prod["tva"];
$ra = $prod["rit"];
@ $px[$tva."_".$ra] += $prod["qte"] * $prod["px_unit"];
}
$prix = array();
$totalHT = 0;
$totalTTC = 0;
$totalTVA = 0;
$totalRIT = 0;
$y = 261;
reset ($px);
natsort( $px );
while ( list($code_tva, $articleHT) = each( $px ) )
{
$rit=substr($code_tva,strpos($code_tva,'_')+1,strlen($code_tva));
$code_tva=substr($code_tva,0,strpos($code_tva,'_'));
$tva = $tab_tva[$code_tva];
}
}
function temporaire( $texte )
{
$this->SetFont('Helvetica','B',50);
$this->SetTextColor(203,203,203);
$this->Rotate(45,55,190);
$this->Text(55,190,$texte);
$this->Rotate(0);
$this->SetTextColor(0,0,0);
}
function Footer() {
global $footerMsg;
$this->SetY(-15);
$this->SetFont('Helvetica','IB',8);
$this->Write(3,$_SESSION['note']);
}
}
?>