Added 11 default line types and Row Number column and Exporter func. and View rights for Import / Export

This commit is contained in:
dhanabalan
2025-05-28 16:50:14 +05:30
parent 68dd7d2a7a
commit 6477c7d47a

View File

@@ -2,10 +2,12 @@
namespace App\Filament\Resources;
use App\Filament\Exports\LineExporter;
use App\Filament\Imports\LineImporter;
use App\Filament\Resources\LineResource\Pages;
use App\Filament\Resources\LineResource\RelationManagers;
use App\Models\Line;
use Filament\Facades\Filament;
use Filament\Forms;
use Filament\Forms\Form;
use Filament\Forms\Get;
@@ -16,6 +18,7 @@ use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Filament\Forms\Components\Section;
use Filament\Tables\Actions\ExportAction;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Unique;
@@ -115,9 +118,44 @@ class LineResource extends Resource
->where('plant_id', $get('plant_id'))
->ignore($get('id')); // Ignore current record during updates
}),
Forms\Components\TextInput::make('type')
// Forms\Components\TextInput::make('type')
// ->required()
// ->placeholder('Scan the valid type')
// ->reactive()
// ->afterStateUpdated(function ($state, callable $set, callable $get) {
// $lineTyp = $get('type');
// // Ensure `linestop_id` is not cleared
// if (!$lineTyp) {
// $set('lTypeError', 'Scan the valid type.');
// return;
// }
// else
// {
// $set('lTypeError', null);
// }
// })
// ->extraAttributes(fn ($get) => [
// 'class' => $get('lTypeError') ? 'border-red-500' : '',
// ])
// ->hint(fn ($get) => $get('lTypeError') ? $get('lTypeError') : null)
// ->hintColor('danger'),
Forms\Components\Select::make('type')
->label('Type')
->required()
->placeholder('Scan the valid type')
->options([
'Sub Assembly Serial' => 'Sub Assembly Serial',
'Sub Assembly Lot' => 'Sub Assembly Lot',
'Base FG Line' => 'Base FG Line',
'SFG Line' => 'SFG Line',
'FG Line' => 'FG Line',
'Machining Cell' => 'Machining Cell',
'Blanking Cell' => 'Blanking Cell',
'Forming Cell' => 'Forming Cell',
'Welding Cell' => 'Welding Cell',
'Die-Casting Cell' => 'Die-Casting Cell',
'Brazzing Cell' => 'Brazzing Cell',
])
->searchable()
->reactive()
->afterStateUpdated(function ($state, callable $set, callable $get) {
$lineTyp = $get('type');
@@ -148,29 +186,48 @@ class LineResource extends Resource
{
return $table
->columns([
Tables\Columns\TextColumn::make('id')
->label('ID')
->numeric()
->sortable(),
// Tables\Columns\TextColumn::make('id')
// ->label('ID')
// ->numeric()
// ->sortable(),
Tables\Columns\TextColumn::make('No.')
->label('No.')
->getStateUsing(function ($record, $livewire, $column, $rowLoop) {
$paginator = $livewire->getTableRecords();
$perPage = method_exists($paginator, 'perPage') ? $paginator->perPage() : 10;
$currentPage = method_exists($paginator, 'currentPage') ? $paginator->currentPage() : 1;
return ($currentPage - 1) * $perPage + $rowLoop->iteration;
}),
Tables\Columns\TextColumn::make('name')
->label('Line')
->alignCenter()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('type')
->label('Type')
->alignCenter()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('plant.name')
->label('Plant')
->alignCenter()
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('created_at')
->label('Created At')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
->alignCenter()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->label('Updated At')
->dateTime()
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
Tables\Columns\TextColumn::make('deleted_at')
->label('Deleted At')
->dateTime()
->alignCenter()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
@@ -190,7 +247,15 @@ class LineResource extends Resource
])
->headerActions([
ImportAction::make()
->importer(LineImporter::class),
->importer(LineImporter::class)
->visible(function() {
return Filament::auth()->user()->can('view import line');
}),
ExportAction::make()
->exporter(LineExporter::class)
->visible(function() {
return Filament::auth()->user()->can('view export line');
}),
]);
}