<?php
require_once("dbconfig.php");
//$db_handle = new DBController();
$result = $con->c(
"SELECT invoices.invoice_no,invoices.date, invoices.customer_id, customers.name,invoices.nett, invoices.vat,invoices.gross, invoices.status status_id,
invoice_status.name as status
FROM invoices
LEFT JOIN invoice_status ON invoices.status = invoice_status.id
LEFT JOIN customers ON invoices.customer_id = customers.id order by invoices.invoice_no DESC");

$header = ("SELECT `COLUMN_NAME` 
FROM `INFORMATION_SCHEMA`.`COLUMNS` 
WHERE `TABLE_SCHEMA`='ezycab' 
    AND `TABLE_NAME`='invoices'");

require('../pdf_demo/fpdf.php');

// Begin configuration

$textColour = array( 0, 0, 0 );
$headerColour = array( 100, 100, 100 );
$tableHeaderTopTextColour = array( 255, 255, 255 );
$tableHeaderTopFillColour = array( 125, 152, 179 );
$tableHeaderTopProductTextColour = array( 0, 0, 0 );
$tableHeaderTopProductFillColour = array( 143, 173, 204 );
$tableHeaderLeftTextColour = array( 99, 42, 57 );
$tableHeaderLeftFillColour = array( 184, 207, 229 );
$tableBorderColour = array( 50, 50, 50 );
$tableRowFillColour = array( 213, 170, 170 );
$reportName = "Drivers Report";
$reportNameYPos = 160;
$logoFile = "widget-company-logo.png";
$logoXPos = 50;
$logoYPos = 108;
$logoWidth = 110;
$columnLabels = array( "Invoice", "Date", "Company", "Nett" , "VAT" , "Gross" );
$rowLabels = array( "SupaWidget", "WonderWidget", "MegaWidget", "HyperWidget" );


// End configuration



$count=count($result);
$pdf = new FPDF();
$pdf->AddPage('L','A4');


$pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
$pdf->SetFont( 'Arial', '', 20 );
$pdf->Write( 19, "List of Invoices" );

$pdf->Ln(15);
// Create the table header row
$pdf->SetFont( 'Arial', 'B', 15 );

// Create the table header row
$pdf->SetFont( 'Arial', 'B', 15 );

// "PRODUCT" cell
$pdf->SetTextColor( $tableHeaderTopProductTextColour[0], $tableHeaderTopProductTextColour[1], $tableHeaderTopProductTextColour[2] );
$pdf->SetFillColor( $tableHeaderTopProductFillColour[0], $tableHeaderTopProductFillColour[1], $tableHeaderTopProductFillColour[2] );

// Remaining header cells
$pdf->SetTextColor( $tableHeaderTopTextColour[0], $tableHeaderTopTextColour[1], $tableHeaderTopTextColour[2] );
$pdf->SetFillColor( $tableHeaderTopFillColour[0], $tableHeaderTopFillColour[1], $tableHeaderTopFillColour[2] );

for ( $i=0; $i<count($columnLabels); $i++ ) {
  $pdf->Cell( 40, 12, $columnLabels[$i], 1, 0, 'C', true );
}

$pdf->Ln( 12 );

$validColumn = array('invoice_no','date','name','nett','vat','gross');
 foreach($result[0] as $key=>$value)
 {
 	if(array_search($key,$validColumn) !== false)
 	{
		
 		//$pdf->Cell(40,12,$key, 1, 0, 'L', true);
 	}
	
 }

$pdf->Ln(2 );
$pdf->SetFont('Arial','B',10);

 foreach($result as $key=>$value)
 {
 	foreach($value as $innerkey=>$innervalue)
 	{

 	    if(array_search($innerkey,$validColumn) !== false)
 		{
			
			
			// Create the data cells
  $pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
  $pdf->SetFillColor( $tableRowFillColour[0], $tableRowFillColour[1], $tableRowFillColour[2] );
  $pdf->SetFont( 'Arial', '', 12 );
			//$innervalue[3]=date("d/m/Y",strtotime($innervalue[3]));
 			$pdf->Cell(40,12,$innervalue,1);
 		}
		
 	}
 	$pdf->Ln();
 }

$pdf->Output();
?>