<html>
<head>
<title>ThaiCreate.Com PHP PDF</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php
require('fpdf.php');
define('FODF_FONTPATH','font/'); //หาไฟล์ใน folder font
class PDF extends FPDF
{
//Load data
function LoadData($file)
{
//Read file lines
$lines=file($file);
$data=array();
foreach($lines as $line)
$data[]=explode(';',chop($line));
return $data;
}
//Colored table
function FancyTable($header,$data)
{
//Colors, line width and bold font
$this->SetFillColor(255,0,0);
$this->SetTextColor(255);
$this->SetDrawColor(128,0,0);
$this->SetLineWidth(.3);
$this->SetFont('','B');
//Header
$w=array(20,30,55,25,25,25);
for($i=0;$i<count($header);$i++)
$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
//$this->Cell($w[$i],7,iconv('UTF-8', 'cp874', $header[$i]),1,0,'C');
$this->Ln();
//Color and font restoration
$this->SetFillColor(224,235,255);
$this->SetTextColor(0);
$this->SetFont('angsa','',16); //set size
//Data
$fill=false;
foreach($data as $row)
{
$this->Cell($w[0],6,$row[0],'LR',0,'L',$fill);
$this->Cell($w[1],6,$row[1],'LR',0,'L',$fill);
$this->Cell($w[2],6,$row[2],'LR',0,'L',$fill);
$this->Cell($w[3],6,$row[3],'LR',0,'C',$fill);
$this->Cell($w[4],6,number_format($row[4]),'LR',0,'R',$fill);
$this->Cell($w[5],6,number_format($row[5]),'LR',0,'R',$fill);
$this->Ln();
$fill=!$fill;
}
$this->Cell(array_sum($w),0,'','T');
}
}
$pdf=new PDF();
//Column titles
$header=array('รหัส','Name','Email','Country Code','Budget','Used');
//Data loading
//*** Load MySQL Data ***//
include"../config.inc.php";
$con = mysql_connect($host,$username,$password);
if (!$con)
{ die('Could not connect: ' . mysql_error()); }
mysql_select_db($database, $con);
mysql_query("SET NAMES UTF8");
$date_sub=$_REQUEST['date_sub'];
$num=0;
if($date_sub==""){
$msg="รายงานสินค้าทั้งหมด";
$strSQL="SELECT
pd.name_pro as name,
pd.id_pro as id_pro1,
spd.date_sub,
sum( coalesce( spd.sub_out, 0) ) as quan
FROM products pd
LEFT JOIN sub_products spd
ON pd.id_pro=spd.id_pro
WHERE spd.sub_out!='0'
GROUP BY pd.id_pro
ORDER BY sum( spd.sub_out) DESC LIMIT 3";
}elseif($date_sub!=""){
$msg="รายงานสินค้าประจำวัน";
$day_start=$date_sub;
$strSQL="SELECT
pd.name_pro as name,
pd.id_pro as id_pro1,
spd.date_sub,
sum( coalesce( spd.sub_out, 0) ) as quan
FROM products pd
LEFT JOIN sub_products spd
ON pd.id_pro=spd.id_pro
WHERE spd.date_sub='$day_start' and spd.sub_out!='0'
GROUP BY pd.id_pro
ORDER BY sum( spd.sub_out) DESC";
}
$objQuery = mysql_query($strSQL);
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
$result = mysql_fetch_array($objQuery);
array_push($resultData,$result);
}
//************************//
$pdf->AddFont('angsa','','angsa.php');//set font
$pdf->AddFont('angsa','B','angsa.php');
$pdf->AddFont('angsa','I','angsa.php');
$pdf->AddFont('angsa','BI','angsa.php');
$pdf->SetFont('angsa','',12);
//*** Table 3 ***//
$pdf->AddPage();
$pdf->Image('logo.png',80,8,33);
$pdf->Ln(35);
$pdf->FancyTable($header,$resultData);
$pdf->Output("MyPDF/MyPDF.pdf","F");
?>
PDF Created Click <a href="MyPDF/MyPDF.pdf">here</a> to Download
</body>
</html>