/
home
/
efamember
/
domains
/
efa-member.com
/
public_html
/
main
/
ajax
/
account_receipt
/
up file
home
<?php session_start(); include('../../../config/main_function.php'); $secure = "cAh3DrJACzw4RbU"; $connection = connectDB($secure); // set_time_limit(0); /** PHPExcel */ require('../../../PHPExcel-1.8/Classes/PHPExcel.php'); // /** PHPExcel_IOFactory - Reader */ require('../../../PHPExcel-1.8/Classes/PHPExcel/IOFactory.php'); // สร้าง object ของ Class PHPExcel ขึ้นมาใหม่ $objPHPExcel = new PHPExcel(); // กำหนดค่าต่างๆ $objPHPExcel->getProperties()->setCreator("Company Co., Ltd."); $objPHPExcel->getProperties()->setLastModifiedBy("Company Co., Ltd."); $objPHPExcel->getProperties()->setTitle("Office 2007 XLSX ReportQuery Document"); $objPHPExcel->getProperties()->setSubject("Office 2007 XLSX ReportQuery Document"); $objPHPExcel->getProperties()->setDescription("ReportQuery from Company Co., Ltd."); $sheet = $objPHPExcel->getActiveSheet(); $pageMargins = $sheet->getPageMargins(); // margin is set in inches (0.5cm) $margin = 0.5 / 2.54; $pageMargins->setTop($margin); $pageMargins->setBottom($margin); $pageMargins->setLeft($margin); $pageMargins->setRight(0); $styleHeader = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'bold' => true, 'size' => 10, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleHeader2 = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'bold' => true, 'size' => 12, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleNumber = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleText = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleText_green = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', 'color' => array('rgb' => '21BA21'), ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleText_red = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', 'color' => array('rgb' => 'FF0000'), ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleText_blue = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', 'color' => array('rgb' => '0000FF'), ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleText_yell = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', 'color' => array('rgb' => 'F7FF00'), ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); // 'color' => array('rgb' => '32CD32'), $styleTextCenter = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'size' => 9, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_CENTER, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $styleTextRight = array( //'fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID,'color' => array('rgb' => 'ffff00')), 'borders' => array( 'allborders' => array( 'style' => PHPExcel_Style_Border::BORDER_THIN, 'color' => array('rgb' => '#000000') ) ), 'font' => array( 'bold' => true, 'size' => 10, 'name' => 'Arial', ), 'alignment' => array( 'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_RIGHT, 'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER, ) ); $columnCharacter = array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'AA', 'AB', 'AC', 'AD', 'AE', 'AF', 'AG', 'AH', 'AI', 'AJ', 'AK', 'AL', 'AM', 'AN', 'AO', 'AP', 'AQ', 'AR', 'AS', 'AT', 'AU', 'AV', 'AW', 'AX', 'AY', 'AZ', 'BA', 'BB', 'BC', 'BD', 'BE', 'BF', 'BG', 'BH', 'BI', 'BJ', 'BK', 'BL', 'BM', 'BN', 'BO', 'BP', 'BQ', 'BR', 'BS', 'BT', 'BU', 'BV', 'BW', 'BX', 'BY', 'BZ' ); /*------------------------------------------------------------------------------------------------------------------------------*/ // หัวตาราง $rowCell = 1; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[0] . $rowCell, 'รายการออกใบเสร็จ ระหว่างวันที่ '); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[0] . $rowCell . ':' . $columnCharacter[9] . ($rowCell)); $objPHPExcel->getActiveSheet()->getStyle($columnCharacter[0] . $rowCell . ':' . $columnCharacter[9] . $rowCell)->applyFromArray($styleHeader2); $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(30); $rowCell = 2; $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[0] . $rowCell, 'วันที่สมัคร'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[0] . $rowCell . ':' . $columnCharacter[0] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[0])->setWidth(16); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[1] . $rowCell, 'เลขบัตรประจำตัวประชาชน'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[1] . $rowCell . ':' . $columnCharacter[1] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[1])->setWidth(30); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[2] . $rowCell, 'ชื่อ - นามสกุล'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[2] . $rowCell . ':' . $columnCharacter[2] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[2])->setWidth(25); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[3] . $rowCell, 'ที่อยู่'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[3] . $rowCell . ':' . $columnCharacter[3] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[3])->setWidth(50); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[4] . $rowCell, 'ชื่อสถานประกอบการ'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[4] . $rowCell . ':' . $columnCharacter[4] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[4])->setWidth(50); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[5] . $rowCell, 'ที่อยู่สถานประกอบการ'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[5] . $rowCell . ':' . $columnCharacter[5] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[5])->setWidth(50); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[6] . $rowCell, 'ระดับ /' . ' ประเภท'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[6] . $rowCell . ':' . $columnCharacter[6] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[6])->setWidth(25); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[7] . $rowCell, 'วันที่ออกใบเสร็จ'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[7] . $rowCell . ':' . $columnCharacter[7] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[7])->setWidth(25); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[8] . $rowCell, 'หมายเลขใบเสร็จ'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[8] . $rowCell . ':' . $columnCharacter[8] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[8])->setWidth(25); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[9] . $rowCell, 'ยอดสุทธิ'); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[9] . $rowCell . ':' . $columnCharacter[9] . ($rowCell)); $objPHPExcel->getActiveSheet()->getColumnDimension($columnCharacter[9])->setWidth(25); $objPHPExcel->getActiveSheet()->getRowDimension('4')->setRowHeight(11); $objPHPExcel->getActiveSheet()->getStyle($columnCharacter[0] . $rowCell . ':' . $columnCharacter[9] . ($rowCell))->getAlignment()->setWrapText(true); $objPHPExcel->getActiveSheet()->getStyle($columnCharacter[0] . $rowCell . ':' . $columnCharacter[9] . ($rowCell))->applyFromArray($styleHeader); ///////////////////////////////////////////////////////////////////////////// $type = mysqli_real_escape_string($connection, $_POST['type']); $level = mysqli_real_escape_string($connection, $_POST['level']); $search = mysqli_real_escape_string($connection, $_POST['search']); $date_start = date_picker(mysqli_real_escape_string($connection, $_POST['date_start'])); $date_end = date_picker(mysqli_real_escape_string($connection, $_POST['date_end'])); $sql_member = "SELECT rhead.* ,rdetail.* ,memd.member_name ,memd.member_name_en ,memd.citizen_no ,mem.register_datetime ,mem.register_level ,mem.register_type ,memd.title_name ,memd.company_name ,memd.company_phone ,memd.company_email ,memd.card_district_id ,memd.company_district_id FROM tbl_receipt_head rhead LEFT JOIN tbl_receipt_detail rdetail ON rdetail.receipt_id = rhead.receipt_id LEFT JOIN tbl_member mem ON mem.member_id = rhead.member_id LEFT JOIN tbl_member_detail memd ON memd.member_id = rhead.member_id WHERE rhead.create_datetime BETWEEN '$date_start 00:00:00' AND '$date_end 23:59:59' ORDER BY rhead.receipt_no DESC "; $res_member = mysqli_query($connection, $sql_member); /////////////////////////////////////////////////////////////////////////// //////////////// $rowCell = 3; while ($row_member = mysqli_fetch_assoc($res_member)) { $citizen_no = bigsara_decode($row_member['citizen_no'], $key); $register_type = $row_member['register_type']; if ($register_type == 1) { $register_type = 'นายจ้าง'; } elseif ($register_type == 2) { $register_type = 'บนจ.'; } elseif ($register_type == 3) { $register_type = 'Agency'; } elseif ($register_type == 4) { $register_type = 'แรงงาน'; } $register_level = $row_member['register_level']; if ($register_level == 'g9k1s') { $register_level = 'ทั่วไป'; } elseif ($register_level == 'kki22') { $register_level = 'วิสามัญ'; } elseif ($register_level == 'x9fkq') { $register_level = 'สามัญ.'; } $temp_id = bigsara_encode($row_member['member_id'], $row_member['secure_text'], $row_member['secure_pointer']); $member_printId = $temp_id . "." . $row_member['secure_text']; $card_district_id = $row_member['card_district_id']; if ($card_district_id != "") { $sqlAddressCard = "SELECT `tbl_district`.`district_name_th` , `tbl_amphoe`.`amphoe_name_th` , `tbl_province`.`province_name_th` , `tbl_district`.`district_zipcode` FROM `tbl_district` JOIN `tbl_amphoe` ON `tbl_amphoe`.`amphoe_id` = `tbl_district`.`ref_amphoe` JOIN `tbl_province` ON `tbl_province`.`province_id` = `tbl_amphoe`.`ref_province` WHERE `tbl_district`.`district_id` = '$card_district_id'"; $rsAddressCard = mysqli_query($connection, $sqlAddressCard); $rowAddressCard = mysqli_fetch_array($rsAddressCard); //// ที่อยู่ $full_address = $row_member['card_address'] . " ตำบล" . $rowAddressCard['district_name_th'] . " อำเภอ" . $rowAddressCard['amphoe_name_th'] . " จังหวัด" . $rowAddressCard['province_name_th'] . " " . $rowAddressCard['district_zipcode']; }else{ $company_address = "-"; } $objPHPExcel->getActiveSheet()->getStyle($columnCharacter[1] . $rowCell . ':' . $columnCharacter[1] . $rowCell)->getNumberFormat()->setFormatCode('###'); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[0] . $rowCell, date("d/m/Y", strtotime($row_member['register_datetime']))); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[0] . $rowCell . ':' . $columnCharacter[0] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[1] . $rowCell, $row_member['citizen_no']); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[1] . $rowCell . ':' . $columnCharacter[1] . ($rowCell)); if ($row['member_name'] == "membre_name") { $member_name = "member_name"; } else { $member_name = "member_name_en"; } $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[2] . $rowCell, $row_member['member_name']); // $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[2] . $rowCell, ($row_member['member_name'] != "REZuYlBuekMyMmtpdUlM") ? bigsara_decode($row_member['member_name'], $key) : bigsara_decode($row_member['member_name_en'], $key) ."\r\n".$citizen_no); // $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[2] . $rowCell, $row_member['member_name'].$row_member['member_name_en']); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[2] . $rowCell . ':' . $columnCharacter[2] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[3] . $rowCell, $full_address); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[3] . $rowCell . ':' . $columnCharacter[3] . ($rowCell)); $company_district_id = $row_member['card_district_id']; if ($company_district_id != "") { $sqlAddressCard = "SELECT `tbl_district`.`district_name_th` , `tbl_amphoe`.`amphoe_name_th` , `tbl_province`.`province_name_th` , `tbl_district`.`district_zipcode` FROM `tbl_district` JOIN `tbl_amphoe` ON `tbl_amphoe`.`amphoe_id` = `tbl_district`.`ref_amphoe` JOIN `tbl_province` ON `tbl_province`.`province_id` = `tbl_amphoe`.`ref_province` WHERE `tbl_district`.`district_id` = '$company_district_id'"; $rsAddressCard = mysqli_query($connection, $sqlAddressCard); $rowAddressCard = mysqli_fetch_array($rsAddressCard); //// ที่อยู่ $company_address = $row_member['company_address'] . " ตำบล" . $rowAddressCard['district_name_th'] . " อำเภอ" . $rowAddressCard['amphoe_name_th'] . " จังหวัด" . $rowAddressCard['province_name_th'] . " " . $rowAddressCard['district_zipcode']; } else { $company_address = "-"; } $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[4] . $rowCell, $row_member['company_name']); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[4] . $rowCell . ':' . $columnCharacter[4] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[5] . $rowCell, $company_address); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[5] . $rowCell . ':' . $columnCharacter[5] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[6] . $rowCell, $register_type . " / " . $register_level); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[6] . $rowCell . ':' . $columnCharacter[6] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[7] . $rowCell, date("d/m/Y", strtotime($row_member['create_datetime']))); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[7] . $rowCell . ':' . $columnCharacter[7] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[8] . $rowCell, $row_member['receipt_no']); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[8] . $rowCell . ':' . $columnCharacter[8] . ($rowCell)); $objPHPExcel->setActiveSheetIndex(0)->setCellValue($columnCharacter[9] . $rowCell, $row_member['total_amount']); $objPHPExcel->setActiveSheetIndex(0)->mergeCells($columnCharacter[9] . $rowCell . ':' . $columnCharacter[9] . ($rowCell)); $objPHPExcel->getActiveSheet()->getStyle($columnCharacter[0] . $rowCell . ':' . $columnCharacter[9] . ($rowCell))->getAlignment()->setWrapText(true)->applyFromArray($styleTextCenter); $rowCell++; } /*-------------------------------------------------------------------------------------------------------------------------------*/ $objPHPExcel->setActiveSheetIndex(0); //ตั้งชื่อไฟล์ $file_name = "รายการออกใบเสร็จ ระหว่างวันที่ " . date("d-m-Y", strtotime($row_cer_lot['certification_date'])); // // Save Excel 2007 file #echo date('H:i:s') . " Write to Excel2007 format\n"; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); ob_end_clean(); // We'll be outputting an excel file header('Content-type: application/vnd.ms-excel'); // It will be called file.xls header('Content-Disposition: attachment;filename="' . $file_name . '.xlsx'); $objWriter->save('php://output'); exit();