2026-04-03 04:22:34 +07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Filament\Resources\Activities\Tables;
|
|
|
|
|
|
2026-04-04 07:35:52 +07:00
|
|
|
use App\Models\Activity;
|
2026-04-03 04:34:21 +07:00
|
|
|
use Filament\Actions\Action;
|
2026-04-03 04:22:34 +07:00
|
|
|
use Filament\Actions\BulkActionGroup;
|
|
|
|
|
use Filament\Actions\DeleteBulkAction;
|
|
|
|
|
use Filament\Actions\EditAction;
|
|
|
|
|
use Filament\Tables\Columns\TextColumn;
|
|
|
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
|
|
|
use Filament\Tables\Table;
|
|
|
|
|
|
|
|
|
|
class ActivitiesTable
|
|
|
|
|
{
|
|
|
|
|
public static function configure(Table $table): Table
|
|
|
|
|
{
|
|
|
|
|
return $table
|
2026-04-04 07:35:52 +07:00
|
|
|
->modifyQueryUsing(function ($query) {
|
2026-04-04 09:44:14 +07:00
|
|
|
if (! auth()->user()->can('ViewDraft:Activity')) {
|
2026-04-04 07:35:52 +07:00
|
|
|
$query->where(fn ($q) => $q
|
|
|
|
|
->where('status', '!=', 'draft')
|
|
|
|
|
->orWhere('created_by', auth()->id())
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
})
|
2026-04-03 04:22:34 +07:00
|
|
|
->columns([
|
|
|
|
|
TextColumn::make('title')->label('Judul')->searchable()->sortable(),
|
|
|
|
|
TextColumn::make('start_date')->label('Mulai')->date('d M Y')->sortable(),
|
|
|
|
|
TextColumn::make('end_date')->label('Selesai')->date('d M Y'),
|
|
|
|
|
TextColumn::make('status')->badge()
|
|
|
|
|
->color(fn ($state) => match ($state) {
|
|
|
|
|
'approved' => 'success',
|
|
|
|
|
'rejected' => 'danger',
|
|
|
|
|
'pending' => 'warning',
|
|
|
|
|
default => 'gray',
|
|
|
|
|
}),
|
|
|
|
|
TextColumn::make('creator.name')->label('Dibuat Oleh'),
|
|
|
|
|
])
|
|
|
|
|
->filters([
|
|
|
|
|
SelectFilter::make('status')->options([
|
|
|
|
|
'draft' => 'Draft',
|
|
|
|
|
'pending' => 'Pending',
|
|
|
|
|
'approved' => 'Disetujui',
|
|
|
|
|
'rejected' => 'Ditolak',
|
|
|
|
|
]),
|
|
|
|
|
])
|
2026-04-03 04:34:21 +07:00
|
|
|
->recordActions([
|
|
|
|
|
EditAction::make(),
|
|
|
|
|
Action::make('submit')
|
|
|
|
|
->label('Ajukan')
|
|
|
|
|
->icon('heroicon-o-paper-airplane')
|
|
|
|
|
->color('info')
|
|
|
|
|
->requiresConfirmation()
|
|
|
|
|
->visible(fn ($record) => $record->status === 'draft')
|
|
|
|
|
->action(fn ($record) => $record->update(['status' => 'pending'])),
|
|
|
|
|
Action::make('approve')
|
|
|
|
|
->label('Setujui')
|
|
|
|
|
->icon('heroicon-o-check-circle')
|
|
|
|
|
->color('success')
|
|
|
|
|
->requiresConfirmation()
|
2026-04-04 07:35:52 +07:00
|
|
|
->visible(fn ($record) => $record->status === 'pending'
|
2026-04-04 09:44:14 +07:00
|
|
|
&& auth()->user()->can('Update:Activity'))
|
2026-04-03 04:34:21 +07:00
|
|
|
->action(fn ($record) => $record->update([
|
|
|
|
|
'status' => 'approved',
|
|
|
|
|
'approved_by' => auth()->id(),
|
|
|
|
|
'approved_at' => now(),
|
|
|
|
|
])),
|
|
|
|
|
Action::make('reject')
|
|
|
|
|
->label('Tolak')
|
|
|
|
|
->icon('heroicon-o-x-circle')
|
|
|
|
|
->color('danger')
|
|
|
|
|
->requiresConfirmation()
|
2026-04-04 07:35:52 +07:00
|
|
|
->visible(fn ($record) => $record->status === 'pending'
|
2026-04-04 09:44:14 +07:00
|
|
|
&& auth()->user()->can('Update:Activity'))
|
2026-04-03 04:34:21 +07:00
|
|
|
->action(fn ($record) => $record->update(['status' => 'rejected'])),
|
|
|
|
|
])
|
2026-04-03 04:22:34 +07:00
|
|
|
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
|
|
|
|
}
|
|
|
|
|
}
|