Updated validation logic on importer file
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled

This commit is contained in:
dhanabalan
2026-02-20 19:18:37 +05:30
parent 0e651e8bcc
commit 3c4a4bf136

View File

@@ -112,22 +112,30 @@ class CharacteristicValueImporter extends Importer
$iCode = trim($this->data['item']);
$workCenter = trim($this->data['machine']);
$lineName = trim($this->data['line']);
$status = trim($this->data['status']);
$createdBy = trim($this->data['created_by']);
$coilNo = trim($this->data['coil_number']);
$obserVal = trim($this->data['observed_value']);
$status = trim($this->data['status']);
$createdBy = trim($this->data['created_by']);
if ($plantCode == null || $plantCode == '') {
$warnMsg[] = 'Plant code cannot be empty';
} elseif ($iCode == null || $iCode == '') {
} elseif ($iCode == null || $iCode == '') {// process_order
$warnMsg[] = 'Item code cannot be empty';
} elseif ($processOrder == null || $processOrder == '') {//
$warnMsg[] = 'Process Order cannot be empty';
} elseif ($workCenter == null || $workCenter == '') {
$warnMsg[] = 'Work center cannot be empty';
} elseif ($lineName == null || $lineName == '') {
$warnMsg[] = 'Line cannot be empty';
$warnMsg[] = 'Line name cannot be empty';
} elseif ($coilNo == null || $coilNo == '') {
$warnMsg[] = 'Coil number cannot be empty';
} elseif ($obserVal == null || $obserVal == '') {
$warnMsg[] = 'Observed value cannot be empty';
} elseif ($status == null || $status == '') {
$warnMsg[] = 'Status cannot be empty';
}
if (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode)) {
if (Str::length($plantCode) > 0 && (Str::length($plantCode) < 4 || ! is_numeric($plantCode) || ! preg_match('/^[1-9]\d{3,}$/', $plantCode))) {
$warnMsg[] = 'Invalid plant code found';
} else {
$plant = Plant::where('code', $plantCode)->first();
@@ -138,7 +146,7 @@ class CharacteristicValueImporter extends Importer
}
}
if (Str::length($iCode) < 6 || ! ctype_alnum($iCode)) {
if (Str::length($iCode) > 0 && (Str::length($iCode) < 6 || ! ctype_alnum($iCode))) {
$warnMsg[] = 'Invalid item code found';
} else {
$itemCode = Item::where('code', $iCode)->first();
@@ -198,25 +206,15 @@ class CharacteristicValueImporter extends Importer
}
}
if ($processOrder == null || $processOrder == '') {
$warnMsg[] = 'Process Order cannot be empty';
}
if ($coilNo == null || $coilNo == '') {
$warnMsg[] = 'Coil No cannot be empty';
} elseif (! is_numeric($coilNo)) {
if (Str::length($coilNo) > 0 && ! is_numeric($coilNo)) {
$warnMsg[] = 'Coil number should contain only numeric values!';
}
if ($obserVal == null || $obserVal == '') {
$warnMsg[] = 'Observed value cannot be empty';
} elseif (! is_numeric($obserVal)) {
if (Str::length($obserVal) > 0 && ! is_numeric($obserVal)) {
$warnMsg[] = 'Observed value should contain only numeric values!';
}
if ($status == null || $status == '' || ! $status) {
$warnMsg[] = 'Status cannot be empty';
} elseif (! in_array($status, ['Ok', 'NotOk'], true)) {
if (Str::length($status) > 0 && ! in_array($status, ['Ok', 'NotOk'], true)) {
$warnMsg[] = "Status must be either 'Ok' or 'NotOk'!";
}
// else {
@@ -255,7 +253,7 @@ class CharacteristicValueImporter extends Importer
$warnMsg[] = 'Created By cannot be empty';
}
if ($plantId != null) {
if ($plantId) {
$user = User::where('name', $createdBy)->first();
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
@@ -280,7 +278,7 @@ class CharacteristicValueImporter extends Importer
}
}
if ($plant && $itemCode && $processOrder != '') {
if ($plant && $itemCode && $processOrder != '' && $processOrder != null) {
$existingOrder = ProcessOrder::where('plant_id', $plantId)
->where('process_order', $processOrder)