1 changed files with 480 additions and 480 deletions
@ -1,481 +1,481 @@ |
|||||
<?php |
<?php |
||||
ini_set('display_errors', 'on'); |
ini_set('display_errors', 'on'); |
||||
|
|
||||
// 汰改 前三碼 流水號 + 後兩碼 號機 |
// 汰改 前三碼 流水號 + 後兩碼 號機 |
||||
// 新梯 流水號 |
// 新梯 流水號 |
||||
|
|
||||
class CreateFacilityNo |
class CreateFacilityNo |
||||
{ |
{ |
||||
/** |
/** |
||||
* 連接資料庫 |
* 連接資料庫 |
||||
*/ |
*/ |
||||
function connectionDB() |
function connectionDB() |
||||
{ |
{ |
||||
try { |
try { |
||||
$options = [ |
$options = [ |
||||
PDO::ATTR_PERSISTENT => false, |
PDO::ATTR_PERSISTENT => false, |
||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, |
||||
PDO::ATTR_EMULATE_PREPARES => false, |
PDO::ATTR_EMULATE_PREPARES => false, |
||||
PDO::ATTR_STRINGIFY_FETCHES => false, |
PDO::ATTR_STRINGIFY_FETCHES => false, |
||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', |
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8mb4', |
||||
]; |
]; |
||||
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=appwms', 'masadaroot', 'x6h5E5p#u8y', $options); |
$pdo = new PDO('mysql:host=localhost;port=3306;dbname=appwms', 'masadaroot', 'x6h5E5p#u8y', $options); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
return $pdo; |
return $pdo; |
||||
} catch (PDOException $e) { |
} catch (PDOException $e) { |
||||
die("Something wrong: {$e->getMessage()}"); |
die("Something wrong: {$e->getMessage()}"); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 結束資料庫連線 |
* 結束資料庫連線 |
||||
*/ |
*/ |
||||
function endConnectionDB($pdo) |
function endConnectionDB($pdo) |
||||
{ |
{ |
||||
unset($pdo); |
unset($pdo); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 取得下一個新的作番 |
* 取得下一個新的作番 |
||||
* @param string $facility_type : M:新梯 T:汰改 B:保養 |
* @param string $facility_type : M:新梯 T:汰改 B:保養 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @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 $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @param int $num : 號機 |
* @param int $num : 號機 |
||||
* @return array $new_facility_arr |
* @return array $new_facility_arr |
||||
*/ |
*/ |
||||
function getNextFacilityNo($facility_type, $sale_type, $make_type, $num = 1) |
function getNextFacilityNo($facility_type, $sale_type, $make_type, $num = 1) |
||||
{ |
{ |
||||
$this->checkYearAndResetAllSeq(); |
$this->checkYearAndResetAllSeq(); |
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
|
|
||||
switch ($facility_type) { |
switch ($facility_type) { |
||||
case "M": |
case "M": |
||||
$next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1; |
$next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1; |
||||
$new_facility_arr = []; |
$new_facility_arr = []; |
||||
for ($start_num = 1; $start_num <= $num; $start_num++) { |
for ($start_num = 1; $start_num <= $num; $start_num++) { |
||||
$facility_no_tmp = $Y . $sale_type . $make_type |
$facility_no_tmp = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq, 5, "0", STR_PAD_LEFT); |
. str_pad($next_seq, 5, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_arr, $facility_no_tmp); |
array_push($new_facility_arr, $facility_no_tmp); |
||||
$next_seq++; |
$next_seq++; |
||||
} |
} |
||||
return $new_facility_arr; |
return $new_facility_arr; |
||||
case "T": |
case "T": |
||||
$next_seq = $this->getNextFacilitySeq("tf_vol_no"); |
$next_seq = $this->getNextFacilitySeq("tf_vol_no"); |
||||
$new_facility_arr = []; |
$new_facility_arr = []; |
||||
for ($start_num = 1; $start_num <= $num; $start_num++) { |
for ($start_num = 1; $start_num <= $num; $start_num++) { |
||||
$facility_no_tmp = $Y . $sale_type . $make_type |
$facility_no_tmp = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
||||
. str_pad($start_num, 2, "0", STR_PAD_LEFT); |
. str_pad($start_num, 2, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_arr, $facility_no_tmp); |
array_push($new_facility_arr, $facility_no_tmp); |
||||
} |
} |
||||
return $new_facility_arr; |
return $new_facility_arr; |
||||
case "B": |
case "B": |
||||
$next_seq = $this->getNextFacilitySeq("bf_vol_no"); |
$next_seq = $this->getNextFacilitySeq("bf_vol_no"); |
||||
$new_facility_arr = []; |
$new_facility_arr = []; |
||||
for ($start_num = 1; $start_num <= $num; $start_num++) { |
for ($start_num = 1; $start_num <= $num; $start_num++) { |
||||
$facility_no_tmp = $Y . $sale_type . $make_type |
$facility_no_tmp = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
||||
. str_pad($start_num, 2, "0", STR_PAD_LEFT); |
. str_pad($start_num, 2, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_arr, $facility_no_tmp); |
array_push($new_facility_arr, $facility_no_tmp); |
||||
} |
} |
||||
return $new_facility_arr; |
return $new_facility_arr; |
||||
default: |
default: |
||||
return "不存在的作番類型"; |
return "不存在的作番類型"; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立新的作番 |
* 建立新的作番 |
||||
* @param string $facility_type : M:新梯 T:汰改 B:保養 |
* @param string $facility_type : M:新梯 T:汰改 B:保養 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @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 $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @param string $num : 號機 (非必填) |
* @param string $num : 號機 (非必填) |
||||
* @return string $new_facility_no |
* @return string $new_facility_no |
||||
*/ |
*/ |
||||
function makeFacilityNo($facility_type, $sale_type, $make_type, $num = null) |
function makeFacilityNo($facility_type, $sale_type, $make_type, $num = null) |
||||
{ |
{ |
||||
|
|
||||
$this->checkYearAndResetAllSeq(); |
$this->checkYearAndResetAllSeq(); |
||||
|
|
||||
$faclikity_details = array( |
$faclikity_details = array( |
||||
'facility_type' => $facility_type, |
'facility_type' => $facility_type, |
||||
'sale_type' => $sale_type, |
'sale_type' => $sale_type, |
||||
'make_type' => $make_type, |
'make_type' => $make_type, |
||||
'num' => $num |
'num' => $num |
||||
); |
); |
||||
|
|
||||
switch ($facility_type) { |
switch ($facility_type) { |
||||
case "M": |
case "M": |
||||
return $this->makeNewMFacilityNo($faclikity_details); |
return $this->makeNewMFacilityNo($faclikity_details); |
||||
break; |
break; |
||||
case "T": |
case "T": |
||||
return $this->makeNewTFacilityNo($faclikity_details); |
return $this->makeNewTFacilityNo($faclikity_details); |
||||
break; |
break; |
||||
case "B": |
case "B": |
||||
return $this->makeNewBFacilityNo($faclikity_details); |
return $this->makeNewBFacilityNo($faclikity_details); |
||||
break; |
break; |
||||
default: |
default: |
||||
return "不存在的作番類型"; |
return "不存在的作番類型"; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立作番 -- 新梯 |
* 建立作番 -- 新梯 |
||||
*/ |
*/ |
||||
function makeNewMFacilityNo($faclikity_details) |
function makeNewMFacilityNo($faclikity_details) |
||||
{ |
{ |
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$sale_type = $faclikity_details['sale_type']; |
$sale_type = $faclikity_details['sale_type']; |
||||
$make_type = $faclikity_details['make_type']; |
$make_type = $faclikity_details['make_type']; |
||||
$num = $faclikity_details['num']; |
$num = $faclikity_details['num']; |
||||
$next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1; |
$next_seq = $this->getNextFacilitySeq("mf_vol_no") + 1; |
||||
$new_facility_no_arr = []; |
$new_facility_no_arr = []; |
||||
|
|
||||
for ($i = 1; $i <= $num; $i++) { |
for ($i = 1; $i <= $num; $i++) { |
||||
$new_facility_no = $Y . $sale_type . $make_type |
$new_facility_no = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq, 5, "0", STR_PAD_LEFT); |
. str_pad($next_seq, 5, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_no_arr, $new_facility_no); |
array_push($new_facility_no_arr, $new_facility_no); |
||||
$next_seq++; |
$next_seq++; |
||||
} |
} |
||||
|
|
||||
foreach ($new_facility_no_arr as $new_facility_no) { |
foreach ($new_facility_no_arr as $new_facility_no) { |
||||
if ($this->getMakeNewMFacilityNoStatus($faclikity_details) !== "1") { |
if ($this->getMakeNewMFacilityNoStatus($faclikity_details) !== "1") { |
||||
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
||||
} |
} |
||||
// seq +1 |
// seq +1 |
||||
$this->facilitySeqAddOne("M"); |
$this->facilitySeqAddOne("M"); |
||||
} |
} |
||||
return $new_facility_no_arr; |
return $new_facility_no_arr; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立作番 -- 汰改 |
* 建立作番 -- 汰改 |
||||
*/ |
*/ |
||||
function makeNewTFacilityNo($faclikity_details) |
function makeNewTFacilityNo($faclikity_details) |
||||
{ |
{ |
||||
|
|
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$sale_type = $faclikity_details['sale_type']; |
$sale_type = $faclikity_details['sale_type']; |
||||
$make_type = $faclikity_details['make_type']; |
$make_type = $faclikity_details['make_type']; |
||||
$num = $faclikity_details['num']; |
$num = $faclikity_details['num']; |
||||
$next_seq = $this->getNextFacilitySeq("tf_vol_no"); |
$next_seq = $this->getNextFacilitySeq("tf_vol_no"); |
||||
$new_facility_no_arr = []; |
$new_facility_no_arr = []; |
||||
|
|
||||
for ($i = 1; $i <= $num; $i++) { |
for ($i = 1; $i <= $num; $i++) { |
||||
$new_facility_no = $Y . $sale_type . $make_type |
$new_facility_no = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
||||
. str_pad($i, 2, "0", STR_PAD_LEFT); |
. str_pad($i, 2, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_no_arr, $new_facility_no); |
array_push($new_facility_no_arr, $new_facility_no); |
||||
} |
} |
||||
|
|
||||
foreach ($new_facility_no_arr as $new_facility_no) { |
foreach ($new_facility_no_arr as $new_facility_no) { |
||||
if ($this->getMakeNewTFacilityNoStatus($faclikity_details) !== "1") { |
if ($this->getMakeNewTFacilityNoStatus($faclikity_details) !== "1") { |
||||
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
||||
} |
} |
||||
// seq +1 |
// seq +1 |
||||
$this->facilitySeqAddOne("T"); |
$this->facilitySeqAddOne("T"); |
||||
return $new_facility_no_arr; |
return $new_facility_no_arr; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立作番 -- 保養 |
* 建立作番 -- 保養 |
||||
*/ |
*/ |
||||
function makeNewBFacilityNo($faclikity_details) |
function makeNewBFacilityNo($faclikity_details) |
||||
{ |
{ |
||||
|
|
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$sale_type = $faclikity_details['sale_type']; |
$sale_type = $faclikity_details['sale_type']; |
||||
$make_type = $faclikity_details['make_type']; |
$make_type = $faclikity_details['make_type']; |
||||
$num = $faclikity_details['num']; |
$num = $faclikity_details['num']; |
||||
$next_seq = $this->getNextFacilitySeq("bf_vol_no"); |
$next_seq = $this->getNextFacilitySeq("bf_vol_no"); |
||||
$new_facility_no_arr = []; |
$new_facility_no_arr = []; |
||||
|
|
||||
for ($i = 1; $i <= $num; $i++) { |
for ($i = 1; $i <= $num; $i++) { |
||||
$new_facility_no = $Y . $sale_type . $make_type |
$new_facility_no = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
||||
. str_pad($i, 2, "0", STR_PAD_LEFT); |
. str_pad($i, 2, "0", STR_PAD_LEFT); |
||||
array_push($new_facility_no_arr, $new_facility_no); |
array_push($new_facility_no_arr, $new_facility_no); |
||||
} |
} |
||||
|
|
||||
foreach ($new_facility_no_arr as $new_facility_no) { |
foreach ($new_facility_no_arr as $new_facility_no) { |
||||
if ($this->getMakeNewTFacilityNoStatus($faclikity_details) !== "1") { |
if ($this->getMakeNewTFacilityNoStatus($faclikity_details) !== "1") { |
||||
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
||||
} |
} |
||||
// seq +1 |
// seq +1 |
||||
$this->facilitySeqAddOne("B"); |
$this->facilitySeqAddOne("B"); |
||||
return $new_facility_no_arr; |
return $new_facility_no_arr; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查作番編列狀態 - 新梯 |
* 檢查作番編列狀態 - 新梯 |
||||
* @param array $faclikity_details |
* @param array $faclikity_details |
||||
* @return string $status : 1:正確 else:error message |
* @return string $status : 1:正確 else:error message |
||||
*/ |
*/ |
||||
function getMakeNewMFacilityNoStatus($faclikity_details) |
function getMakeNewMFacilityNoStatus($faclikity_details) |
||||
{ |
{ |
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$sale_type = $faclikity_details['sale_type']; |
$sale_type = $faclikity_details['sale_type']; |
||||
$make_type = $faclikity_details['make_type']; |
$make_type = $faclikity_details['make_type']; |
||||
$next_seq = $this->getNextFacilitySeq("mf_vol_no"); |
$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); |
$new_facility_no = $Y . $sale_type . $make_type . str_pad($next_seq + 1, 5, "0", STR_PAD_LEFT); |
||||
|
|
||||
if ($this->checkSaleTypeStatus($sale_type) == false) |
if ($this->checkSaleTypeStatus($sale_type) == false) |
||||
return "銷售代號錯誤"; |
return "銷售代號錯誤"; |
||||
if ($this->checkMakeTypeStatus($make_type) == false) |
if ($this->checkMakeTypeStatus($make_type) == false) |
||||
return "製造編號類型錯誤"; |
return "製造編號類型錯誤"; |
||||
return "1"; |
return "1"; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查作番編列狀態 - 汰改 |
* 檢查作番編列狀態 - 汰改 |
||||
* @param array $faclikity_details |
* @param array $faclikity_details |
||||
* @return string $status : 1:正確 else:error message |
* @return string $status : 1:正確 else:error message |
||||
*/ |
*/ |
||||
function getMakeNewTFacilityNoStatus($faclikity_details) |
function getMakeNewTFacilityNoStatus($faclikity_details) |
||||
{ |
{ |
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$sale_type = $faclikity_details['sale_type']; |
$sale_type = $faclikity_details['sale_type']; |
||||
$make_type = $faclikity_details['make_type']; |
$make_type = $faclikity_details['make_type']; |
||||
$num = $faclikity_details['num']; |
$num = $faclikity_details['num']; |
||||
$next_seq = $this->getNextFacilitySeq("mf_vol_no"); |
$next_seq = $this->getNextFacilitySeq("mf_vol_no"); |
||||
$new_facility_no = $Y . $sale_type . $make_type |
$new_facility_no = $Y . $sale_type . $make_type |
||||
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
||||
. str_pad($num, 2, "0", STR_PAD_LEFT); |
. str_pad($num, 2, "0", STR_PAD_LEFT); |
||||
|
|
||||
if ($this->checkSaleTypeStatus($sale_type) == false) |
if ($this->checkSaleTypeStatus($sale_type) == false) |
||||
return "銷售代號錯誤"; |
return "銷售代號錯誤"; |
||||
if ($this->checkMakeTypeStatus($make_type) == false) |
if ($this->checkMakeTypeStatus($make_type) == false) |
||||
return "製造編號類型錯誤"; |
return "製造編號類型錯誤"; |
||||
return "1"; |
return "1"; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* seq 取號 |
* seq 取號 |
||||
* @param string $type M:新梯 T:汰改 B:保養 |
* @param string $type M:新梯 T:汰改 B:保養 |
||||
*/ |
*/ |
||||
function facilitySeqAddOne($type) |
function facilitySeqAddOne($type) |
||||
{ |
{ |
||||
$type_arr = array( |
$type_arr = array( |
||||
"M" => "mf_vol_no", |
"M" => "mf_vol_no", |
||||
"T" => "tf_vol_no", |
"T" => "tf_vol_no", |
||||
"B" => "bf_vol_no", |
"B" => "bf_vol_no", |
||||
); |
); |
||||
if (!empty($type_arr[$type])) { |
if (!empty($type_arr[$type])) { |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$sth = $pdo->prepare('UPDATE sequence SET current_val = current_val + 1 WHERE `seq_name` = ?'); |
$sth = $pdo->prepare('UPDATE sequence SET current_val = current_val + 1 WHERE `seq_name` = ?'); |
||||
$sth->bindValue(1, $type_arr[$type]); |
$sth->bindValue(1, $type_arr[$type]); |
||||
$sth->execute(); |
$sth->execute(); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 修正 seq 取號 |
* 修正 seq 取號 |
||||
* @param string $type M:新梯 T:汰改 B:保養 |
* @param string $type M:新梯 T:汰改 B:保養 |
||||
*/ |
*/ |
||||
function facilityFixSeq($type) |
function facilityFixSeq($type) |
||||
{ |
{ |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$type_arr = array( |
$type_arr = array( |
||||
"M" => "mf_vol_no", |
"M" => "mf_vol_no", |
||||
"T" => "tf_vol_no", |
"T" => "tf_vol_no", |
||||
"B" => "bf_vol_no", |
"B" => "bf_vol_no", |
||||
); |
); |
||||
$after_fix_seq = $this->getMaxSeq($type); |
$after_fix_seq = $this->getMaxSeq($type); |
||||
$sql = " |
$sql = " |
||||
UPDATE sequence |
UPDATE sequence |
||||
SET current_val = ? |
SET current_val = ? |
||||
WHERE seq_name = ? |
WHERE seq_name = ? |
||||
"; |
"; |
||||
$sth = $pdo->prepare($sql); |
$sth = $pdo->prepare($sql); |
||||
$sth->bindValue(1, $after_fix_seq); |
$sth->bindValue(1, $after_fix_seq); |
||||
$sth->bindValue(2, $type_arr[$type]); |
$sth->bindValue(2, $type_arr[$type]); |
||||
$sth->execute(); |
$sth->execute(); |
||||
} |
} |
||||
|
|
||||
function getMaxSeq($type) |
function getMaxSeq($type) |
||||
{ |
{ |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$Y = substr(date("Y"), 3, 1); |
$Y = substr(date("Y"), 3, 1); |
||||
$seq_num = $type == 'M' ? 5 : 3; |
$seq_num = $type == 'M' ? 5 : 3; |
||||
$sql = " |
$sql = " |
||||
SELECT MAX(SUBSTR(f.facilityno,4,?))+1 AS seq |
SELECT MAX(SUBSTR(f.facilityno,4,?))+1 AS seq |
||||
FROM facility AS f |
FROM facility AS f |
||||
WHERE 1=1 |
WHERE 1=1 |
||||
AND SUBSTR(f.facilityno,1,1) = ? |
AND SUBSTR(f.facilityno,1,1) = ? |
||||
AND f.define = ? |
AND f.define = ? |
||||
ORDER BY SUBSTR(f.facilityno,4,3) ASC |
ORDER BY SUBSTR(f.facilityno,4,3) ASC |
||||
"; |
"; |
||||
$sth = $pdo->prepare($sql); |
$sth = $pdo->prepare($sql); |
||||
$sth->bindValue(1, $seq_num); |
$sth->bindValue(1, $seq_num); |
||||
$sth->bindValue(2, $Y); |
$sth->bindValue(2, $Y); |
||||
$sth->bindValue(3, $type); |
$sth->bindValue(3, $type); |
||||
$sth->execute(); |
$sth->execute(); |
||||
$result = $sth->fetch(); |
$result = $sth->fetch(); |
||||
return $result['seq']; |
return $result['seq']; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查年月後 新梯及汰改seq歸零 |
* 檢查年月後 新梯及汰改seq歸零 |
||||
*/ |
*/ |
||||
function checkYearAndResetAllSeq() |
function checkYearAndResetAllSeq() |
||||
{ |
{ |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?'); |
$sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?'); |
||||
$sth->bindValue(1, 'mf_vol_no'); |
$sth->bindValue(1, 'mf_vol_no'); |
||||
$sth->execute(); |
$sth->execute(); |
||||
$result = $sth->fetch(); |
$result = $sth->fetch(); |
||||
$yyyymm = $result['yyyymm']; |
$yyyymm = $result['yyyymm']; |
||||
$dataY = substr($yyyymm, 0, 4); |
$dataY = substr($yyyymm, 0, 4); |
||||
$today_Y = date("Y"); |
$today_Y = date("Y"); |
||||
$today_Ym = date("Ym"); |
$today_Ym = date("Ym"); |
||||
if ($dataY != $today_Y) { |
if ($dataY != $today_Y) { |
||||
$sth = $pdo->prepare('UPDATE `sequence` SET `current_val` = ? , `yyyymm` = ? WHERE `seq_name` = ?'); |
$sth = $pdo->prepare('UPDATE `sequence` SET `current_val` = ? , `yyyymm` = ? WHERE `seq_name` = ?'); |
||||
$sth->bindValue(1, '0'); |
$sth->bindValue(1, '0'); |
||||
$sth->bindValue(2, $today_Ym); |
$sth->bindValue(2, $today_Ym); |
||||
$sth->bindValue(3, 'mf_vol_no'); |
$sth->bindValue(3, 'mf_vol_no'); |
||||
$sth->execute(); |
$sth->execute(); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查作番在 facility table 中是否重複 |
* 檢查作番在 facility table 中是否重複 |
||||
* @param string|array $facility_no |
* @param string|array $facility_no |
||||
* @return boolean $status : true:沒重複 false:重複 |
* @return boolean $status : true:沒重複 false:重複 |
||||
*/ |
*/ |
||||
function checkFacilityRepeatStatus($facility_no) |
function checkFacilityRepeatStatus($facility_no) |
||||
{ |
{ |
||||
if (gettype($facility_no) == "string") { |
if (gettype($facility_no) == "string") { |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?'); |
$sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?'); |
||||
$sth->bindValue(1, $facility_no); |
$sth->bindValue(1, $facility_no); |
||||
$sth->execute(); |
$sth->execute(); |
||||
if ($sth->rowCount() == 0) |
if ($sth->rowCount() == 0) |
||||
return true; |
return true; |
||||
return false; |
return false; |
||||
} |
} |
||||
if (gettype($facility_no) == "array") { |
if (gettype($facility_no) == "array") { |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$status = true; |
$status = true; |
||||
foreach ($facility_no as $row) { |
foreach ($facility_no as $row) { |
||||
$sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?'); |
$sth = $pdo->prepare('SELECT * FROM `facility` WHERE `facilityno` = ?'); |
||||
$sth->bindValue(1, $row); |
$sth->bindValue(1, $row); |
||||
$sth->execute(); |
$sth->execute(); |
||||
if ($sth->rowCount() !== 0) |
if ($sth->rowCount() !== 0) |
||||
$status = false; |
$status = false; |
||||
} |
} |
||||
return $status; |
return $status; |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查 $sale_type 是否有存在規則之中 |
* 檢查 $sale_type 是否有存在規則之中 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
||||
* @return boolean $status : true:合法代碼 false:非法代碼 |
* @return boolean $status : true:合法代碼 false:非法代碼 |
||||
*/ |
*/ |
||||
function checkSaleTypeStatus($sale_type) |
function checkSaleTypeStatus($sale_type) |
||||
{ |
{ |
||||
if (in_array($sale_type, ['M', 'E', 'T', 'J', 'X'])) |
if (in_array($sale_type, ['M', 'E', 'T', 'J', 'X'])) |
||||
return true; |
return true; |
||||
return false; |
return false; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查 $sale_type 是否有存在規則之中 |
* 檢查 $sale_type 是否有存在規則之中 |
||||
* @param string $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
* @param string $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @return boolean $status : true:合法代碼 false:非法代碼 |
* @return boolean $status : true:合法代碼 false:非法代碼 |
||||
*/ |
*/ |
||||
function checkMakeTypeStatus($make_type) |
function checkMakeTypeStatus($make_type) |
||||
{ |
{ |
||||
if (in_array($make_type, ['X', 'W', 'H', 'Z', 'F', 'B', 'Q', 'T', 'N', 'W', 'J', 'Y'])) |
if (in_array($make_type, ['X', 'W', 'H', 'Z', 'F', 'B', 'Q', 'T', 'N', 'W', 'J', 'Y'])) |
||||
return true; |
return true; |
||||
return false; |
return false; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 檢查 取得下個作番的 seq |
* 檢查 取得下個作番的 seq |
||||
* @param string $seq_name : 新梯:mf_vol_no 汰改:tf_vol_no 保養:bf_vol_no |
* @param string $seq_name : 新梯:mf_vol_no 汰改:tf_vol_no 保養:bf_vol_no |
||||
* @return int $seq : 作番流水號 |
* @return int $seq : 作番流水號 |
||||
*/ |
*/ |
||||
function getNextFacilitySeq($seq_name) |
function getNextFacilitySeq($seq_name) |
||||
{ |
{ |
||||
$pdo = $this->connectionDB(); |
$pdo = $this->connectionDB(); |
||||
$pdo->exec('SET CHARACTER SET utf8mb4'); |
$pdo->exec('SET CHARACTER SET utf8mb4'); |
||||
$sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?'); |
$sth = $pdo->prepare('SELECT * FROM `sequence` WHERE `seq_name` = ?'); |
||||
$sth->bindValue(1, $seq_name); |
$sth->bindValue(1, $seq_name); |
||||
$sth->execute(); |
$sth->execute(); |
||||
$result = $sth->fetch(); |
$result = $sth->fetch(); |
||||
return $result['current_val']; |
return $result['current_val']; |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立新的新梯作番 |
* 建立新的新梯作番 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @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 $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @param int $seq_name : 幾個案場 0-99 |
* @param int $seq_name : 幾個案場 0-99 |
||||
* @return array $new_facilityno : 作番號 |
* @return array $new_facilityno : 作番號 |
||||
*/ |
*/ |
||||
function makeMFacilityNo($sale_type, $make_type, $num) |
function makeMFacilityNo($sale_type, $make_type, $num) |
||||
{ |
{ |
||||
$new_facility_no = $this->getNextFacilityNo("M", $sale_type, $make_type, $num); |
$new_facility_no = $this->getNextFacilityNo("M", $sale_type, $make_type, $num); |
||||
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
||||
// 如果作番號重複 使用此函數修正 |
// 如果作番號重複 使用此函數修正 |
||||
$this->facilityFixSeq("M"); |
$this->facilityFixSeq("M"); |
||||
} |
} |
||||
return $this->makeFacilityNo("M", $sale_type, $make_type, $num); |
return $this->makeFacilityNo("M", $sale_type, $make_type, $num); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立新的汰改作番 |
* 建立新的汰改作番 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @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 $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @param int $seq_name : 幾個案場 0-99 |
* @param int $seq_name : 幾個案場 0-99 |
||||
* @return array $new_facilityno : 作番號 |
* @return array $new_facilityno : 作番號 |
||||
*/ |
*/ |
||||
function makeTFacilityNo($sale_type, $make_type, $num) |
function makeTFacilityNo($sale_type, $make_type, $num) |
||||
{ |
{ |
||||
$new_facility_no = $this->getNextFacilityNo("T", $sale_type, $make_type, $num); |
$new_facility_no = $this->getNextFacilityNo("T", $sale_type, $make_type, $num); |
||||
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
||||
// 如果作番號重複 使用此函數修正 |
// 如果作番號重複 使用此函數修正 |
||||
$this->facilityFixSeq("T"); |
$this->facilityFixSeq("T"); |
||||
} |
} |
||||
return $this->makeFacilityNo("T", $sale_type, $make_type, $num); |
return $this->makeFacilityNo("T", $sale_type, $make_type, $num); |
||||
} |
} |
||||
|
|
||||
/** |
/** |
||||
* 建立新的保養作番 |
* 建立新的保養作番 |
||||
* @param string $sale_type : M:内銷 E:外銷 T:他社维保 J:汰改 X:特殊部品 |
* @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 $make_type : X:小機房 W:無機房 H:家用梯 Z:雜物梯 F:扶梯 B:部品 Q:品保對策 T:研究開發 N:設備 W:出貨現場要求購買 J:營業問題對策 Y:已出貨作番營業進行規格訂正 |
||||
* @param int $seq_name : 幾個案場 0-99 |
* @param int $seq_name : 幾個案場 0-99 |
||||
* @return array $new_facilityno : 作番號 |
* @return array $new_facilityno : 作番號 |
||||
*/ |
*/ |
||||
function makeBFacilityNo($sale_type, $make_type, $num) |
function makeBFacilityNo($sale_type, $make_type, $num) |
||||
{ |
{ |
||||
$new_facility_no = $this->getNextFacilityNo("B", $sale_type, $make_type, $num); |
$new_facility_no = $this->getNextFacilityNo("B", $sale_type, $make_type, $num); |
||||
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
if ($this->checkFacilityRepeatStatus($new_facility_no) == false) { |
||||
// 如果作番號重複 使用此函數修正 |
// 如果作番號重複 使用此函數修正 |
||||
$this->facilityFixSeq("B"); |
$this->facilityFixSeq("B"); |
||||
} |
} |
||||
return $this->makeFacilityNo("B", $sale_type, $make_type, $num); |
return $this->makeFacilityNo("B", $sale_type, $make_type, $num); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
|
|
||||
$cfn = new CreateFacilityNo; |
$cfn = new CreateFacilityNo; |
||||
|
|
||||
// 建立作番號 - 新梯 |
// 建立作番號 - 新梯 |
||||
print_r($cfn->makeMFacilityNo("M", "X", 5)); |
print_r($cfn->makeMFacilityNo("M", "X", 5)); |
||||
echo "<br/><br/>"; |
echo "<br/><br/>"; |
||||
// 建立作番號 - 汰改 |
// 建立作番號 - 汰改 |
||||
print_r($cfn->makeTFacilityNo( "M", "X", 1)); |
print_r($cfn->makeTFacilityNo( "M", "X", 1)); |
||||
echo "<br/><br/>"; |
echo "<br/><br/>"; |
||||
// 建立作番號 - 保養 |
// 建立作番號 - 保養 |
||||
print_r($cfn->makeBFacilityNo( "M", "X", 1)); |
print_r($cfn->makeBFacilityNo( "M", "X", 1)); |
||||
echo "<br/><br/>"; |
echo "<br/><br/>"; |
Loading…
Reference in new issue