<?php
// (c) Xavier Nicolay
// Exemple de génération de devis/facture PDF
require('pdf_invoice_local.php');
//error_reporting(-1);
//ini_set('display_errors', 'On');
$invoiceid = $_REQUEST['invoiceid'];
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$mobile = $_REQUEST['mobile'];
$line1 = $_REQUEST['line1'];
$line2 = $_REQUEST['line2'];
$area = $_REQUEST['area'];
$city = $_REQUEST['city'];
$state = $_REQUEST['state'];
$pincode = $_REQUEST['pincode'];
$date = $_REQUEST['date'];
$service = $_REQUEST['service'];
$type = $_REQUEST['type'];
$service_cost = $_REQUEST['service_cost'];
$discount = $_REQUEST['discount'];
$delivery = $_REQUEST['delivery'];
$tax = $_REQUEST['tax'];
$express = $_REQUEST['expressamount'];
$total = $_REQUEST['total'];
$items = $_REQUEST['items'];
$itemsarray = json_decode($items);
$promocode_amount = $_REQUEST['promocode_amount'];
$express_amount = $_REQUEST['express_amount'];
$additional_cost = $_REQUEST['additional_cost'];
$special_discuont = $_REQUEST['special_discuont'];

$pdf = new PDF_Invoice( 'P', 'mm', 'A4' );
$pdf->AddPage();
$pdf->Header();

$address = $line1 . "\n" . $line2 . "\n" . $area . " " . $city . "\n" . $state . "\n". $pincode ;

$pdf->addSociete( $name, $email, $mobile,$address);
$pdf->fact_dev( "Order ID: ", "HYG-" . $invoiceid);
$pdf->temporaire( "Hygeia - #". $invoiceid );
$pdf->addDate($date);
$pdf->addClient($service);
$pdf->addReglement($type);
//$this->SetXY( $r1 + ($r2 - $r1)/2 - 5 , $y1+1 );
$cols=array( "S.No"    => 25,
             "Item"  => 45,
             "Price" => 45,
             "Qty"  => 25,
             "Total" => 50 );
$pdf->addCols( $cols);
$cols=array( "S.No"    => "C",
             "Item"  => "C",
             "Price"     => "C",
             "Qty"      => "C",
             "Total" => "C");
$pdf->addLineFormat( $cols);
$pdf->addLineFormat($cols);

$y    = 80;
for($i=0; $i < sizeof($itemsarray); $i++){
	$line = array( "S.No"    => $i+1,
               "Item"  => $itemsarray[$i]->name,
               "Price"     => $itemsarray[$i]->price,
               "Qty"      => $itemsarray[$i]->qty,
               "Total" => $itemsarray[$i]->total);
	$size = $pdf->addLine( $y, $line );
	$y   += $size + 2;
}

$pdf->addTVAs( $service_cost,$discount,$tax,$delivery,$express,$promocode_amount,$additional_cost,$special_discuont,$total);
$pdf->addCadreEurosFrancs($express,$promocode_amount,$additional_cost,$special_discuont);
$filname = 'invoice_' . $invoiceid . '.pdf';
//$pdf->Output($filname,'D');
$pdf->Output();
?>

