Updated validation logic against created_by and updated_by columns on importer #363
@@ -146,6 +146,11 @@ class ProcessOrderImporter extends Importer
|
||||
$reworkStatus = 0;
|
||||
}
|
||||
|
||||
if ($createdBy == null || $createdBy == '') {
|
||||
$createdBy = Filament::auth()->user()?->name;
|
||||
$updatedBy = $createdBy;
|
||||
}
|
||||
|
||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
||||
$warnMsg[] = 'Invalid plant code found';
|
||||
} else {
|
||||
@@ -204,10 +209,22 @@ class ProcessOrderImporter extends Importer
|
||||
$lineId = null;
|
||||
}
|
||||
|
||||
// $user = User::where('name', $this->data['created_by'])->first();
|
||||
// if (! $user) {
|
||||
// $warnMsg[] = 'User not found';
|
||||
// }
|
||||
if ($createdBy != null && $createdBy != '') {
|
||||
if ($plantId) {
|
||||
$user = User::where('name', $createdBy)->first();
|
||||
|
||||
$userPlant = User::where('name', $createdBy)->where('plant_id', $plantId)->first();
|
||||
|
||||
if (! $user) {
|
||||
$warnMsg[] = 'Created By user name not found!';
|
||||
} elseif (! $userPlant && ! $user->hasRole('Super Admin')) {
|
||||
$warnMsg[] = "Created By user '{$createdBy}' not found for Plant '{$plantCod}'!";
|
||||
} elseif (! $user->hasRole(['Super Admin', 'Process Quality Manager', 'Process Manager', 'Process Supervisor', 'Process Employee'])) {
|
||||
$warnMsg[] = 'Created By user does not have rights!';
|
||||
}
|
||||
}
|
||||
$updatedBy = Filament::auth()->user()?->name;
|
||||
}
|
||||
|
||||
if (! empty($warnMsg)) {
|
||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||
|
||||
Reference in New Issue
Block a user