diff --git a/wms/createFacilityNo.php b/wms/contract/api/createFacilityNo.php
similarity index 97%
rename from wms/createFacilityNo.php
rename to wms/contract/api/createFacilityNo.php
index 931eaedf..4ae4adbb 100644
--- a/wms/createFacilityNo.php
+++ b/wms/contract/api/createFacilityNo.php
@@ -1,481 +1,481 @@
- 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=localhost;port=3306;dbname=appwms', 'masadaroot', 'x6h5E5p#u8y', $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 string $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
- . 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
- . 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
- . 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 string $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
- . 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
- . 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
- . 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("B");
- return $new_facility_no_arr;
- }
- }
-
- /**
- * 檢查作番編列狀態 - 新梯
- * @param array $faclikity_details
- * @return string $status : 1:正確 else:error message
- */
- function getMakeNewMFacilityNoStatus($faclikity_details)
- {
- $Y = substr(date("Y"), 3, 1);
- $sale_type = $faclikity_details['sale_type'];
- $make_type = $faclikity_details['make_type'];
- $next_seq = $this->getNextFacilitySeq("mf_vol_no");
- $new_facility_no = $Y . $sale_type . $make_type . str_pad($next_seq + 1, 5, "0", STR_PAD_LEFT);
-
- 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)
- {
- $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");
- $new_facility_no = $Y . $sale_type . $make_type
- . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
- . str_pad($num, 2, "0", STR_PAD_LEFT);
-
- 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 true;
- return false;
- }
-
- /**
- * 檢查 $sale_type 是否有存在規則之中
- * @param string $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
- * @return boolean $status : true:合法代碼 false:非法代碼
- */
- function checkMakeTypeStatus($make_type)
- {
- if (in_array($make_type, ['X', 'W', 'H', 'Z', 'F', 'B', 'Q', 'T', 'N', 'W', 'J', 'Y']))
- return true;
- return false;
- }
-
- /**
- * 檢查 取得下個作番的 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 string $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)
- {
- $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 string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
- * @param string $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)
- {
- $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 string $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)
- {
- $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", 5));
-echo "
";
-// 建立作番號 - 汰改
-print_r($cfn->makeTFacilityNo( "M", "X", 1));
-echo "
";
-// 建立作番號 - 保養
-print_r($cfn->makeBFacilityNo( "M", "X", 1));
+ 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=localhost;port=3306;dbname=appwms', 'masadaroot', 'x6h5E5p#u8y', $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 string $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
+ . 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
+ . 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
+ . 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 string $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
+ . 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
+ . 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
+ . 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("B");
+ return $new_facility_no_arr;
+ }
+ }
+
+ /**
+ * 檢查作番編列狀態 - 新梯
+ * @param array $faclikity_details
+ * @return string $status : 1:正確 else:error message
+ */
+ function getMakeNewMFacilityNoStatus($faclikity_details)
+ {
+ $Y = substr(date("Y"), 3, 1);
+ $sale_type = $faclikity_details['sale_type'];
+ $make_type = $faclikity_details['make_type'];
+ $next_seq = $this->getNextFacilitySeq("mf_vol_no");
+ $new_facility_no = $Y . $sale_type . $make_type . str_pad($next_seq + 1, 5, "0", STR_PAD_LEFT);
+
+ 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)
+ {
+ $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");
+ $new_facility_no = $Y . $sale_type . $make_type
+ . str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT)
+ . str_pad($num, 2, "0", STR_PAD_LEFT);
+
+ 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 true;
+ return false;
+ }
+
+ /**
+ * 檢查 $sale_type 是否有存在規則之中
+ * @param string $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正
+ * @return boolean $status : true:合法代碼 false:非法代碼
+ */
+ function checkMakeTypeStatus($make_type)
+ {
+ if (in_array($make_type, ['X', 'W', 'H', 'Z', 'F', 'B', 'Q', 'T', 'N', 'W', 'J', 'Y']))
+ return true;
+ return false;
+ }
+
+ /**
+ * 檢查 取得下個作番的 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 string $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)
+ {
+ $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 string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品
+ * @param string $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)
+ {
+ $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 string $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)
+ {
+ $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", 5));
+echo "
";
+// 建立作番號 - 汰改
+print_r($cfn->makeTFacilityNo( "M", "X", 1));
+echo "
";
+// 建立作番號 - 保養
+print_r($cfn->makeBFacilityNo( "M", "X", 1));
echo "
";
\ No newline at end of file
diff --git a/wms/fun_global.php b/wms/fun_global.php
index 9cf070b3..48f952b0 100644
--- a/wms/fun_global.php
+++ b/wms/fun_global.php
@@ -145,7 +145,7 @@ function check_user_permission($user_id, $token) {
global $link;
// 不檢查清單
- $ignore_url_arr = ['/wms/index.php', '/wms/notice-index.php', '/wms/notice-edit.php', '/wms/change-password.php', '/wms/wipwhole-change-contractdate.php','/wms/test.php'];
+ $ignore_url_arr = ['/wms/index.php', '/wms/notice-index.php', '/wms/notice-edit.php', '/wms/change-password.php', '/wms/wipwhole-change-contractdate.php', '/wms/wipwhole-change-planning-customer-name.php','/wms/test.php'];
if (in_array($_SERVER["SCRIPT_NAME"], $ignore_url_arr)) return;
$do = "";
diff --git a/wms/wipwhole-change-contractdate.php b/wms/wipwhole-change-contractdate.php
index 556b662c..96a42fe0 100644
--- a/wms/wipwhole-change-contractdate.php
+++ b/wms/wipwhole-change-contractdate.php
@@ -1,11 +1,34 @@
menu_v3($user_id, $accounttype);
+ $login_json = json_encode($jsonres, JSON_UNESCAPED_UNICODE);
+}
+
?>
作番大日程 id
+ * - 'all_contractno_change' => 是否更改全部合約號
+ * - 'real_contract_arrival_date' => 原日期
+ * - 'contract_arrival_date' => 新日期
+ * - 'real_address' => 原工地地址
+ * - 'old_real_address' => 新工地地址
+ * - 'contractno' => 合約號
+ * - 'tds' => 資料時間戳記
+ * - 'form_key' => 本表單 form_key
+ * - 'user_id' => 申請者 id (員工編號)
+ * - 'change_status' => 寫入簽核狀態代碼
+ *
+ * @param object $link: 資料庫連線
+ * @param string $data: 新增資料
+ */
+function addWipwholeChangeContractdateDetails($link, $data)
+{
+ $user_id = $data['user_id'];
+ $tds = $data['tds'];
+ $id = $data['id'];
+ $custom_name = $data['custom_name'];
+ $change_status = $data['change_status'];
+ $sql2 = "
+ INSERT INTO `wipwhole_change_planning_customer_details` (
+ `creater`,
+ `create_at`,
+ `wipwholestatus_id`,
+ `custom_name`,
+ `change_status`
+ ) VALUES (
+ '$user_id',
+ '$tds',
+ '$id',
+ '$custom_name',
+ '$change_status'
+ )
+ ";
+ mysqli_query($link, $sql2);
+}
+
+function addFlow($link, $data)
+{
+ $last_id = $data['last_id'];
+ $form_key = $data['form_key'];
+ $flow_code = $data['change_status'];
+ $sql2 = "
+ INSERT into flow (
+ system_id,
+ flow_id,
+ form_id,
+ form_key,
+ flow_code
+ ) VALUES (
+ 'wws',
+ 'wws04',
+ '$last_id',
+ '$form_key',
+ '$flow_code'
+ )
+ ";
+ mysqli_query($link, $sql2);
+}
+
+function addSubflow($link, $data)
+{
+ $form_key = $data['form_key'];
+ $current_assigner = $data['current_assigner'];
+ $tds = $data['tds'];
+ $seq = $data['seq'];
+ $sql2 = "
+ INSERT INTO subflow (
+ form_key,
+ seq,
+ current_assigner,
+ create_date
+ ) values (
+ '$form_key',
+ '$seq',
+ '$current_assigner',
+ '$tds'
+ )
+ ";
+ mysqli_query($link, $sql2);
+}
+
+/**
+ * 用大日程的合約號取得大日程表單唯一值 (id)
+ * @param object $link:資料庫連線
+ * @param string $contractno:合約編號
+ * @return object 回傳 mysqli_fetch_all
+ */
+function getWipwholestatusIdByConstractNo($link, $contractno)
+{
+ $sql = "
+ SELECT
+ id
+ FROM wipwholestatus
+ WHERE contractno = '$contractno'
+ ";
+ $result = mysqli_query($link, $sql);
+ $data = mysqli_fetch_all($result);
+ mysqli_free_result($result);
+ return $data;
+}
+
+/**
+ * 取得新申請簽核的 formk_key 用於新增
+ * @param object $link 資料庫連線
+ * @return string $formk_key
+ */
+function getFomkeySeq($link)
+{
+ $sql = "SELECT appwms.nextval('form_key') form_key";
+ $res = mysqli_query($link, $sql);
+ if ($row = mysqli_fetch_row($res))
+ return $row[0];
+ return null;
+}
+
+/**
+ * 新增通知
+ * @param object $link 資料庫連線
+ * @param array $data kind:通知類型 related_id:關聯序號 title:通知標題 content:通知內容 permission:觀看者 creater:建立者 create_at:建立時間
+ * @return string 簽核單 cid
+ */
+function addNotice($link, $data)
+{
+ $kind = empty($data['kind']) ? "1" : $data['kind'];
+ $related_id = empty($data['related_id']) ? "" : $data['related_id'];
+ $title = empty($data['title']) ? "" : $data['title'];
+ $content = empty($data['content']) ? "" : $data['content'];
+ $permission = empty($data['permission']) ? "" : $data['permission'];
+ $creater = empty($data['creater']) ? "system" : $data['creater'];
+ $create_at = empty($data['create_at']) ? date("Y-m-d H:i:s") : $data['create_at'];
+
+ $sql = "
+ INSERT INTO notice (
+ kind,
+ related_id,
+ title,
+ content,
+ permission,
+ creater,
+ create_at
+ ) VALUES(
+ '$kind',
+ '$related_id',
+ '$title',
+ '$content',
+ '$permission',
+ '$creater',
+ '$create_at'
+ )
+ ";
+ mysqli_query($link, $sql);
+}
+
+/**
+ * 取得本次簽核的表單 cid 值
+ * @param object $link 資料庫連線
+ * @param string $form_key 簽核單唯一值
+ * @return string 簽核單 cid
+ */
+function getCid($link, $form_key)
+{
+ $sql = "
+ SELECT form_id AS id FROM flow
+ WHERE form_key = '$form_key'
+ ";
+ $result = mysqli_query($link, $sql);
+ $row = mysqli_fetch_array($result);
+ return $row['id'];
+}
+
+/**
+ * 取得此單據的大日程id值
+ * @param object $link 資料庫連線
+ * @param string $cid 簽核單 cid
+ * @return string 簽核單 form_key
+ */
+function getId($link, $cid)
+{
+ $sql = "
+ SELECT wipwholestatus_id AS id
+ FROM wipwhole_change_planning_customer_details
+ WHERE id = '$cid'
+ ";
+ $result = mysqli_query($link, $sql);
+ $row = mysqli_fetch_array($result);
+ return $row['id'];
+}
+
+/**
+ * 取得本次簽核的表單form_key值
+ * @param object $link 資料庫連線
+ * @param string $form_id 簽核單 cid
+ * @return string 簽核單 form_key
+ */
+function getForm_key($link, $form_id)
+{
+ $sql = "
+ SELECT
+ f.form_key
+ FROM flow AS f
+ LEFT JOIN subflow AS s
+ ON f.form_key = s.form_key
+ WHERE 1=1
+ AND f.system_id = 'wws'
+ AND f.flow_id = 'wws04'
+ AND f.form_id = '$form_id'
+ AND f.flow_code IN ('A','B','D','C','Z')
+ ";
+ $result = mysqli_query($link, $sql);
+ $row = mysqli_fetch_array($result);
+ return empty($row['form_key']) ? null : $row['form_key'];
+}
+
+/**
+ * 確認目前簽核狀態
+ * @param object $link 資料庫連線
+ * @return string 工務部主管accountid
+ */
+function checkNowFormStatus($link)
+{
+ if (isset($_GET['cid']) || isset($_GET['form_key'])) {
+ $cid = isset($_GET['cid']) ? $_GET['cid'] : getCid($link, $_GET['form_key']);
+ $form_key = getForm_key($link, $cid);
+ $sql = "
+ SELECT
+ flow_code
+ FROM flow
+ WHERE 1=1
+ AND form_id = '$cid'
+ AND form_key = '$form_key'
+ ";
+ $result = mysqli_query($link, $sql);
+ $row = mysqli_fetch_array($result);
+ return empty($row['0']) ? null : $row['0'];
+ }
+ return null;
+}
+
+/**
+ * 取得工務部主管編號
+ * @param object $link 資料庫連線
+ * @param string $contract_type A:新梯 B:汰改
+ * @return string 工務部主管accountid
+ */
+function getGongWuokNo($link, $contract_type)
+{
+ if (isset($_GET['id']) || isset($_GET['form_key']))
+ $id = isset($_GET['id']) ? $_GET['id'] : getId($link, getCid($link, $_GET['form_key']));
+ $sql = "
+ SELECT DISTINCT
+ SUBSTR(address,1,2)
+ FROM `wipwholestatus`
+ WHERE id = '$id'
+ ";
+ $result = mysqli_query($link, $sql);
+ $row = mysqli_fetch_array($result);
+ // 新梯
+ // 宜蘭=高培軒(M0087) 北=張潘榮(M0041) 中=林瑋隆(M0113) 南=韋宗榮(M0039)改鄭存邑(M0102)
+ // 汰改
+ // 宜蘭=高培軒(M0087) 北=吳宗紘(M0040) 中=林瑋隆(M0113) 南=韋宗榮(M0039)改鄭存邑(M0102)
+ $arr = array(
+ "宜蘭" => "M0087",
+ "北" => "M0041",
+ "台北" => "M0041",
+ "基隆" => "M0041",
+ "新北" => "M0041",
+ "新竹" => "M0041",
+ "桃園" => "M0041",
+ "苗栗" => "M0113",
+ "中" => "M0113",
+ "南投" => "M0113",
+ "台中" => "M0113",
+ "彰化" => "M0113",
+ "雲林" => "M0113",
+ "南" => "M0102",
+ "台南" => "M0102",
+ "嘉義" => "M0102",
+ "屏東" => "M0102",
+ "高雄" => "M0102"
+ );
+ $arr2 = array(
+ "宜蘭" => "M0087",
+ "北" => "M0040",
+ "台北" => "M0040",
+ "基隆" => "M0040",
+ "新北" => "M0040",
+ "新竹" => "M0040",
+ "桃園" => "M0040",
+ "苗栗" => "M0113",
+ "中" => "M0113",
+ "南投" => "M0113",
+ "台中" => "M0113",
+ "彰化" => "M0113",
+ "雲林" => "M0113",
+ "南" => "M0102",
+ "台南" => "M0102",
+ "嘉義" => "M0102",
+ "屏東" => "M0102",
+ "高雄" => "M0102"
+ );
+ if ($contract_type == 'A') {
+ return empty($arr[$row[0]]) ? "" : $arr[$row[0]];
+ } else {
+ return empty($arr2[$row[0]]) ? "" : $arr2[$row[0]];
+ }
+}
+
+/**
+ * 取得簽核者 user_id
+ * @param object $link 資料庫連線
+ * @param string $form_key 本簽核單唯一值
+ * @param string $seq 簽核者順序
+ * @return string 簽核者accountid
+ */
+function getCurrentAssigner($link, $form_key, $seq)
+{
+ $sql = "
+ SELECT
+ *
+ FROM subflow
+ WHERE form_key = '$form_key'
+ AND seq = '$seq'
+ ";
+ $subflow_data = mysqli_query($link, $sql);
+ $subflow = mysqli_fetch_array($subflow_data, MYSQLI_ASSOC);
+ return empty($subflow['current_assigner']) ? null : $subflow['current_assigner'];
+}
+
+/**
+ * 取得本表單狀態代碼
+ * @param object $link 資料庫連線
+ * @param string $cid 本簽核單 id
+ * @return string 表單狀態代碼
+ */
+function getChangeStatus($link, $cid)
+{
+ $sql = "
+ SELECT
+ change_status
+ FROM wipwhole_change_planning_customer_details
+ WHERE id = '$cid'
+ ";
+ $subflow_data = mysqli_query($link, $sql);
+ $subflow = mysqli_fetch_array($subflow_data, MYSQLI_ASSOC);
+ return empty($subflow['change_status']) ? null : $subflow['change_status'];
+}
+
+/**
+ * 取得本表單狀態名稱
+ * @param object $link 資料庫連線
+ * @param string $cid 本簽核單 id
+ * @return string 本單據狀態名稱
+ */
+function getChangeStatusName($link, $cid)
+{
+ $dataArr = array(
+ 'A' => '申請中',
+ 'B' => '申請中',
+ 'C' => '已取消',
+ 'D' => '工務已通過',
+ 'Z' => '已通過',
+ );
+ $sql = "
+ SELECT
+ change_status
+ FROM wipwhole_change_planning_customer_details
+ WHERE id = '$cid'
+ ";
+ $subflow_data = mysqli_query($link, $sql);
+ $subflow = mysqli_fetch_array($subflow_data, MYSQLI_ASSOC);
+ return empty($subflow['change_status']) ? "" : $dataArr[$subflow['change_status']];
+}
+
+function getNowFormStatus($link, $cid)
+{
+ $sql = "
+ SELECT
+ change_status
+ FROM wipwhole_change_planning_customer_details
+ WHERE id = '$cid'
+ ";
+ $subflow_data = mysqli_query($link, $sql);
+ $subflow = mysqli_fetch_array($subflow_data, MYSQLI_ASSOC);
+ return empty($subflow['change_status']) ? "" : $subflow['change_status'];
+}
+
+/**
+ * 取得許MAX options
+ * @param object $link:資料庫連線
+ * @return object 回傳 mysqli_query
+ */
+function getShengguanokOptions($link)
+{
+ $sql = "
+ SELECT
+ accountid AS val ,
+ name AS label
+ FROM `account`
+ WHERE `department_id` IN ('320')
+ AND `role_id` IN ('1')
+ ";
+ return mysqli_query($link, $sql);
+}
+
+/**
+ * 取得工務部門所有員工 options
+ * @param object $link:資料庫連線
+ * @return object 回傳 mysqli_query
+ */
+function getGongwuokOptions($link, $user_id)
+{
+ $sql = "
+ SELECT
+ a1.manager AS val ,
+ a2.name AS label
+ FROM account AS a1
+ LEFT JOIN account AS a2
+ ON a1.manager = a2.accountid
+ WHERE a1.accountid = '$user_id'
+ ";
+ return mysqli_query($link, $sql);
+}
+
+/**
+ * 用 user_id(員工編號) 取得部門代碼 id
+ * @param object $link:資料庫連線
+ * @param string $user_id:使用者 id (員工編號)
+ * @return string 回傳 $department_id:部門代碼
+ */
+function getDepartmentId($link, $user_id)
+{
+ $sql = "
+ SELECT
+ department_id
+ FROM account
+ WHERE accountid = '$user_id'
+ ";
+ $res = mysqli_query($link, $sql);
+ $row = mysqli_fetch_row($res);
+ mysqli_free_result($res);
+ return $row[0];
+}
+function getRoleId($link, $user_id)
+{
+ $sql = "
+ SELECT
+ role_id
+ FROM account
+ WHERE accountid = '$user_id'
+ ";
+ $res = mysqli_query($link, $sql);
+ $row = mysqli_fetch_row($res);
+ mysqli_free_result($res);
+ return $row[0];
+}
+/**
+ * 取得生管主管 options
+ * @param object $link:資料庫連線
+ * @param string $id:作番大日程唯一值
+ * @return object 回傳 mysqli_query
+ */
+function getWipwholestatusDetail($link, $id)
+{
+ $db_query = "
+ SELECT * FROM
+ wipwholestatus WHERE id = '$id'
+ ";
+ $receivabledata = mysqli_query($link, $db_query);
+ return mysqli_fetch_array($receivabledata, MYSQLI_ASSOC);
+}
+
+/**
+ * 取得 wipwhole_change_planning_customer_details 所有資料並放入陣列
+ * @param object $link:資料庫連線
+ * @param string $cid:表單唯一值
+ * @return object 回傳 mysqli_fetch_array
+ */
+function getWipwholeChangeContractdateDetails($link, $cid)
+{
+ $db_query = "
+ SELECT * FROM wipwhole_change_planning_customer_details
+ WHERE id = '$cid'
+ ";
+ $receivabledata = mysqli_query($link, $db_query);
+ return mysqli_fetch_array($receivabledata, MYSQLI_ASSOC);
+}
+
+/**
+ * 取得生管主管 options
+ * @param object $link:資料庫連線
+ * @param string $user_id:使用者 id (員工編號)
+ * @param string $id:大日程唯一值
+ * @return object 回傳 mysqli_query
+ */
+function getDateOptions($link, $user_id, $id)
+{
+ if ($user_id == 'M0060') {
+ $sql = "
+ SELECT
+ *
+ FROM `wipwhole_change_planning_customer_details`
+ WHERE 1=1
+ AND wipwholestatus_id = '$id'
+ AND change_status in ('A','C','D','Z')
+ ";
+ } else if (isLeader($link, $user_id)) {
+ $sql = "
+ SELECT
+ *
+ FROM `wipwhole_change_planning_customer_details`
+ WHERE 1=1
+ AND wipwholestatus_id = '$id'
+ ";
+ } else {
+ $sql = "
+ SELECT
+ *
+ FROM `wipwhole_change_planning_customer_details`
+ WHERE 1=1
+ AND creater = '$user_id'
+ AND wipwholestatus_id = '$id'
+ ";
+ }
+ return mysqli_query($link, $sql);
+}
+
+/**
+ * 取得提交表單後的回傳訊息
+ * @param string $assign_status:簽核狀態代碼
+ * @return string 回傳訊息
+ */
+function getAssignStatusMessage($data, $checkStatus)
+{
+
+ if ($data['assign_status'] == 'A' || $data['assign_status'] == 'B')
+ if (empty($_POST['custom_name']))
+ return "
請填寫 客戶姓名 !
"; + if ($data['assign_status'] == 'C') + return "申請已取消
"; + if ($data['assign_status'] == 'Z') + return "申請已通過
"; + if (!$checkStatus) + return "請勿重複申請!
"; + return "已提交申請!
"; +} + +/** + * 依照此表單狀態給予 select 選項 + * @param object $link:資料庫連線檔 + * @param string $user_id:使用者id (員工編號) + * @param string $nowFormStatus:此表單目前狀態代碼 + * @return string 回傳select字串 + */ +function getAssignStatusSelect($link, $user_id, $nowFormStatus) +{ + $options_str = ""; + return $options_str; +} + +/** + * 取得此簽核單所有人簽核狀況 + * @param object $link:資料庫連線檔 + * @param string $form_key:此簽核單唯一值 + * @return object 回傳 mysqli_query + */ +function getCurrentAssigners($link, $form_key) +{ + $sql = " + SELECT + nowData.*, + nextData.next_current_assigner + FROM( + SELECT + f.flow_code, + s.seq, + (s.seq + 1) AS next_seq , + s.current_assigner, + wccd.change_status + FROM + flow AS f + LEFT JOIN subflow AS s ON f.form_key = s.form_key + LEFT JOIN wipwhole_change_planning_customer_details AS wccd ON wccd.id = f.form_id + WHERE + f.form_key = '$form_key' + AND f.system_id = 'wws' + AND f.flow_id = 'wws04' + ) AS nowData + LEFT JOIN( + SELECT + s.seq, + s.current_assigner AS next_current_assigner + FROM + flow AS f + LEFT JOIN subflow AS s ON f.form_key = s.form_key + LEFT JOIN wipwhole_change_planning_customer_details AS wccd ON wccd.id = f.form_id + WHERE + f.form_key = '$form_key' + AND f.system_id = 'wws' + AND f.flow_id = 'wws04' + ) AS nextData + ON nowData.next_seq = nextData.seq + "; + return mysqli_query($link, $sql); +} + +function checkStatus($link, $cid, $user_id) +{ + $sql = " + SELECT + change_status + FROM wipwhole_change_planning_customer_details + WHERE creater = '$user_id' + AND wipwholestatus_id = '$cid' + AND change_status NOT IN ('C','Z') + "; + $res = mysqli_query($link, $sql); + return $res->num_rows > 0 ? false : true; +} diff --git a/wms/wipwhole-change-planning-customer-name-submit.php b/wms/wipwhole-change-planning-customer-name-submit.php new file mode 100644 index 00000000..29572e94 --- /dev/null +++ b/wms/wipwhole-change-planning-customer-name-submit.php @@ -0,0 +1,273 @@ + $id, + 'all_contractno_change' => $all_contractno_change, + 'custom_name' => $custom_name, + 'contractno' => $contractno, + 'tds' => $tds, + 'form_key' => getFomkeySeq($link), + 'user_id' => $user_id, + 'change_status' => $_POST['assign_status'] + ); + // 寫入表單主檔 + addWipwholeChangeContractdateDetails($link, $data_arr); + // 取得寫入後表單seq + $data_arr['last_id'] = $link->insert_id; + // 寫入待簽 + addFlow($link, $data_arr); + $data_arr['seq'] = '0'; + $data_arr['current_assigner'] = $user_id; + addSubflow($link, $data_arr); + $data_arr['seq'] = '1'; + $data_arr['current_assigner'] = $next_users; + addSubflow($link, $data_arr); + } + + // 批次申請 + if (($_POST['assign_status'] == 'A' || $_POST['assign_status'] == 'B') && !empty($all_contractno_change)) { + $wipwholestatus_id_arr = getWipwholestatusIdByConstractNo($link, $contractno); + foreach ($wipwholestatus_id_arr as $wipwholestatus_id) { + $data_arr = array( + 'id' => $wipwholestatus_id[0], + 'all_contractno_change' => $all_contractno_change, + 'custom_name' => $custom_name, + 'contractno' => $contractno, + 'tds' => $tds, + 'form_key' => getFomkeySeq($link), + 'user_id' => $user_id + ); + // 寫入表單主檔 + addWipwholeChangeContractdateDetails($link, $data_arr); + // 取得寫入後表單seq + $data_arr['last_id'] = $link->insert_id; + // 寫入待簽 + addFlow($link, $data_arr); + $data_arr['seq'] = '0'; + $data_arr['current_assigner'] = $user_id; + addSubflow($link, $data_arr); + $data_arr['seq'] = '1'; + $data_arr['current_assigner'] = $next_users; + addSubflow($link, $data_arr); + } + } + } + } + + // 單次申請 營業 + if ($_POST['assign_status'] == 'D') { + $tds = date("Y-m-d H:i:s"); + $next_users = $_POST['next_users']; + $seq = $_POST['seq']; + $sql = " + UPDATE wipwhole_change_planning_customer_details + SET change_status = 'D' + WHERE id = '$cid' + "; + mysqli_query($link, $sql); + $sql = " + UPDATE flow + SET flow_code = 'D' + WHERE form_key = '$form_key' + "; + mysqli_query($link, $sql); + $sql = " + INSERT into subflow ( + form_key, + seq, + current_assigner, + create_date + ) VALUES ( + '$form_key', + '2', + '$next_users', + '$tds' + ) + "; + mysqli_query($link, $sql); + } + // 取消 + if ($_POST['assign_status'] == 'C') { + $tds = date("Y-m-d H:i:s"); + $next_users = "00000"; + if ($user_id == 'M0060') { + if (getChangeStatus($link, $cid) == 'D' || getChangeStatus($link, $cid) == 'A') { + $seq = $_POST['seq']; + } + $sql = " + INSERT into subflow ( + form_key, + seq, + current_assigner, + create_date + ) VALUES ( + '$form_key', + '$seq', + '$next_users', + '$tds' + ) + "; + mysqli_query($link, $sql); + } else if (isLeader($link, $user_id)) { + if (getChangeStatus($link, $cid) == 'D') { + $sql = " + UPDATE subflow + SET current_assigner = '$next_users', + create_date = '$tds' + WHERE form_key = '$form_key' + AND seq = '$seq' + "; + mysqli_query($link, $sql); + } else if (getChangeStatus($link, $cid) == 'A') { + $seq = $_POST['seq']; + $sql = " + UPDATE subflow + SET current_assigner = '$next_users', + create_date = '$tds' + WHERE form_key = '$form_key' + AND seq = '$seq' + "; + mysqli_query($link, $sql); + } else { + $seq = $_POST['seq']; + $sql = " + INSERT into subflow ( + form_key, + seq, + current_assigner, + create_date + ) VALUES ( + '$form_key', + '$seq', + '$next_users', + '$tds' + ) + "; + mysqli_query($link, $sql); + } + } else { + $seq = $_POST['seq']; + $sql = " + UPDATE subflow + SET current_assigner = '$next_users', + create_date = '$tds' + WHERE form_key = '$form_key' + AND seq = '$seq' + "; + mysqli_query($link, $sql); + } + $sql = " + UPDATE wipwhole_change_planning_customer_details + SET change_status = 'C' + WHERE id = '$cid' + "; + mysqli_query($link, $sql); + $sql = " + UPDATE flow + SET flow_code = 'Z' + WHERE form_key = '$form_key' + "; + mysqli_query($link, $sql); + } + + // 通過 + if ($_POST['assign_status'] == 'Z') { + if ($user_id == 'M0060') { + $tds = date("Y-m-d H:i:s"); + $next_users = $_POST['next_users']; + $seq = $_POST['seq'] + 1; + $sql = " + UPDATE wipwhole_change_planning_customer_details + SET change_status = 'Z' + WHERE id = '$cid' + "; + mysqli_query($link, $sql); + $sql = " + UPDATE flow + SET flow_code = 'Z' + WHERE form_key = '$form_key' + "; + mysqli_query($link, $sql); + $sql = " + INSERT into subflow ( + form_key, + seq, + current_assigner, + create_date + ) VALUES ( + '$form_key', + '$seq', + '$next_users', + '$tds' + ) + "; + mysqli_query($link, $sql); + +// // 發送系統通知 +// $contractno = $_POST['contractno']; +// $facilityno = $_POST['facilityno']; +// $real_contract_arrival_date = $_POST['real_contract_arrival_date']; +// $salesid = $_POST['salesid']; +// $gongWuokid = $_POST['gongWuokid']; +// $old_real_address = $_POST['old_real_address']; +// $real_address = $_POST['real_address']; +// $content = "合約號 : $contractno +// 作番號 : $facilityno +// 出貨日期微調: " . substr($real_contract_arrival_date, 0, 10) . " => " . substr($contract_arrival_date_tmp, 0, 10) . " +// 工地地址微調: " . $old_real_address . " => " . $real_address_tmp; + +// // 大日程出貨日調整 通知營業人員 +// $noticeData = array( +// 'related_id' => $cid, +// 'title' => '作番大日程(新梯)出貨日調整通知 > ' . $facilityno, +// 'content' => $content, +// 'permission' => $salesid, +// ); +// addNotice($link, $noticeData); +// // 大日程出貨日調整 通知工務人員 +// $noticeData = array( +// 'related_id' => $cid, +// 'title' => '作番大日程(新梯)出貨日調整通知 > ' . $facilityno, +// 'content' => $content, +// 'permission' => $gongWuokid, +// ); +// addNotice($link, $noticeData); + +// $shengguano_arr = getShengguanokOptions($link); +// foreach ($shengguano_arr as $row) : +// $contractno = $_POST['contractno']; +// $facilityno = $_POST['facilityno']; +// $real_contract_arrival_date = $_POST['real_contract_arrival_date']; +// $gongWuokid = $_POST['gongWuokid']; +// $old_real_address = $_POST['old_real_address']; +// $real_address = $_POST['real_address']; +// $content = "合約號 : $contractno +// 作番號 : $facilityno +// 出貨日期微調: " . substr($real_contract_arrival_date, 0, 10) . " => " . substr($contract_arrival_date_tmp, 0, 10) . " +// 工地地址微調: " . $old_real_address . " => " . $real_address_tmp; + +// // 大日程出貨日調整 通知營業人員 +// $noticeData = array( +// 'related_id' => $cid, +// 'title' => '作番大日程(新梯)出貨日調整通知 > ' . $facilityno, +// 'content' => $content, +// 'permission' => $row['val'], +// ); +// addNotice($link, $noticeData); +// endforeach; + } + } +} diff --git a/wms/wipwhole-change-planning-customer-name.php b/wms/wipwhole-change-planning-customer-name.php new file mode 100644 index 00000000..0742c977 --- /dev/null +++ b/wms/wipwhole-change-planning-customer-name.php @@ -0,0 +1,503 @@ +menu_v3($user_id, $accounttype); + $login_json = json_encode($jsonres, JSON_UNESCAPED_UNICODE); +} + +?> + + options +$max_options = getShengguanokOptions($link); +$self_leader_options = getGongwuokOptions($link, $user_id); + +// 帶入大日程資料 +$row = getWipwholestatusDetail($link, $id); +// 帶入所有人歷史單據 +$date_options = getDateOptions($link, $user_id, $id); +// 檢查此單據狀態非新申請則帶入申請資料 +if (!empty(checkNowFormStatus($link))) + $row2 = getWipwholeChangeContractdateDetails($link, $cid); + +?> + +