Browse Source

修正出貨地區預定明細報表

gary
gary_chen\gary_chen 1 year ago
parent
commit
061a770e05
  1. 134
      wms/estimated_shipping_date_report.php

134
wms/estimated_shipping_date_report.php

@ -29,6 +29,8 @@ $sql = "
w.contract_type
FROM wipwholestatus AS w
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
WHERE 1 = 1
GROUP BY this_order.contract_type,
@ -41,7 +43,7 @@ $data = [];
while ($row = $result->fetch_assoc()) {
$data[] = $row;
}
// print_r($data);
function findData($data, $searchData)
{
foreach ($data as $item) {
@ -115,7 +117,6 @@ function findAllDataByYearMonth($data, $searchData)
&& $item['date_year'] == $i
&& $item['date_month'] == str_pad($j, 2, '0', STR_PAD_LEFT)
) {
// echo $item['facility_count']." ";
$count += $item['facility_count'];
}
}
@ -134,8 +135,9 @@ $sql = "
FROM wipwholestatus AS w
WHERE 1=1
AND status = '1'
AND real_contract_arrival_date >= '$start_y-$start_m-0'
AND real_contract_arrival_date <= '$end_y-$end_m-0'
AND contract_type = 'A'
AND real_contract_arrival_date >= '$start_y-$start_m-1'
AND real_contract_arrival_date <= '$end_y-$end_m-31'
) AS new_order
WHERE 1 = 1
GROUP BY new_order.facility_kind
@ -175,8 +177,8 @@ $sql = "
FROM wipwholestatus AS w
WHERE 1=1
AND status = '1'
AND real_contract_arrival_date >= '$start_y-$start_m-0'
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'
AND contract_type = 'B'
";
$result = mysqli_query($link, $sql);
@ -184,28 +186,42 @@ $data3 = [];
while ($row = $result->fetch_assoc()) {
$data3[] = $row;
}
$M1 = 0;
$M2 = 0;
$M3 = 0;
$M4 = 0;
$MA = 0;
$M_count = 0;
// 分開計算
// $M1 = 0;
// $M2 = 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) {
$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_type_arr[implode("+", json_decode($row['renovate_type']))]++;
}
//數字轉英文(0=>A、1=>B、26=>AA...以此類推)
function num2alpha($n)
@ -224,7 +240,7 @@ function alpha2num($a)
$n = $n * 26 + ord($a[$i]) - 0x40;
return $n - 1;
}
if($_SERVER["REQUEST_METHOD"] == 'POST'){
if ($_POST['excel_output'] == 'excel_output') {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
@ -443,30 +459,25 @@ if ($_POST['excel_output'] == 'excel_output') {
$title_col_num = 0;
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "類型");
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M1");
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M2");
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M3");
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "M4");
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "MA");
foreach ($m_type_arr as $key => $val) {
$title_tmp = empty($key) ? '未分類' : $key;
$sheet->setCellValue(num2alpha($title_col_num++) . '33', $title_tmp);
}
$sheet->setCellValue(num2alpha($title_col_num++) . '33', "合計");
$title_col_num = 0;
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "數量");
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M1);
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M2);
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M3);
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M4);
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $MA);
foreach ($m_type_arr as $key => $val) {
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $val);
}
$sheet->setCellValue(num2alpha($title_col_num++) . '34', $M_count);
$title_col_num = 0;
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "百分比");
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M1 / $M_count, 4) * 100) . "%");
$sheet->setCellValue(num2alpha($title_col_num++) . '34', (round($M2 / $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++) . '34', (round($MA / $M_count, 4) * 100) . "%");
$sheet->setCellValue(num2alpha($title_col_num++) . '34', "100%");
$sheet->setCellValue(num2alpha($title_col_num++) . '35', "百分比");
foreach ($m_type_arr as $key => $val) {
$sheet->setCellValue(num2alpha($title_col_num++) . '35', (round($val / $M_count, 4) * 100) . "%");
}
$sheet->setCellValue(num2alpha($title_col_num++) . '35', "100%");
$writer = new Xlsx($spreadsheet);
@ -480,7 +491,7 @@ if ($_POST['excel_output'] == 'excel_output') {
}
exit();
}
}
?>
<style>
@ -1234,29 +1245,30 @@ if ($_POST['excel_output'] == 'excel_output') {
<tbody>
<tr>
<th>類型</th>
<th>M1</th>
<th>M2</th>
<th>M3</th>
<th>M4</th>
<th>MA</th>
<?php
foreach ($m_type_arr as $key => $val) {
$title_tmp = empty($key) ? '未分類' : $key;
echo "<th>" . $title_tmp . "</th>";
}
?>
<th>合計</th>
</tr>
<tr>
<th>數量</th>
<th><?php echo $M1; ?></th>
<th><?php echo $M2; ?></th>
<th><?php echo $M3; ?></th>
<th><?php echo $M4; ?></th>
<th><?php echo $MA; ?></th>
<?php
foreach ($m_type_arr as $key => $val) {
echo "<th>" . $val . "</th>";
}
?>
<th><?php echo $M_count; ?></th>
</tr>
<tr>
<th>百分比</th>
<th><?php echo (round($M1 / $M_count, 4) * 100) . "%"; ?></th>
<th><?php echo (round($M2 / $M_count, 4) * 100) . "%"; ?></th>
<th><?php echo (round($M3 / $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>
<?php
foreach ($m_type_arr as $key => $val) {
echo "<th>" . round($val / $M_count, 4) * 100 . "%" . "</th>";
}
?>
<th>100%</th>
</tr>
</tbody>

Loading…
Cancel
Save