File: /var/www/html/amberconcept/test_po_item_break.php.bak20111122
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
//include wp libriries and set timezone to HK
require_once('wp-load.php');
require_once('PHPExcel.php');
require_once('TCPDF/data/tcpdf_include.php');
date_default_timezone_set("Asia/Hong_Kong");
$order_id = $_GET['order_id'];
$order = wc_get_order($order_id);
$isFotomax = $order->get_user_id()==7?true:false;
// draw header table
$htmlHeader = '<div id="headerSection">
<table cellspacing="2" cellpadding="2">
<tr>
<td>
<table id="po_table" cellspacing="1" cellpadding="1">
<tr>
<td colspan="2"><h1>PURCHASE ORDER</h1></td>
</tr>
<tr>
<td></td><td></td>
</tr>
<tr>
<td>DATE:</td><td>'.date('F d, Y', strtotime($order->get_date_created())).'</td>
</tr>
<tr>
<td>VENDOR NO.:</td><td>Wink Impression</td>
</tr>
<tr>
<td>ORDER ID:</td><td>PO# '.$order->get_order_number().'</td>
</tr>
</table>
</td>
<td></td>
<td>
<table id="amber_table" cellspacing="1" cellpadding="1" style="text-align: right;">
<tr>
<td><img src="custom/image/Amber.png" width="150"></td>
</tr>
<tr>
<td><small>Flat 6A, Kin Ho Industrial Building, Block 1<br>14-24 Au Pui Wan Street, Fotan, NT, HK</small></td>
</tr>
<tr>
<td><small>Tel: 852-2278 5768<br>Fax: 852-2691 0724<br>Email: cs.hk@amberconcept.com</small></td>
</tr>
</table>
</td>
</tr>
</table>
</div>';
// draw address table
$htmlAddress = '<div id="addressSection">
<table cellspacing="0" cellpadding="0" border="1">
<tr>
<td width="30%">
<table id="vendor_table" cellspacing="1" cellpadding="1">
<tr style="background-color:#000;color:#FFF">
<td>Vendor</td>
</tr>
<tr>
<td>Wink Impression</td>
</tr>
<tr>
<td>中國廣東省東莞市樟木頭鎮莞樟東路311號</td>
</tr>
<tr>
<td>Tel: (+86) 076987191122</td>
</tr>
<tr>
<td>Fax: (+86) 076987782619</td>
</tr>
<tr>
<td>Email: hongli_pang@w-impression.com</td>
</tr>
<tr>
<td>Attn: 紅麗</td>
</tr>
</table>
</td>
<td width="30%">
<table id="ship_table" cellspacing="1" cellpadding="1">
<tr style="background-color:#000;color:#FFF">
<td>Ship To</td>
</tr>
<tr>
<td>Amber Concept Ltd.</td>
</tr>
<tr>
<td>Flat 6A, Blk 1, Kin Ho Industrial Building</td>
</tr>
<tr>
<td>14-24 Au Pui Wan St. Fotan, HK</td>
</tr>
<tr>
<td>Tel: (852) 2278 5700</td>
</tr>
<tr>
<td>Fax: (852) 2691 0724</td>
</tr>
<tr>
<td>Email: sam.lee@amberconcept.com</td>
</tr>
<tr>
<td>Attn: Sam Lee</td>
</tr>
</table>
</td>
<td width="40%">
<table id="other_table" cellspacing="1" cellpadding="1">
<tr style="background-color:#000;color:#FFF">
<td colspan="2">Other Information</td>
</tr>
<tr>
<td>Ship Via: </td><td>'.$order->get_shipping_method().'</td>
</tr>
<tr>
<td>Shipment Term: </td><td>FOB</td>
</tr>
<tr>
<td>Payment Term: </td><td>Net 30 Days</td>
</tr>
<tr>
<td>Request Delivery Date: </td><td>'.($isFotomax?'Fotomax單, 7日內交':'10日內交').'</td>
</tr>
<tr>
<td>Courier: </td><td>Fedex/SF Express/GE-DHL</td>
</tr>
<tr>
<td>Shippng Document Value: </td><td>US$50 /pc</td>
</tr>
<tr>
<td>Weight & Ctn Size: </td><td>Pls see packing list</td>
</tr>
</table>
</td>
</tr>
</table>
</div>';
// draw footer cell (right)
$htmlPrice = '
<table cellspacing="1" cellpadding="1" border="1">
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Sub Total:</td>
<td width="30%" align="center"></td>
</tr>
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Discount:</td>
<td width="30%" align="center"></td>
</tr>
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Sales Tax Rate:</td>
<td width="30%" align="center"></td>
</tr>
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Sales Tax:</td>
<td width="30%" align="center"></td>
</tr>
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Other Cost:</td>
<td width="30%" align="center"></td>
</tr>
<tr>
<td width="70%" align="right" style="background-color:#000;color:#FFF">Grand Total:</td>
<td width="30%" align="center"></td>
</tr>
</table>';
// draw date cell (left)
$htmlDate = '<table id="dateSection" width="100%">
<tr>
<td><h1>'.date('F d, Y', strtotime($order->get_date_created())).'</h1></td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>Date</td>
</tr>
</table>';
// draw sign cell (right)
$htmlSign = '<table id="signSection" width="100%">
<tr>
<td><h1>Sam Lee</h1></td>
</tr>
<tr>
<td><hr></td>
</tr>
<tr>
<td>Authorized Signature</td>
</tr>
</table>';
// Extend the TCPDF class to create custom Header and Footer
class MYPDF extends TCPDF {
public $htmlHeader;
public $htmlAddress;
public $htmlShipping;
public $htmlPrice;
public $htmlDate;
public $htmlSign;
//Page header
public function Header() {
$this->writeHTML($this->htmlHeader, true, false, false, false, '');
$this->Line(10, 38, 200, 38, array('width' => 0.7));
$this->writeHTML($this->htmlAddress, true, false, false, false, '');
}
// Page footer
public function Footer() {
// Position at 60 mm from bottom
$this->SetY(-60);
$this->SetFillColor(204,204,204);
$this->SetTextColor(0, 0, 0);
$this->writeHTMLCell(60, '', 10, 235, $this->htmlShipping, 0, 1, 1, true, 'L', true);
$this->SetFillColor(255, 255, 255);
$this->writeHTMLCell(60, '', 140, 235, $this->htmlPrice, 0, 1, 1, true, 'J', true);
$this->writeHTMLCell(60, '', 10, 265, $this->htmlDate, 0, 1, 1, true, 'J', true);
$this->writeHTMLCell(60, '', 140, 265, $this->htmlSign, 0, 1, 1, true, 'J', true);
$this->Line(10, 286, 200, 286, array('width' => 0.3));
// Page number
$this->Cell(205, 20, 'Page '.$this->getAliasNumPage().'/'.$this->getAliasNbPages(), 0, false, 'R', 0, '', 0, false, 'T', 'M');
}
}
// create new PDF document
$pdf = new MYPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->htmlHeader = $htmlHeader;
$pdf->htmlAddress = $htmlAddress;
$pdf->htmlPrice = $htmlPrice;
$pdf->htmlDate = $htmlDate;
$pdf->htmlSign = $htmlSign;
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('WH-HKMIS');
$pdf->SetTitle('AMBER PO');
$pdf->SetSubject('AMBER PO');
$pdf->SetKeywords('AMBER PO');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);
// set header and footer fonts
$pdf->setHeaderFont(Array('DroidSansFallback', '', PDF_FONT_SIZE_DATA));
$pdf->setFooterFont(Array('DroidSansFallback', '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, 80, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(10);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, 60);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// ---------------------------------------------------------
// set font
$pdf->SetFont('DroidSansFallback', '', 8, '', true);
// add a page
// draw product table
$i = 1;
foreach( $order->get_items() as $item_id => $item ) {
$pdf->AddPage();
$htmlProduct = '<div id="productSection">';
$htmlProduct .= '<table cellspacing="0" cellpadding="0" border="1"><tr><td>
<table cellspacing="1" cellpadding="1" border="0">
<tr style="background-color:#000;color:#FFF">
<td width="70%" align="left">Description '.$i.'</td>
<td width="10%" align="center">Qty.</td>
<td width="10%" align="center">Unit Price</td>
<td width="10%" align="center">Total</td>
</tr> ';
$i++;
$product = wc_get_product( $item->get_product_id());
$formatted_meta_data = $item->get_formatted_meta_data( '_', true );
$htmlProduct .= '
<tr>
<td>Name 產品名稱: '.$item->get_name().'</td>
<td align="center">'.$item->get_quantity().'</td>
<td align="center"></td>
<td align="center"></td>
</tr>';
$array_attributes = array();
foreach($formatted_meta_data as $metaObj){
$array_attributes[$metaObj->display_key] = strip_tags($metaObj->display_value);
}
/*
if(!isset($array_attributes['Orientation'])){
$array_attributes['Orientation'] = "Lanscape";
}
*/
$array_orientation = array(
'Portrait' => '直度',
'Square' => '正方',
'Lanscape' => '橫度'
);
$bill_to_name = $order->get_formatted_billing_full_name();
$array_logo_file = array(
'Upload' => get_customer_logo_po($bill_to_name)!=""?get_customer_logo_po(trim($bill_to_name)):'Logo圖樣',
'Letterpress' => "壓字粒"
);
//print_r($array_attributes);
foreach($array_attributes as $display_name => $display_value) {
$display_value = trim($display_value);
switch(trim($display_name)){
case "Color":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 封殼物料: '.$display_value.' ('.get_value_from_cover_box_material($display_value,'cover_material').')</td></tr>';
break;
case "Binding":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 釘裝方式: '.$display_value.' ('.get_display_binding($array_attributes['Size'],$array_attributes['Orientation'],$display_value).', '.get_inner_paper_material($array_attributes['Size'],$array_attributes['Orientation'],$array_attributes['Binding'],$array_attributes['Spreads']).')</td></tr>';
if(get_display_binding($array_attributes['Size'],$array_attributes['Orientation'],$display_value)=="雜誌裝"){
$htmlProduct .= '<tr><td colspan="4">Book Tap 書頭布: '.get_value_from_cover_box_material($array_attributes['Color'],'book_tape').'</td></tr>';
}
$htmlProduct .= '<tr><td colspan="4">Lining Material 襯層物料: '.get_lining_material($array_attributes['Size'],$array_attributes['Orientation'],$display_value).'</td></tr>';
break;
case "Size":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 尺寸: '.get_display_size($display_value,$array_attributes['Orientation']).'</td></tr>';
break;
case "Orientation":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 方向: '.$array_orientation[$display_value].'</td></tr>';
break;
case "Logo File":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.': '.$array_logo_file[$display_value].'</td></tr>';
break;
case "Logo Finishing":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 相冊後工序: '.get_display_finishing($display_value).' ('.get_finishing_material($display_value).')</td></tr>';
break;
case "Font":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 字款: '.get_display_fonts($display_value).'</td></tr>';
break;
case "Logo Position":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 位置: '.get_display_position($display_value).'</td></tr>';
break;
case "Letterpress Finishing":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 相冊後工序: '.get_display_finishing($display_value).' ('.get_finishing_material($display_value).')</td></tr>';
break;
case "Letterpress Position":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 位置: '.get_display_position($display_value).'</td></tr>';
break;
case "Text on Lining":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 文字: '.$display_value.'</td></tr>';
$htmlProduct .= '<tr><td colspan="4"><span style="color:#FFF">'.$display_name.'</span> 字款: Avenir 25pt</td></tr>';
$htmlProduct .= '<tr><td colspan="4"><span style="color:#FFF">'.$display_name.'</span> 位置: 上下左右分中</td></tr>';
$htmlProduct .= '<tr><td colspan="4"><span style="color:#FFF">'.$display_name.'</span> 顏色: White 白色</td></tr>';
break;
case "Spreads":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 頁數: '.$display_value.'P</td></tr>';
break;
case "Remark":
$htmlProduct .= '<tr><td colspan="4">'.$display_name.' 備註: '.$display_value.'</td></tr>';
break;
case "Box":
//$htmlProduct .= '<tr><td colspan="3">'.$display_value.'</td></tr>';
if(trim($display_value)!="None"){
if(trim($display_value)=="Matte Box"){
$htmlProduct .= '<tr><td colspan="3">Box 盒子: 天地蓋黑盒 ('.get_value_from_cover_box_material($array_attributes['Color'],'matte_box_material').')</td></tr>';
$htmlProduct .= '<tr><td colspan="3">Ribbon 絲帶: '.get_value_from_cover_box_material($array_attributes['Color'],'matte_box_ribbon').'</td></tr>';
}
if(trim($display_value)=="Luxe Presentation Box"){
$htmlProduct .= '<tr><td colspan="3">Box 盒子: 配色掀蓋盒 ('.get_value_from_cover_box_material($array_attributes['Color'],'luxe_presentation_box_material').')</td></tr>';
$htmlProduct .= '<tr><td colspan="3">Ribbon 絲帶: '.get_value_from_cover_box_material($array_attributes['Color'],'luxe_presentation_box_ribbon').'</td></tr>';
}
$htmlProduct .= '<tr><td colspan="3">Box Finishing 盒面後工序: 跟相薄封面</td></tr>';
$htmlProduct .= '<tr><td colspan="3">Box Size 盒尺寸: 適合放入相冊尺寸</td></tr>';
}
break;
case "Black Matt Box":
if(trim($display_value)!="None"){
if(strpos($display_value,"Yes")!==false){
$htmlProduct .= '<tr><td colspan="3">Box 盒子: 天地蓋黑盒 ('.get_value_from_cover_box_material($array_attributes['Color'],'matte_box_material').')</td></tr>';
$htmlProduct .= '<tr><td colspan="3">Ribbon 絲帶: '.get_value_from_cover_box_material($array_attributes['Color'],'matte_box_ribbon').'</td></tr>';
}
$htmlProduct .= '<tr><td colspan="3">Box Finishing 盒面後工序: 跟相薄封面</td></tr>';
$htmlProduct .= '<tr><td colspan="3">Box Size 盒尺寸: 適合放入相冊尺寸</td></tr>';
}
break;
default:
$htmlProduct .= '<tr><td colspan="3">'.$display_name.': '.$display_value.'</td></tr>';
break;
}
}
if($isFotomax){
$htmlProduct .= '<tr><td colspan="3">Remark 備註 :封底內頁底部左下角燙Amber logo,右下角燙fotomax logo (跟PO100000548-1)</td></tr>';
}
$htmlProduct .= '<tr><td colspan="3">Packaging 包裝方式: 產品用氣泡袋及海棉護角保護後入AMBER坑箱</td></tr>';
if(trim($item->get_name())=="Canvas"){
$file = get_post_meta($order_id, '_wcuf_uploaded_files', true);
if($file!=""){
foreach($file as $fileArr){
$htmlProduct .= '<tr><td colspan="3"><img src="'.$fileArr['absolute_path'][0].'" width="300"><img></td></tr>';
}
}
}
//Image(file, x = '', y = '', w = 0, h = 0, type = '', link = nil, align = '', resize = false, dpi = 300, palign = '', ismask = false, imgmask = false, border = 0, fitbox = false, hidden = false, fitonpage = false)
//$pdf->Image('/var/www/html/amberconcept/document/file/Tulips.jpg', 10, 140, 0, 50, 'JPG', '', '', true, 150, '', false, false, 0, false, false, false);
$htmlProduct .= '</table></td></tr></table>';
$htmlProduct .= '</div>';
$pdf->writeHTML($htmlProduct, true, false, false, false, '');
// draw footer cell (left)
if($isFotomax){
$htmlShipping = "Fotomax<br>(".$array_attributes['Fotomax PO'].")";
} else {
$fullname = $order->get_formatted_shipping_full_name()==""?"":$order->get_formatted_shipping_full_name();
$company = $order->get_shipping_company()==""?"":"<br>".$order->get_shipping_company();
$address1 = $order->get_shipping_address_1()==""?"":"<br>".$order->get_shipping_address_1();
$address2 = $order->get_shipping_address_2()==""?"":"<br>".$order->get_shipping_address_2();
$city = $order->get_shipping_city()==""?"":"<br>".$order->get_shipping_city();
$state = $order->get_shipping_state()==""?"":"<br>".$order->get_shipping_state();
$country = $order->get_shipping_country()==""?"":"<br>".$order->get_shipping_country();
$htmlShipping = $fullname.$company.$address1.$address2.$city.$state.$country;
}
$pdf->htmlShipping = $htmlShipping;
$pdf->lastPage();
}
// print a block of text using Write()
$pdf->Write(0, $txt, '', 0, 'C', true, 0, false, false, 0);
// ---------------------------------------------------------
//Close and output PDF document
$output_path = "/var/www/html/amberconcept/document/po/";
//Close and output PDF document
//$pdf->Output($output_path.'PO'.$order->get_order_number().'.pdf', 'F');
$pdf->Output('PO'.$order->get_order_number().'.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+