Files
hr/app/Filament/Resources/Employees/Tables/EmployeesTable.php
2026-07-31 18:08:08 +05:00

147 lines
5.9 KiB
PHP

<?php
namespace App\Filament\Resources\Employees\Tables;
use App\Enums\EmploymentStatus;
use App\Enums\Gender;
use App\Models\Department;
use App\Models\Employee;
use App\Filament\Support\ExportExcelAction;
use Filament\Actions\BulkAction;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
use Filament\Actions\EditAction;
use Filament\Actions\ForceDeleteBulkAction;
use Filament\Actions\RestoreBulkAction;
use Filament\Actions\ViewAction;
use Filament\Forms\Components\Select;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Filters\SelectFilter;
use Filament\Tables\Filters\TrashedFilter;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Collection;
class EmployeesTable
{
public static function configure(Table $table): Table
{
return $table
->columns([
TextColumn::make('employee_number')
->label(__('hr.fields.number'))
->searchable()
->sortable(),
TextColumn::make('full_name')
->searchable()
->sortable(),
TextColumn::make('national_id')
->label(__('hr.fields.national_id'))
->searchable()
->toggleable(),
TextColumn::make('gender')
->badge()
->color(fn (Gender $state): string => $state->color())
->formatStateUsing(fn (Gender $state): string => $state->label())
->searchable(),
TextColumn::make('phone')
->searchable()
->toggleable(),
TextColumn::make('department.name')
->label(__('hr.fields.department'))
->badge()
->color('info')
->searchable()
->sortable(),
TextColumn::make('position.name')
->label(__('hr.fields.position'))
->badge()
->color('primary')
->searchable()
->sortable(),
TextColumn::make('shift.name')
->label(__('hr.fields.shift'))
->badge()
->color('gray')
->searchable()
->sortable(),
TextColumn::make('employment_status')
->label(__('hr.fields.status'))
->badge()
->color(fn (EmploymentStatus $state): string => $state->color())
->formatStateUsing(fn (EmploymentStatus $state): string => $state->label())
->searchable()
->sortable(),
TextColumn::make('hire_date')
->date()
->sortable(),
TextColumn::make('termination_date')
->date()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('created_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('updated_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
TextColumn::make('deleted_at')
->dateTime()
->sortable()
->toggleable(isToggledHiddenByDefault: true),
])
->filters([
SelectFilter::make('department_id')
->label(__('hr.fields.department'))
->relationship('department', 'name')
->searchable()
->preload(),
SelectFilter::make('position_id')
->label(__('hr.fields.position'))
->relationship('position', 'name')
->searchable()
->preload(),
SelectFilter::make('shift_id')
->label(__('hr.fields.shift'))
->relationship('shift', 'name')
->searchable()
->preload(),
SelectFilter::make('employment_status')
->label(__('hr.fields.employment_status'))
->options(EmploymentStatus::class),
TrashedFilter::make(),
])
->recordActions([
ViewAction::make(),
EditAction::make(),
])
->toolbarActions([
BulkActionGroup::make([
ExportExcelAction::bulk('exportSelected', \App\Exports\EmployeesExport::class, 'employees.xlsx'),
BulkAction::make('changeDepartment')
->label(__('hr.actions.change_department'))
->icon('heroicon-o-building-office-2')
->schema([
Select::make('department_id')
->label(__('hr.fields.department'))
->options(fn (): array => Department::query()->orderBy('name')->pluck('name', 'id')->all())
->searchable()
->required(),
])
->action(function (Collection $records, array $data): void {
$records->each(
fn (Employee $employee) => $employee->update([
'department_id' => $data['department_id'],
]),
);
})
->deselectRecordsAfterCompletion(),
DeleteBulkAction::make(),
ForceDeleteBulkAction::make(),
RestoreBulkAction::make(),
]),
]);
}
}