|
@ -1,9 +1,12 @@ |
|
|
<?php |
|
|
<?php |
|
|
ini_set('display_errors', 'on'); |
|
|
// ini_set('display_errors', 'on'); |
|
|
|
|
|
|
|
|
// 汰改 前三碼 流水號 + 後兩碼 號機 |
|
|
// 汰改 前三碼 流水號 + 後兩碼 號機 |
|
|
// 新梯 流水號 |
|
|
// 新梯 流水號 |
|
|
|
|
|
|
|
|
|
|
|
// 新增 seq 的初始值 |
|
|
|
|
|
// INSERT INTO `sequence` (`seq_name`, `current_val`, `increment_val`, `remark`, `yyyymm`, `prefix`, `creator`, `create_at`) VALUES ('bf_vol_no', '0', '1', '保養-作番編號', '202310', '', 'M0117', '2023-10-26 11:28:11'), ('mf_vol_no', '0', '1', '新梯-作番編號', '202310', '', 'M0117', '2023-10-26 11:28:11'), ('tf_vol_no', '0', '1', '汰改-作番編號', '202310', '', 'M0117', '2023-10-26 11:28:11') |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class CreateFacilityNo |
|
|
class CreateFacilityNo |
|
|
{ |
|
|
{ |
|
|
/** |
|
|
/** |
|
@ -11,6 +14,25 @@ class CreateFacilityNo |
|
|
*/ |
|
|
*/ |
|
|
function connectionDB() |
|
|
function connectionDB() |
|
|
{ |
|
|
{ |
|
|
|
|
|
$envFile = __DIR__ . '/../../../.env'; |
|
|
|
|
|
if (file_exists($envFile)) { |
|
|
|
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); |
|
|
|
|
|
if ($lines !== false) { |
|
|
|
|
|
foreach ($lines as $line) { |
|
|
|
|
|
list($key, $value) = explode('=', $line, 2); |
|
|
|
|
|
$key = trim($key); |
|
|
|
|
|
$value = trim($value); |
|
|
|
|
|
putenv("$key=$value"); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
date_default_timezone_set("Asia/Taipei"); |
|
|
|
|
|
$host = getenv('DB_HOST'); |
|
|
|
|
|
$dbport = getenv('DB_PORT'); |
|
|
|
|
|
$dbuser = getenv('DB_USERNAME'); |
|
|
|
|
|
$dbpassword = getenv('DB_PASSWORD'); |
|
|
|
|
|
$dbname = getenv('DB_DATABASE'); |
|
|
|
|
|
|
|
|
try { |
|
|
try { |
|
|
$options = [ |
|
|
$options = [ |
|
|
PDO::ATTR_PERSISTENT => false, |
|
|
PDO::ATTR_PERSISTENT => false, |
|
@ -19,7 +41,7 @@ class CreateFacilityNo |
|
|
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=' . $host . ';port=' . $dbport . ';dbname=' . $dbname . '', $dbuser, $dbpassword, $options); |
|
|
$pdo->exec('SET CHARACTER SET utf8mb4'); |
|
|
$pdo->exec('SET CHARACTER SET utf8mb4'); |
|
|
return $pdo; |
|
|
return $pdo; |
|
|
} catch (PDOException $e) { |
|
|
} catch (PDOException $e) { |
|
@ -199,8 +221,8 @@ class CreateFacilityNo |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
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->getMakeNewBFacilityNoStatus($faclikity_details) !== "1") { |
|
|
return $new_facility_no . ":" . $this->getMakeNewTFacilityNoStatus($faclikity_details); |
|
|
return $new_facility_no . ":" . $this->getMakeNewBFacilityNoStatus($faclikity_details); |
|
|
} |
|
|
} |
|
|
// seq +1 |
|
|
// seq +1 |
|
|
$this->facilitySeqAddOne("B"); |
|
|
$this->facilitySeqAddOne("B"); |
|
@ -215,11 +237,8 @@ class CreateFacilityNo |
|
|
*/ |
|
|
*/ |
|
|
function getMakeNewMFacilityNoStatus($faclikity_details) |
|
|
function getMakeNewMFacilityNoStatus($faclikity_details) |
|
|
{ |
|
|
{ |
|
|
$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"); |
|
|
|
|
|
$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 "銷售代號錯誤"; |
|
@ -235,14 +254,25 @@ class CreateFacilityNo |
|
|
*/ |
|
|
*/ |
|
|
function getMakeNewTFacilityNoStatus($faclikity_details) |
|
|
function getMakeNewTFacilityNoStatus($faclikity_details) |
|
|
{ |
|
|
{ |
|
|
$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']; |
|
|
|
|
|
$next_seq = $this->getNextFacilitySeq("mf_vol_no"); |
|
|
if ($this->checkSaleTypeStatus($sale_type) == false) |
|
|
$new_facility_no = $Y . $sale_type . $make_type |
|
|
return "銷售代號錯誤"; |
|
|
. str_pad($next_seq + 1, 3, "0", STR_PAD_LEFT) |
|
|
if ($this->checkMakeTypeStatus($make_type) == false) |
|
|
. str_pad($num, 2, "0", STR_PAD_LEFT); |
|
|
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) |
|
|
if ($this->checkSaleTypeStatus($sale_type) == false) |
|
|
return "銷售代號錯誤"; |
|
|
return "銷售代號錯誤"; |
|
@ -474,8 +504,8 @@ $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/>"; |
|
|