|
|
Code
<?php
session_start();
define('FPDF_FONTPATH','../../fpdf17/font/');
require('../../inc/connect.php');
require('../../inc/function1.php');
require('../actions/query_user.php');
require_once('../../fpdf17/fpdf.php');
//checklogin($_SESSION['username']);
$invS = "SELECT
inv.id AS inv_id,
inv.name AS inv_no,
inv.p_id AS project_id,
inv.p_name AS project_name,
inv.date AS inv_date,
inv.po_no AS po_no,
inv.quo_no AS quo_no,
inv.c_id AS c_id,
inv.c_thai AS c_thai,
inv.c_taxid AS tax_id,
inv.c_branch AS c_branch,
inv.co_name AS contact,
inv.project_type AS pj_type,
inv.vat AS vat,
inv.tax AS tax,
inv.inv_term AS credit_term,
inv.curency AS curency,
inv.cur_rate AS cur_rate,
inv.note AS inv_note,
inv.inv_total AS inv_total,
inv.inv_discount AS inv_discount,
inv.inv_sub_total AS inv_sub_total,
inv.inv_vat AS inv_vat,
inv.inv_inc_vat AS inv_inc_vat,
inv.inv_tax AS inv_tax,
inv.inv_paid AS inv_paid,
inv.bahttext AS bahttext,
adr.id AS adr_id,
adr.line1 AS line1,
adr.line2 AS line2,
adr.line3 AS line3,
adr.city AS city,
adr.province AS province,
adr.zipcode AS zipcode,
adr.country AS country,
c.phone1 AS phone1,
c.phone2 AS phone2,
c.fax1 AS fax1,
c.fax2 AS fax2,
p.date AS p_date
FROM invoice AS inv
LEFT JOIN invoice_client_company_address AS adr ON inv.id=adr.inv_id
LEFT JOIN client_company AS c ON c.id=inv.c_id
LEFT JOIN project AS p ON inv.p_id=p.id
WHERE inv.id='{$_GET['id']}'";
$invQ = mysql_query($invS) or die("INVOICE SQL=".mysql_error());
$invN = mysql_num_rows($invQ);
$invR = mysql_fetch_array($invQ);
$inv_date = date("j M Y",strtotime($invR['inv_date']));
$ypDate = date("Ym",strtotime($invR['p_date']));
$invTotal = number_format($invR['inv_total'],2);
$invDiscount = number_format($invR['inv_discount'],2);
$invDisRate = number_format(($invR['inv_discount']*100)/$invR['inv_total'],2);
$invSubtotal = number_format($invR['inv_sub_total'],2);
$invVat = number_format($invR['inv_vat'],2);
$invIncVat = number_format($invR['inv_inc_vat'],2);
$invTax = number_format($invR['inv_tax'],2);
$invPaid = number_format($invR['inv_paid'],2);
$invVatRate = number_format($invR['vat']*100,0);
$invTaxRate = number_format($invR['tax']*100,0);
$invoice_item = mysql_query("SELECT
i.id AS id,
i.inv_id AS inv_id,
i.product_id AS product_id,
i.name AS name,
i.start AS start,
i.end AS end,
i.break AS break,
i.qty AS qty,
i.price AS price,
i.total_total AS total_total,
i.discount_rate AS discount_rate,
i.discount AS discount,
i.amt_total AS amt_total,
i.vat AS vat,
i.inc_vat AS inc_vat,
i.tax AS tax,
i.after_tax AS after_tax,
i.operate AS operate,
i.operate_ass AS operate_ass,
i.producer AS producer,
i.producer_ass AS producer_ass,
i.note AS note,
i.status AS status,
i.contact AS contact,
pd.code AS code
FROM invoice_items AS i
LEFT JOIN product_boi AS pb ON i.product_id=pb.p_id
LEFT JOIN product AS pd ON i.product_id=pd.id
WHERE i.inv_id='{$_GET['id']}'
ORDER BY i.start ASC")or die("Invoice Item=".mysql_error());
$invoice_item_num = mysql_num_rows($invoice_item);
//echo $cid."<br>".$invR['c_thai'];
//ทำการสืบทอดคลาส FPDF ให้เป็นคลาสใหม่
class PDF extends FPDF
{
function Header(){ //Override คำสั่ง (เมธอด) Header
$this->SetFont('Circular','',14);
$this->Image('../../img/Onecool_Ramindra_logo_noname.jpg',5, 5, 50, 0);
$this->Cell(0,6, iconv('UTF-8','TIS-620', 'บริษัท วัน คูล แอนด์ รามอินทรา ซาวด์ สตูดิโอ จำกัด | One Cool & Ramindra Sound Studio Co., Ltd.'),0,1,'R');
$this->Cell(45,0,'',0,0,' ');
$this->Cell(0,0,iconv('UTF-8','TIS-620', ' '),1,1,'R');
$this->SetFont('Circular','',10);
$this->Cell(45,0,'',0,0,' ');
$this->Cell(0,5,iconv('UTF-8','TIS-620', '226 ถนนประดิษฐ์มนูธรรม แขวงพลับพลา เขตวังทองหลาง กรุงเทพฯ 10310 โทร 02-148-1100 แฟกซ์ 02-148-1100'),0,1,'');
$this->Cell(45,0,'',0,0,' ');
$this->Cell(0,2,iconv('UTF-8','TIS-620', '226 Praditmanuthum Road, Phapphla, Wongthonglang, Bangkok 10310 Tel. 662-1481-100 Fax. 662-148-1100'),0,1,'');
$this->Cell(45,0,'',0,0,' ');
$this->Cell(80,5,iconv('UTF-8','TIS-620', 'เลขประจำตัวผู้เสียภาษี / Tax ID : 0 10 555 709 831 2'),0,0,'');
$this->Cell(0,5,iconv('UTF-8','TIS-620','สำนักงานใหญ่'),0,1,'');
$this->SetFont('Circular','B',16);
$this->Cell(0,10,iconv('UTF-8','TIS-620','ใบแจ้งหนี้ / INVOICE'),0,1,'R');
/*
$this->SetFont('Circular','B',12);
$this->Cell(30,0,iconv('UTF-8','TIS-620','Code / รหัสลูกค้า'),0,0,'R');
$this->SetFont('Circular','',12);
$this->Cell(20,0,iconv('UTF-8','TIS-620',''.$invR['c_id']),0,0,'');
$this->SetFont('Circular','B',12);
$this->Cell(30,0,iconv('UTF-8','TIS-620','TAX ID / เลขประจำตัวผู้เสียภาษี'),0,0,'R');
$this->SetFont('Circular','',12);
$this->Cell(0,0,iconv('UTF-8','TIS-620',''.$invR['tax_id']),0,1,'');*/
//ปัดบรรทัด กำหนดความกว้างของบรรทัด 20หน่วย
$this->Ln();
}
//Override คำสั่ง (เมธอด) Footer
function Footer(){
$this->SetY( -30 ); //นับจากขอบกระดาษด้านล่างขึ้นมา 30 มม.
$this->SetFont('Circular','',12);
$this->Cell(65,5,iconv('UTF-8','TIS-620','_________________________________'),0,0,'C');
$this->Cell(65,5,iconv('UTF-8','TIS-620',''),0,0,'C');
$this->Cell(65,5,iconv('UTF-8','TIS-620','_________________________________'),0,1,'C');
$this->Cell(65,5,iconv('UTF-8','TIS-620','ผู้รับบิล / RECEIVED BY'),0,0,'C');
$this->Cell(65,5,iconv('UTF-8','TIS-620',''),0,0,'C');
$this->Cell(65,5,iconv('UTF-8','TIS-620','ผู้มีอำนาจลงนาม / AUTHORIZED BY'),0,1,'C');
$this->Cell(65,10,iconv('UTF-8','TIS-620','วันที่ / DATE _____/_____/_____'),0,0,'C');
$this->Cell(65,10,iconv('UTF-8','TIS-620',''),0,0,'C');
$this->Cell(65,10,iconv('UTF-8','TIS-620','วันที่ / DATE _____/_____/_____'),0,1,'C');
}
}
//ตั้งค่าหน้ากระดาษ
$pdf=new PDF('P' , 'mm' ,'letter');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวธรรมดา กำหนด ชื่อ เป็น Circular
$pdf->AddFont('Circular','','Circular.php');
// เพิ่มฟอนต์ภาษาไทยเข้ามา ตัวหนา กำหนด ชื่อ เป็น Circular
$pdf->AddFont('Circular','B','CircularBold.php');
//สร้างหน้าเอกสาร
$pdf->AddPage();
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','Code / รหัสลูกค้า'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(20,0,iconv('UTF-8','TIS-620',''.$invR['c_id']),0,0,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','TAX ID / เลขประจำตัวผู้เสียภาษี'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(0,0,iconv('UTF-8','TIS-620',''.$invR['tax_id']),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','Company / บริษัท'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,10,iconv('UTF-8','TIS-620',''.$invR['c_thai']),0,0,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','No. / เลขที่'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(35,10,iconv('UTF-8','TIS-620',''.$invR['inv_no']),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','Branch / สาขา'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,0,iconv('UTF-8','TIS-620',''.$invR['c_branch']),0,0,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','Date / วันที่'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(35,0,iconv('UTF-8','TIS-620',''.$inv_date),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','Address / ที่อยู่'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,10,iconv('UTF-8','TIS-620',''.$invR['line1']." ".$invR['line2']),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620',''),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,0,iconv('UTF-8','TIS-620',''.$invR['line3'].", ".$invR['city'].", ".$invR['province']." ".$invR['zipcode']),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','Telephone / โทรศัพท์'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,10,iconv('UTF-8','TIS-620',''.$invR['phone1']." ".$invR['phone2']),0,0,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','Credit / เงื่อนไขการชำระเงิน'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(15,10,iconv('UTF-8','TIS-620',''.$invR['credit_term']),0,0,'C');
$pdf->Cell(20,10,iconv('UTF-8','TIS-620','Day(s)'),0,1,'L');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','FAX / โทรสาร'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(100,0,iconv('UTF-8','TIS-620',''.$invR['fax1']." ".$invR['fax2']),0,0,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,0,iconv('UTF-8','TIS-620','Currency / สกุลเงิน'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(35,0,iconv('UTF-8','TIS-620',''.$invR['curency']),0,1,'ศ');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(30,10,iconv('UTF-8','TIS-620','Subject / ชื่องาน'),0,0,'R');
$pdf->SetFont('Circular','',12);
$pdf->Cell(165,10,iconv('UTF-8','TIS-620',''.$invR['project_name']),0,1,'');
$pdf->SetFont('Circular','B',12);
$pdf->Cell(80,5,iconv('UTF-8','TIS-620','Contact Name / ผู้ติดต่อ'),'TLR',0,'C');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','PJ No / เลขที่งาน'),'TR',0,'C');
$pdf->Cell(45,5,iconv('UTF-8','TIS-620','PO No / ใบสั่งซื้อ'),'TR',0,'C');
$pdf->Cell(40,5,iconv('UTF-8','TIS-620','Quo No / ใบเสนอราคา'),'TR',1,'C');
$pdf->SetFont('Circular','',12);
$pdf->Cell(80,5,iconv('UTF-8','TIS-620',''.$invR['contact']),'BLR',0,'C');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$ypDate."-".$invR['project_id']),'BR',0,'C');
$pdf->Cell(45,5,iconv('UTF-8','TIS-620',''.$invR['po_no']),'BR',0,'C');
$pdf->Cell(40,5,iconv('UTF-8','TIS-620',''.$invR['quo_no']),'BR',1,'C');
$pdf->SetFont('Circular','B',10);
$pdf->Cell(50,5,iconv('UTF-8','TIS-620','Description'),0,0,'C');
$pdf->Cell(25,5,iconv('UTF-8','TIS-620','Date'),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620','In'),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620','Out'),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620','Break'),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620','QTY'),0,0,'C');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Price'),0,0,'C');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Total'),0,1,'C');
//Invoice Items
for($i=1;$i<=$invoice_item_num;$i++){
$invoice_item_row = mysql_fetch_array($invoice_item);
if($invoice_item_row['start']=="0000-00-00 00:00:00"){
$iDate = "";
$iIn = "";
}else{
$iDate = date("d/m-Y",strtotime($invoice_item_row['start']));
$iIn = date("H:i",strtotime($invoice_item_row['start']));
}
if($invoice_item_row['end']=="0000-00-00 00:00:00"){
$ieIn = "";
}else{
$iout = date("H:i",strtotime($invoice_item_row['end']));
}
$ibreak = number_format($invoice_item_row['break'],2);
$iqty = number_format($invoice_item_row['qty'],2);
$iprice = number_format($invoice_item_row['price'],2);
$itotal = number_format($invoice_item_row['total_total'],2);
$pdf->SetFont('Circular','',10);
$pdf->Cell(50,5,iconv('UTF-8','TIS-620',''.$i.". ".$invoice_item_row['name']),0,0,'L');
$pdf->Cell(25,5,iconv('UTF-8','TIS-620',''.$iDate),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620',''.$iIn),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620',''.$iout),0,0,'C');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620',''.$ibreak),0,0,'R');
$pdf->Cell(15,5,iconv('UTF-8','TIS-620',''.$iqty),0,0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$iprice),0,0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$itotal),0,1,'R');
}
//Invoice Note
$pdf->SetFont('Circular','B',10);
$pdf->Cell(10,5,iconv('UTF-8','TIS-620','Note: '),'B',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(155,5,iconv('UTF-8','TIS-620',''.$invR['inv_note']),'B',0,'L');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',' '),'B',1,'L');
//Invoice Total
$pdf->SetFont('Circular','B',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620','หมายเหตุ: '),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Total / รวม :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invTotal),'',1,'R');
$pdf->SetFont('Circular','',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620','1. กรุณาชำระเงินดังกล่าวตามเงื่อนไขการชำระเงินข้างต้น นับจากวันที่รับใบแจ้งหนี้ ในกรณีชำระเงินล่าช้ากว่ากำหนด'),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Discount / ส่วนลด '.$invDisRate.'% :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invDiscount),'B',1,'R');
$pdf->SetFont('Circular','',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620',' บริษัทฯ จะคิดอัตราเบี้ยล่าช้าในอัตราร้อยละ 1.5 ต่อเดือน จนกว่าจะชำระหนี้แล้วเสร็จ'),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Sub Total / รวมทั้งสิ้น :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invSubtotal),'',1,'R');
$pdf->SetFont('Circular','',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620','2. กรณีใบแจ้งหนี้ผิดพลาด จะต้องส่งแก้ไขภายใน 7 วัน นับแต่วันที่ได้รับใบแจ้งหนี้ มิฉะนั้นทางบริษัทฯ จะไม่รับแก้ไข'),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','VAT / ภาษีมูลค่าเพิ่ม '.$invVatRate.'% :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invVat),'B',1,'R');
$pdf->SetFont('Circular','',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620',' และถือว่าท่านยินดีที่จะจ่ายชำระหนี้ตามใบแจ้งหนี้'),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Grand Total / รวมทั้งสิ้น :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invIncVat),'',1,'R');
$pdf->SetFont('Circular','',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620',''),'',0,'L');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','WT / ภาษีเงินได้ หัก ณ ที่จ่าย'.$invTaxRate.'% :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invTax),'B',1,'R');
$pdf->SetFont('Circular','B',10);
$pdf->Cell(135,5,iconv('UTF-8','TIS-620',''.$invR['bahttext']),'',0,'C');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,5,iconv('UTF-8','TIS-620','Total Amount / จำนวนเงินที่ต้องชำระ :'),'',0,'R');
$pdf->Cell(30,5,iconv('UTF-8','TIS-620',''.$invPaid),'B',1,'R');
$pdf->SetFont('Circular','B',10);
$pdf->Cell(135,1,iconv('UTF-8','TIS-620',''),'',0,'C');
$pdf->SetFont('Circular','',10);
$pdf->Cell(30,1,iconv('UTF-8','TIS-620',''),'',0,'R');
$pdf->Cell(30,1,iconv('UTF-8','TIS-620',''),'B',1,'R');
$pdf->Output();
?>
ตามหัวข้อนะครับ ในส่วนของ //Invoice Items อ่ะครับ หากครบแล้วให้ขึ้นหน้าใหม่ และผมสอบถามเพิ่มเติมครับ ในส่วนของ
//Invoice Total ลงมา หากให้ Fix ตำแหน่งเลยจะทำได้ไหมครับ ไม่ให้เลื่อนขึ้นเลื่อนลงตามจำนวนข้อมูลของแถวที่ Query มาได้
Tag : PHP, HTML/CSS
|
|
|
|
|
|
Date :
2016-06-24 18:46:24 |
By :
NuengDunk |
View :
2289 |
Reply :
3 |
|
|
|
|
|
|
|
|
|