You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

224 lines
8.6 KiB

<?php
error_reporting(0);
include "header.php";
// 設置一個空陣列來放資料
$data = $contractno_arr = $company_arr = array();
$test_arr = ["B000000001", "Sky", "Aaron"];
$tds = date("Y-m-d");
$sdate = ($_REQUEST["sdate"]) ? $_REQUEST["sdate"] : "2022-01-01"; // default
$edate = ($_REQUEST["edate"]) ? $_REQUEST["edate"] : $tds;
if ($edate < $sdate) {
$st_date = $edate;
$ed_date = $sdate;
} else {
$st_date = $sdate;
$ed_date = $edate;
}
// stars |stars_b2|customer_signature :面評
// stars_c1|stars_c2|customer_self_signature:事後評
$db_query = "select id, contractno, repairerid, repairername, stars, stars_b2, stars_c1, stars_c2 from schedule ";
$db_query .= "where actualdate >= '$st_date 00:00:00' and actualdate <= '$ed_date 23:59:59'";
//echo $db_query;
$res = mysqli_query($link, $db_query);
while ($row = mysqli_fetch_array($res)) {
if (in_array($row["repairerid"], $test_arr)) continue;
$data[$row["repairerid"]]["id"][] = $row["id"];
$contractno_arr[$row["contractno"]] = 1;
$data[$row["repairerid"]]["contractno"][$row["contractno"]] = 1;
$data[$row["repairerid"]]["repairername"] = $row["repairername"];
//if (!$row["evidences"]) $data[$row["repairerid"]]["no_evidences"]++; // 未上傳照片
//if (!$row["customer_self_signature"]) $data[$row["repairerid"]]["no_signature"]++; // 客戶未簽名
$stars1 = ($row["stars_c1"]) ? $row["stars_c1"] : $row["stars"]; // 保養品質
$stars2 = ($row["stars_c2"]) ? $row["stars_c2"] : $row["stars_b2"]; // 服務態度
//$signature = ($row["customer_self_signature"]) ? $row["customer_self_signature"] : $row["customer_signature"]; // 客戶簽名
$data[$row["repairerid"]]["s1_eval_total"]++;
if ($stars1 > 0) {
$data[$row["repairerid"]]["s1_score"] += $stars1;
$data[$row["repairerid"]]["s1_eval_real"]++;
$data[$row["repairerid"]]["s1_eval_yet"] = 0 + $data[$row["repairerid"]]["s1_eval_yet"];
} else {
$data[$row["repairerid"]]["s1_score"] += 0 + $stars1;
$data[$row["repairerid"]]["s1_eval_yet"]++;
$data[$row["repairerid"]]["s1_eval_real"] = 0 + $data[$row["repairerid"]]["s1_eval_real"];
}
$data[$row["repairerid"]]["s2_eval_total"]++;
if ($stars2 > 0) {
$data[$row["repairerid"]]["s2_score"] += $stars2;
$data[$row["repairerid"]]["s2_eval_real"]++;
$data[$row["repairerid"]]["s2_eval_yet"] = 0 + $data[$row["repairerid"]]["s2_eval_yet"];
} else {
$data[$row["repairerid"]]["s2_score"] += 0 + $stars2;
$data[$row["repairerid"]]["s2_eval_yet"]++;
$data[$row["repairerid"]]["s2_eval_real"] = 0 + $data[$row["repairerid"]]["s2_eval_real"];
}
}
mysqli_free_result($res);
if ($data) {
// 查詢保養照片
$sidraw_arr = $sid_arr = [];
$image_directory = "../app/maintenance_uploads/";
//$photo_arr = glob($image_directory."*.*");
//print_r($photo_arr);
$handle = opendir($image_directory);
while (false!==($file = readdir($handle))) {
if (preg_match("/^\d+-[after|before]{1}/", $file, $matches)) {
$sidraw_arr[] = substr($matches[0], 0, strpos($matches[0], "-"));
}
}
closedir($handle);
$sid_arr = array_unique($sidraw_arr);
// 統計保養上傳照片狀況
foreach ($data as $k => $v) {
foreach ($v["id"] as $val) {
if (in_array($val, $sid_arr)) $photo_arr[$k]["upload"]++;
}
$photo_arr[$k]["total"] = count($v["id"]);
}
// 查詢登入過的客戶帳號;日後再改成撈DB
$account_path_arr = glob("../app/account_log/M*.ini");
foreach ($account_path_arr as $filename) {
if (preg_match("/M[0-9]{6}/", $filename, $matches)) {
$login_arr[$matches[0]] = 1;
}
}
$sql = "select contractno, company from contract where contractno in ('".implode("','", array_keys($contractno_arr))."')";
$res = mysqli_query($link, $sql);
while ($row = mysqli_fetch_array($res)) {
$company_arr[$row["contractno"]] = $row["company"];
}
mysqli_free_result($res);
?>
<style>
table {
table-layout:fixed;
width: 100%;
}
td {
word-wrap:break-word;
}
img {
width:125px;
}
.width_style_1 {
width:125px;
}
table {
width:100%;
}
th, td {
text-align: center;
}
#table_index_filter {
float:right;
}
#table_index_paginate {
float:right;
}
label {
display: inline-flex;
margin-bottom: .5rem;
margin-top: .5rem;
}
</style>
<script>
$(document).ready(function() {
// 隱藏分頁
$("select[name=table_index_length]").val(100).trigger("change");
$(".dataTables_length").hide();
$(".dataTables_info").hide();
$("#table_index_paginate").hide();
} );
</script>
<div class="container" style="float:left;">
<form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
實際保養日期:
<input type="date" name="sdate" id="sdate" value="<?php echo $st_date; ?>">~<input type="date" name="edate" id="edate" value="<?php echo $ed_date; ?>">
<button type="submit" name="btn_srh">搜尋</button> 
<small>* 平均分數 = 實評分數總和 / 應評件數</small>
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
</div>
<div style="overflow-x:auto;float:right">
<table id="table_index" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th rowspan="2">項次</th>
<th rowspan="2">人員<br>代號</th>
<th rowspan="2">人員<br>名稱</th>
<th colspan="5">保養品質</th>
<th colspan="5">服務態度</th>
<th style="width:34%" colspan="2">備註</th>
</tr>
<tr>
<th>應評</th>
<th>未評</th>
<th>實評</th>
<th>實評比例</th>
<th>平均分數</th>
<th>應評</th>
<th>未評</th>
<th>實評</th>
<th>實評比例</th>
<th>平均分數</th>
<th>未上傳照片</th>
<!--<th>客戶<br>未簽名</th>-->
<th>客戶未登入(註冊)</th>
</tr>
</thead>
<tbody>
<?php
$i = 0;
foreach($data as $rid => $val) :
$i++;
$customer_nologin = 0;
$customer_nologin_list = "";
foreach ($val["contractno"] as $ckey => $cval) {
if (!array_key_exists($ckey, $login_arr)) {
$customer_nologin++;
$customer_nologin_list .= $ckey." ".$company_arr[$ckey]."<br>";
}
}
?>
<tr>
<td><?php echo $i; ?></td>
<td class="text-nowrap"><?php echo $rid; ?></td>
<td class="text-nowrap"><?php echo $val['repairername']; ?></td>
<td><?php echo $val['s1_eval_total']; ?></td>
<td><?php echo $val['s1_eval_yet']; ?></td>
<td><?php echo $val['s1_eval_real']; ?></td>
<td><?php echo number_format(($val['s1_eval_real']/$val['s1_eval_total'])*100,1); ?>%</td>
<td><?php echo ($val['s1_eval_real']) ? number_format($val['s1_score']/$val['s1_eval_total'], 1) : 0; ?></td>
<td><?php echo $val['s2_eval_total']; ?></td>
<td><?php echo $val['s2_eval_yet']; ?></td>
<td><?php echo $val['s2_eval_real']; ?></td>
<td><?php echo number_format(($val['s2_eval_real']/$val['s2_eval_total'])*100,1); ?>%</td>
<td><?php echo ($val['s2_eval_real']) ? number_format($val['s2_score']/$val['s2_eval_total'], 1) : 0; ?></td>
<!--<td><?php echo ($val['no_evidences']) ? $val['no_evidences'] : 0; ?></td>
<td><?php echo ($val['no_signature']) ? $val['no_signature'] : 0; ?></td>-->
<td><?php echo $photo_arr[$rid]["total"] - $photo_arr[$rid]["upload"]; ?></td>
<td><a data-toggle="collapse" data-target="#cust<?php echo $i; ?>" role="button"><?php echo $customer_nologin; ?></a>
<div id="cust<?php echo $i; ?>" class="collapse small text-left"><?php echo $customer_nologin_list; ?></div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
} else {
echo "<h2>There is no record!</h2>";
}
#代表結束連線
mysqli_close($link);
include "footer.php";
?>