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

This commit is contained in:
dhanabalan
2026-02-26 20:13:38 +05:30
parent 5aec248632
commit 0f29c0071c

View File

@@ -110,7 +110,7 @@ class ProductCharacteristicsMasterImporter extends Importer
$groupWorkCenter = trim($this->data['work_group_master_id']) ?? null;
$workCenter = trim($this->data['machine']) ?? 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;
$lower = trim($this->data['lower']) ?? null;
$middle = trim($this->data['middle']) ?? null;
@@ -123,6 +123,7 @@ class ProductCharacteristicsMasterImporter extends Importer
$lineId = null;
$workGroupMasterId = null;
$machineId = null;
if ($plantCod == null || $plantCod == '') {
$warnMsg[] = "Plant code can't be empty!";
} 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 == '') {
$warnMsg[] = "Work center can't be empty!";
}
if ($charTyp == null || $charTyp == '') {
$warnMsg[] = "Characteristics type can't be empty!";
if ($charTyp != 'Product' && $charTyp != 'Process') {
$warnMsg[] = "Characteristics type must be either 'Product' or 'Process'!";
}
if ($charName == null || $charName == '') {
if ($charNam == null || $charNam == '') {
$warnMsg[] = "Characteristics name can't be empty!";
}
if ($inspectTyp == null || $inspectTyp == '') {
$warnMsg[] = "Inspection type can't be empty!";
if ($inspectTyp != 'Visual' && $inspectTyp != 'Value') {
$warnMsg[] = "Inspection type must be either 'Visual' or 'Value'!";
}
if ($lower == null || $lower == '') {
$warnMsg[] = "Lower value can't be empty!";
}
if ($middle == null || $middle == '') {
$warnMsg[] = "Middle value can't be empty!";
}
if ($upper == null || $upper == '') {
$warnMsg[] = "Upper value can't be empty!";
if ($lower == null || $lower == '' || $middle == null || $middle == '' || $upper == null || $upper == '' || $upper == 0 || $upper == '0') {
$lower = 0;
$middle = 0;
$upper = 0;
}
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();
if (! $machine) {
$warnMsg[] = 'Work center not found for the given line!';
$warnMsg[] = "Work center '{$workCenter}' is not mapped for the given line!";
} else {
$machine = Machine::where('work_center', $workCenter)->where('plant_id', $plantId)->where('line_id', $lineId)->where('work_group_master_id', $workGroupMasterId)->first();
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 {
$machineId = $machine->id;
}
@@ -259,17 +256,22 @@ class ProductCharacteristicsMasterImporter extends Importer
$warnMsg[] = 'Upper, Lower, and Middle values are required.';
} elseif (! is_numeric($upper) || ! is_numeric($lower) || ! is_numeric($middle)) {
$warnMsg[] = 'Upper, Lower, and Middle values must be numeric.';
} elseif ($lower == $upper) {
if ($lower != $middle) {
$warnMsg[] = "For 'Value' inspection type, values must satisfy: Lower = Middle = Upper.";
} else {
$lower = (float) $lower;
$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 {
$lower = null;
$middle = null;
$upper = null;
$lower = 0;
$middle = 0;
$upper = 0;
}
}
@@ -278,10 +280,9 @@ class ProductCharacteristicsMasterImporter extends Importer
}
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();
// ->where('characteristics_type', $get('characteristics_type'))
$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();
if ($record) {
$createdBy = $record->created_by;
$createdBy = $record->created_by ?? $createdBy;
}
ProductCharacteristicsMaster::updateOrCreate(
@@ -291,11 +292,10 @@ class ProductCharacteristicsMasterImporter extends Importer
'line_id' => $lineId,
'work_group_master_id' => $workGroupMasterId,
'machine_id' => $machineId,
// 'characteristics_type' => $charTyp,
'characteristics_type' => $charTyp,
'name' => $charNam,
],
[
'name' => $charName,
'characteristics_type' => $charTyp,
'inspection_type' => $inspectTyp,
'lower' => $lower,
'middle' => $middle,