101 lines
4.0 KiB
PHP
101 lines
4.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Filament\Resources\ActivityLogs\Tables;
|
|
|
|
use App\Models\Bonus;
|
|
use App\Models\Department;
|
|
use App\Models\DisciplinaryReport;
|
|
use App\Models\Employee;
|
|
use App\Models\User;
|
|
use App\Models\Vacation;
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Forms\Components\DatePicker;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\Filter;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
class ActivityLogsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('created_at')
|
|
->label(__('hr.fields.date'))
|
|
->dateTime()
|
|
->sortable(),
|
|
TextColumn::make('description')
|
|
->searchable()
|
|
->limit(50),
|
|
TextColumn::make('event')
|
|
->badge()
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('subject_type')
|
|
->label(__('hr.fields.subject_type'))
|
|
->formatStateUsing(fn (?string $state): string => $state ? class_basename($state) : '—')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('subject_id')
|
|
->label(__('hr.fields.subject_id'))
|
|
->sortable(),
|
|
TextColumn::make('causer.name')
|
|
->label(__('hr.fields.causer'))
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('log_name')
|
|
->toggleable(isToggledHiddenByDefault: true),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
SelectFilter::make('subject_type')
|
|
->label(__('hr.fields.subject_type'))
|
|
->options([
|
|
Employee::class => __('hr.audit.employee'),
|
|
Vacation::class => __('hr.audit.vacation'),
|
|
Bonus::class => __('hr.audit.bonus'),
|
|
DisciplinaryReport::class => __('hr.audit.disciplinary_report'),
|
|
Department::class => __('hr.audit.department'),
|
|
User::class => __('hr.audit.user'),
|
|
]),
|
|
SelectFilter::make('event')
|
|
->options(fn (): array => \Spatie\Activitylog\Models\Activity::query()
|
|
->whereNotNull('event')
|
|
->distinct()
|
|
->pluck('event', 'event')
|
|
->all()),
|
|
SelectFilter::make('causer')
|
|
->label(__('hr.fields.causer'))
|
|
->relationship('causer', 'name')
|
|
->searchable()
|
|
->preload(),
|
|
Filter::make('created_at')
|
|
->schema([
|
|
DatePicker::make('from')
|
|
->label(__('hr.fields.from')),
|
|
DatePicker::make('until')
|
|
->label(__('hr.fields.until')),
|
|
])
|
|
->query(function (Builder $query, array $data): Builder {
|
|
return $query
|
|
->when(
|
|
$data['from'] ?? null,
|
|
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '>=', $date),
|
|
)
|
|
->when(
|
|
$data['until'] ?? null,
|
|
fn (Builder $query, string $date): Builder => $query->whereDate('created_at', '<=', $date),
|
|
);
|
|
}),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
])
|
|
->toolbarActions([]);
|
|
}
|
|
}
|