<?php
header('Content-Type: text/html; charset=utf-8');

require("fpdf182/fpdf.php");



include('db.php');

$cmd=$_GET['cmd'];

$ver=$db->prepare('SELECT tbl_invoice.*, serveur.nom FROM tbl_invoice, serveur WHERE serveur.id=tbl_invoice.serveur AND tbl_invoice.num_cmd=?');
$ver->execute(array($cmd));
while ($vers=$ver->fetch()) {
    $num_cmd=$vers['num_cmd'];
    $nom_serveur=$vers['nom'];
    $tables=$vers['tables'];
    $total=$vers['total'];
    $remise=$vers['remise'];
    $nap=$vers['nap'];
    $order_date=$vers['order_date'];
    $order_time=$vers['order_time'];
}


$sel=$db->prepare('SELECT * FROM param');
$sel->execute(array());
while ($sels=$sel->fetch()) {
  $_SESSION['raison_sociale']=$sels['raison_sociale'];
  $_SESSION['adresse']=$sels['adresse'];
  $_SESSION['tel']=$sels['tel'];
}


$pdf = new FPDF ('P','mm',array(80,150));

$pdf->AddPage();


$pdf->SetFont('Arial','B',13);

$pdf->Cell(60,8,$_SESSION['raison_sociale'],1,1,'C');

$pdf->SetFont('Arial','B',7);

//$pdf->Cell(60,5,'Block 5 Saadi Town, Karachi',0,1,'C');
$pdf->Cell(60,5,'Contact : '.$_SESSION['tel'].'',0,1,'C');
$pdf->Ln(2);
$pdf->Cell(60,5,'Adresse : '.$_SESSION['adresse'].'',0,1,'C');


//Line(x1,y1,x2,y2);
//$pdf->Line(7,38,72,38);




//Line break
$pdf->Ln(1);

$pdf->SetFont('Arial','B',7);
//$pdf->Cell(20,4,'Date : ',0,0,'');
$pdf->Cell(10,4,'Table: ',0,0,'');
//$pdf->SetFont('Arial','BI',8);
$pdf->Cell(35,4,utf8_decode($tables),0,0,'');


//$pdf->SetFont('Arial','BI',8);
$pdf->Cell(12,4,'Serveur: ',0,0,'');

$pdf->SetFont('Arial','B',7);
$pdf->Cell(40,4,utf8_decode($nom_serveur),0,1,'');
$pdf->Ln(2);


$pdf->SetFont('Arial','B',7);
$pdf->Cell(20,4,'Ticket no: ',0,0,'');

$pdf->SetFont('Arial','B',7);
$pdf->Cell(10,4,$num_cmd,0,1,'');
$pdf->Ln(2);



$pdf->SetFont('Arial','B',7);
//$pdf->Cell(20,4,'Date : ',0,0,'');
$pdf->Cell(8,4,'Date : ',0,0,'');
//$pdf->SetFont('Arial','BI',8);
$pdf->Cell(40,4,$order_date,0,0,'');


//$pdf->SetFont('Arial','BI',8);
$pdf->Cell(10,4,'Heure : ',0,0,'');

$pdf->SetFont('Arial','B',7);
$pdf->Cell(40,4,$order_time,0,1,'');
$pdf->Ln(2);

/////////////////////////



$pdf->SetX(7);
$pdf->SetFont('Courier','B',7);
$pdf->SetFillColor(208,208,208);
$pdf->Cell(38,5,'DESIGNATION',1,0,'C'); //100
$pdf->Cell(11,5,'QTE',1,0,'C');
$pdf->Cell(8,5,'PRIX',1,0,'C');
$pdf->Cell(12,5,'TOTAL',1,1,'C');


$select=$db->prepare('SELECT * FROM table_invoice_details WHERE num_cmd=? AND valid=1');
$select->execute(array($num_cmd));
//$item=$select->fetch(PDO::FETCH_OBJ)
    
    
    while($item=$select->fetch(PDO::FETCH_OBJ)){
        
     $pdf->SetX(7);   
        $pdf->SetFont('Helvetica','B',7);
$pdf->Cell(38,5,utf8_decode($item->designation),1,0,'L'); //100
$pdf->Cell(11,5,$item->qte,1,0,'C');
$pdf->Cell(8,5,$item->price,1,0,'C');
$pdf->Cell(12,5,$item->total,1,1,'C');
        
    }










$pdf->Ln(2);
//product table code

$pdf->SetX(7);
$pdf->SetFont('courier','B',7);
$pdf->Cell(20,5,'',0,0,'L'); //100
//$pdf->Cell(20,5,'',0,0,'C');
$pdf->Cell(29,5,'SOUS-TOTAL',1,0,'C');
$pdf->Cell(20,5,$total,1,1,'C');
$pdf->Ln(2);



//$pdf->SetX(7);
//$pdf->SetFont('courier','B',8);
//$pdf->Cell(20,5,'',0,0,'L'); //100
////$pdf->Cell(20,5,'',0,0,'C');
//$pdf->Cell(25,5,'PAID',1,0,'C');
//$pdf->Cell(20,5,$row->paid,1,1,'C');



//$pdf->SetX(7);
//$pdf->SetFont('courier','B',8);
//$pdf->Cell(20,5,'',0,0,'L'); //100
////$pdf->Cell(20,5,'',0,0,'C');
//$pdf->Cell(25,5,'DUE',1,0,'C');
//$pdf->Cell(20,5,$row->due,1,1,'C');


//$pdf->SetX(7);
//$pdf->SetFont('courier','B',8);
//$pdf->Cell(20,5,'',0,0,'L'); //100
//$pdf->Cell(20,5,'',0,0,'C');
//$pdf->Cell(25,5,'MODE PAIEMENT',1,0,'C');
//$pdf->Cell(20,5,$row->payment_type,1,1,'C');


//$pdf->Cell(60,5,'Invoice',0,1,'C');

//$pdf->SetFont('Arial','',8);
//$pdf->Cell(85,5,'Invoice :' .$row->invoice_id,0,1,'R');
//
//$pdf->SetFont('Arial','',8);
//$pdf->Cell(87,5,'Date : '.$row->order_date,0,1,'R');





$pdf->Cell(20,5,'',0,1,'');
$pdf->SetX(3);
$pdf->SetFont('Courier','B',9);
$pdf->Cell(65,5,'BON DE COMMANDE',0,1,'C');
$pdf->Ln(2);

$pdf->SetX(3);
$pdf->SetFont('Courier','B',10);
$pdf->Cell(65,5,$_SESSION['raison_sociale'],0,1,'C');
$pdf->Ln(2);


$pdf->Ln(2);

//$pdf->SetX(7);
//$pdf->SetFont('Courier','BI',8);
//$pdf->Cell(75,3,'Contact  : +229 96127228',0,1,'');




$pdf->Output();
?>