@ -148,6 +148,27 @@ while ($row = $result->fetch_assoc()) {
$data2[] = $row;
}
$sql = "
SELECT
new_order.facility_kind,
COUNT(new_order.facility_kind) AS facility_count
FROM(
SELECT
w.facility_kind
FROM wipwholestatus AS w
WHERE 1=1
AND status = '1'
AND contract_type = 'A'
) AS new_order
WHERE 1 = 1
GROUP BY new_order.facility_kind
";
$result = mysqli_query($link, $sql);
$data4 = [];
while ($row = $result->fetch_assoc()) {
$data4[] = $row;
}
function findFacilityTypeAllCount($data2)
{
$count = 0;
@ -187,6 +208,20 @@ while ($row = $result->fetch_assoc()) {
$data3[] = $row;
}
$sql = "
SELECT
w.renovate_type
FROM wipwholestatus AS w
WHERE 1=1
AND status = '1'
AND contract_type = 'B'
";
$result = mysqli_query($link, $sql);
$data5 = [];
while ($row = $result->fetch_assoc()) {
$data5[] = $row;
}
// 分開計算
// $M1 = 0;
@ -222,6 +257,16 @@ foreach ($data3 as $row) {
$m_type_arr[implode("+", json_decode($row['renovate_type']))]++;
}
$M_count2 = count($data5);
$m_type_arr2 = [];
$m_type_arr2[''] = 0;
foreach ($data5 as $row) {
$m_type_arr2[implode("+", json_decode($row['renovate_type']))] = 0;
}
foreach ($data5 as $row) {
$m_type_arr2[implode("+", json_decode($row['renovate_type']))]++;
}
//數字轉英文(0=>A、1=>B、26=>AA...以此類推)
function num2alpha($n)
@ -240,7 +285,7 @@ function alpha2num($a)
$n = $n * 26 + ord($a[$i]) - 0x40;
return $n - 1;
}
if($_SERVER["REQUEST_METHOD"] == 'POST'){
if ($_SERVER["REQUEST_METHOD"] == 'POST') {
if ($_POST['excel_output'] == 'excel_output') {
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
@ -1183,96 +1228,186 @@ if($_SERVER["REQUEST_METHOD"] == 'POST'){
< / table >
< / div >
< br / > < br / >
< div class = "col-12 col-md-8" >
< table class = "table table-striped" >
< thead >
< tr >
< td colsapn = " <?php echo count ( $data2 ); ?> " > 受定規格分析</ td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 代碼< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . $row['facility_kind'] . "< / td > ";
}
?>
< th > < / th >
< / tr >
< tr >
< th > 機種< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . getFacilityNamebyType($row['facility_kind']) . "< / td > ";
}
?>
< th > 合計< / th >
< / tr >
< tr >
< th > 數量< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . $row['facility_count'] . "< / td > ";
}
?>
< th > <?php echo findFacilityTypeAllCount ( $data2 ); ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . (round($row['facility_count'] / findFacilityTypeAllCount($data2), 4) * 100) . "%" . "< / td > ";
}
?>
< th > <?php echo "100%" ; ?> </ th >
< / tr >
< / tbody >
< / table >
< / div >
< div class = "row" >
< div class = "col-12 col-md-8" >
< table class = "table table-striped" >
< thead >
< tr >
< td colsapn = " <?php echo count ( $data2 ); ?> " > 受定規格分析(時間區間)</ td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 代碼< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . $row['facility_kind'] . "< / td > ";
}
?>
< th > < / th >
< / tr >
< tr >
< th > 機種< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . getFacilityNamebyType($row['facility_kind']) . "< / td > ";
}
?>
< th > 合計< / th >
< / tr >
< tr >
< th > 數量< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . $row['facility_count'] . "< / td > ";
}
?>
< th > <?php echo findFacilityTypeAllCount ( $data2 ); ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($data2 as $row) {
echo "< td > " . (round($row['facility_count'] / findFacilityTypeAllCount($data2), 4) * 100) . "%" . "< / td > ";
}
?>
< th > <?php echo "100%" ; ?> </ th >
< / tr >
< / tbody >
< / table >
< / div >
< div class = "col-12 col-md-4" >
< table class = "table table-striped" >
< thead >
< tr >
< td colspan = '3' > 舊改受訂規格分析(時間區間)< / td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 類型< / 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 >
<?php
foreach ($m_type_arr as $key => $val) {
echo "< th > " . $val . "< / th > ";
}
?>
< th > <?php echo $M_count ; ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($m_type_arr as $key => $val) {
echo "< th > " . round($val / $M_count, 4) * 100 . "%" . "< / th > ";
}
?>
< th > 100%< / th >
< / tr >
< / tbody >
< / table >
< / div >
< / div >
< br / > < br / >
< div class = "row" >
< div class = "col-12 col-md-8" >
< table class = "table table-striped" >
< thead >
< tr >
< td colsapn = " <?php echo count ( $data4 ); ?> " > 受定規格分析(全部)</ td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 代碼< / th >
<?php
foreach ($data4 as $row) {
echo "< td > " . $row['facility_kind'] . "< / td > ";
}
?>
< th > < / th >
< / tr >
< tr >
< th > 機種< / th >
<?php
foreach ($data4 as $row) {
echo "< td > " . getFacilityNamebyType($row['facility_kind']) . "< / td > ";
}
?>
< th > 合計< / th >
< / tr >
< tr >
< th > 數量< / th >
<?php
foreach ($data4 as $row) {
echo "< td > " . $row['facility_count'] . "< / td > ";
}
?>
< th > <?php echo findFacilityTypeAllCount ( $data4 ); ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($data4 as $row) {
echo "< td > " . (round($row['facility_count'] / findFacilityTypeAllCount($data4), 4) * 100) . "%" . "< / td > ";
}
?>
< th > <?php echo "100%" ; ?> </ th >
< / tr >
< / tbody >
< / table >
< / div >
< div class = "col-12 col-md-4" >
< table class = "table table-striped" >
< thead >
< tr >
< td > 舊改受訂規格分析< / td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 類型< / 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 >
<?php
foreach ($m_type_arr as $key => $val) {
echo "< th > " . $val . "< / th > ";
}
?>
< th > <?php echo $M_count ; ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($m_type_arr as $key => $val) {
echo "< th > " . round($val / $M_count, 4) * 100 . "%" . "< / th > ";
}
?>
< th > 100%< / th >
< / tr >
< / tbody >
< / table >
< div class = "col-12 col-md-4" >
< table class = "table table-striped" >
< thead >
< tr >
< td colspan = '3' > 舊改受訂規格分析(全部)< / td >
< / tr >
< / thead >
< tbody >
< tr >
< th > 類型< / th >
<?php
foreach ($m_type_arr2 as $key => $val) {
$title_tmp = empty($key) ? '未分類' : $key;
echo "< th > " . $title_tmp . "< / th > ";
}
?>
< th > 合計< / th >
< / tr >
< tr >
< th > 數量< / th >
<?php
foreach ($m_type_arr2 as $key => $val) {
echo "< th > " . $val . "< / th > ";
}
?>
< th > <?php echo $M_count2 ; ?> </ th >
< / tr >
< tr >
< th > 百分比< / th >
<?php
foreach ($m_type_arr2 as $key => $val) {
echo "< th > " . round($val / $M_count2, 4) * 100 . "%" . "< / th > ";
}
?>
< th > 100%< / th >
< / tr >
< / tbody >
< / table >
< / div >
< / div >
< script >
const formData = new FormData();