fetch_assoc()) $data[] = $row; $result->close(); } else { echo "Query failed: " . $connection->error; } // 建立一個新的 Spreadsheet 物件 $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $colArr = [ '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' ]; $colTitleArr = [ '區域', '合約號', '作番號', '汰改方案', '客戶名稱', '地址', '工地地址', '規格', '依合約客戶需求日', '下單日(普來特富)', '預計發貨日(普來特富)', '預計到廠日(觀音廠)', '實際到廠日(觀音廠)', '預計出貨日(到工地)', '工務確認', '樓高通報', '樓高通報日期', '工勘確認', '工勘確認日期', '營業/契約確認', '營業/契約規格', '營業/契約規格日期', '客戶計劃圖(意匠圖)', '客戶計劃圖(意匠圖)日期', '客戶顏色', '客戶顏色日期', '客戶樣式', '客戶樣式日期', '工勘聯絡表', '工勘聯絡表日期', '設計確認', '設計規格', '設計規格日期', '設計計劃圖', '設計計劃圖日期', '設計顏色', '設計顏色日期', '設計樣式', '設計樣式日期', '設計主管', '設計主管日期', '生管確認', '是否齊備', '是否齊備日期', '下單日(下單普來特富)', '下單日(下單普來特富)日期', '預計發貨日(出港日)', '預計發貨日(出港日)日期', '預計實際到貨日(到觀音廠日)', '預計實際到貨日(到觀音廠日)日期', '普來特富(發貨類別)', '普來特富(發貨類別)日期', '台灣自理項目(發貨類別)', '台灣自理項目(發貨類別)日期', '實際到貨日(到觀音廠日)', '實際到貨日(到觀音廠日)日期', '安裝圖上傳狀態', '完工驗收單上傳狀態', '移交日附件(核准函)上傳狀態' ]; $sheet->setTitle('作番大日程(汰改)'); for ($i = 0; $i < count($colArr); $i++) { $sheet->setCellValue($colArr[$i] . '1', $colTitleArr[$i]); } $i = 2; foreach ($data as $row) { //規格 $Specification = $row['facility_kind']; $Specification .= !empty($row['numberofpassenger']) ? "-" . $row['numberofpassenger'] : ""; $Specification .= !empty($row['weight']) ? "-" . $row['weight'] : ""; $Specification .= !empty($row['numberofstop']) ? "-" . $row['numberofstop'] : ""; $Specification .= !empty($row['numberoffloor']) ? "/" . $row['numberoffloor'] : ""; $Specification .= !empty($row['opentype']) ? "-" . $row['opentype'] : ""; $Specification .= !empty($row['speed']) ? $row['speed'] : ""; //工務 $gongwuok = 0; // 營業 $yingyeok = 0; // 設計 $shejiok = 0; // 生管 $shengguanok = 0; // 財務 // $caiwuok = 0; // 工務統計已確認 if ($row['building_heigh_verify'] == 0) $gongwuok += 1; if (!in_array($row['site_survey_contact_verify'], ['1', 'A'])) $gongwuok += 1; // 營業統計已確認 if ($row['sales_spec_verify'] == 0) $yingyeok += 1; if ($row['customer_color_verify'] == 0) $yingyeok += 1; if ($row['customer_style_verify'] == 0) $yingyeok += 1; if ($row['site_survey_contact_form_verify'] == 0) $yingyeok += 1; if ($row['customer_planning_verify'] == 0) $yingyeok += 1; // 設計統計已確認 if ($row['desin_spec_verify'] == 0) $shejiok += 1; if ($row['desin_planning_verify'] == 0) $shejiok += 1; if ($row['desin_color_verify'] == 0) $shejiok += 1; if ($row['desin_style_verify'] == 0) $shejiok += 1; if ($row['desin_leader_verify'] == 0) $shejiok += 1; // 生管統計已確認 if ($row['shengguanok_status'] == 0) $shengguanok += 1; if ($row['prattford_order_date_verify'] == 0) $shengguanok += 1; if ($row['estimated_shipping_date_verify'] == 0) $shengguanok += 1; if ($row['estimated_shipping_schedule_date_verify'] == 0) $shengguanok += 1; if ($row['goods_type'] == 'A' || $row['goods_type'] == 'C') $shengguanok += 1; if ($row['taiwan_goods_type'] == 'A' || $row['taiwan_goods_type'] == 'C') $shengguanok += 1; if ($row['arrival_date_verify'] == 'A') $shengguanok += 1; // 工勘狀態 $site_survey_contact_verify = $row['site_survey_contact_verify'] == 1 ? "未確認" : "已確認"; $status_arr = array( '0' => '已完成', '1' => '進行中', '2' => '無需求' ); $status2_arr = array( '1' => '未確認', 'A' => 'A:全級發貨', 'B' => 'B:欠件發貨', 'C' => 'C:無發貨需求' ); $status3_arr = array( '1' => '未確認', 'A' => 'A:皆到貨', 'B' => 'B:皆欠件', 'C' => 'C:普來特富欠件', 'D' => 'D:台灣欠件', ); $site_survey_status = array( "0" => "已確認", "1" => "未確認", "2" => "無工勘需求", "A" => "未動工", "B" => "地下室施工", "C" => "打樁", "D" => "地基", "E" => "挖土", "G" => "機房", "H" => "機械式淨高", "M" => "樓中樓", "OH" => "最高層(頂樓高度)", "P" => "PIT(機坑深度)", "R" => "R 樓", "S" => "停工", "T" => "TOP", "TC" => "頂部間隙", "TS" => "行程", "TH" => "全高", "Y" => "已搭、已出", "YB" => "退購結案", "YF" => "既有建物", "YN" => "已搭、未出" ); for ($j = 1; $j < 200; $j++) { $site_survey_status[$j . "F"] = $j . "F"; } // 營業 營業/契約確認規格 $sales_spec_verify_status = !empty($status_arr[$row['sales_spec_verify']]) ? $status_arr[$row['sales_spec_verify']] : ""; // 營業 客戶計劃圖(意匠圖) $customer_planning_verify_status = !empty($status_arr[$row['customer_planning_verify']]) ? $status_arr[$row['customer_planning_verify']] : ""; // 營業 客戶顏色 $customer_color_verify_status = !empty($status_arr[$row['customer_color_verify']]) ? $status_arr[$row['customer_color_verify']] : ""; // 營業 客戶樣式 $customer_style_verify_status = !empty($status_arr[$row['customer_style_verify']]) ? $status_arr[$row['customer_style_verify']] : ""; // 營業 工勘聯絡表 $site_survey_contact_form_verify_status = !empty($status_arr[$row['site_survey_contact_form_verify']]) ? $status_arr[$row['site_survey_contact_form_verify']] : ""; // 設計 規格確認 $desin_spec_verify_status = !empty($status_arr[$row['desin_spec_verify']]) ? $status_arr[$row['desin_spec_verify']] : ""; // 設計 設計計劃圖確認 $desin_planning_verify_status = !empty($status_arr[$row['desin_planning_verify']]) ? $status_arr[$row['desin_planning_verify']] : ""; // 設計 設計顏色確認 $desin_color_verify_status = !empty($status_arr[$row['desin_color_verify']]) ? $status_arr[$row['desin_color_verify']] : ""; // 設計 設計樣式確認 $desin_style_verify_status = !empty($status_arr[$row['desin_style_verify']]) ? $status_arr[$row['desin_style_verify']] : ""; // 設計 設計主管確認 $desin_leader_verify_status = !empty($status_arr[$row['desin_leader_verify']]) ? $status_arr[$row['desin_leader_verify']] : ""; // 工務 樓高通報確認 $dbuilding_heigh_verify_status = !empty($status_arr[$row['building_heigh_verify']]) ? $status_arr[$row['building_heigh_verify']] : ""; // 工務 工勘確認 $site_survey_contact_verify_status = !empty($site_survey_status[$row['site_survey_contact_verify']]) ? $site_survey_status[$row['site_survey_contact_verify']] : ""; // 生管 是否齊備確認 $shengguanok_status = !empty($status_arr[$row['shengguanok_status']]) ? $status_arr[$row['shengguanok_status']] : ""; $prattford_order_date_verify_status = !empty($status_arr[$row['prattford_order_date_verify']]) ? $status_arr[$row['prattford_order_date_verify']] : ""; $estimated_shipping_date_verify_status = !empty($status_arr[$row['estimated_shipping_date_verify']]) ? $status_arr[$row['estimated_shipping_date_verify']] : ""; $estimated_shipping_schedule_date_verify_status = !empty($status_arr[$row['estimated_shipping_schedule_date_verify']]) ? $status_arr[$row['estimated_shipping_schedule_date_verify']] : ""; $goods_type_status = !empty($status2_arr[$row['goods_type']]) ? $status2_arr[$row['goods_type']] : ""; $taiwan_goods_type_status = !empty($status2_arr[$row['taiwan_goods_type']]) ? $status2_arr[$row['taiwan_goods_type']] : ""; $arrival_date_verify_status = !empty($status3_arr[$row['arrival_date_verify']]) ? $status3_arr[$row['arrival_date_verify']] : ""; $colContentArr = [ getArea($row['address']), $row['contractno'], $row['facilityno'], implode("+", json_decode($row['renovate_type'])), $row['custom'], $row['address'], $row['real_address'], $Specification, substr($row['contract_arrival_date'], 0, 10), substr($row['prattford_order_date'], 0, 10), substr($row['estimated_shipping_date'], 0, 10), substr($row['estimated_shipping_schedule_date'], 0, 10), substr($row['actual_tofactory_date'], 0, 10), substr($row['real_contract_arrival_date'], 0, 10), // getGunwuName($row['address']) . $gongwuok . "/2", accountidToName($row['warehouseid']) . $gongwuok . "/2", $dbuilding_heigh_verify_status, substr($row['building_heigh_verify_at'], 0, 10), $site_survey_contact_verify_status, substr($row['site_survey_contact_verify_at'], 0, 10), accountidToName($row['salesid']) . " " . $yingyeok . "/5", $sales_spec_verify_status, substr($row['sales_spec_verify_at'], 0, 10), $customer_planning_verify_status, substr($row['customer_planning_verify_at'], 0, 10), $customer_color_verify_status, substr($row['customer_color_verify_at'], 0, 10), $customer_style_verify_status, substr($row['customer_style_verify_at'], 0, 10), $site_survey_contact_form_verify_status, substr($row['site_survey_contact_form_verify_at'], 0, 10), '林昭翰 ' . $shejiok . "/5", $desin_spec_verify_status, substr($row['desin_spec_verify_at'], 0, 10), $desin_planning_verify_status, substr($row['desin_planning_verify_at'], 0, 10), $desin_color_verify_status, substr($row['desin_color_verify_at'], 0, 10), $desin_style_verify_status, substr($row['desin_style_verify_at'], 0, 10), $desin_leader_verify_status, substr($row['desin_leader_verify_at'], 0, 10), '許伃廷 ' . $shengguanok . "/7", $shengguanok_status, substr($row['shengguanok_status_at'], 0, 10), $prattford_order_date_verify_status, substr($row['prattford_order_date'], 0, 10), $estimated_shipping_date_verify_status, substr($row['estimated_shipping_date'], 0, 10), $estimated_shipping_schedule_date_verify_status, substr($row['estimated_shipping_schedule_date'], 0, 10), $goods_type_status, substr($row['goods_type_date'], 0, 10), $taiwan_goods_type_status, substr($row['taiwan_goods_type_date'], 0, 10), $arrival_date_verify_status, substr($row['actual_tofactory_date'], 0, 10), empty($row['plan_diagram_file']) ? "無" : "已上傳", empty($row['completion_acceptance_file']) ? "無" : "已上傳", empty($row['delivery_date_file']) ? "無" : "已上傳" ]; for ($j = 0; $j < count($colContentArr); $j++) $sheet->setCellValue($colArr[$j] . $i, $colContentArr[$j]); $i++; } // 調整欄位大小 foreach ($sheet->getColumnIterator() as $column) $sheet->getColumnDimension($column->getColumnIndex())->setAutoSize(true); // 背景顏色為藍色 $styleA1toC1 = $sheet->getStyle('A1:N1'); $fillA1toC1 = $styleA1toC1->getFill(); $fillA1toC1->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('8EA9DB'); // 背景顏色為橘色 $styleA1toC1 = $sheet->getStyle('O1:S1'); $fillA1toC1 = $styleA1toC1->getFill(); $fillA1toC1->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('FFBB66'); // 背景顏色為綠色 $styleA1toC1 = $sheet->getStyle('T1:AD1'); $fillA1toC1 = $styleA1toC1->getFill(); $fillA1toC1->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('DDFF77'); // 背景顏色為藍色 $styleA1toC1 = $sheet->getStyle('AE1:AO1'); $fillA1toC1 = $styleA1toC1->getFill(); $fillA1toC1->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('BBFFEE'); // 背景顏色為橘色 $styleA1toC1 = $sheet->getStyle('AP1:BE1'); $fillA1toC1 = $styleA1toC1->getFill(); $fillA1toC1->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('FFCCCC'); // 第二個分頁 $worksheet2 = $spreadsheet->createSheet(); $spreadsheet->setActiveSheetIndex(1); // 在第二個工作表寫入數據 $worksheet2->setCellValue('A1', '確認進度統計表'); // 設定活動工作表回到第一個工作表 $spreadsheet->setActiveSheetIndex(0); $writer = new Xlsx($spreadsheet); $file_path = dirname(__DIR__) . '/wms/excel/' . 'gary_test.xlsx'; try { $writer->save($file_path); // 回傳檔案路徑給 JavaScript echo $file_path; } catch (Exception $e) { echo 'Error: ' . $e->getMessage(); } exit(); }