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

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
dhanabalan
2026-04-29 16:05:22 +05:30
parent c481793e16
commit ac1e87886f
3 changed files with 67 additions and 57 deletions

View File

@@ -27,15 +27,15 @@ class WorkGroupMasterImporter extends Importer
->rules(['required']),
ImportColumn::make('name')
->requiredMapping()
->exampleHeader('Work Group Name')
->exampleHeader('Group Work Center')
->example('RMGCEABC')
->label('Work Group Name')
->label('Group Work Center')
->rules(['required']),
ImportColumn::make('description')
->requiredMapping()
->exampleHeader('Work Group Description')
->exampleHeader('Description')
->example('Testing Model 1')
->label('Work Group Description')
->label('Description')
->rules(['required']),
ImportColumn::make('operation_number')
->requiredMapping()
@@ -60,85 +60,92 @@ class WorkGroupMasterImporter extends Importer
// ]);
$warnMsg = [];
$plantCod = $this->data['plant'];
$createdBy = $this->data['created_by'];
$groupWorkCenter = $this->data['name'];
$desc = trim($this->data['description']);
$opNo = $this->data['operation_number'];
$plantId = null;
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
$warnMsg[] = 'Invalid plant code found';
if (! $plantCod || $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)) {
$warnMsg[] = "Invalid plant code '{$plantCod}' found!";
} else {
$plant = Plant::where('code', $plantCod)->first();
if (! $plant) {
$warnMsg[] = 'Plant not found';
$warnMsg[] = "Plant code '{$plantCod}' not found!";
} else {
$plantId = $plant->id;
}
}
if (Str::length($this->data['name']) <= 0) { // || !ctype_alnum($this->data['description'])
$warnMsg[] = 'Invalid work group name found';
if (Str::length($groupWorkCenter) <= 0) { // || !ctype_alnum($desc)
$warnMsg[] = 'Invalid group work center found!';
}
if (Str::length(trim($this->data['description'])) <= 0) {
$warnMsg[] = 'Invalid work group description found';
if (Str::length(trim($desc)) <= 0) {
$warnMsg[] = 'Invalid description found!';
}
$desc = trim($this->data['description']);
if (Str::length($desc) > 44) {
$warnMsg[] = ' work group description should be less than 44 digits.';
$warnMsg[] = 'Description should be less than 44 digits.';
}
if (Str::length($this->data['operation_number']) <= 0) {
$warnMsg[] = 'Invalid operation number found';
if (Str::length($opNo) <= 0) {
$warnMsg[] = 'Invalid operation number found!';
}
if (! is_numeric($this->data['operation_number'])) {
$warnMsg[] = 'Invalid operation number found must be numeric';
if (! is_numeric($opNo)) {
$warnMsg[] = 'Operation number must be numeric values only.';
}
$user = User::where('name', $this->data['created_by'])->first();
$user = User::where('name', $createdBy)->first();
if (! $user) {
$warnMsg[] = 'Operator ID not found';
$warnMsg[] = "Operator ID '{$createdBy}' not found!";
}
if (! empty($warnMsg)) {
throw new RowImportFailedException(implode(', ', $warnMsg));
} else {
// Check (plant_id, name)
$existingByName = WorkGroupMaster::where('plant_id', $plantId)
->where('name', $this->data['name'])
->first();
// $existingByName = WorkGroupMaster::where('plant_id', $plantId)
// ->where('name', $groupWorkCenter)
// ->first();
if ($existingByName) {
throw new RowImportFailedException('Work group name already exists for this plant!');
}
// if ($existingByName) {
// throw new RowImportFailedException('Group work center already exists for this plant!');
// }
// Check (plant_id, operation_number)
$existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
->where('operation_number', $this->data['operation_number'])
->where('name', $this->data['name'])
->first();
// $existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
// ->where('operation_number', $opNo)
// ->where('name', $groupWorkCenter)
// ->first();
if ($existingByOpNum) {
throw new RowImportFailedException('Operation number already exists for this plant!');
}
// if ($existingByOpNum) {
// throw new RowImportFailedException('Operation number already exists for this plant!');
// }
// Check (plant_id)
$existingByOperator = WorkGroupMaster::where('plant_id', $plantId)
->where('name', $this->data['name'])
$existingByOperator = WorkGroupMaster::whereNot('plant_id', $plantId)
->where('name', $groupWorkCenter)
->first();
if ($existingByOperator) {
throw new RowImportFailedException('Already work group name assigned to another plant!');
throw new RowImportFailedException('Already group work center assigned to another plant!');
}
}
WorkGroupMaster::updateOrCreate([
'plant_id' => $plantId,
'name' => $this->data['name'],
'description' => $this->data['description'],
'operation_number' => $this->data['operation_number'],
'created_by' => $this->data['created_by'],
]);
'name' => $groupWorkCenter,
],
[
'description' => $desc,
'operation_number' => $opNo,
'created_by' => $createdBy,
]
);
return null;