<?php
error_reporting(E_ALL);
require('pdf_demo/fpdf.php');
		//print_r($_POST);
		//exit;
	class PDF_reciept extends FPDF 
	
	{ 
    public function __construct($orientation = 'P', $unit = 'pt', $format = 'Letter', $margin = 20)
{
    parent::__construct($orientation, $unit, $format, $margin);
    //$this->FPDF($orientation, $unit, $format);
    $this->SetTopMargin($margin);
    $this->SetLeftMargin($margin);
    $this->SetRightMargin($margin);
    $this->SetAutoPageBreak(false, $margin);
}
	function showMoney($money){
        $this->cell(iconv("UTF-8", "ISO-8859-1", "£"). $money);
	}

	function PriceTable($id,$pickUpdate,$hours,$mins,$passenger,$pickup_from,$post_code,$drop_address,$drop_post_code,$driver,$waitingTime,$fare,$waitingCharge,$parking,$others,$totalFare){
	//,$driver,$waitingTime,$fare,$waitingCharge) { 

    $this->SetFont('Arial', 'B', 9); 
    $this->SetTextColor(0,0,0); 
     
	$this->SetX(13);
	$this->SetFillColor(248, 232,232); 
    $this->SetLineWidth(1); 


	
	$this->Cell(30, 25, "Id", 'LTR', 0, 'C', true); 
    $this->Cell(40, 25, "Date", 'LTR', 0, 'C', true);
	$this->Cell(40, 25, "Time", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Passenger", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Pickup From", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Drop To", 'LTR', 0, 'C', true); 
    $this->Cell(40, 25, "Driver", 'LTR', 0, 'C', true);
	$this->Cell(50, 25, "W/Time", 'LTR', 0, 'C', true); 
	//$this->SetX(500);
	$this->Cell(40, 25, "Fare", 'LTR', 0, 'C', true);
	$this->Cell(50, 25, "W/Chrge", 'LTR', 0, 'C', true);
	$this->Cell(40, 25, "Prkng", 'LTR', 0, 'C', true);
	$this->Cell(35, 25, "Othr", 'LTR', 0, 'C', true); 
	$this->Cell(45, 25, "Total Fare", 'LTR', 10, 'C', true);

 
    $this->SetFont('Arial', 'B', 9);  
    $this->SetFillColor(238); 
    $this->SetLineWidth(0.2); 
    $fill = false; 
    
	//set initial y axis position per page
	$y_axis_initial = 25;
	//initialize counter
	$rows = 0;
	//Set maximum rows per page
	$max = 5;

	//Set Row Height
	$row_height = 6;


    for ($i = 0; $i < count($passenger); $i++) { 
	   
		if($rows==$max){ 
		$this->AddPage('L');
		
		$this->SetY(170);
		$this->SetX(13);
		$this->SetFillColor(248, 232,232); 
    $this->Cell(30, 25, "Id", 'LTR', 0, 'C', true); 
    $this->Cell(40, 25, "Date", 'LTR', 0, 'C', true);
	$this->Cell(40, 25, "Time", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Passenger", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Pickup From", 'LTR', 0, 'C', true);
	$this->Cell(120, 25, "Drop To", 'LTR', 0, 'C', true); 
    $this->Cell(40, 25, "Driver", 'LTR', 0, 'C', true);
	$this->Cell(50, 25, "W/Time", 'LTR', 0, 'C', true); 
	//$this->SetX(500);
	$this->Cell(40, 25, "Fare", 'LTR', 0, 'C', true);
	$this->Cell(50, 25, "W/Chrge", 'LTR', 0, 'C', true);
	$this->Cell(40, 25, "Prkng", 'LTR', 0, 'C', true);
	$this->Cell(35, 25, "Othr", 'LTR', 0, 'C', true); 
	$this->Cell(45, 25, "Total Fare", 'LTR', 10, 'C', true);

		$rows=0;
		
		
		}
		$this->SetFillColor(232, 232,232); 
		$this->SetX(13);
	    $this->Cell(30, 40, $id[$i], 1, 0, 'L', $fill);
		$this->Cell(40, 40, $pickUpdate[$i], 1, 0, 'L', $fill); 
		$this->Cell(40, 40, $hours[$i].":".$mins[$i], 1, 0, 'L', $fill);
		$this->Cell(120, 40, $passenger[$i], 1, 0, 'L', $fill);
	    $pickup_address=$pickup_from[$i].",".$post_code[$i];
		$drop_address=$drop_address[$i].",".$drop_post_code[$i];
		$address=$pickup_address.'<br>'.$drop_address;
		$this->Cell(120, 40, $address, 1, 0, 'L', $fill);
		
        $this->Cell(40, 40, $driver[$i], 1, 0, 'L', $fill);
		$this->Cell(50, 40, $waitingTime[$i], 1, 0, ':', $fill); 
		$this->Cell(40, 40, number_format($fare[$i],2), 1, 0, 'R', $fill); 
		$this->Cell(50, 40, number_format($waitingCharge[$i],2), 1, 0, 'R', $fill); 
		$this->Cell(40, 40, number_format($parking[$i],2), 1, 0, 'R', $fill); 
		$this->Cell(35, 40, number_format($others[$i],2), 1, 0, 'R', $fill); 
		$this->Cell(45, 40, number_format($totalFare[$i],2), 1, 1, 'R', $fill); 
        $fill = !$fill; 
		$rows=$rows+1;	
			
    } 
    $this->Ln(5);
	$this->SetX(618); 
    $this->Cell(95, 20, "Total Net Amount", 1,'R');
	$total= number_format(array_sum($totalFare),2);
    $this->Cell(70, 20,$total, 1, 1, 'R'); 
	
}

function grand_total($totalFare){
	return array_sum($totalFare);
}

//header
function Header() {
	
    $this->SetFont('Arial', 'B', 20); 
    $this->SetFillColor(0,0,125); 
    $this->SetTextColor(225); 
    $this->Cell(0, 30, "Service Invoice", 0, 0, 'L', true); 

    $this->SetY(75);   
    $this->SetTextColor(200); 
 	$this->SetFont('Arial', 'B', 12); 
	$this->Cell(150, 20, "Limo Chauffeurs Ltd.", 0, 0, 'L', true);
	$this->SetY(105); 
	$this->SetFont('Arial', '', 12); 
	$this->SetTextColor(0); 
	$this->Cell(100, 10, "12 Lampton Park Road,",0,1);
    $this->Ln(3);
	$this->Cell(100, 10, "Hounslow,",0,1);
    $this->Ln(3);
	$this->Cell(100, 10, "Middlesex",0,1);
	$this->Ln(3);
	$this->Cell(100, 10, "TW3 4HS ",0,1);
	$this->Ln(3); 
	$this->Cell(100, 10, "United Kingdom ",0,1); 

	$this->SetXY(610,100);   
    $this->SetTextColor(0); 
 	$this->SetFont('Arial', '', 10); 
	$this->Cell(100, 10, "Phone: (0)2082304594",0,1);
	$this->Ln(8);
	$this->SetXY(610,115);   
	$this->Cell(100, 10, "Mobile:(0)7808939220,",0,1);
	$this->Ln(8);
	$this->SetXY(610,130);
	$this->Cell(100, 10, "Email: info@limochauffeurs.com",0,1);
	$this->Ln(3);
	$this->SetXY(610,145);
	
	$this->Cell(100, 10, "Website: www.limochauffeurs.com");
	$this->SetFont('Arial', 'B', 11); 
	$this->Ln(3);
	$this->SetXY(610,160);
	
	$this->Cell(100, 10, "VAT No: 1234569898");
	// Set up the Invoice To Data
	
	$this->SetXY(300,75);
	$this->SetFont('Arial', 'B', 14); 
    $this->SetFillColor(133,0,0); 
    $this->SetTextColor(225); 
	$this->Cell(150, 20, "Invoice To:", 0, 0, 'L', true);
	$this->Ln(15);
	$this->SetFont('Arial', '', 10);
	$this->SetTextColor(0); 
	$this->SetXY(300,105);
	$company=$_POST['customer_name'];
	$company_address=$_POST['company_address1'];
	$company_city=$_POST['company_city'];
	$company_post_code=$_POST['company_post_code'];
	
	
	$this->Cell(250, 10, "$company",0,1);
	$this->Ln(20);
	$this->SetXY(300,120);
	
	$this->Cell(100, 10, "$company_address",0,1);
	$this->Ln(15);
	$this->SetXY(300,130); 
	$this->Cell(110, 20, "$company_city,",0,1);
	$this->Ln(15);
	$this->SetXY(300,145);
 
	$this->Cell(110, 20, "$company_post_code",0,1);
	
	$this->Image('logo.png',625,65,150);
	// iNVICE INFO
	$this->Ln(15);
	$this->SetXY(20,180);  
	$this->SetFont('Arial', 'B', 20); 
    $this->SetFillColor(255,0,0); 
    $this->SetTextColor(225);
	$gross=$_POST['gross']; 
	
    $this->Cell(430, 30,"Total Due: ". iconv("UTF-8", "ISO-8859-1", "£"). $gross, 0, 0, 'L', true); 


}
 //footer
 function Footer() { 
    $this->SetFont('Arial', '', 10); 
    $this->SetTextColor(0); 
    $this->SetXY(0,-80);
	$this->Cell(0, 20, "Thank you for ordering at Limo Chauffeurs Ltd", 'T', 1, 'C');
    $this->Cell(0, 20, "Barclays Bank Account. xxxxxxx",0,1);
    $this->Cell(0, 20, "Sort Code: xx-xx-xx",0,1);
    $this->Cell(0, 20, "Branch: Hounslow",0,1); 
    
	
	//$this->Image('footer.JPG',0,750,620,50); 
}

// Add Watermark
function RotatedText($x, $y, $txt, $angle)
{
    //Text rotated around its origin
    $this->Rotate($angle,$x,$y);
    $this->Text($x,$y,$txt);
    $this->Rotate(0);
}

}

$pdf = new PDF_reciept(); 
$pdf->AddPage('L'); 
$pdf->SetFont('Arial', 'B', 11);
//move our cursor; we can do this by using the SetY method.
$pdf->SetY(225);
$pdf->SetX(25);
$pdf->SetFont('Arial', 'B'); 
$pdf->Cell(60, 10, 'Invoice Date: '); 
$pdf->SetFont('Arial', ''); 
$pdf->SetX(115);
$invoice_date=$_POST['invoice_date'];
$invoice_date = date("d-m-Y", strtotime($invoice_date));
$pdf->Cell(100, 10, $invoice_date, 0, 1);
$pdf->Ln(15);
$pdf->SetX(25);
$pdf->SetFont('Arial', 'B'); 
$pdf->Cell(60, 10, 'Invoice No: '); 
$pdf->SetFont('Arial', '');
$invoice_no=$_POST['invoice_no']; 
$pdf->Cell(100, 10,$invoice_no, 0, 1); 

$pdf->Ln(20);
$pdf->SetX(10);

$grand=$pdf->grand_total($_POST['total_fare']);
$vat=$grand*.20; //or $_POST['tax']
//$grand="6800.00";
$pdf->PriceTable($_POST['booking_id'], $_POST['booking_date'], $_POST['hours'],$_POST['mins'], $_POST['company_contact'],$_POST['address1'],$_POST['post_code'],$_POST['drop_address'],$_POST['drop_post_code'],$_POST['driver'],$_POST['waiting_time'],$_POST['fare'],$_POST['waiting_charges'],$_POST['parking'],$_POST['other'],$_POST['total_fare']);
//,$_POST['city']);

$pdf->Ln(5);
$pdf->SetX(618); 
$pdf->Cell(94, 20, "VAT (20%))", 1,'R'); 
$pdf->Cell(70, 20, number_format($vat,2), 1, 1, 'R');
$pdf->Ln(5);
$grand=$pdf->grand_total($_POST['total_fare']);
$grand=$grand+$vat;
setlocale(LC_MONETARY, 'en_IN');

$grand = number_format($grand,2);
$pdf->SetX(618); 
$pdf->Cell(94, 20, "Grand Total", 1,'R'); 
$pdf->Cell(70, 20,$grand, 1, 1, 'R');

$date=date('F j, Y');
$file='invoice_'.$invoice_no."-".$date.'.pdf';


//
//$file,'d'
$pdf->Output();


?>

