= 0 || $_GET["order_id"] || (int)$_GET["order_id"] >= 0)) {
echo "";
exit;
}
/**
* PHPExcel
*
* Copyright (C) 2006 - 2014 PHPExcel
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category PHPExcel
* @package PHPExcel
* @copyright Copyright (c) 2006 - 2014 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.8.0, 2014-03-02
*/
/** Error reporting */
/*error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);*/
date_default_timezone_set('Asia/Hong_Kong');
ini_set('apc.cache_by_default', 0);
/*if (PHP_SAPI == 'cli')
die('This example should only be run from a Web Browser');*/
/** Include PHPExcel */
require_once dirname(__FILE__) . '/PHPExcel_1.8.0/Classes/PHPExcel.php';
$reader = PHPExcel_IOFactory::createReader('Excel5'); // 讀取舊版 excel 檔案
$PHPExcel = $reader->load("../webadmin/PHPExcel_1.8.0/invoice_template_withdrawal.xls"); // 檔案名稱
$sheet = $PHPExcel->getSheet(0); // 讀取第一個工作表(編號從 0 開始)
// Set Orientation, size and scaling
$PHPExcel->setActiveSheetIndex(0);
$PHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$PHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);
$PHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(true);
$PHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
$PHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(0);
if (!empty($_GET["type"])) {
if (!empty($_GET["invoice_id"])) {
$invoice_id = (int)$_GET["invoice_id"];
}
if (!empty($_GET["order_id"])) {
$order_id = $_GET["order_id"];
}
$invoice_type_info = get_master_type_code("PAYMENT_TYPE", $_GET["type"]);
$remark = "";
if ($_GET["type"] == "DEPOSIT") { //按金發票
if (!empty($_GET["invoice_id"])) {
$invoice_info = get_deposit($invoice_id);
$balance = $invoice_info["deposit_balance"];
$code = $invoice_info["deposit_code"];
$order_info = get_order($invoice_info["order_id"]);
if ($invoice_info["deposit_status"] === "RETURNED" && !$order_info["withdraw_date"]){
$order_info = get_order_by_first_order_id_latest($invoice_info["order_id"]);
}
$customer_info = get_customer($invoice_info["customer_id"]);
}
if (!empty($_GET["order_id"])) {
$order_info = get_order($order_id);
$invoice_info = get_deposit_by_order_id($order_info['first_order_id']);
$balance = $invoice_info["deposit_balance"];
$code = $invoice_info["deposit_code"];
$customer_info = get_customer($order_info["customer_id"]);
}
// $invoice_info = get_deposit($invoice_id);
// Add some data (invoice header)
$sheet
->setCellValue('A3', "退倉收據")
->setCellValue('H4', $customer_info["code"])
->setCellValue('H6', rsa_crypt($order_info["customer_address"], 2))
// ->setCellValue('AX4', date("Y-m-d", strtotime($invoice_info["docdate"])))
->setCellValue('AX4', date("Y-m-d"))
->setCellValue('AX5', $code)
->setCellValue('AX6', substr($order_info["withdraw_date"],0 ,10))
->setCellValue('AX6', substr($order_info["withdraw_date"],0 ,10))
->setCellValue('AQ7', $invoice_info['invoice_balance'])
// ->setCellValue('A12', "遲退還迷你倉導致扣按金:")
// ->setCellValue('AX12', numberformat($order_info["withdraw_remuneration"]))
// ->setCellValue('A12', "實際退回金額:")
->setCellValue('AX12', numberformat($invoice_info["actual_returnamount"]));
//->setCellValue('AU6', $invoice_info["duedate"]);
if($order_info["customer_typeid"] == "PERSONAL"){
$sheet
->setCellValue('H5', $order_info["customer_name"]);
}else{
$sheet
->setCellValue('H5', $order_info["customer_companyname"]);
}
//$sheet->insertNewRowBefore(10, 1);
//$order_info = get_order($invoice_info["order_id"]);
$order_room_info = get_order_room($order_info["id"]);
$sheet->insertNewRowBefore(10, (1 + count($order_room_info)));
$sheet->getStyle('AZ10')->getNumberFormat()->setFormatCode('0.00');
$sheet->mergeCells('AZ10:BE10');
$sheet
->setCellValue('A10', "按金")
->setCellValue('AZ10', numberformat($invoice_info["deposit_amount"]));
$sheet->getStyle('AZ10')
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$sheet->getStyle("A10:BE10")->getFont()->setBold(false);
$sheet->setCellValue('AZ' . (12 + count($order_room_info)), numberformat($invoice_info["deposit_amount"]));
$order_room_list = "";
$k = 1;
foreach ($order_room_info as $order_room) {
$room_info = get_room($order_room["room_id"]);
$master_room_info = get_master_room($room_info["master_room_id"]);
$order_room_list = check_combine_room($room_info["code"]) . " (" . $master_room_info["length"] . "'x" . $master_room_info["width"] . "'x" . $master_room_info["height"] . "')";
//$order_room_list = substr_replace($order_room_list ,"",-2);
if ($k == 1) {
$sheet->setCellValue('B' . (10 + $k), "合約編號: " . $order_info["code"] . ", 租用單位: " . $order_room_list);
} else {
$sheet->setCellValue('V' . (10 + $k), $order_room_list);
}
$sheet->getStyle("A" . (10 + $k) . ":AZ" . (10 + $k))->getFont()->setBold(false);
$k++;
}
// set withdraw remuneration row
$sheet->insertNewRowBefore(10 + $k, 4);
$contract_expiry_date_row_num = 11 + $k;
$sheet->setCellValue('A' . $contract_expiry_date_row_num, "合約到期日:" . substr($order_info["enddate"],0 ,4) . "年" . substr($order_info["enddate"],5 ,2) . "月" . substr($order_info["enddate"],8 ,2) . "日");
$withdraw_date_row_num = 12 + $k;
$sheet->setCellValue('A' . $withdraw_date_row_num, "退還日期:" . substr($order_info["withdraw_date"],0 ,4) . "年" . substr($order_info["withdraw_date"],5 ,2) . "月" . substr($order_info["withdraw_date"],8 ,2) . "日");
$withdraw_remuneration_row_num = 13 + $k;
$sheet->getStyle('A' . $withdraw_remuneration_row_num)
->getFont()
->setBold(true);
$sheet->getStyle('AZ'. $withdraw_remuneration_row_num)
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$sheet->mergeCells('AZ'. $withdraw_remuneration_row_num. ':BE' . $withdraw_remuneration_row_num);
$sheet->getStyle('AZ'. $withdraw_remuneration_row_num)->getNumberFormat()->setFormatCode('0.00');
$sheet->setCellValue('A' . $withdraw_remuneration_row_num, "額外租金")
->setCellValue('AZ'. $withdraw_remuneration_row_num, numberformat($order_info["withdraw_remuneration"]));
// ->setCellValue('AZ'. $withdraw_remuneration_row_num, $order_info["withdraw_remuneration"]);
/* print withdraw remuneration only
$sheet->insertNewRowBefore(10 + $k, 2);
$withdraw_remuneration_row_num = 11 + $k;
$sheet->getStyle('A' . $withdraw_remuneration_row_num)
->getFont()
->setBold(true);
$sheet->getStyle('AZ'. $withdraw_remuneration_row_num)
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$sheet->mergeCells('AZ'. $withdraw_remuneration_row_num. ':BE' . $withdraw_remuneration_row_num);
$sheet->setCellValue('A' . $withdraw_remuneration_row_num, "遲退還迷你倉租金")
->setCellValue('AZ'. $withdraw_remuneration_row_num, numberformat($order_info["withdraw_remuneration"]));
*/
}
// Redirect output to a client’s web browser (Excel5)
// get all room_id
$order_room_info = get_order_room($order_info["id"]);
$order_room_list = "";
foreach ($order_room_info as $detail) {
$room_info = get_room($detail["room_id"]);
$order_room_list .= check_combine_room($room_info["code"]) . ", ";
}
$order_info["order_room_list"] = substr_replace($order_room_list, "", -2);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="TerminationReceipt_' . $order_info["order_room_list"]. "_" . $code . '.xlsx"');
/*header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Invoice_' . $code . '.xls"');*/
header('Cache-Control: max-age=0');
/*// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0*/
//$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
} elseif (!empty($_GET["order_id"]) && !empty($_GET["type"])) { // no deposit
$order_id = $_GET["order_id"];
$invoice_type_info = get_master_type_code("PAYMENT_TYPE", $_GET["type"]);
$remark = "";
if ($_GET["type"] == "DEPOSIT") { //按金發票
// $invoice_info = get_deposit($invoice_id);
$balance = '0.00';
$code = '不適用';
$order_info = get_order($order_id);
$customer_info = get_customer($order_info["customer_id"]);
$invoice_info = get_deposit_by_order_id($order_info['first_order_id']);
// die(var_dump($invoice_info));
// Add some data (invoice header)
$sheet
->setCellValue('A3', "退倉收據")
->setCellValue('H4', $customer_info["code"])
->setCellValue('H6', rsa_crypt($order_info["customer_address"], 2))
->setCellValue('AX4', date("Y-m-d"))
->setCellValue('AX5', $code)
->setCellValue('AX6', substr($order_info["withdraw_date"],0 ,10))
// ->setCellValue('A12', "遲退還迷你倉導致扣按金:")
// ->setCellValue('AX12', numberformat($order_info["withdraw_remuneration"]))
// ->setCellValue('A12', "實際退回金額:")
->setCellValue('AX12', 0.00);
//->setCellValue('AU6', $invoice_info["duedate"]);
if($order_info["customer_typeid"] == "PERSONAL"){
$sheet
->setCellValue('H5', $order_info["customer_name"]);
}else{
$sheet
->setCellValue('H5', $order_info["customer_companyname"]);
}
//$sheet->insertNewRowBefore(10, 1);
//$order_info = get_order($invoice_info["order_id"]);
$order_room_info = get_order_room($order_info["id"]);
$sheet->insertNewRowBefore(10, (1 + count($order_room_info)));
$sheet->getStyle('AZ10')->getNumberFormat()->setFormatCode('0.00');
$sheet->mergeCells('AZ10:BE10');
$sheet
->setCellValue('A10', "按金")
->setCellValue('AZ10', numberformat($invoice_info["deposit_amount"]));
$sheet->getStyle('AZ10')
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$sheet->getStyle("A10:BE10")->getFont()->setBold(false);
$sheet->setCellValue('AZ' . (12 + count($order_room_info)), numberformat($invoice_info["deposit_amount"]));
$order_room_list = "";
$k = 1;
foreach ($order_room_info as $order_room) {
$room_info = get_room($order_room["room_id"]);
$master_room_info = get_master_room($room_info["master_room_id"]);
$order_room_list = check_combine_room($room_info["code"]) . " (" . $master_room_info["length"] . "'x" . $master_room_info["width"] . "'x" . $master_room_info["height"] . "')";
//$order_room_list = substr_replace($order_room_list ,"",-2);
if ($k == 1) {
$sheet->setCellValue('B' . (10 + $k), "合約編號: " . $order_info["code"] . ", 租用單位: " . $order_room_list);
} else {
$sheet->setCellValue('V' . (10 + $k), $order_room_list);
}
$sheet->getStyle("A" . (10 + $k) . ":AZ" . (10 + $k))->getFont()->setBold(false);
$k++;
}
// set withdraw remuneration row
$sheet->insertNewRowBefore(10 + $k, 2);
$withdraw_remuneration_row_num = 11 + $k;
$sheet->getStyle('A' . $withdraw_remuneration_row_num)
->getFont()
->setBold(true);
$sheet->getStyle('AZ'. $withdraw_remuneration_row_num)
->getAlignment()
->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
$sheet->mergeCells('AZ'. $withdraw_remuneration_row_num. ':BE' . $withdraw_remuneration_row_num);
$sheet->setCellValue('A' . $withdraw_remuneration_row_num, "遲退還迷你倉導致扣按金:")
->setCellValue('AZ'. $withdraw_remuneration_row_num, '0.00');
}
// Redirect output to a client’s web browser (Excel5)
// get all room_id
$order_room_info = get_order_room($order_info["id"]);
$order_room_list = "";
foreach ($order_room_info as $detail) {
$room_info = get_room($detail["room_id"]);
$order_room_list .= check_combine_room($room_info["code"]) . ", ";
}
$order_info["order_room_list"] = substr_replace($order_room_list, "", -2);
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment;filename="TerminationReceipt_' . $order_info["order_room_list"]. '.xlsx"');
/*header('Content-Type: application/vnd.ms-excel');
header('Content-Disposition: attachment;filename="Invoice_' . $code . '.xls"');*/
header('Cache-Control: max-age=0');
/*// If you're serving to IE 9, then the following may be needed
header('Cache-Control: max-age=1');
// If you're serving to IE over SSL, then the following may be needed
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); // Date in the past
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); // always modified
header('Cache-Control: cache, must-revalidate'); // HTTP/1.1
header('Pragma: public'); // HTTP/1.0*/
//$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel5');
$objWriter = PHPExcel_IOFactory::createWriter($PHPExcel, 'Excel2007');
$objWriter->save('php://output');
exit;
} else {
echo "";
exit;
}