Updated validation logic for Product Characteristics Master import and setting default values
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
All checks were successful
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Successful in 12s
This commit is contained in:
@@ -110,7 +110,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$groupWorkCenter = trim($this->data['work_group_master_id']) ?? null;
|
$groupWorkCenter = trim($this->data['work_group_master_id']) ?? null;
|
||||||
$workCenter = trim($this->data['machine']) ?? null;
|
$workCenter = trim($this->data['machine']) ?? null;
|
||||||
$charTyp = trim($this->data['characteristics_type']) ?? null;
|
$charTyp = trim($this->data['characteristics_type']) ?? null;
|
||||||
$charName = trim($this->data['name']) ?? null;
|
$charNam = trim($this->data['name']) ?? null;
|
||||||
$inspectTyp = trim($this->data['inspection_type']) ?? null;
|
$inspectTyp = trim($this->data['inspection_type']) ?? null;
|
||||||
$lower = trim($this->data['lower']) ?? null;
|
$lower = trim($this->data['lower']) ?? null;
|
||||||
$middle = trim($this->data['middle']) ?? null;
|
$middle = trim($this->data['middle']) ?? null;
|
||||||
@@ -123,6 +123,7 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$lineId = null;
|
$lineId = null;
|
||||||
$workGroupMasterId = null;
|
$workGroupMasterId = null;
|
||||||
$machineId = null;
|
$machineId = null;
|
||||||
|
|
||||||
if ($plantCod == null || $plantCod == '') {
|
if ($plantCod == null || $plantCod == '') {
|
||||||
$warnMsg[] = "Plant code can't be empty!";
|
$warnMsg[] = "Plant code can't be empty!";
|
||||||
} elseif (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
} elseif (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||||
@@ -142,23 +143,19 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
if ($workCenter == null || $workCenter == '') {
|
if ($workCenter == null || $workCenter == '') {
|
||||||
$warnMsg[] = "Work center can't be empty!";
|
$warnMsg[] = "Work center can't be empty!";
|
||||||
}
|
}
|
||||||
if ($charTyp == null || $charTyp == '') {
|
if ($charTyp != 'Product' && $charTyp != 'Process') {
|
||||||
$warnMsg[] = "Characteristics type can't be empty!";
|
$warnMsg[] = "Characteristics type must be either 'Product' or 'Process'!";
|
||||||
}
|
}
|
||||||
if ($charName == null || $charName == '') {
|
if ($charNam == null || $charNam == '') {
|
||||||
$warnMsg[] = "Characteristics name can't be empty!";
|
$warnMsg[] = "Characteristics name can't be empty!";
|
||||||
}
|
}
|
||||||
if ($inspectTyp == null || $inspectTyp == '') {
|
if ($inspectTyp != 'Visual' && $inspectTyp != 'Value') {
|
||||||
$warnMsg[] = "Inspection type can't be empty!";
|
$warnMsg[] = "Inspection type must be either 'Visual' or 'Value'!";
|
||||||
}
|
}
|
||||||
if ($lower == null || $lower == '') {
|
if ($lower == null || $lower == '' || $middle == null || $middle == '' || $upper == null || $upper == '' || $upper == 0 || $upper == '0') {
|
||||||
$warnMsg[] = "Lower value can't be empty!";
|
$lower = 0;
|
||||||
}
|
$middle = 0;
|
||||||
if ($middle == null || $middle == '') {
|
$upper = 0;
|
||||||
$warnMsg[] = "Middle value can't be empty!";
|
|
||||||
}
|
|
||||||
if ($upper == null || $upper == '') {
|
|
||||||
$warnMsg[] = "Upper value can't be empty!";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
@@ -229,12 +226,12 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->first();
|
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->first();
|
||||||
|
|
||||||
if (! $machine) {
|
if (! $machine) {
|
||||||
$warnMsg[] = 'Work center not found for the given line!';
|
$warnMsg[] = "Work center '{$workCenter}' is not mapped for the given line!";
|
||||||
} else {
|
} else {
|
||||||
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->first();
|
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->first();
|
||||||
|
|
||||||
if (! $machine) {
|
if (! $machine) {
|
||||||
$warnMsg[] = 'Work center not found for the given group work center!';
|
$warnMsg[] = "Work center '{$workCenter}' is not mapped for the given group work center!";
|
||||||
} else {
|
} else {
|
||||||
$machineId = $machine->id;
|
$machineId = $machine->id;
|
||||||
}
|
}
|
||||||
@@ -259,17 +256,22 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
$warnMsg[] = 'Upper, Lower, and Middle values are required.';
|
$warnMsg[] = 'Upper, Lower, and Middle values are required.';
|
||||||
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
|
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
|
||||||
$warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
|
$warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
|
||||||
} elseif ($lower == $upper) {
|
} else {
|
||||||
if ($lower != $middle) {
|
$lower = (float) $lower;
|
||||||
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower = Middle = Upper.";
|
$middle = (float) $middle;
|
||||||
|
$upper = (float) $upper;
|
||||||
|
if ($lower == $upper) {
|
||||||
|
if ($lower != $middle) {
|
||||||
|
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower = Middle = Upper.";
|
||||||
|
}
|
||||||
|
} elseif (! ($lower < $middle && $middle < $upper)) {
|
||||||
|
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower < Middle < Upper.";
|
||||||
}
|
}
|
||||||
} elseif (! ($lower < $middle && $middle < $upper)) {
|
|
||||||
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower < Middle < Upper.";
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$lower = null;
|
$lower = 0;
|
||||||
$middle = null;
|
$middle = 0;
|
||||||
$upper = null;
|
$upper = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -278,10 +280,9 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($machineId) {
|
if ($machineId) {
|
||||||
$record = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->where('machine_id', $machineId)->where('item_id', $itemId)->first();
|
$record = ProductCharacteristicsMaster::where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->where('machine_id', $machineId)->where('item_id', $itemId)->where('characteristics_type', $charTyp)->where('name', $charNam)->first();
|
||||||
// ->where('characteristics_type', $get('characteristics_type'))
|
|
||||||
if ($record) {
|
if ($record) {
|
||||||
$createdBy = $record->created_by;
|
$createdBy = $record->created_by ?? $createdBy;
|
||||||
}
|
}
|
||||||
|
|
||||||
ProductCharacteristicsMaster::updateOrCreate(
|
ProductCharacteristicsMaster::updateOrCreate(
|
||||||
@@ -291,11 +292,10 @@ class ProductCharacteristicsMasterImporter extends Importer
|
|||||||
'line_id' => $lineId,
|
'line_id' => $lineId,
|
||||||
'work_group_master_id' => $workGroupMasterId,
|
'work_group_master_id' => $workGroupMasterId,
|
||||||
'machine_id' => $machineId,
|
'machine_id' => $machineId,
|
||||||
// 'characteristics_type' => $charTyp,
|
'characteristics_type' => $charTyp,
|
||||||
|
'name' => $charNam,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => $charName,
|
|
||||||
'characteristics_type' => $charTyp,
|
|
||||||
'inspection_type' => $inspectTyp,
|
'inspection_type' => $inspectTyp,
|
||||||
'lower' => $lower,
|
'lower' => $lower,
|
||||||
'middle' => $middle,
|
'middle' => $middle,
|
||||||
|
|||||||
Reference in New Issue
Block a user