|
|
@@ -1,5 +1,5 @@
|
|
|
<?php
|
|
|
-include($_SERVER['DOCUMENT_ROOT']."/Authorization/script/php/permission/check_right.php");
|
|
|
+include($_SERVER['DOCUMENT_ROOT'] . "/Authorization/script/php/permission/check_right.php");
|
|
|
include("./API/equipment.php");
|
|
|
include("./connect_sql.php");
|
|
|
require '../../assets/vendor/autoload.php';
|
|
|
@@ -36,7 +36,7 @@ if (isset($_FILES["excel"])) {
|
|
|
$date_value = $header->getCell('J2')->getValue();
|
|
|
$timestamp = \PhpOffice\PhpSpreadsheet\Shared\Date::excelToTimestamp($date_value);
|
|
|
$date = date('Y/m/d', $timestamp);
|
|
|
-
|
|
|
+ $equipment_name = "";
|
|
|
for ($s = 0; $s < $sheetCount; $s++) {
|
|
|
$data = array();
|
|
|
$sheet = $spreadsheet->getSheet($s);
|
|
|
@@ -54,24 +54,28 @@ if (isset($_FILES["excel"])) {
|
|
|
$endR = $equipment_data[$index_key]["endR"] !== 0 ? $equipment_data[$index_key]["endR"] : $column['row']; //結尾列數 若為0則總列數
|
|
|
for ($i = $startR; $i <= $endR; $i++) {
|
|
|
$skip = false;
|
|
|
+ $first = true;
|
|
|
$row = array();
|
|
|
$col_count = 0;
|
|
|
array_push($row, $date);
|
|
|
if (str_contains($sheetName, "SIS") || str_contains($sheetName, "SID")) { //若為SIS取出儀器名稱
|
|
|
- if(str_contains($sheetName,"區")){
|
|
|
+ if (str_contains($sheetName, "區")) {
|
|
|
$equipment_name = explode("區", $sheetName)[1];
|
|
|
}
|
|
|
- if(str_contains($sheetName,"(")){
|
|
|
+ if (str_contains($sheetName, "(")) {
|
|
|
$temp = explode("(", $sheetName);
|
|
|
- $equipment_name = $temp[0].$temp[1];
|
|
|
+ $equipment_name = $temp[0] . $temp[1];
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$equipment_name = str_replace(" ", "", $equipment_name);
|
|
|
$col_count++;
|
|
|
array_push($row, $equipment_name);
|
|
|
}
|
|
|
for ($j = $startC; $j <= $endC; $j++) {
|
|
|
if ($skipC != $j) {
|
|
|
+ if($first){
|
|
|
+ $first = false;
|
|
|
+ }
|
|
|
$col_count++;
|
|
|
$key = $j . $i;
|
|
|
$value = $sheet->getCell($key)->getCalculatedValue();
|
|
|
@@ -90,7 +94,12 @@ if (isset($_FILES["excel"])) {
|
|
|
if (!$skip) {
|
|
|
array_push($data, $row);
|
|
|
$row_merge = str_repeat(", ?", $col_count);
|
|
|
- $sql = "INSERT INTO [{$type}_Data] VALUES (? {$row_merge});";
|
|
|
+ $sql = "BEGIN
|
|
|
+ IF NOT EXISTS (SELECT [date] FROM [{$type}_Data] WHERE [date] = '{$date}' AND [EquipmentID] = '')
|
|
|
+ BEGIN
|
|
|
+ INSERT INTO [{$type}_Data] VALUES (? {$row_merge})
|
|
|
+ END
|
|
|
+ END";
|
|
|
$stmt = sqlsrv_query($conn, $sql, $row);
|
|
|
if ($stmt === false) {
|
|
|
if (($errors = sqlsrv_errors()) != null) {
|
|
|
@@ -130,7 +139,7 @@ if (isset($_FILES["excel"])) {
|
|
|
}
|
|
|
}
|
|
|
header("Location: ../../Upload.php?status=success");
|
|
|
-}else{
|
|
|
+} else {
|
|
|
header("Location: ../../Upload.php?status=failed");
|
|
|
}
|
|
|
|