$row) { foreach ($row as $field => $value) { if ($value === null) { $data[$key][$field] = ''; } } } return $data; } // 出貨台數 function getShipping($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' AND ( real_arrival_date IS NOT NULL AND real_arrival_date != '' ) "; if (!empty($month)) { $sql .= " AND real_arrival_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND real_arrival_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); $data = mysqli_fetch_all($result, MYSQLI_ASSOC); return json_encode(fixDataNull($data), JSON_UNESCAPED_UNICODE); } // 在裝台數 function getInstalling($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' AND ( tryrun_end_date = '' OR tryrun_end_date IS NULL ) "; if (!empty($month)) { $sql .= " AND real_arrival_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND real_arrival_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); $data = mysqli_fetch_all($result, MYSQLI_ASSOC); return json_encode(fixDataNull($data), JSON_UNESCAPED_UNICODE); } // 完工台數 function getInstalling2($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND tryrun_end_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND tryrun_end_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); $data = mysqli_fetch_all($result, MYSQLI_ASSOC); return json_encode(fixDataNull($data), JSON_UNESCAPED_UNICODE); } // QC台數 function getQCing($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND end_qc_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND end_qc_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); $data = mysqli_fetch_all($result, MYSQLI_ASSOC); return json_encode(fixDataNull($data), JSON_UNESCAPED_UNICODE); } // 移交台數 function getDeliverying($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND delivery_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND delivery_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); $data = mysqli_fetch_all($result, MYSQLI_ASSOC); return json_encode(fixDataNull($data), JSON_UNESCAPED_UNICODE); } // 出貨台數 產生excel function getShipping_makeExcel($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' AND ( real_arrival_date IS NOT NULL AND real_arrival_date != '' ) "; if (!empty($month)) { $sql .= " AND real_arrival_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND real_arrival_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); return mysqli_fetch_all($result, MYSQLI_ASSOC); } // 在裝台數 產生excel function getInstalling_makeExcel($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' AND ( tryrun_end_date = '' OR tryrun_end_date IS NULL ) "; if (!empty($month)) { $sql .= " AND real_arrival_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND real_arrival_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); return mysqli_fetch_all($result, MYSQLI_ASSOC); } // 完工台數 產生excel function getInstalling2_makeExcel($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND tryrun_end_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND tryrun_end_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); return mysqli_fetch_all($result, MYSQLI_ASSOC); } // QC台數 產生excel function getQCing_makeExcel($type, $mtype, $year, $month) { global $link; $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND end_qc_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND end_qc_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); return mysqli_fetch_all($result, MYSQLI_ASSOC); } // 移交台數 產生excel function getDeliverying_makeExcel($type, $mtype, $year, $month) { global $link; // 建立一個新的 Spreadsheet 物件 $sql = " SELECT * FROM wipwholestatus WHERE status = '1' "; if (!empty($month)) { $sql .= " AND delivery_date BETWEEN '$year-$month-01' AND '$year-$month-31'"; } else { $sql .= " AND delivery_date BETWEEN '$year-01-01' AND '$year-12-31'"; } $sql .= !empty($type) ? " AND contract_type = '$type'" : ""; $sql .= !empty($mtype) ? " AND renovate_type Like '%$mtype%'" : ""; $result = mysqli_query($link, $sql); return mysqli_fetch_all($result, MYSQLI_ASSOC); } function downloadExcel($data) { $spreadsheet = new Spreadsheet(); $sheet = $spreadsheet->getActiveSheet(); $colArr = [ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', ]; $colTitleArr = [ '合約號', '作番號', '客戶名稱', '預計出貨日', '試車完工日', 'QC合格日', '官檢日', '移交日', ]; $sheet->setTitle('出貨完工推移表'); for ($i = 0; $i < count($colArr); $i++) $sheet->setCellValue($colArr[$i] . '1', $colTitleArr[$i]); $i = 2; foreach ($data as $row) { $colContentArr = [ $row['contractno'], $row['facilityno'], $row['custom'], $row['real_arrival_date'], $row['tryrun_end_date'], $row['end_qc_date'], $row['official_check_date'], $row['delivery_date'] ]; 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); } $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(); }