1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412
|
<?php
/***************************************************/
/* Créé le 27/05/2012 par xxxxxxxxxxxxx : */
/* Page permettant de visualiser la facture en PDF */
/***************************************************/
/******************************************/
/* ACTIVATION DES SESSIONS + CONNEXION BD */
/******************************************/
// On garde les sessions au passage sur cette page
session_start();
// On va chercher le fichier des fonctions
include_once("fonctions.php");
require('fpdf.php');
// On reçoit le numéro de commande en paramètre puis tout s'enchaine
$num_commande = $_GET['ID'];
if ($num_commande == '') {
$num_commande = $_POST['ID'];
}
class PDF_MySQL_Table extends FPDF {
var $ProcessingTable=false;
var $aCols=array();
var $TableX;
var $HeaderColor;
var $RowColors;
var $ColorIndex;
function Header() {
//Imprime l'en-tête du tableau si nécessaire
if($this->ProcessingTable)
$this->TableHeader();
}
function TableHeader() {
$this->SetFont('Arial','B',12);
$this->SetX($this->TableX);
$fill=!empty($this->HeaderColor);
if($fill)
$this->SetFillColor($this->HeaderColor[0],$this->HeaderColor[1],$this->HeaderColor[2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],6,$col['c'],1,0,'C',$fill);
$this->Ln();
}
function Row($data) {
$this->SetX($this->TableX);
$ci=$this->ColorIndex;
$fill=!empty($this->RowColors[$ci]);
if($fill)
$this->SetFillColor($this->RowColors[$ci][0],$this->RowColors[$ci][1],$this->RowColors[$ci][2]);
foreach($this->aCols as $col)
$this->Cell($col['w'],5,$data[$col['f']],1,0,$col['a'],$fill);
$this->Ln();
$this->ColorIndex=1-$ci;
}
function CalcWidths($width,$align) {
//Calcule les largeurs des colonnes
$TableWidth=0;
foreach($this->aCols as $i=>$col) {
$w=$col['w'];
if($w==-1)
$w=$width/count($this->aCols);
elseif(substr($w,-1)=='%')
$w=$w/100*$width;
$this->aCols[$i]['w']=$w;
$TableWidth+=$w;
}
//Calcule l'abscisse du tableau
if($align=='C')
$this->TableX=max(($this->w-$TableWidth)/2,0);
elseif($align=='R')
$this->TableX=max($this->w-$this->rMargin-$TableWidth,0);
else
$this->TableX=$this->lMargin;
}
function AddCol($field=-1,$width=-1,$caption='',$align='L') {
//Ajoute une colonne au tableau
if($field==-1)
$field=count($this->aCols);
$this->aCols[]=array('f'=>$field,'c'=>$caption,'w'=>$width,'a'=>$align);
}
function Table($query,$prop=array()) {
//Exécute la requête
$res=mysql_query($query) or die('Erreur: '.mysql_error()."<BR>Requête: $query");
//Ajoute toutes les colonnes si aucune n'a été définie
if(count($this->aCols)==0) {
$nb=mysql_num_fields($res);
for($i=0;$i<$nb;$i++)
$this->AddCol();
}
//Détermine les noms des colonnes si non spécifiés
foreach($this->aCols as $i=>$col) {
if($col['c']=='') {
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
//Traite les propriétés
if(!isset($prop['width']))
$prop['width']=0;
if($prop['width']==0)
$prop['width']=$this->w-$this->lMargin-$this->rMargin;
if(!isset($prop['align']))
$prop['align']='C';
if(!isset($prop['padding']))
$prop['padding']=$this->cMargin;
$cMargin=$this->cMargin;
$this->cMargin=$prop['padding'];
if(!isset($prop['HeaderColor']))
$prop['HeaderColor']=array();
$this->HeaderColor=$prop['HeaderColor'];
if(!isset($prop['color1']))
$prop['color1']=array();
if(!isset($prop['color2']))
$prop['color2']=array();
$this->RowColors=array($prop['color1'],$prop['color2']);
//Calcule les largeurs des colonnes
$this->CalcWidths($prop['width'],$prop['align']);
//Imprime l'en-tête
$this->TableHeader();
//Imprime les lignes
$this->SetFont('Arial','',11);
$this->ColorIndex=0;
$this->ProcessingTable=true;
while($row=mysql_fetch_array($res))
$this->Row($row);
$this->ProcessingTable=false;
$this->cMargin=$cMargin;
$this->aCols=array();
}
}
class PDF extends PDF_MySQL_Table {
// En-tête
function Header() {
// Saut de ligne
$this->ln(10);
// Entête Facture
$this->SetFont("Times",'',14);
$this->MultiCell(0, 6, "SPARTAN FIGHT\n141 rue de Stalingrad\n38100 GRENOBLE\nTel. 06.75.12.21.58\nSIRET: 538427758 00015", 0, "L", 0);
// Décalage à droite
$this->Cell(40);
// Logo
$this->Image('http://www.spartan-fight.com/Images/General/logo_facture.jpg',120,20,80,30);
}
// Pied de page
function Footer() {
// Positionnement à 1,5 cm du bas
$this->SetY(-15);
// Entête Facture
$this->SetFont("Arial","I",10);
$this->MultiCell(0, 5, "Spartan Fight - www.spartan-fight.com - Page ".$this->PageNo()."/{nb}", 0, "C", 0);
}
}
// Connexion à la BD
ouvrir_BD();
// Requête permettant d'afficher les infos de l'entete commande
$query1 = "SELECT * FROM Commande WHERE Numero_commande = '$num_commande'";
$result1 = mysql_query($query1) or die (mysql_error());
$ligne1 = mysql_fetch_array($result1);
// Requête permettant d'afficher les infos des lignes de la commande
$query2 = "SELECT * FROM Detail_commande WHERE Num_com_detail = '$num_commande'";
$result2 = mysql_query($query2) or die (mysql_error());
// Requête permettant d'afficher les infos de l'adresse
$query3 = "SELECT * FROM Adresse WHERE ID_adresse = '$ligne1[Adresse_commande]'";
$result3 = mysql_query($query3) or die (mysql_error());
$ligne3 = mysql_fetch_array($result3);
// Requête permettant d'afficher les infos de l'utilisateur
$query4 = "SELECT * FROM Users WHERE ID_Users = '$ligne1[User_commande]'";
$result4 = mysql_query($query4) or die (mysql_error());
$ligne4 = mysql_fetch_array($result4);
$tot_ligne = 0;
while ($ligne2 = mysql_fetch_array($result2)) {
if ($ligne2['PrixPromo_produit_detail'] == 0) {
$prix = $ligne2['PrixVente_produit_detail'];
} else {
$prix = $ligne2['PrixPromo_produit_detail'];
}
$tot_ligne = $tot_ligne + $prix;
}
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
// Saut de ligne
$pdf->ln(10);
// Ligne Facture
$pdf->SetFont("Arial","B",22);
$pdf->MultiCell(0, 8, 'Facture', 0, "C", 0);
// Saut de ligne
$pdf->ln(10);
// Ligne Date facture + n° facture
$pdf->SetFont("Arial","",16);
$pdf->MultiCell(0, 8, 'Date de Facture : '.changedate($ligne1['Date_regle_commande']).' Facture N° '.$num_commande.'', 0, "L", 0);
// Saut de ligne
$pdf->ln(10);
// Tableau de la commande avec détail
$pdf->AddCol('Libelle_produit_detail',105,'Désignation','C');
$pdf->AddCol('Quantite_produit_detail',15,'Qté','C');
$pdf->AddCol('Prix',40,'Prix Unitaire HT','C');
$pdf->AddCol('Montant',30,'Montant HT','C');
$prop=array('HeaderColor'=>array(195,195,195),
'color1'=>array(255,255,255),
'color2'=>array(231,231,231),
'padding'=>2);
$pdf->Table('SELECT Libelle_produit_detail, Quantite_produit_detail,
IF (PrixPromo_produit_detail = 0, PrixVente_produit_detail, PrixPromo_produit_detail) as Prix,
Quantite_produit_detail * IF (PrixPromo_produit_detail = 0, PrixVente_produit_detail, PrixPromo_produit_detail) as Montant
FROM Detail_commande WHERE Num_com_detail='.$num_commande.'',$prop);
// Pavé Montant total
$montant = $ligne1['Montant_commande'];
$fraisdeport = $montant - $tot_ligne;
$dec = (false !== strpos($fraisdeport, '.')) ? 2 : 0;
$dec2 = (false !== strpos($tot_ligne, '.')) ? 2 : 0;
$dec3 = (false !== strpos($montant, '.')) ? 2 : 0;
if ($fraisdeport == 0) {
$fraisdeport = 'Offerts';
} else {
$fraisdeport = number_format($fraisdeport, $dec).' €';
}
// Saut de ligne
$pdf->ln(5);
// Décalage à droite
$pdf->Cell(150);
// Frais de port
$pdf->MultiCell(0, 8, 'Frais de Port : '.$fraisdeport.'', 0, "L", 0);
// Saut de ligne
$pdf->ln(5);
// Décalage à droite
$pdf->Cell(138);
// Montant Total HT
$pdf->MultiCell(0, 8, 'Montant Total HT : '.$ligne1['Montant_commande'].' €', 0, "L", 0);
// Saut de ligne
$pdf->ln(5);
// Décalage à droite
$pdf->Cell(121);
// TVA
$pdf->MultiCell(0, 8, 'TVA non applicable, art.293 B du CGI', 0, "L", 0);
// Saut de ligne
$pdf->ln(5);
// Décalage à droite
$pdf->Cell(136);
// Montant Total TTC
$pdf->MultiCell(0, 8, 'Montant Total TTC : '.$ligne1['Montant_commande'].' €', 0, "L", 0);
// Saut de ligne
$pdf->ln(5);
// Facturé à
$pdf->MultiCell(0, 8, 'Facturé à : '.$ligne4['Prenom_Users'].' '.$ligne4['Nom_Users'].'', 0, "L", 0);
// Saut de ligne
$pdf->ln(5);
// Adresse
$pdf->MultiCell(80, 8, "A l'adresse :\n".stripslashes($ligne4['Prenom_Users']).' '.stripslashes($ligne4['Nom_Users'])."\n".stripslashes($ligne3['Adresse_adresse'])."\n".$ligne3['Codepostal_adresse']." ".stripslashes($ligne3['Ville_adresse'])."", 0, "L", 0);
// Saut de ligne
$pdf->ln(15);
// Merci de votre confiance
$pdf->MultiCell(0, 8, 'Merci de votre confiance', 0, "L", 0);
// Saut de ligne
$pdf->ln(10);
// Déconnexion de la base de données
mysql_close();
$pdf->Output();
?> |
Partager