refactor: hapus menu approvals, pindahkan tombol setujui/tolak langsung ke halaman transaksi kas
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Models\ApprovalItem;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
@@ -20,35 +20,61 @@ class ApprovalsTable
|
||||
return $table
|
||||
->columns([
|
||||
TextColumn::make('model_type')->label('Tipe')
|
||||
->formatStateUsing(fn ($state) => class_basename($state)),
|
||||
TextColumn::make('model_id')->label('ID'),
|
||||
TextColumn::make('required_approvals')->label('Dibutuhkan'),
|
||||
TextColumn::make('items_count')->counts('items')->label('Sudah Approve'),
|
||||
->formatStateUsing(fn ($state) => match ($state) {
|
||||
'App\\Models\\CashRecord' => '💰 Transaksi Kas',
|
||||
'App\\Models\\Activity' => '📅 Kegiatan',
|
||||
default => class_basename($state),
|
||||
}),
|
||||
TextColumn::make('subject')
|
||||
->label('Deskripsi')
|
||||
->state(function (Approval $record): string {
|
||||
$subject = $record->approvable;
|
||||
return match (true) {
|
||||
$subject instanceof \App\Models\CashRecord =>
|
||||
$subject->description . ' — Rp ' . number_format($subject->amount, 0, ',', '.'),
|
||||
$subject instanceof \App\Models\Activity =>
|
||||
$subject->title,
|
||||
default => "#{$record->model_id}",
|
||||
};
|
||||
})
|
||||
->limit(50),
|
||||
TextColumn::make('progress')
|
||||
->label('Progress')
|
||||
->state(fn (Approval $record) =>
|
||||
$record->items()->where('decision', 'approve')->count()
|
||||
. ' / ' . $record->required_approvals . ' persetujuan')
|
||||
->badge()->color('info'),
|
||||
TextColumn::make('status')->badge()
|
||||
->color(fn ($state) => match ($state) {
|
||||
'approved' => 'success',
|
||||
'rejected' => 'danger',
|
||||
default => 'warning',
|
||||
})
|
||||
->formatStateUsing(fn ($state) => match ($state) {
|
||||
'approved' => 'Disetujui',
|
||||
'rejected' => 'Ditolak',
|
||||
default => 'Menunggu',
|
||||
}),
|
||||
TextColumn::make('created_at')->label('Dibuat')->date('d M Y'),
|
||||
TextColumn::make('created_at')->label('Dibuat')->date('d M Y')->sortable(),
|
||||
])
|
||||
->defaultSort('created_at', 'desc')
|
||||
->filters([
|
||||
SelectFilter::make('status')->options([
|
||||
'pending' => 'Pending',
|
||||
'pending' => 'Menunggu',
|
||||
'approved' => 'Disetujui',
|
||||
'rejected' => 'Ditolak',
|
||||
]),
|
||||
])
|
||||
->recordActions([
|
||||
ViewAction::make()->label('Detail'),
|
||||
Action::make('approve')
|
||||
->label('Setujui')
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (Approval $record) => $record->status === 'pending')
|
||||
->form([
|
||||
Textarea::make('notes')->label('Catatan')->rows(2),
|
||||
])
|
||||
->visible(fn (Approval $record) => $record->status === 'pending'
|
||||
&& ! $record->items()->where('user_id', auth()->id())->exists())
|
||||
->form([Textarea::make('notes')->label('Catatan')->rows(2)])
|
||||
->action(function (Approval $record, array $data): void {
|
||||
ApprovalItem::create([
|
||||
'approval_id' => $record->id,
|
||||
@@ -56,31 +82,25 @@ class ApprovalsTable
|
||||
'decision' => 'approve',
|
||||
'notes' => $data['notes'] ?? null,
|
||||
]);
|
||||
|
||||
$approveCount = $record->items()->where('decision', 'approve')->count();
|
||||
|
||||
if ($approveCount >= $record->required_approvals) {
|
||||
$count = $record->items()->where('decision', 'approve')->count();
|
||||
if ($count >= $record->required_approvals) {
|
||||
$record->update(['status' => 'approved']);
|
||||
}
|
||||
|
||||
\App\Models\ActivityLog::create([
|
||||
'user_id' => auth()->id(),
|
||||
'action' => 'approved',
|
||||
'model_type' => Approval::class,
|
||||
'model_id' => $record->id,
|
||||
'description' => auth()->user()->name . " menyetujui " . class_basename($record->model_type) . " #{$record->model_id}",
|
||||
'description' => auth()->user()->name . " menyetujui persetujuan #{$record->id}",
|
||||
]);
|
||||
}),
|
||||
|
||||
Action::make('reject')
|
||||
->label('Tolak')
|
||||
->icon('heroicon-o-x-circle')
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->visible(fn (Approval $record) => $record->status === 'pending')
|
||||
->form([
|
||||
Textarea::make('notes')->label('Alasan Penolakan')->required()->rows(2),
|
||||
])
|
||||
->visible(fn (Approval $record) => $record->status === 'pending'
|
||||
&& ! $record->items()->where('user_id', auth()->id())->exists())
|
||||
->form([Textarea::make('notes')->label('Alasan Penolakan')->required()->rows(2)])
|
||||
->action(function (Approval $record, array $data): void {
|
||||
ApprovalItem::create([
|
||||
'approval_id' => $record->id,
|
||||
@@ -88,19 +108,15 @@ class ApprovalsTable
|
||||
'decision' => 'reject',
|
||||
'notes' => $data['notes'],
|
||||
]);
|
||||
|
||||
$record->update(['status' => 'rejected']);
|
||||
|
||||
\App\Models\ActivityLog::create([
|
||||
'user_id' => auth()->id(),
|
||||
'action' => 'rejected',
|
||||
'model_type' => Approval::class,
|
||||
'model_id' => $record->id,
|
||||
'description' => auth()->user()->name . " menolak " . class_basename($record->model_type) . " #{$record->model_id}",
|
||||
'description' => auth()->user()->name . " menolak persetujuan #{$record->id}",
|
||||
]);
|
||||
}),
|
||||
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([BulkActionGroup::make([DeleteBulkAction::make()])]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user