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
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:
@@ -25,15 +25,15 @@ class WorkGroupMasterExporter extends Exporter
|
||||
ExportColumn::make('plant.code')
|
||||
->label('PLANT CODE'),
|
||||
ExportColumn::make('name')
|
||||
->label('WORK GROUP NAME'),
|
||||
->label('GROUP WORK CENTER'),
|
||||
ExportColumn::make('description')
|
||||
->label('WORK GROUP DESCRIPTION'),
|
||||
->label('DESCRIPTION'),
|
||||
ExportColumn::make('operation_number')
|
||||
->label('OPERATION NUMBER'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('created_at')
|
||||
->label('CREATED AT'),
|
||||
ExportColumn::make('created_by')
|
||||
->label('CREATED BY'),
|
||||
ExportColumn::make('updated_at')
|
||||
->label('UPDATED AT'),
|
||||
ExportColumn::make('deleted_at')
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Forms\Components\Section;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\Forms\Get;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables;
|
||||
use Filament\Tables\Actions\ExportAction;
|
||||
@@ -37,7 +38,7 @@ class WorkGroupMasterResource extends Resource
|
||||
Section::make('')
|
||||
->schema([
|
||||
Forms\Components\Select::make('plant_id')
|
||||
->label('Plant')
|
||||
->label('Plant Name')
|
||||
->relationship('plant', 'name')
|
||||
->reactive()
|
||||
->columnSpan(1)
|
||||
@@ -47,6 +48,10 @@ class WorkGroupMasterResource extends Resource
|
||||
|
||||
return ($userHas && strlen($userHas) > 0) ? Plant::where('id', $userHas)->pluck('name', 'id')->toArray() : Plant::orderBy('code')->pluck('name', 'id')->toArray();
|
||||
})
|
||||
->default(function () {
|
||||
return optional(WorkGroupMaster::latest()->first())->plant_id;
|
||||
})
|
||||
->disabled(fn (Get $get) => ! empty($get('id')))
|
||||
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||
$plantId = $get('plant_id');
|
||||
|
||||
@@ -68,7 +73,7 @@ class WorkGroupMasterResource extends Resource
|
||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||
->hintColor('danger'),
|
||||
Forms\Components\TextInput::make('name')
|
||||
->label('Name')
|
||||
->label('Group Work Center')
|
||||
->required()
|
||||
->minLength(6)
|
||||
->columnSpan(1)
|
||||
@@ -119,12 +124,12 @@ class WorkGroupMasterResource extends Resource
|
||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||
}),
|
||||
Tables\Columns\TextColumn::make('plant.name')
|
||||
->label('Plant')
|
||||
->label('Plant Name')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('name')
|
||||
->label('Name')
|
||||
->label('Group Work Center')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
@@ -138,23 +143,21 @@ class WorkGroupMasterResource extends Resource
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_by')
|
||||
->label('Created By')
|
||||
->alignCenter()
|
||||
->searchable()
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('created_at')
|
||||
->label('Created At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
Tables\Columns\TextColumn::make('updated_at')
|
||||
->label('Updated At')
|
||||
->alignCenter()
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
->sortable(),
|
||||
Tables\Columns\TextColumn::make('deleted_at')
|
||||
->label('Deleted At')
|
||||
->alignCenter()
|
||||
|
||||
Reference in New Issue
Block a user