|
@ -29,6 +29,8 @@ $sql = " |
|
|
w.contract_type |
|
|
w.contract_type |
|
|
FROM wipwholestatus AS w |
|
|
FROM wipwholestatus AS w |
|
|
WHERE status = '1' |
|
|
WHERE status = '1' |
|
|
|
|
|
AND real_contract_arrival_date >= '$start_y-$start_m-1' |
|
|
|
|
|
AND real_contract_arrival_date <= '$end_y-$end_m-31' |
|
|
) AS this_order |
|
|
) AS this_order |
|
|
WHERE 1 = 1 |
|
|
WHERE 1 = 1 |
|
|
GROUP BY this_order.contract_type, |
|
|
GROUP BY this_order.contract_type, |
|
@ -41,7 +43,7 @@ $data = []; |
|
|
while ($row = $result->fetch_assoc()) { |
|
|
while ($row = $result->fetch_assoc()) { |
|
|
$data[] = $row; |
|
|
$data[] = $row; |
|
|
} |
|
|
} |
|
|
// print_r($data); |
|
|
|
|
|
function findData($data, $searchData) |
|
|
function findData($data, $searchData) |
|
|
{ |
|
|
{ |
|
|
foreach ($data as $item) { |
|
|
foreach ($data as $item) { |
|
@ -115,7 +117,6 @@ function findAllDataByYearMonth($data, $searchData) |
|
|
&& $item['date_year'] == $i |
|
|
&& $item['date_year'] == $i |
|
|
&& $item['date_month'] == str_pad($j, 2, '0', STR_PAD_LEFT) |
|
|
&& $item['date_month'] == str_pad($j, 2, '0', STR_PAD_LEFT) |
|
|
) { |
|
|
) { |
|
|
// echo $item['facility_count']." "; |
|
|
|
|
|
$count += $item['facility_count']; |
|
|
$count += $item['facility_count']; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -134,8 +135,9 @@ $sql = " |
|
|
FROM wipwholestatus AS w |
|
|
FROM wipwholestatus AS w |
|
|
WHERE 1=1 |
|
|
WHERE 1=1 |
|
|
AND status = '1' |
|
|
AND status = '1' |
|
|
AND real_contract_arrival_date >= '$start_y-$start_m-0' |
|
|
AND contract_type = 'A' |
|
|
AND real_contract_arrival_date <= '$end_y-$end_m-0' |
|
|
AND real_contract_arrival_date >= '$start_y-$start_m-1' |
|
|
|
|
|
AND real_contract_arrival_date <= '$end_y-$end_m-31' |
|
|
) AS new_order |
|
|
) AS new_order |
|
|
WHERE 1 = 1 |
|
|
WHERE 1 = 1 |
|
|
GROUP BY new_order.facility_kind |
|
|
GROUP BY new_order.facility_kind |
|
@ -175,8 +177,8 @@ $sql = " |
|
|
FROM wipwholestatus AS w |
|
|
FROM wipwholestatus AS w |
|
|
WHERE 1=1 |
|
|
WHERE 1=1 |
|
|
AND status = '1' |
|
|
AND status = '1' |
|
|
AND real_contract_arrival_date >= '$start_y-$start_m-0' |
|
|
AND real_contract_arrival_date >= '$start_y-$start_m-1' |
|
|
AND real_contract_arrival_date <= '$end_y-$end_m-0' |
|
|
AND real_contract_arrival_date <= '$end_y-$end_m-31' |
|
|
AND contract_type = 'B' |
|
|
AND contract_type = 'B' |
|
|
"; |
|
|
"; |
|
|
$result = mysqli_query($link, $sql); |
|
|
$result = mysqli_query($link, $sql); |
|
@ -184,28 +186,42 @@ $data3 = []; |
|
|
while ($row = $result->fetch_assoc()) { |
|
|
while ($row = $result->fetch_assoc()) { |
|
|
$data3[] = $row; |
|
|
$data3[] = $row; |
|
|
} |
|
|
} |
|
|
$M1 = 0; |
|
|
|
|
|
$M2 = 0; |
|
|
// 分開計算 |
|
|
$M3 = 0; |
|
|
|
|
|
$M4 = 0; |
|
|
// $M1 = 0; |
|
|
$MA = 0; |
|
|
// $M2 = 0; |
|
|
$M_count = 0; |
|
|
// $M3 = 0; |
|
|
|
|
|
// $M4 = 0; |
|
|
|
|
|
// $MA = 0; |
|
|
|
|
|
// $M_count = 0; |
|
|
|
|
|
// foreach ($data3 as $row) { |
|
|
|
|
|
// $renovate_type_arr = json_decode($row['renovate_type']); |
|
|
|
|
|
// foreach ($renovate_type_arr as $row2) { |
|
|
|
|
|
// if ($row2 == 'M1') |
|
|
|
|
|
// $M1++; |
|
|
|
|
|
// if ($row2 == 'M2') |
|
|
|
|
|
// $M2++; |
|
|
|
|
|
// if ($row2 == 'M3') |
|
|
|
|
|
// $M3++; |
|
|
|
|
|
// if ($row2 == 'M4') |
|
|
|
|
|
// $M4++; |
|
|
|
|
|
// if ($row2 == 'MA') |
|
|
|
|
|
// $MA++; |
|
|
|
|
|
// } |
|
|
|
|
|
// } |
|
|
|
|
|
// $M_count = $M1 + $M2 + $M3 + $M4 + $MA; |
|
|
|
|
|
|
|
|
|
|
|
$M_count = count($data3); |
|
|
|
|
|
$m_type_arr = []; |
|
|
|
|
|
$m_type_arr[''] = 0; |
|
|
|
|
|
foreach ($data3 as $row) { |
|
|
|
|
|
$m_type_arr[implode("+", json_decode($row['renovate_type']))] = 0; |
|
|
|
|
|
} |
|
|
foreach ($data3 as $row) { |
|
|
foreach ($data3 as $row) { |
|
|
$renovate_type_arr = json_decode($row['renovate_type']); |
|
|
$m_type_arr[implode("+", json_decode($row['renovate_type']))]++; |
|
|
foreach ($renovate_type_arr as $row2) { |
|
|
|
|
|
if ($row2 == 'M1') |
|
|
|
|
|
$M1++; |
|
|
|
|
|
if ($row2 == 'M2') |
|
|
|
|
|
$M2++; |
|
|
|
|
|
if ($row2 == 'M3') |
|
|
|
|
|
$M3++; |
|
|
|
|
|
if ($row2 == 'M4') |
|
|
|
|
|
$M4++; |
|
|
|
|
|
if ($row2 == 'MA') |
|
|
|
|
|
$MA++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
$M_count = $M1 + $M2 + $M3 + $M4 + $MA; |
|
|
|
|
|
|
|
|
|
|
|
//數字轉英文(0=>A、1=>B、26=>AA...以此類推) |
|
|
//數字轉英文(0=>A、1=>B、26=>AA...以此類推) |
|
|
function num2alpha($n) |
|
|
function num2alpha($n) |
|
@ -224,264 +240,259 @@ function alpha2num($a) |
|
|
$n = $n * 26 + ord($a[$i]) - 0x40; |
|
|
$n = $n * 26 + ord($a[$i]) - 0x40; |
|
|
return $n - 1; |
|
|
return $n - 1; |
|
|
} |
|
|
} |
|
|
|
|
|
if($_SERVER["REQUEST_METHOD"] == 'POST'){ |
|
|
|
|
|
if ($_POST['excel_output'] == 'excel_output') { |
|
|
|
|
|
$spreadsheet = new Spreadsheet(); |
|
|
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
|
|
|
|
|
$sheet->setTitle('出貨總表'); |
|
|
|
|
|
|
|
|
if ($_POST['excel_output'] == 'excel_output') { |
|
|
$title_col_num = 3; |
|
|
$spreadsheet = new Spreadsheet(); |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
$sheet = $spreadsheet->getActiveSheet(); |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$sheet->setTitle('出貨總表'); |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
|
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
$title_col_num = 3; |
|
|
$title_col_num += 2; |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
break; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
} |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
|
|
|
$title_col_num += 2; |
|
|
|
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$sheet->mergeCells('A1:' . num2alpha($title_col_num) . '1'); |
|
|
$sheet->mergeCells('A1:' . num2alpha($title_col_num) . '1'); |
|
|
$sheet->setCellValue('A1', '出貨地區預定明細'); |
|
|
$sheet->setCellValue('A1', '出貨地區預定明細'); |
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', ''); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', ''); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', ''); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', ''); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
|
|
|
|
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) |
|
|
if ($i == $end_y && $j == ($end_m + 1)) |
|
|
break; |
|
|
break; |
|
|
$sheet->mergeCells(num2alpha($title_col_num) . '2:' . num2alpha($title_col_num + 1) . '2'); |
|
|
$sheet->mergeCells(num2alpha($title_col_num) . '2:' . num2alpha($title_col_num + 1) . '2'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', $i . '年' . $j . '月'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', $i . '年' . $j . '月'); |
|
|
$title_col_num += 2; |
|
|
$title_col_num += 2; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', '累計台數'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', '累計台數'); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', '累計台數'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '2', '累計台數'); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '區域'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '區域'); |
|
|
$title_col_num = 2; |
|
|
$title_col_num = 2; |
|
|
|
|
|
|
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
break; |
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '新梯'); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '汰改'); |
|
|
|
|
|
$title_col_num++; |
|
|
} |
|
|
} |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '新梯'); |
|
|
} |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '新梯'); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '汰改'); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
|
|
|
|
|
|
$area_arr = [ |
|
|
|
|
|
[4, 6, '台北'], |
|
|
|
|
|
[7, 9, '桃竹苗'], |
|
|
|
|
|
[10, 13, '中部'], |
|
|
|
|
|
[14, 17, '南部'], |
|
|
|
|
|
[18, 20, '宜花東'], |
|
|
|
|
|
[21, 21, '未分類'] |
|
|
|
|
|
]; |
|
|
|
|
|
foreach ($area_arr as $row) { |
|
|
|
|
|
$title_col_num = 0; |
|
|
|
|
|
$sheet->mergeCells(num2alpha($title_col_num) . $row[0] . ':' . num2alpha($title_col_num) . $row[1]); |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], $row[2]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$area_arr = [ |
|
|
|
|
|
[4, '台北'], |
|
|
|
|
|
[5, '新北'], |
|
|
|
|
|
[6, '基隆'], |
|
|
|
|
|
[7, '桃園'], |
|
|
|
|
|
[8, '新竹'], |
|
|
|
|
|
[9, '苗栗'], |
|
|
|
|
|
[10, '台中'], |
|
|
|
|
|
[11, '南投'], |
|
|
|
|
|
[12, '彰化'], |
|
|
|
|
|
[13, '雲林'], |
|
|
|
|
|
[14, '嘉義'], |
|
|
|
|
|
[15, '台南'], |
|
|
|
|
|
[16, '高雄'], |
|
|
|
|
|
[17, '屏東'], |
|
|
|
|
|
[18, '宜蘭'], |
|
|
|
|
|
[19, '花蓮'], |
|
|
|
|
|
[20, '台東'], |
|
|
|
|
|
[21, ''] |
|
|
|
|
|
]; |
|
|
|
|
|
foreach ($area_arr as $row) { |
|
|
|
|
|
$title_col_num = 0; |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], $row[1]); |
|
|
|
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
|
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
|
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
|
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
|
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
$tmp_arr = array( |
|
|
|
|
|
'date_year' => $i, |
|
|
|
|
|
'date_month' => str_pad($j, 2, '0', STR_PAD_LEFT), |
|
|
|
|
|
'sub_address' => $row[1], |
|
|
|
|
|
'contract_type' => 'A', |
|
|
|
|
|
); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findData($data, $tmp_arr)); |
|
|
|
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findData($data, $tmp_arr)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$tmp_arr = array( |
|
|
|
|
|
'start_y' => $start_y, |
|
|
|
|
|
'end_y' => $end_y, |
|
|
|
|
|
'start_m' => $start_m, |
|
|
|
|
|
'end_m' => $end_m, |
|
|
|
|
|
'sub_address' => $row[1], |
|
|
|
|
|
'contract_type' => 'A', |
|
|
|
|
|
); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '汰改'); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findDataByCity($data, $tmp_arr)); |
|
|
|
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findDataByCity($data, $tmp_arr)); |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '新梯'); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '3', '汰改'); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
|
|
|
|
|
|
$area_arr = [ |
|
|
|
|
|
[4, 6, '台北'], |
|
|
|
|
|
[7, 9, '桃竹苗'], |
|
|
|
|
|
[10, 13, '中部'], |
|
|
|
|
|
[14, 17, '南部'], |
|
|
|
|
|
[18, 20, '宜花東'], |
|
|
|
|
|
[21, 21, '未分類'] |
|
|
|
|
|
]; |
|
|
|
|
|
foreach ($area_arr as $row) { |
|
|
|
|
|
$title_col_num = 0; |
|
|
|
|
|
$sheet->mergeCells(num2alpha($title_col_num) . $row[0] . ':' . num2alpha($title_col_num) . $row[1]); |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], $row[2]); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$area_arr = [ |
|
|
|
|
|
[4, '台北'], |
|
|
|
|
|
[5, '新北'], |
|
|
|
|
|
[6, '基隆'], |
|
|
|
|
|
[7, '桃園'], |
|
|
|
|
|
[8, '新竹'], |
|
|
|
|
|
[9, '苗栗'], |
|
|
|
|
|
[10, '台中'], |
|
|
|
|
|
[11, '南投'], |
|
|
|
|
|
[12, '彰化'], |
|
|
|
|
|
[13, '雲林'], |
|
|
|
|
|
[14, '嘉義'], |
|
|
|
|
|
[15, '台南'], |
|
|
|
|
|
[16, '高雄'], |
|
|
|
|
|
[17, '屏東'], |
|
|
|
|
|
[18, '宜蘭'], |
|
|
|
|
|
[19, '花蓮'], |
|
|
|
|
|
[20, '台東'], |
|
|
|
|
|
[21, ''] |
|
|
|
|
|
]; |
|
|
|
|
|
foreach ($area_arr as $row) { |
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], $row[1]); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', "合計"); |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) { |
|
|
if ($i == $end_y && $j == ($end_m + 1)) |
|
|
break; |
|
|
break; |
|
|
} |
|
|
|
|
|
$tmp_arr = array( |
|
|
$tmp_arr = array( |
|
|
'date_year' => $i, |
|
|
'date_year' => $i, |
|
|
'date_month' => str_pad($j, 2, '0', STR_PAD_LEFT), |
|
|
'date_month' => str_pad($j, 2, '0', STR_PAD_LEFT), |
|
|
'sub_address' => $row[1], |
|
|
|
|
|
'contract_type' => 'A', |
|
|
'contract_type' => 'A', |
|
|
); |
|
|
); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findData($data, $tmp_arr)); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findDataByYearMonth($data, $tmp_arr)); |
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findData($data, $tmp_arr)); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findDataByYearMonth($data, $tmp_arr)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
$tmp_arr = array( |
|
|
$tmp_arr = array( |
|
|
'start_y' => $start_y, |
|
|
'start_y' => $start_y, |
|
|
'end_y' => $end_y, |
|
|
'end_y' => $end_y, |
|
|
'start_m' => $start_m, |
|
|
'start_m' => $start_m, |
|
|
'end_m' => $end_m, |
|
|
'end_m' => $end_m, |
|
|
'sub_address' => $row[1], |
|
|
|
|
|
'contract_type' => 'A', |
|
|
'contract_type' => 'A', |
|
|
); |
|
|
); |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findDataByCity($data, $tmp_arr)); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findAllDataByYearMonth($data, $tmp_arr)); |
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . $row[0], findDataByCity($data, $tmp_arr)); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findAllDataByYearMonth($data, $tmp_arr)); |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', "合計"); |
|
|
|
|
|
for ($i = $start_y; $i <= $end_y; $i++) { |
|
|
|
|
|
$this_start_m = $i == $start_y ? $start_m : 1; |
|
|
|
|
|
$this_end_m = $i == $start_y ? 12 : $end_m; |
|
|
|
|
|
for ($j = $this_start_m; $j <= $this_end_m; $j++) { |
|
|
|
|
|
if ($i == $end_y && $j == ($end_m + 1)) |
|
|
|
|
|
break; |
|
|
|
|
|
$tmp_arr = array( |
|
|
|
|
|
'date_year' => $i, |
|
|
|
|
|
'date_month' => str_pad($j, 2, '0', STR_PAD_LEFT), |
|
|
|
|
|
'contract_type' => 'A', |
|
|
|
|
|
); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findDataByYearMonth($data, $tmp_arr)); |
|
|
|
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findDataByYearMonth($data, $tmp_arr)); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$tmp_arr = array( |
|
|
|
|
|
'start_y' => $start_y, |
|
|
|
|
|
'end_y' => $end_y, |
|
|
|
|
|
'start_m' => $start_m, |
|
|
|
|
|
'end_m' => $end_m, |
|
|
|
|
|
'contract_type' => 'A', |
|
|
|
|
|
); |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findAllDataByYearMonth($data, $tmp_arr)); |
|
|
|
|
|
$tmp_arr['contract_type'] = 'B'; |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '22', findAllDataByYearMonth($data, $tmp_arr)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sheet->mergeCells('A25:I25'); |
|
|
$sheet->mergeCells('A25:I25'); |
|
|
$sheet->setCellValue('A25', '受定規格分析'); |
|
|
$sheet->setCellValue('A25', '受定規格分析'); |
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '26', "代碼"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '26', "代碼"); |
|
|
foreach ($data2 as $row) { |
|
|
foreach ($data2 as $row) { |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '26', $row['facility_kind']); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '26', $row['facility_kind']); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', "機種"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', "機種"); |
|
|
foreach ($data2 as $row) { |
|
|
foreach ($data2 as $row) { |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', getFacilityNamebyType($row['facility_kind'])); |
|
|
|
|
|
} |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', getFacilityNamebyType($row['facility_kind'])); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', "合計"); |
|
|
} |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '27', "合計"); |
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', "數量"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', "數量"); |
|
|
foreach ($data2 as $row) { |
|
|
foreach ($data2 as $row) { |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', $row['facility_count']); |
|
|
|
|
|
} |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', $row['facility_count']); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', findFacilityTypeAllCount($data2)); |
|
|
} |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '28', findFacilityTypeAllCount($data2)); |
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', "百分比"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', "百分比"); |
|
|
foreach ($data2 as $row) { |
|
|
foreach ($data2 as $row) { |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', (round($row['facility_count'] / findFacilityTypeAllCount($data2), 4) * 100) . "%"); |
|
|
|
|
|
} |
|
|
$title_col_num++; |
|
|
$title_col_num++; |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', (round($row['facility_count'] / findFacilityTypeAllCount($data2), 4) * 100) . "%"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', "100%"); |
|
|
} |
|
|
|
|
|
$title_col_num++; |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num) . '29', "100%"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$sheet->mergeCells('A32:G32'); |
|
|
$sheet->mergeCells('A32:G32'); |
|
|
$sheet->setCellValue('G25', '舊改受訂規格分析'); |
|
|
$sheet->setCellValue('G25', '舊改受訂規格分析'); |
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "類型"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "類型"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M1"); |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M2"); |
|
|
$title_tmp = empty($key) ? '未分類' : $key; |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M3"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', $title_tmp); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M4"); |
|
|
} |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "MA"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "合計"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "合計"); |
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "數量"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "數量"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M1); |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M2); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $val); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M3); |
|
|
} |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M4); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M_count); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $MA); |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M_count); |
|
|
|
|
|
|
|
|
|
|
|
$title_col_num = 0; |
|
|
$title_col_num = 0; |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "百分比"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '35', "百分比"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M1 / $M_count, 4) * 100) . "%"); |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M2 / $M_count, 4) * 100) . "%"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '35', (round($val / $M_count, 4) * 100) . "%"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M3 / $M_count, 4) * 100) . "%"); |
|
|
} |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M4 / $M_count, 4) * 100) . "%"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '35', "100%"); |
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($MA / $M_count, 4) * 100) . "%"); |
|
|
|
|
|
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "100%"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$writer = new Xlsx($spreadsheet); |
|
|
$writer = new Xlsx($spreadsheet); |
|
|
$file_path = dirname(__DIR__) . '/wms/excel/' . 'estimated_shipping_date_report.xlsx'; |
|
|
$file_path = dirname(__DIR__) . '/wms/excel/' . 'estimated_shipping_date_report.xlsx'; |
|
|
try { |
|
|
try { |
|
|
$writer->save($file_path); |
|
|
$writer->save($file_path); |
|
|
// 回傳檔案路徑給 JavaScript |
|
|
// 回傳檔案路徑給 JavaScript |
|
|
echo $file_path; |
|
|
echo $file_path; |
|
|
} catch (Exception $e) { |
|
|
} catch (Exception $e) { |
|
|
echo 'Error: ' . $e->getMessage(); |
|
|
echo 'Error: ' . $e->getMessage(); |
|
|
|
|
|
} |
|
|
|
|
|
exit(); |
|
|
} |
|
|
} |
|
|
exit(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
?> |
|
|
?> |
|
|
<style> |
|
|
<style> |
|
|
|
|
|
|
|
@ -1234,29 +1245,30 @@ if ($_POST['excel_output'] == 'excel_output') { |
|
|
<tbody> |
|
|
<tbody> |
|
|
<tr> |
|
|
<tr> |
|
|
<th>類型</th> |
|
|
<th>類型</th> |
|
|
<th>M1</th> |
|
|
<?php |
|
|
<th>M2</th> |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
<th>M3</th> |
|
|
$title_tmp = empty($key) ? '未分類' : $key; |
|
|
<th>M4</th> |
|
|
echo "<th>" . $title_tmp . "</th>"; |
|
|
<th>MA</th> |
|
|
} |
|
|
|
|
|
?> |
|
|
<th>合計</th> |
|
|
<th>合計</th> |
|
|
</tr> |
|
|
</tr> |
|
|
<tr> |
|
|
<tr> |
|
|
<th>數量</th> |
|
|
<th>數量</th> |
|
|
<th><?php echo $M1; ?></th> |
|
|
<?php |
|
|
<th><?php echo $M2; ?></th> |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
<th><?php echo $M3; ?></th> |
|
|
echo "<th>" . $val . "</th>"; |
|
|
<th><?php echo $M4; ?></th> |
|
|
} |
|
|
<th><?php echo $MA; ?></th> |
|
|
?> |
|
|
<th><?php echo $M_count; ?></th> |
|
|
<th><?php echo $M_count; ?></th> |
|
|
</tr> |
|
|
</tr> |
|
|
<tr> |
|
|
<tr> |
|
|
<th>百分比</th> |
|
|
<th>百分比</th> |
|
|
<th><?php echo (round($M1 / $M_count, 4) * 100) . "%"; ?></th> |
|
|
<?php |
|
|
<th><?php echo (round($M2 / $M_count, 4) * 100) . "%"; ?></th> |
|
|
foreach ($m_type_arr as $key => $val) { |
|
|
<th><?php echo (round($M3 / $M_count, 4) * 100) . "%"; ?></th> |
|
|
echo "<th>" . round($val / $M_count, 4) * 100 . "%" . "</th>"; |
|
|
<th><?php echo (round($M4 / $M_count, 4) * 100) . "%"; ?></th> |
|
|
} |
|
|
<th><?php echo (round($MA / $M_count, 4) * 100) . "%"; ?></th> |
|
|
?> |
|
|
<th>100%</th> |
|
|
<th>100%</th> |
|
|
</tr> |
|
|
</tr> |
|
|
</tbody> |
|
|
</tbody> |
|
|