diff --git a/wms/contract-repair/api/deleteNewContractData.php b/wms/contract-repair/api/deleteNewContractData.php
new file mode 100644
index 00000000..d7feb1c1
--- /dev/null
+++ b/wms/contract-repair/api/deleteNewContractData.php
@@ -0,0 +1,15 @@
+prepare($sql_str);
+ $stmt->bindParam(":contractid", $id);
+ $stmt->execute();
+ header("HTTP/1.1 204 No Content");
+ }catch(PDOException $e){
+ die("ERROR!!!: ". $e->getMessage());
+ }
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/getComboNo.php b/wms/contract-repair/api/getComboNo.php
new file mode 100644
index 00000000..c258be15
--- /dev/null
+++ b/wms/contract-repair/api/getComboNo.php
@@ -0,0 +1,59 @@
+'BW002',
+ 'month'=>'EM002',
+ 'quarter'=>'EQ002',
+ 'half'=>'HY002',
+ 'year'=>'EY002'
+ ];
+ private $bwarr = [
+ 'week','month','week','month','week','quarter',
+ 'week','month','week','month','week','half',
+ 'week','month','week','month','week','quarter',
+ 'week','month','week','month','week','year'
+ ];
+ private $emarr = [
+ 'month','month','quarter','month','month','half',
+ 'month','month','quarter','month','month','year'
+ ];
+ private $combo;
+ private $startdate;
+ private $enddate;
+ public function __construct($combo, $startdate, $enddate){
+ $this->combo = $combo;
+ $this->startdate = $startdate;
+ $this->enddate = $enddate;
+ }
+ public function getComboNo(){
+ $comboarr = (array) $this->combo === 'bw' ? $this->bwarr : $this->emarr;
+
+ $startdate = new DateTime($this->startdate);
+ $enddate = new DateTime($this->enddate);
+
+ $interval = date_diff($startdate, $enddate);
+
+ $months = $interval->y * 12 + $interval->m;
+ $months = $this->combo === 'bw' ? $months*2 : $months;
+
+ $newarr = [];
+ $idx = 0;
+ $ori_first_month = date('m', strtotime($this->startdate));
+ $first_day = date('Y-m-d', strtotime($this->startdate. ' + 3 days'));
+ $new_first_month = date('m', strtotime($first_day));
+ if($ori_first_month != $new_first_month){
+ $first_day = date('Y-m-t', strtotime($this->startdate));
+ }
+ $scheduleDate = new DateTime($first_day);
+ for ($i = 0; $i < $months; $i++){
+ $newarr[] = [$this->comboarr[$comboarr[$idx]], $scheduleDate->format("Y-m-d")];
+ $idx ++;
+ $scheduleDate = $startdate->modify("+1 month");
+ if($idx >= count($comboarr)){
+ $idx = 0;
+ }
+ }
+ return json_encode($newarr);
+ }
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/getContractData.php b/wms/contract-repair/api/getContractData.php
new file mode 100644
index 00000000..df52d1dd
--- /dev/null
+++ b/wms/contract-repair/api/getContractData.php
@@ -0,0 +1,60 @@
+prepare($sql_str);
+ $stmt->bindParam(':vol_no', $contractno);
+ $stmt->execute();
+ $contract= $stmt->fetch(PDO::FETCH_ASSOC);
+
+ if(empty($contract)){
+ echo false;
+ exit;
+ }
+ $apply_key = $contract['apply_key'];
+ $sql_str = "SELECT * FROM con_maintance_examine_clear WHERE apply_key = :apply_key";
+ $stmt = $conn->prepare($sql_str);
+ $stmt->bindParam(':apply_key', $apply_key);
+ $stmt->execute();
+ $elevators= $stmt->fetchAll(PDO::FETCH_ASSOC);
+ $count = COUNT($elevators);
+ $contract['elevators'] = $elevators;
+ $contract['num'] = $count;
+
+ $contractResponse = json_encode($contract);
+
+ // 設定回應標頭為 JSON
+ header('Content-Type: application/json');
+
+ // 將 JSON 回應返回給客戶端
+ echo $contractResponse;
+ // echo json_encode($contractResponse);
+ }catch (PDOException $e ){
+ die("ERROR!!!: ". $e->getMessage());
+ }
+}
+
+if(isset($_GET['contractno']) && $_GET['contractno']!='' && isset($_GET['contracttype']) && $_GET['contracttype']=='m'){
+ try{
+ $contractno = $_GET['contractno'];
+ $sql_str = "SELECT * FROM hope_elevator_customer WHERE vol_no = :vol_no ORDER BY created_at DESC";
+ $stmt = $conn->prepare($sql_str);
+ $stmt->bindParam(':vol_no', $contractno);
+ $stmt->execute();
+ $contract= $stmt->fetch(PDO::FETCH_ASSOC);
+ $contractResponse = json_encode($contract);
+
+ // 設定回應標頭為 JSON
+ header('Content-Type: application/json');
+
+ // 將 JSON 回應返回給客戶端
+ echo $contractResponse;
+ }catch (PDOException $e ){
+ die("ERROR!!!: ". $e->getMessage());
+ }
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/getFacilityNo.php b/wms/contract-repair/api/getFacilityNo.php
new file mode 100644
index 00000000..fcf0b76f
--- /dev/null
+++ b/wms/contract-repair/api/getFacilityNo.php
@@ -0,0 +1,518 @@
+ false,
+ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_EMULATE_PREPARES => false,
+ PDO::ATTR_STRINGIFY_FETCHES => false,
+ PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4',
+ ];
+ $pdo = new PDO('mysql:host=' . $host . ';port=' . $dbport . ';dbname=' . $dbname . '', $dbuser, $dbpassword, $options);
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ return $pdo;
+ } catch (PDOException $e) {
+ die("Something wrong: {$e->getMessage()}");
+ }
+ }
+
+ /**
+ * 結束資料庫連線
+ */
+ function endConnectionDB($pdo)
+ {
+ unset($pdo);
+ }
+
+ /**
+ * 取得下一個新的作番
+ * @param string $facility_type : M:新梯 T:汰改 B:保養
+ * @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @param int $num : 號機
+ * @return array $new_facility_arr
+ */
+ function getNextFacilityNo($facility_type, $sale_type, $make_type, $num = 1)
+ {
+ $this->checkYearAndResetAllSeq();
+ $Y = substr(date("Y"), 3, 1);
+
+ switch ($facility_type) {
+ case "M":
+ $next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1;
+ $new_facility_arr = [];
+ for ($start_num = 1; $start_num <= $num; $start_num++) {
+ $facility_no_tmp = $Y . $sale_type . $make_type[$start_num - 1]
+ . str_pad($next_seq, 5, "0", STR_PAD_LEFT);
+ array_push($new_facility_arr, $facility_no_tmp);
+ $next_seq++;
+ }
+ return $new_facility_arr;
+ case "T":
+ $next_seq = $this->getNextFacilitySeq("tf_vol_no");
+ $new_facility_arr = [];
+ for ($start_num = 1; $start_num <= $num; $start_num++) {
+ $facility_no_tmp = $Y . $sale_type . $make_type[$start_num - 1]
+ . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
+ . str_pad($start_num, 2, "0", STR_PAD_LEFT);
+ array_push($new_facility_arr, $facility_no_tmp);
+ }
+ return $new_facility_arr;
+ case "B":
+ $next_seq = $this->getNextFacilitySeq("bf_vol_no");
+ $new_facility_arr = [];
+ for ($start_num = 1; $start_num <= $num; $start_num++) {
+ $facility_no_tmp = $Y . $sale_type . $make_type[$start_num - 1]
+ . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
+ . str_pad($start_num, 2, "0", STR_PAD_LEFT);
+ array_push($new_facility_arr, $facility_no_tmp);
+ }
+ return $new_facility_arr;
+ default:
+ return "不存在的作番類型";
+ }
+ }
+
+ /**
+ * 建立新的作番
+ * @param string $facility_type : M:新梯 T:汰改 B:保養
+ * @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @param string $num : 號機 (非必填)
+ * @return string $new_facility_no
+ */
+ function makeFacilityNo($facility_type, $sale_type, $make_type, $num = null)
+ {
+
+ $this->checkYearAndResetAllSeq();
+
+ $faclikity_details = array(
+ 'facility_type' => $facility_type,
+ 'sale_type' => $sale_type,
+ 'make_type' => $make_type,
+ 'num' => $num
+ );
+
+ switch ($facility_type) {
+ case "M":
+ return $this->makeNewMFacilityNo($faclikity_details);
+ break;
+ case "T":
+ return $this->makeNewTFacilityNo($faclikity_details);
+ break;
+ case "B":
+ return $this->makeNewBFacilityNo($faclikity_details);
+ break;
+ default:
+ return "不存在的作番類型";
+ }
+ }
+
+ /**
+ * 建立作番 -- 新梯
+ */
+ function makeNewMFacilityNo($faclikity_details)
+ {
+ $Y = substr(date("Y"), 3, 1);
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+ $num = $faclikity_details['num'];
+ $next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1;
+ $new_facility_no_arr = [];
+
+ for ($i = 1; $i <= $num; $i++) {
+ $new_facility_no = $Y . $sale_type . $make_type[$i - 1]
+ . str_pad($next_seq, 5, "0", STR_PAD_LEFT);
+ array_push($new_facility_no_arr, $new_facility_no);
+ $next_seq++;
+ }
+
+ foreach ($new_facility_no_arr as $new_facility_no) {
+ if ($this->getMakeNewMFacilityNoStatus($faclikity_details) !== "1") {
+ return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details);
+ }
+ // seq +1
+ $this->facilitySeqAddOne("M");
+ }
+ return $new_facility_no_arr;
+ }
+
+ /**
+ * 建立作番 -- 汰改
+ */
+ function makeNewTFacilityNo($faclikity_details)
+ {
+
+ $Y = substr(date("Y"), 3, 1);
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+ $num = $faclikity_details['num'];
+ $next_seq = $this->getNextFacilitySeq("tf_vol_no");
+ $new_facility_no_arr = [];
+
+ for ($i = 1; $i <= $num; $i++) {
+ $new_facility_no = $Y . $sale_type . $make_type[$i - 1]
+ . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
+ . str_pad($i, 2, "0", STR_PAD_LEFT);
+ array_push($new_facility_no_arr, $new_facility_no);
+ }
+
+ foreach ($new_facility_no_arr as $new_facility_no) {
+ if ($this->getMakeNewTFacilityNoStatus($faclikity_details) !== "1") {
+ return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details);
+ }
+ // seq +1
+ $this->facilitySeqAddOne("T");
+ return $new_facility_no_arr;
+ }
+ }
+
+ /**
+ * 建立作番 -- 保養
+ */
+ function makeNewBFacilityNo($faclikity_details)
+ {
+
+ $Y = substr(date("Y"), 3, 1);
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+ $num = $faclikity_details['num'];
+ $next_seq = $this->getNextFacilitySeq("bf_vol_no");
+ $new_facility_no_arr = [];
+
+ for ($i = 1; $i <= $num; $i++) {
+ $new_facility_no = $Y . $sale_type . $make_type[$i - 1]
+ . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
+ . str_pad($i, 2, "0", STR_PAD_LEFT);
+ array_push($new_facility_no_arr, $new_facility_no);
+ }
+
+ foreach ($new_facility_no_arr as $new_facility_no) {
+ if ($this->getMakeNewBFacilityNoStatus($faclikity_details) !== "1") {
+ return $new_facility_no . ":" . $this->getMakeNewBFacilityNoStatus($faclikity_details);
+ }
+ // seq +1
+ $this->facilitySeqAddOne("B");
+ return $new_facility_no_arr;
+ }
+ }
+
+ /**
+ * 檢查作番編列狀態 - 新梯
+ * @param array $faclikity_details
+ * @return string $status : 1:正確 else:error message
+ */
+ function getMakeNewMFacilityNoStatus($faclikity_details)
+ {
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+
+ if ($this->checkSaleTypeStatus($sale_type) == false)
+ return "銷售代號錯誤";
+ if ($this->checkMakeTypeStatus($make_type) == false)
+ return "製造編號類型錯誤";
+ return "1";
+ }
+
+ /**
+ * 檢查作番編列狀態 - 汰改
+ * @param array $faclikity_details
+ * @return string $status : 1:正確 else:error message
+ */
+ function getMakeNewTFacilityNoStatus($faclikity_details)
+ {
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+
+ if ($this->checkSaleTypeStatus($sale_type) == false)
+ return "銷售代號錯誤";
+ if ($this->checkMakeTypeStatus($make_type) == false)
+ return "製造編號類型錯誤";
+ return "1";
+ }
+
+ /**
+ * 檢查作番編列狀態 - 保養
+ * @param array $faclikity_details
+ * @return string $status : 1:正確 else:error message
+ */
+ function getMakeNewBFacilityNoStatus($faclikity_details)
+ {
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+
+ if ($this->checkSaleTypeStatus($sale_type) == false)
+ return "銷售代號錯誤";
+ if ($this->checkMakeTypeStatus($make_type) == false)
+ return "製造編號類型錯誤";
+ return "1";
+ }
+
+ /**
+ * seq 取號
+ * @param string $type M:新梯 T:汰改 B:保養
+ */
+ function facilitySeqAddOne($type)
+ {
+ $type_arr = array(
+ "M" => "mf_vol_no",
+ "T" => "tf_vol_no",
+ "B" => "bf_vol_no",
+ );
+ if (!empty($type_arr[$type])) {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $sth = $pdo->prepare('UPDATE sequence SET current_val = current_val + 1 WHERE `seq_name` = ?');
+ $sth->bindValue(1, $type_arr[$type]);
+ $sth->execute();
+ }
+ }
+
+ /**
+ * 修正 seq 取號
+ * @param string $type M:新梯 T:汰改 B:保養
+ */
+ function facilityFixSeq($type)
+ {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $type_arr = array(
+ "M" => "mf_vol_no",
+ "T" => "tf_vol_no",
+ "B" => "bf_vol_no",
+ );
+ $after_fix_seq = $this->getMaxSeq($type);
+ $sql = "
+ UPDATE sequence
+ SET current_val = ?
+ WHERE seq_name = ?
+ ";
+ $sth = $pdo->prepare($sql);
+ $sth->bindValue(1, $after_fix_seq);
+ $sth->bindValue(2, $type_arr[$type]);
+ $sth->execute();
+ }
+
+ function getMaxSeq($type)
+ {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $Y = substr(date("Y"), 3, 1);
+ $seq_num = $type == 'M' ? 5 : 3;
+ $sql = "
+ SELECT MAX(SUBSTR(f.facilityno,4,?))+1 AS seq
+ FROM facility AS f
+ WHERE 1=1
+ AND SUBSTR(f.facilityno,1,1) = ?
+ AND f.define = ?
+ ORDER BY SUBSTR(f.facilityno,4,3) ASC
+ ";
+ $sth = $pdo->prepare($sql);
+ $sth->bindValue(1, $seq_num);
+ $sth->bindValue(2, $Y);
+ $sth->bindValue(3, $type);
+ $sth->execute();
+ $result = $sth->fetch();
+ return $result['seq'];
+ }
+
+ /**
+ * 檢查年月後 新梯及汰改seq歸零
+ */
+ function checkYearAndResetAllSeq()
+ {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?');
+ $sth->bindValue(1, 'mf_vol_no');
+ $sth->execute();
+ $result = $sth->fetch();
+ $yyyymm = $result['yyyymm'];
+ $dataY = substr($yyyymm, 0, 4);
+ $today_Y = date("Y");
+ $today_Ym = date("Ym");
+ if ($dataY != $today_Y) {
+ $sth = $pdo->prepare('UPDATE `sequence` SET `current_val` = ? , `yyyymm` = ? WHERE `seq_name` = ?');
+ $sth->bindValue(1, '0');
+ $sth->bindValue(2, $today_Ym);
+ $sth->bindValue(3, 'mf_vol_no');
+ $sth->execute();
+ }
+ }
+
+ /**
+ * 檢查作番在 facility table 中是否重複
+ * @param string|array $facility_no
+ * @return boolean $status : true:沒重複 false:重複
+ */
+ function checkFacilityRepeatStatus($facility_no)
+ {
+ if (gettype($facility_no) == "string") {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?');
+ $sth->bindValue(1, $facility_no);
+ $sth->execute();
+ if ($sth->rowCount() == 0)
+ return true;
+ return false;
+ }
+ if (gettype($facility_no) == "array") {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $status = true;
+ foreach ($facility_no as $row) {
+ $sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?');
+ $sth->bindValue(1, $row);
+ $sth->execute();
+ if ($sth->rowCount() !== 0)
+ $status = false;
+ }
+ return $status;
+ }
+ }
+
+ /**
+ * 檢查 $sale_type 是否有存在規則之中
+ * @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @return boolean $status : true:合法代碼 false:非法代碼
+ */
+ function checkSaleTypeStatus($sale_type)
+ {
+
+ if (!in_array($sale_type, ['M', 'E', 'T', 'J', 'X']))
+ return false;
+ return true;
+ }
+
+ /**
+ * 檢查 $sale_type 是否有存在規則之中
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @return boolean $status : true:合法代碼 false:非法代碼
+ */
+ function checkMakeTypeStatus($make_type)
+ {
+ foreach ($make_type as $row)
+ if (!in_array($row, ['X', 'W', 'H', 'Z', 'F', 'B', 'Q', 'T', 'N', 'W', 'J', 'Y']))
+ return false;
+ return true;
+ }
+
+ /**
+ * 檢查 取得下個作番的 seq
+ * @param string $seq_name : 新梯:mf_vol_no 汰改:tf_vol_no 保養:bf_vol_no
+ * @return int $seq : 作番流水號
+ */
+ function getNextFacilitySeq($seq_name)
+ {
+ $pdo = $this->connectionDB();
+ $pdo->exec('SET CHARACTER SET utf8mb4');
+ $sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?');
+ $sth->bindValue(1, $seq_name);
+ $sth->execute();
+ $result = $sth->fetch();
+ return $result['current_val'];
+ }
+
+ /**
+ * 建立新的新梯作番
+ * @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @param int $seq_name : 幾個案場 0-99
+ * @return array $new_facilityno : 作番號
+ */
+ function makeMFacilityNo($sale_type, $make_type, $num)
+ {
+ if (count($make_type) !== $num)
+ return "陣列數量不一致!";
+ $new_facility_no = $this->getNextFacilityNo("M", $sale_type, $make_type, $num);
+ if ($this->checkFacilityRepeatStatus($new_facility_no) == false) {
+ // 如果作番號重複 使用此函數修正
+ $this->facilityFixSeq("M");
+ }
+ return $this->makeFacilityNo("M", $sale_type, $make_type, $num);
+ }
+
+ /**
+ * 建立新的汰改作番
+ * @param array $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @param int $seq_name : 幾個案場 0-99
+ * @return array $new_facilityno : 作番號
+ */
+ function makeTFacilityNo($sale_type, $make_type, $num)
+ {
+ if (count($make_type) !== $num)
+ return "陣列數量不一致!";
+ $new_facility_no = $this->getNextFacilityNo("T", $sale_type, $make_type, $num);
+ if ($this->checkFacilityRepeatStatus($new_facility_no) == false) {
+ // 如果作番號重複 使用此函數修正
+ $this->facilityFixSeq("T");
+ }
+ return $this->makeFacilityNo("T", $sale_type, $make_type, $num);
+ }
+
+ /**
+ * 建立新的保養作番
+ * @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param array $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @param int $seq_name : 幾個案場 0-99
+ * @return array $new_facilityno : 作番號
+ */
+ function makeBFacilityNo($sale_type, $make_type, $num = 1)
+ {
+ if (count($make_type) !== $num)
+ return "陣列數量不一致!";
+ $new_facility_no = $this->getNextFacilityNo("B", $sale_type, $make_type, $num);
+ if ($this->checkFacilityRepeatStatus($new_facility_no) == false) {
+ // 如果作番號重複 使用此函數修正
+ $this->facilityFixSeq("B");
+ }
+ return $this->makeFacilityNo("B", $sale_type, $make_type, $num);
+ }
+}
+
+
+// $cfn = new CreateFacilityNo;
+// // 建立作番號 - 新梯
+// print_r($cfn->makeMFacilityNo("M", ["X", "W"], 2));
+// echo "
";
+// // 建立作番號 - 汰改
+// print_r($cfn->makeTFacilityNo("M", ["X", "W"], 2));
+// echo "
";
+// // 建立作番號 - 保養
+// print_r($cfn->makeBFacilityNo("M", ["X", "W"], 2));
+// echo "
";
diff --git a/wms/contract-repair/api/getPriceview.php b/wms/contract-repair/api/getPriceview.php
new file mode 100644
index 00000000..0d52f0a8
--- /dev/null
+++ b/wms/contract-repair/api/getPriceview.php
@@ -0,0 +1,16 @@
+prepare($sql_str);
+ $stmt->bindParam(':id',$id);
+ $stmt->execute();
+ $prices = $stmt->fetch(PDO::FETCH_ASSOC);
+ header("Content-Type: application/json");
+
+ echo json_encode(['prices'=> $prices]);
+
+}catch (PDOException $e ){
+ die("ERROR!!!: ". $e->getMessage());
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/postContractData.php b/wms/contract-repair/api/postContractData.php
new file mode 100644
index 00000000..69e7d859
--- /dev/null
+++ b/wms/contract-repair/api/postContractData.php
@@ -0,0 +1,319 @@
+ 0) {
+ header("HTTP/1.1 422 Unprocessable Entity");
+ echo json_encode($fail_arr);
+ exit();
+ }
+
+ //create account table
+ $accounttype = "A";
+ $accountid = $vat;
+ $pwd = "123";
+ $name = $partyA;
+ $tel = $phone ?? '';
+ $repairerid = $mworker;
+ $creater = $user_id;
+ $create_at = date('Y-m-d H:i:s');
+
+ $conn->beginTransaction();
+
+ $sql_str = "INSERT INTO account (accounttype, accountid, pwd, name, tel, address, email, repairerid, creater, create_at) VALUES (:accounttype, :accountid, :pwd, :name, :tel, :address, :email, :repairerid, :creater, :create_at)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':accounttype' ,$accounttype);
+ $stmt -> bindParam(':accountid' ,$accountid);
+ $stmt -> bindParam(':pwd' ,$pwd);
+ $stmt -> bindParam(':name' ,$name);
+ $stmt -> bindParam(':tel' ,$tel);
+ $stmt -> bindParam(':address' ,$address);
+ $stmt -> bindParam(':email' ,$email);
+ $stmt -> bindParam(':repairerid' ,$repairerid);
+ $stmt -> bindParam(':creater' ,$creater);
+ $stmt -> bindParam(':create_at' ,$create_at);
+ $stmt -> execute();
+
+ //create contract table
+
+ $contracttype = $mtype;
+ $company = $partyA;
+ $taxid = $vat;
+ $tel = $phone;
+ $promiser = $partyA;
+ $contractperson = $partyA;
+
+ $contractaddress = $address;
+ $contracttel = $phone;
+ $contractemail = $email;
+ $contract_employee = $salesman;
+ $start_date = $contract_begin_date;
+ $end_date = $contract_end_date;
+
+ $sql_str = "INSERT INTO contract (contracttype, contractno, company, taxid, address, tel, promiser, contractperson, contractaddress, contracttel, contractemail, contract_employee, start_date, end_date, creater, create_at) VALUES (:contracttype, :contractno, :company, :taxid, :address, :tel, :promiser, :contractperson, :contractaddress, :contracttel, :contractemail, :contract_employee, :start_date, :end_date, :creater, :create_at)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':contracttype' ,$contracttype);
+ $stmt -> bindParam(':contractno' ,$contractno);
+ $stmt -> bindParam(':company' ,$company);
+ $stmt -> bindParam(':taxid' ,$taxid);
+ $stmt -> bindParam(':address' ,$address);
+ $stmt -> bindParam(':tel' ,$tel);
+ $stmt -> bindParam(':promiser' ,$promiser);
+ $stmt -> bindParam(':contractperson' ,$contractperson);
+ $stmt -> bindParam(':contractaddress' ,$contractaddress);
+ $stmt -> bindParam(':contracttel' ,$contracttel);
+ $stmt -> bindParam(':contractemail' ,$contractemail);
+ $stmt -> bindParam(':contract_employee' ,$contract_employee);
+ $stmt -> bindParam(':start_date' ,$start_date);
+ $stmt -> bindParam(':end_date' ,$end_date);
+ $stmt -> bindParam(':creater' ,$creater);
+ $stmt -> bindParam(':create_at' ,$create_at);
+ $stmt -> execute();
+
+ //create facility table
+ $createFacilityNo = new CreateFacilityNo();
+ $dailyNecessities = [
+ 'MAE100'=>'X',
+ 'MAM200'=>'W',
+ 'MAH100'=>'H',
+ 'MAQ100'=>'Z',
+ 'MAF100'=>'F',
+ 'MAZ100'=>'B',
+ ];
+ $facility_arr = [];
+ foreach($elevators as $elevator){
+ $facility_arr[] = $dailyNecessities[$elevator['spec']];
+ }
+ echo json_encode($facility_arr);
+ $facilityno = $createFacilityNo->makeBFacilityNo("T", $facility_arr, (int)$num);
+ echo json_encode($facilityno);
+ echo '-------';
+ $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid";
+ $stmt = $conn->prepare($sql_str);
+ $stmt->bindParam(':accountid',$mworker);
+ $stmt->execute();
+ $worker = $stmt->fetch(PDO::FETCH_ASSOC);
+ $customerid = $vat;
+ $define = "B";
+ $repairtype = $mtype;
+ $repairerid = $mworker;
+ $repairername = $worker['name'];
+ foreach($elevators as $idx=>$elevator){
+ $sql_str = "INSERT INTO facility (contractno, define, facilityno, latitude, longitude, customerid, weight, numberofpassenger, numberofstop, numberoffloor, opentype, speed, repairtype, maintainance, facility_kind, address, repairerid, repairername, creater, create_at, area, takecertificatedate, licensedate)
+ VALUES (:contractno, :define, :facilityno, :latitude, :longitude, :customerid, :weight, :numberofpassenger, :numberofstop, :numberoffloor, :opentype, :speed, :repairtype, :maintainance, :facility_kind, :address, :repairerid, :repairername, :creater, :create_at, :area, :takecertificatedate, :licensedate)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':contractno' ,$contractno);
+ $stmt -> bindParam(':define' ,$define);
+ $stmt -> bindParam(':facilityno' ,$facilityno[$idx]);
+ $stmt -> bindParam(':latitude' ,$elevator['latitude']);
+ $stmt -> bindParam(':longitude' ,$elevator['longitude']);
+ $stmt -> bindParam(':customerid' ,$customerid);
+ $stmt -> bindParam(':weight' ,$elevator['weight']);
+ $stmt -> bindParam(':numberofpassenger' ,$elevator['persons']);
+ $stmt -> bindParam(':numberofstop' ,$elevator['stop']);
+ $stmt -> bindParam(':numberoffloor' ,$elevator['floors']);
+ $stmt -> bindParam(':opentype' ,$elevator['opendoor']);
+ $stmt -> bindParam(':speed' ,$elevator['speed']);
+ $stmt -> bindParam(':repairtype' ,$repairtype);
+ $stmt -> bindParam(':maintainance' ,$elevator['maintainance']);
+ $stmt -> bindParam(':facility_kind' ,$elevator['spec']);
+ $stmt -> bindParam(':address' ,$address);
+ $stmt -> bindParam(':repairerid' ,$repairerid);
+ $stmt -> bindParam(':repairername' ,$repairername);
+ $stmt -> bindParam(':creater' ,$creater);
+ $stmt -> bindParam(':create_at' ,$create_at);
+ $stmt -> bindParam(':area' ,$area);
+ $stmt -> bindParam(':takecertificatedate' ,$elevator['takecertificatedate']);
+ $stmt -> bindParam(':licensedate' ,$elevator['useful_date']);
+ $result = $stmt -> execute();
+ }
+
+ //create schedule table
+
+ $comboNo = new CreateComboNo($mcycle, $contract_begin_date, $contract_end_date);
+ $comboArr = json_decode($comboNo->getComboNo(), true);
+ foreach($facilityno as $no){
+ foreach($comboArr as $combo){
+ $sql_str = 'INSERT INTO schedule (contractno, facilityno, combono, repairerid, repairername, duedate, creater, create_at) VALUES (:contractno, :facilityno, :combono, :repairerid, :repairername, :duedate, :creater, :create_at)';
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':contractno' ,$contractno);
+ $stmt -> bindParam(':facilityno' ,$no);
+ $stmt -> bindParam(':combono' ,$combo[0]);
+ $stmt -> bindParam(':repairerid' ,$repairerid);
+ $stmt -> bindParam(':repairername' ,$repairername);
+ $stmt -> bindParam(':duedate' ,$combo[1]);
+ $stmt -> bindParam(':creater' ,$creater);
+ $stmt -> bindParam(':create_at' ,$create_at);
+ $result = $stmt -> execute();
+ }
+ }
+ // create contract_b_signed_back table
+ $contract_type = $mtype;
+ $company = $customer;
+ $customer_no = $vat;
+ $salesperson = $salesman;
+ $customer_phone = $phone;
+ $customer_email = $email;
+ $repairman = $mworker;
+ $cycle = $mcycle;
+ $contact_person = $partyA;
+ $contact_address = $partyAaddress;
+ $contact_phone = $partyAphone;
+ $contract_email = $partyAemail;
+ $elevators_number = $num;
+ $bonus = 1000;
+ $max_bonus = 2000;
+
+ if(!empty($files)){
+ $englisharr = range('a', 'z');
+ $file = $_FILES['files'];
+ $file_name = $file['name'];
+ $file_type = $file['type'];
+ $tmp_name = $file['tmp_name'];
+ $file_size = $file['size'];
+ $error = $file['error'];
+ $newfiles = [];
+ foreach( $files as $file ){
+ $i = 0; //新陣列的索引編號
+ foreach( $file as $key => $val ){
+ $newfiles[$i]['name'] = $files['name'][$key];
+ $newfiles[$i]['type'] = $files['type'][$key];
+ $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
+ $newfiles[$i]['error'] = $files['error'][$key];
+ $newfiles[$i]['size'] = $files['size'][$key];
+ $i++;
+ } //foreach 第2層 end
+ }
+ $max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M)
+ $allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型
+ $path = '../images/contracts/';
+ if (!file_exists($path)) { mkdir($path); }
+ $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
+ $datetime = (string)date('YmdHis');
+ $files_id = 'b' . $datetime; // 保養=>b + 日期時間
+ foreach( $newfiles as $key => $file ){
+ $randNum = rand(1000,9999);
+ $randEnglish = $englisharr[rand(0,25)];
+ $file_name = 'b' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name'];
+ $msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name );
+ if($msg==1){
+ $msg = '檔案傳送成功!';
+ $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':files_id' ,$files_id);
+ $stmt -> bindParam(':file_name' ,$file_name);
+ $stmt -> bindParam(':file_mime' ,$file['type']);
+ $stmt -> bindParam(':file_size' ,$file['size']);
+ $stmt -> bindParam(':created_at' ,$created_at);
+ $stmt -> bindParam(':created_by' ,$user_id);
+ $stmt ->execute();
+ }
+ $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
';
+ $src_name = $path.$file['name'];
+ if( file_exists($src_name) ){
+ //副檔名
+ $extname = pathinfo($src_name, PATHINFO_EXTENSION);
+ //主檔名
+ $basename = basename($src_name, '.'.$extname);
+ }
+
+ }
+ }else{
+ $files = null;
+ }
+ $sql_str = "INSERT INTO contract_b_signed_back (contract_no, contract_type, company, customer_no, salesperson, contract_start_date, contract_end_date, total_price, customer_phone, customer_email, repairman, cycle, contact_person, contact_address, contact_phone, contact_email, elevators_number, area, address, files_id, bonus, max_bonus, created_at, created_by)
+ VALUES (:contract_no, :contract_type, :company, :customer_no, :salesperson, :contract_start_date, :contract_end_date, :total_price, :customer_phone, :customer_email, :repairman, :cycle, :contact_person, :contact_address, :contact_phone, :contact_email, :elevators_number, :area, :address, :files_id, :bonus, :max_bonus, :created_at, :created_by)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(":contract_no",$contractno);
+ $stmt -> bindParam(":contract_type",$contract_type);
+ $stmt -> bindParam(":company",$company);
+ $stmt -> bindParam(":customer_no",$customer_no);
+ $stmt -> bindParam(":salesperson",$salesperson);
+ $stmt -> bindParam(":contract_start_date",$contract_begin_date);
+ $stmt -> bindParam(":contract_end_date",$contract_end_date);
+ $stmt -> bindParam(":total_price",$total_price);
+ $stmt -> bindParam(":customer_phone",$customer_phone);
+ $stmt -> bindParam(":customer_email",$customer_email);
+ $stmt -> bindParam(":repairman",$repairman);
+ $stmt -> bindParam(":cycle",$cycle);
+ $stmt -> bindParam(":contact_person",$contact_person);
+ $stmt -> bindParam(":contact_address",$contact_address);
+ $stmt -> bindParam(":contact_phone",$contact_phone);
+ $stmt -> bindParam(":contact_email",$contact_email);
+ $stmt -> bindParam(":elevators_number",$elevators_number);
+ $stmt -> bindParam(":area",$area);
+ $stmt -> bindParam(":address",$address);
+ $stmt -> bindParam(":files_id",$files_id);
+ $stmt -> bindParam(":bonus",$bonus);
+ $stmt -> bindParam(":max_bonus",$max_bonus);
+ $stmt -> bindParam(":created_at", $created_at);
+ $stmt -> bindParam(":created_by",$user_id);
+
+ $stmt -> execute();
+
+ header('Content-Type: application/json');
+ $jsonData = json_encode($files);
+
+ $conn->commit();
+ }catch(PDOException $e){
+ $conn->rollback();
+ echo $e->getMessage();
+ die('Error!:'.$e->getMessage());
+ }
+}
+
+
+
+
diff --git a/wms/contract-repair/api/postContractNewApplyData.php b/wms/contract-repair/api/postContractNewApplyData.php
new file mode 100644
index 00000000..f0032a78
--- /dev/null
+++ b/wms/contract-repair/api/postContractNewApplyData.php
@@ -0,0 +1,68 @@
+beginTransaction();
+ try{
+ if($isFirst == 1){
+ $sql_str = "INSERT INTO contract_new_apply (mid, contractno, sales_man, apply_date, apply_type, case_name, customer, manager, vat, total_price, buy_fee, install_fee, contact_address, workdeadline_a, workdeadline_b, test_time, freedeadline, trade_address, tradedeadline, progress, status, created_at, created_by) VALUES (:mid, :contractno, :sales_man, :apply_date, :apply_type, :case_name, :customer, :manager, :vat, :total_price, :buy_fee, :install_fee, :contact_address, :workdeadline_a, :workdeadline_b, :test_time, :freedeadline, :trade_address, :tradedeadline, :progress, :status, :created_at, :created_by)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt ->bindParam(':mid', $mid);
+ $stmt ->bindParam(':contractno', $vol_no);
+ $stmt ->bindParam(':sales_man', $salesman);
+ $stmt ->bindParam(':apply_date', $apply_date);
+ $stmt ->bindParam(':apply_type', $apply_type);
+ $stmt ->bindParam(':case_name', $case_name);
+ $stmt ->bindParam(':customer', $customer);
+ $stmt ->bindParam(':manager', $manager);
+ $stmt ->bindParam(':vat', $vat);
+ $stmt ->bindParam(':total_price', $total_price);
+ $stmt ->bindParam(':buy_fee', $buy_fee);
+ $stmt ->bindParam(':install_fee', $install_fee);
+ $stmt ->bindParam(':contact_address', $contact_address);
+ $stmt ->bindParam(':workdeadline_a', $workdeadline_a);
+ $stmt ->bindParam(':workdeadline_b', $workdeadline_b);
+ $stmt ->bindParam(':test_time', $test_time);
+ $stmt ->bindParam(':freedeadline', $freedeadline);
+ $stmt ->bindParam(':trade_address', $trade_address);
+ $stmt ->bindParam(':tradedeadline', $tradedeadline);
+ $stmt ->bindParam(':progress', $progress);
+ $stmt ->bindParam(':status', $status);
+ $stmt ->bindParam(':created_at', $created_at);
+ $stmt ->bindParam(':created_by', $created_by);
+ $stmt ->execute();
+ header("HTTP/1.1 201 success!");
+ $conn->commit();
+ }
+ }catch(PDOException $e){
+ $conn->rollback();
+ echo $e->getMessage();
+ die('Error!:'.$e->getMessage());
+ }
+
+
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/postNewContractData.php b/wms/contract-repair/api/postNewContractData.php
new file mode 100644
index 00000000..001fe1f5
--- /dev/null
+++ b/wms/contract-repair/api/postNewContractData.php
@@ -0,0 +1,139 @@
+ 0) {
+ header("HTTP/1.1 422 Unprocessable Entity");
+ echo json_encode($fail_arr);
+ exit();
+ }
+
+
+ $conn->beginTransaction();
+
+ $sql_str = "SELECT accountid, name FROM account WHERE accountid = :accountid ORDER BY create_at DESC";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(":accountid",$salesman);
+ $stmt -> execute();
+ $saleman = $stmt->fetch(PDO::FETCH_ASSOC);
+ $salesman_name = $saleman['name'];
+ if(!empty($files)){
+ $englisharr = range('a', 'z');
+ $files = $_FILES['files'];
+ $newfiles = [];
+ foreach( $files as $file ){
+ $i = 0; //新陣列的索引編號
+ foreach( $file as $key => $val ){
+ $newfiles[$i]['name'] = $files['name'][$key];
+ $newfiles[$i]['type'] = $files['type'][$key];
+ $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
+ $newfiles[$i]['error'] = $files['error'][$key];
+ $newfiles[$i]['size'] = $files['size'][$key];
+ $i++;
+ } //foreach 第2層 end
+ }
+ $max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M)
+ $allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型
+ $path = '../images/contracts/';
+ if (!file_exists($path)) { mkdir($path); }
+ $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
+ $datetime = (string)date('YmdHis');
+ $files_id = 'm' . $datetime; // 保養=>b + 日期時間
+ foreach( $newfiles as $key => $file ){
+ $randNum = rand(1000,9999);
+ $randEnglish = $englisharr[rand(0,25)];
+ $file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name'];
+ $msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name );
+ if($msg==1){
+ $msg = '檔案傳送成功!';
+ $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':files_id' ,$files_id);
+ $stmt -> bindParam(':file_name' ,$file_name);
+ $stmt -> bindParam(':file_mime' ,$file['type']);
+ $stmt -> bindParam(':file_size' ,$file['size']);
+ $stmt -> bindParam(':created_at' ,$created_at);
+ $stmt -> bindParam(':created_by' ,$created_by);
+ $stmt ->execute();
+ }else{
+ throw new PDOException('檔案上傳失敗:' . $msg);
+ }
+ $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
';
+ $src_name = $path.$file['name'];
+ if( file_exists($src_name) ){
+ //副檔名
+ $extname = pathinfo($src_name, PATHINFO_EXTENSION);
+ //主檔名
+ $basename = basename($src_name, '.'.$extname);
+ }
+ }
+ }else{
+ $files = null;
+ }
+
+ $sql_str = "INSERT INTO contract_m_signed_back (contract_no, customer, manager, vat, case_name, linkman, lm_tel, address, salesman, salesman_name, files_id, created_at, created_by, qc_official_type) VALUES (:contract_no, :customer, :manager, :vat, :case_name, :linkman, :lm_tel, :address, :salesman, :salesman_name, :files_id, :created_at, :created_by, :qc)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(":contract_no",$contractno);
+ $stmt -> bindParam(":customer",$customer);
+ $stmt -> bindParam(":manager",$manager);
+ $stmt -> bindParam(":vat",$vat);
+ $stmt -> bindParam(":case_name",$case_name);
+ $stmt -> bindParam(":linkman",$linkman);
+ $stmt -> bindParam(":lm_tel",$lm_tel);
+ $stmt -> bindParam(":address",$address);
+ $stmt -> bindParam(":salesman",$salesman);
+ $stmt -> bindParam(":salesman_name",$salesman_name);
+ $stmt -> bindParam(":files_id",$files_id);
+ $stmt -> bindParam(":created_at",$created_at);
+ $stmt -> bindParam(":created_by",$created_by);
+ $stmt -> bindParam(":qc",$qc);
+ $stmt -> execute();
+
+
+ $result = $conn->commit();
+ if($result){
+ header("HTTP/1.1 201 Created");
+ }
+
+ }catch(PDOException $e){
+ $conn->rollback();
+ header("HTTP/1.1 500 Internal Server Error");
+ die('Error!:'.$e->getMessage());
+ }
+ }
\ No newline at end of file
diff --git a/wms/contract-repair/api/putContractData.php b/wms/contract-repair/api/putContractData.php
new file mode 100644
index 00000000..f1e78164
--- /dev/null
+++ b/wms/contract-repair/api/putContractData.php
@@ -0,0 +1,135 @@
+ 0) {
+ header("HTTP/1.1 422 Unprocessable Entity");
+ echo json_encode($fail_arr);
+ exit();
+ }
+
+ $conn->beginTransaction();
+
+ $sql_str = "UPDATE contract_m_signed_back SET contract_no=:contract_no, customer=:customer, manager=:manager, vat=:vat, case_name=:case_name, linkman=:linkman, lm_tel=:lm_tel, address=:address, salesman=:salesman, qc_official_type=:qc WHERE id = :id";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':contract_no' ,$contract_no);
+ $stmt -> bindParam(':customer' ,$customer);
+ $stmt -> bindParam(':manager' ,$manager);
+ $stmt -> bindParam(':vat' ,$vat);
+ $stmt -> bindParam(':case_name' ,$case_name);
+ $stmt -> bindParam(':linkman' ,$linkman);
+ $stmt -> bindParam(':lm_tel' ,$lm_tel);
+ $stmt -> bindParam(':address' ,$address);
+ $stmt -> bindParam(':salesman' ,$salesman);
+ $stmt -> bindParam(':qc' ,$qc);
+ $stmt -> bindParam(':id' ,$id);
+ $stmt -> execute();
+ if(!empty($deletefiles)){
+ $sql_str = "DELETE FROM contract_back_files WHERE id IN ($deletefiles)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> execute();
+ }
+
+ if(!empty($files)){
+ $englisharr = range('a', 'z');
+ $files = $_FILES['files'];
+ $newfiles = [];
+ foreach( $files as $file ){
+ $i = 0; //新陣列的索引編號
+ foreach( $file as $key => $val ){
+ $newfiles[$i]['name'] = $files['name'][$key];
+ $newfiles[$i]['type'] = $files['type'][$key];
+ $newfiles[$i]['tmp_name'] = $files['tmp_name'][$key];
+ $newfiles[$i]['error'] = $files['error'][$key];
+ $newfiles[$i]['size'] = $files['size'][$key];
+ $i++;
+ } //foreach 第2層 end
+ }
+ $max_size = 4096*4096; //設定允許上傳檔案容量的最大值(1M)
+ $allow_ext = array('jpeg', 'jpg', 'png','JPG','JPEG','PNG','GIF'); //設定允許上傳檔案的類型
+ $path = '../images/contracts/';
+ if (!file_exists($path)) { mkdir($path); }
+ $msg_result = ''; //負責接收所有檔案檢測後的回傳訊息
+ $datetime = (string)date('YmdHis');
+ $files_id = ($files_id !== null ) ? $files_id : 'm' . $datetime; // 新梯=>m + 日期時間
+ foreach( $newfiles as $key => $file ){
+ $randNum = rand(1000,9999);
+ $randEnglish = $englisharr[rand(0,25)];
+ $file_name = 'm' . (string)date('YmdHis') . $randNum . $randEnglish . $randNum.$file['name'];
+ $msg = upload_chk( $file,$path, $max_size, $allow_ext, $file_name );
+ if($msg==1){
+ $msg = '檔案傳送成功!';
+ $sql_str = "INSERT INTO contract_back_files (files_id, file_name, file_mime, file_size, created_at, created_by) VALUES (:files_id, :file_name, :file_mime, :file_size, :created_at, :created_by)";
+ $stmt = $conn -> prepare($sql_str);
+ $stmt -> bindParam(':files_id' ,$files_id);
+ $stmt -> bindParam(':file_name' ,$file_name);
+ $stmt -> bindParam(':file_mime' ,$file['type']);
+ $stmt -> bindParam(':file_size' ,$file['size']);
+ $stmt -> bindParam(':created_at' ,$created_at);
+ $stmt -> bindParam(':created_by' ,$created_by);
+ $stmt ->execute();
+ }else{
+ throw new PDOException('檔案上傳失敗:' . $msg);
+ }
+ $msg_result .= '第' . ($key+1) . '個上傳檔案的結果:' . $msg . '
';
+ $src_name = $path.$file['name'];
+ if( file_exists($src_name) ){
+ //副檔名
+ $extname = pathinfo($src_name, PATHINFO_EXTENSION);
+ //主檔名
+ $basename = basename($src_name, '.'.$extname);
+ }
+ }
+ }else{
+ $files = null;
+ }
+
+ $conn->commit();
+ }catch(PDOException $e) {
+ $conn->rollback();
+ header("HTTP/1.1 500 Internal Server Error");
+ die('Error!:'.$e->getMessage());
+ }
+
+
+
+
+
+
+
+
+
+}
\ No newline at end of file
diff --git a/wms/contract-repair/api/store_contract.php b/wms/contract-repair/api/store_contract.php
new file mode 100644
index 00000000..e69de29b
diff --git a/wms/contract-repair/api/upload_chk.php b/wms/contract-repair/api/upload_chk.php
new file mode 100644
index 00000000..958cb6d5
--- /dev/null
+++ b/wms/contract-repair/api/upload_chk.php
@@ -0,0 +1,61 @@
+ $max_size ){
+ //當目前檔案容量超過容量限制時, 以下準備顯示的資訊
+ if( $max_size >= 4096*4096 ){
+ $max_size /= (4096*4096);
+ $max_size .= 'M';
+ }elseif( $max_size >= 4096 ){
+ $max_size /= 4096;
+ $max_size .= 'K';
+ }
+ $msg ='上傳檔案過大,請選擇容量小於 '.$max_size.' 的檔案';
+
+ //3.判斷檔案類型 ===========================================
+ //in_array($ext, $allow_ext) 判斷 $ext變數的值 是否在 $allow_ext 這個陣列變數中
+ }elseif( !in_array( $ext, $allow_ext ) ){
+ $allow_str = ''; //準備將允許檔案類型的陣列內容, 組合成字串
+ foreach( $allow_ext as $key=>$value ){
+ //if的縮寫語法:條件?成立執行的工作:不成立執行的工作;
+ $key==0? $allow_str.= $value : $allow_str.=', '.$value;
+ }
+ $msg = '檔案類型不符合,請選擇 '.$allow_str.' 檔案';
+
+ //4.以上條件都沒問題的話, 則進行最後else中的工作===============
+ }else{
+ //搬移檔案 move_uploaded_file(要搬移的檔案, 目的地位置及目的檔案名稱), 成功傳回true(1)
+ $msg = @move_uploaded_file($tmp_name, $path.$file_name);
+ }
+ }else{
+ //這裡表示上傳有錯誤, 匹配錯誤編號顯示對應的訊息 ======================================
+ switch ($error) {
+ case 1: $msg = '上傳檔案超過 upload_max_filesize 容量最大值'; break;
+ case 2: $msg = '上傳檔案超過 post_max_size 總容量最大值'; break;
+ case 3: $msg = '檔案只有部份被上傳'; break;
+ case 4: $msg = '沒有檔案被上傳'; break;
+ case 6: $msg = '找不到主機端暫存檔案的目錄位置'; break;
+ case 7: $msg = '檔案寫入失敗'; break;
+ case 8: $msg = '上傳檔案被PHP程式中斷,表示主機端系統錯誤'; break;
+ }
+ } //if( $error == 0 ){ ..... end
+
+ return $msg; //回傳$msg的結果
+ }
\ No newline at end of file
diff --git a/wms/contract-repair/conn.php b/wms/contract-repair/conn.php
new file mode 100644
index 00000000..b92e67e5
--- /dev/null
+++ b/wms/contract-repair/conn.php
@@ -0,0 +1,43 @@
+errorInfo()的形式獲取錯誤資訊
+ //PDO::ERRMODE_WARNING: 引發 E_WARNING 錯誤,主動報錯
+ //PDO::ERRMODE_EXCEPTION: 主動抛出 exceptions 異常,需要以try{}cath(){}輸出錯誤資訊。
+ //設定主動以警告的形式報錯
+ $conn->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
+ //如果連接錯誤,將抛出一個PDOException異常對象
+}
+catch ( PDOException $e ){
+ //如果連結資料庫失敗則顯示錯誤訊並停止本頁的工作
+ die("ERROR!!!: ". $e->getMessage());
+}
+
+//$conn = null; //關閉資料庫的連線
\ No newline at end of file
diff --git a/wms/contract-repair/contract-repair-input.php b/wms/contract-repair/contract-repair-input.php
new file mode 100644
index 00000000..09351a13
--- /dev/null
+++ b/wms/contract-repair/contract-repair-input.php
@@ -0,0 +1,351 @@
+prepare($sql_str);
+$stmt->bindParam(':accounttype',$accounttype);
+$stmt->execute();
+$workers = $stmt->fetchAll(PDO::FETCH_ASSOC);
+$accounttype = "M";
+$sql_str = "SELECT id,accountid, name FROM account WHERE accounttype = :accounttype";
+$stmt = $conn->prepare($sql_str);
+$stmt->bindParam(':accounttype',$accounttype);
+$stmt->execute();
+$contractpersons = $stmt->fetchAll(PDO::FETCH_ASSOC);
+?>
+
+
+
+
+
+
+
+ 合約入力(修理)+ |
+ |||||||
合約號 | ++ + + | ++ + | + +|||||
+ 業務確認項+ |
+ + + + | +||||||
立約人 | +
+
+ 未填寫 + |
+ 營業員 | +
+
+ 未填寫 + |
+ 合約開始時間 | +
+
+ 未填寫 + |
+ 合約終止時間 | +
+
+ 未填寫 + |
+
電梯台數 | +
+
+ 未填寫 +電梯數量需大於0 + |
+
+ 統一編號/身分證 | +
+
+ 未填寫 + |
+ 維修型態 | +
+
+ 未填寫 + |
+ + | + |
客戶電話 | +
+
+ 未填寫 + |
+
+
+ 未填寫 + |
+ 保養員 | +
+
+ 未填寫 + |
+ 保養頻率 | +
+
+ 未填寫 + |
+ |
業務聯繫人 | +
+
+ 未填寫 + |
+ 業務聯繫人地址 | +
+
+ 未填寫 + |
+ 業務聯繫人電話 | +
+
+ 未填寫 + |
+ 業務聯繫人Email | +
+
+ 未填寫 + |
+
區域 | +
+
+ 未填寫 + |
+ 詳細地址 | +
+
+ 未填寫 + |
+ 附件 | ++ + | +||
+ | |||||||
機種 | +
+
+ 未填寫 + |
+ 載重 | +
+
+ 未填寫 + |
+ 速度 | +
+
+ 未填寫 + |
+
+ 人乘 | +
+
+ 未填寫 + |
+
樓停 | +
+
+ 未填寫 + |
+ 樓層 | +
+
+ 未填寫 + |
+ 緯度 | +
+
+ 未填寫 + |
+
+ 經度 | +
+
+ 未填寫 + |
+
廠牌 | +
+
+ 未填寫 + |
+ + 開門方式 + | +
+
+ 未填寫 + |
+ 保養別 | +
+
+ 未填寫 + |
+ 竣檢日 | +
+
+ 未填寫 + |
+
許可證有效時間 | +
+
+ 未填寫 + |
+ ||||||
+ | + | + | + | + | + | + |