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')
|
ExportColumn::make('plant.code')
|
||||||
->label('PLANT CODE'),
|
->label('PLANT CODE'),
|
||||||
ExportColumn::make('name')
|
ExportColumn::make('name')
|
||||||
->label('WORK GROUP NAME'),
|
->label('GROUP WORK CENTER'),
|
||||||
ExportColumn::make('description')
|
ExportColumn::make('description')
|
||||||
->label('WORK GROUP DESCRIPTION'),
|
->label('DESCRIPTION'),
|
||||||
ExportColumn::make('operation_number')
|
ExportColumn::make('operation_number')
|
||||||
->label('OPERATION NUMBER'),
|
->label('OPERATION NUMBER'),
|
||||||
ExportColumn::make('created_by')
|
|
||||||
->label('CREATED BY'),
|
|
||||||
ExportColumn::make('created_at')
|
ExportColumn::make('created_at')
|
||||||
->label('CREATED AT'),
|
->label('CREATED AT'),
|
||||||
|
ExportColumn::make('created_by')
|
||||||
|
->label('CREATED BY'),
|
||||||
ExportColumn::make('updated_at')
|
ExportColumn::make('updated_at')
|
||||||
->label('UPDATED AT'),
|
->label('UPDATED AT'),
|
||||||
ExportColumn::make('deleted_at')
|
ExportColumn::make('deleted_at')
|
||||||
|
|||||||
@@ -27,15 +27,15 @@ class WorkGroupMasterImporter extends Importer
|
|||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('name')
|
ImportColumn::make('name')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Work Group Name')
|
->exampleHeader('Group Work Center')
|
||||||
->example('RMGCEABC')
|
->example('RMGCEABC')
|
||||||
->label('Work Group Name')
|
->label('Group Work Center')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('description')
|
ImportColumn::make('description')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
->exampleHeader('Work Group Description')
|
->exampleHeader('Description')
|
||||||
->example('Testing Model 1')
|
->example('Testing Model 1')
|
||||||
->label('Work Group Description')
|
->label('Description')
|
||||||
->rules(['required']),
|
->rules(['required']),
|
||||||
ImportColumn::make('operation_number')
|
ImportColumn::make('operation_number')
|
||||||
->requiredMapping()
|
->requiredMapping()
|
||||||
@@ -60,85 +60,92 @@ class WorkGroupMasterImporter extends Importer
|
|||||||
// ]);
|
// ]);
|
||||||
$warnMsg = [];
|
$warnMsg = [];
|
||||||
$plantCod = $this->data['plant'];
|
$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;
|
$plantId = null;
|
||||||
|
|
||||||
if (Str::length($plantCod) < 4 || ! is_numeric($plantCod) || ! preg_match('/^[1-9]\d{3,}$/', $plantCod)) {
|
if (! $plantCod || $plantCod == null || $plantCod == '') {
|
||||||
$warnMsg[] = 'Invalid plant code found';
|
$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 {
|
} else {
|
||||||
$plant = Plant::where('code', $plantCod)->first();
|
$plant = Plant::where('code', $plantCod)->first();
|
||||||
if (! $plant) {
|
if (! $plant) {
|
||||||
$warnMsg[] = 'Plant not found';
|
$warnMsg[] = "Plant code '{$plantCod}' not found!";
|
||||||
} else {
|
} else {
|
||||||
$plantId = $plant->id;
|
$plantId = $plant->id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length($this->data['name']) <= 0) { // || !ctype_alnum($this->data['description'])
|
if (Str::length($groupWorkCenter) <= 0) { // || !ctype_alnum($desc)
|
||||||
$warnMsg[] = 'Invalid work group name found';
|
$warnMsg[] = 'Invalid group work center found!';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Str::length(trim($this->data['description'])) <= 0) {
|
if (Str::length(trim($desc)) <= 0) {
|
||||||
$warnMsg[] = 'Invalid work group description found';
|
$warnMsg[] = 'Invalid description found!';
|
||||||
}
|
}
|
||||||
|
|
||||||
$desc = trim($this->data['description']);
|
|
||||||
|
|
||||||
if (Str::length($desc) > 44) {
|
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) {
|
if (Str::length($opNo) <= 0) {
|
||||||
$warnMsg[] = 'Invalid operation number found';
|
$warnMsg[] = 'Invalid operation number found!';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! is_numeric($this->data['operation_number'])) {
|
if (! is_numeric($opNo)) {
|
||||||
$warnMsg[] = 'Invalid operation number found must be numeric';
|
$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) {
|
if (! $user) {
|
||||||
$warnMsg[] = 'Operator ID not found';
|
$warnMsg[] = "Operator ID '{$createdBy}' not found!";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! empty($warnMsg)) {
|
if (! empty($warnMsg)) {
|
||||||
throw new RowImportFailedException(implode(', ', $warnMsg));
|
throw new RowImportFailedException(implode(', ', $warnMsg));
|
||||||
} else {
|
} else {
|
||||||
// Check (plant_id, name)
|
// Check (plant_id, name)
|
||||||
$existingByName = WorkGroupMaster::where('plant_id', $plantId)
|
// $existingByName = WorkGroupMaster::where('plant_id', $plantId)
|
||||||
->where('name', $this->data['name'])
|
// ->where('name', $groupWorkCenter)
|
||||||
->first();
|
// ->first();
|
||||||
|
|
||||||
if ($existingByName) {
|
// if ($existingByName) {
|
||||||
throw new RowImportFailedException('Work group name already exists for this plant!');
|
// throw new RowImportFailedException('Group work center already exists for this plant!');
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check (plant_id, operation_number)
|
// Check (plant_id, operation_number)
|
||||||
$existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
|
// $existingByOpNum = WorkGroupMaster::where('plant_id', $plantId)
|
||||||
->where('operation_number', $this->data['operation_number'])
|
// ->where('operation_number', $opNo)
|
||||||
->where('name', $this->data['name'])
|
// ->where('name', $groupWorkCenter)
|
||||||
->first();
|
// ->first();
|
||||||
|
|
||||||
if ($existingByOpNum) {
|
// if ($existingByOpNum) {
|
||||||
throw new RowImportFailedException('Operation number already exists for this plant!');
|
// throw new RowImportFailedException('Operation number already exists for this plant!');
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Check (plant_id)
|
// Check (plant_id)
|
||||||
$existingByOperator = WorkGroupMaster::where('plant_id', $plantId)
|
$existingByOperator = WorkGroupMaster::whereNot('plant_id', $plantId)
|
||||||
->where('name', $this->data['name'])
|
->where('name', $groupWorkCenter)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($existingByOperator) {
|
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([
|
WorkGroupMaster::updateOrCreate([
|
||||||
'plant_id' => $plantId,
|
'plant_id' => $plantId,
|
||||||
'name' => $this->data['name'],
|
'name' => $groupWorkCenter,
|
||||||
'description' => $this->data['description'],
|
],
|
||||||
'operation_number' => $this->data['operation_number'],
|
[
|
||||||
'created_by' => $this->data['created_by'],
|
'description' => $desc,
|
||||||
]);
|
'operation_number' => $opNo,
|
||||||
|
'created_by' => $createdBy,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ use Filament\Facades\Filament;
|
|||||||
use Filament\Forms;
|
use Filament\Forms;
|
||||||
use Filament\Forms\Components\Section;
|
use Filament\Forms\Components\Section;
|
||||||
use Filament\Forms\Form;
|
use Filament\Forms\Form;
|
||||||
|
use Filament\Forms\Get;
|
||||||
use Filament\Resources\Resource;
|
use Filament\Resources\Resource;
|
||||||
use Filament\Tables;
|
use Filament\Tables;
|
||||||
use Filament\Tables\Actions\ExportAction;
|
use Filament\Tables\Actions\ExportAction;
|
||||||
@@ -37,7 +38,7 @@ class WorkGroupMasterResource extends Resource
|
|||||||
Section::make('')
|
Section::make('')
|
||||||
->schema([
|
->schema([
|
||||||
Forms\Components\Select::make('plant_id')
|
Forms\Components\Select::make('plant_id')
|
||||||
->label('Plant')
|
->label('Plant Name')
|
||||||
->relationship('plant', 'name')
|
->relationship('plant', 'name')
|
||||||
->reactive()
|
->reactive()
|
||||||
->columnSpan(1)
|
->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();
|
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) {
|
->afterStateUpdated(function ($state, $set, callable $get) {
|
||||||
$plantId = $get('plant_id');
|
$plantId = $get('plant_id');
|
||||||
|
|
||||||
@@ -68,7 +73,7 @@ class WorkGroupMasterResource extends Resource
|
|||||||
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
->hint(fn ($get) => $get('pqPlantError') ? $get('pqPlantError') : null)
|
||||||
->hintColor('danger'),
|
->hintColor('danger'),
|
||||||
Forms\Components\TextInput::make('name')
|
Forms\Components\TextInput::make('name')
|
||||||
->label('Name')
|
->label('Group Work Center')
|
||||||
->required()
|
->required()
|
||||||
->minLength(6)
|
->minLength(6)
|
||||||
->columnSpan(1)
|
->columnSpan(1)
|
||||||
@@ -119,12 +124,12 @@ class WorkGroupMasterResource extends Resource
|
|||||||
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
|
||||||
}),
|
}),
|
||||||
Tables\Columns\TextColumn::make('plant.name')
|
Tables\Columns\TextColumn::make('plant.name')
|
||||||
->label('Plant')
|
->label('Plant Name')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('name')
|
Tables\Columns\TextColumn::make('name')
|
||||||
->label('Name')
|
->label('Group Work Center')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
@@ -138,23 +143,21 @@ class WorkGroupMasterResource extends Resource
|
|||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
|
Tables\Columns\TextColumn::make('created_at')
|
||||||
|
->label('Created At')
|
||||||
|
->alignCenter()
|
||||||
|
->dateTime()
|
||||||
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('created_by')
|
Tables\Columns\TextColumn::make('created_by')
|
||||||
->label('Created By')
|
->label('Created By')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->searchable()
|
->searchable()
|
||||||
->sortable(),
|
->sortable(),
|
||||||
Tables\Columns\TextColumn::make('created_at')
|
|
||||||
->label('Created At')
|
|
||||||
->alignCenter()
|
|
||||||
->dateTime()
|
|
||||||
->sortable()
|
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
|
||||||
Tables\Columns\TextColumn::make('updated_at')
|
Tables\Columns\TextColumn::make('updated_at')
|
||||||
->label('Updated At')
|
->label('Updated At')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
->dateTime()
|
->dateTime()
|
||||||
->sortable()
|
->sortable(),
|
||||||
->toggleable(isToggledHiddenByDefault: true),
|
|
||||||
Tables\Columns\TextColumn::make('deleted_at')
|
Tables\Columns\TextColumn::make('deleted_at')
|
||||||
->label('Deleted At')
|
->label('Deleted At')
|
||||||
->alignCenter()
|
->alignCenter()
|
||||||
|
|||||||
Reference in New Issue
Block a user