fix: tambah notifikasi ke ketua saat transaksi butuh persetujuan, dan ke bendahara setelah disetujui/ditolak

This commit is contained in:
2026-04-03 08:12:12 +07:00
parent e246c1ff9e
commit cd2fa2d350
2 changed files with 35 additions and 3 deletions
@@ -6,6 +6,7 @@ use App\Models\Approval;
use App\Models\ApprovalItem;
use App\Models\CashCategory;
use App\Models\CashRecord;
use App\Services\NotificationService;
use Filament\Actions\Action;
use Filament\Actions\BulkActionGroup;
use Filament\Actions\DeleteBulkAction;
@@ -83,6 +84,14 @@ class CashRecordsTable
'notes' => $data['notes'] ?? null,
]);
$approval->update(['status' => 'approved']);
NotificationService::send(
$record->creator,
'Transaksi Kas Disetujui',
"Transaksi \"{$record->description}\" senilai Rp " . number_format($record->amount, 0, ',', '.') . " telah disetujui. Silakan lakukan verifikasi.",
'success',
route('filament.admin.resources.cash-records.index')
);
}),
// Ketua: tolak transaksi 500rb2jt
@@ -108,6 +117,14 @@ class CashRecordsTable
'notes' => $data['notes'],
]);
$approval->update(['status' => 'rejected']);
NotificationService::send(
$record->creator,
'Transaksi Kas Ditolak',
"Transaksi \"{$record->description}\" ditolak: {$data['notes']}",
'danger',
route('filament.admin.resources.cash-records.index')
);
}),
// Bendahara/ketua: verifikasi (hanya jika approval sudah selesai atau tidak diperlukan)
+18 -3
View File
@@ -6,6 +6,7 @@ use App\Models\ActivityLog;
use App\Models\Approval;
use App\Models\CashRecord;
use App\Models\Vote;
use App\Services\NotificationService;
use Illuminate\Support\Facades\Auth;
class CashRecordObserver
@@ -20,17 +21,24 @@ class CashRecordObserver
'description' => "Transaksi kas baru: {$record->description} sebesar Rp " . number_format($record->amount, 0, ',', '.'),
]);
// Threshold: 500rb2jt → buat approval ketua
// Threshold: 500rb2jt → buat approval ketua + notif
if ($record->amount >= 500_000 && $record->amount <= 2_000_000) {
Approval::create([
$approval = Approval::create([
'model_type' => CashRecord::class,
'model_id' => $record->id,
'required_approvals' => 1,
'status' => 'pending',
]);
NotificationService::toRole('ketua',
'Transaksi Kas Butuh Persetujuan',
"Transaksi \"{$record->description}\" senilai Rp " . number_format($record->amount, 0, ',', '.') . " menunggu persetujuan Anda.",
'warning',
route('filament.admin.resources.cash-records.index')
);
}
// Threshold: > 2jt → buat voting
// Threshold: > 2jt → buat voting + notif semua anggota
if ($record->amount > 2_000_000) {
Vote::create([
'title' => "Persetujuan Transaksi: {$record->description}",
@@ -41,6 +49,13 @@ class CashRecordObserver
'deadline' => now()->addDays(3),
'created_by' => Auth::id(),
]);
NotificationService::toRole('ketua',
'Voting Transaksi Besar Dibuat',
"Transaksi \"{$record->description}\" senilai Rp " . number_format($record->amount, 0, ',', '.') . " memerlukan voting.",
'warning',
route('filament.admin.resources.votes.index')
);
}
}