feat: tambah widget statistik kas dan perbaikan alur verifikasi transaksi
- Tambah CashStatsWidget: total saldo, pemasukan/pengeluaran bulan ini, saldo bulan lalu - Widget hanya tampil di halaman transaksi kas (bukan dashboard) - Hanya transaksi yang sudah diverifikasi masuk ke perhitungan total kas - Perbaiki namespace Action notifikasi (Filament v5) - Perbaiki observer: hapus throw Exception yang menyebabkan widget hilang - Tambah redirect setelah aksi setujui/tolak/verifikasi agar halaman refresh otomatis - Tambah file DOKUMENTASI.md
This commit is contained in:
@@ -61,35 +61,7 @@ class CashRecordObserver
|
||||
|
||||
public function updated(CashRecord $record): void
|
||||
{
|
||||
if ($record->getOriginal('verified_at') !== null) {
|
||||
throw new \Exception('Transaksi yang sudah diverifikasi tidak dapat diubah.');
|
||||
}
|
||||
|
||||
if ($record->wasChanged('verified_by') && $record->verified_by !== null) {
|
||||
// Pastikan threshold terpenuhi sebelum verifikasi
|
||||
if ($record->amount >= 500_000 && $record->amount <= 2_000_000) {
|
||||
$approval = Approval::where('model_type', CashRecord::class)
|
||||
->where('model_id', $record->id)
|
||||
->first();
|
||||
|
||||
if (! $approval || $approval->status !== 'approved') {
|
||||
throw new \Exception('Transaksi ini memerlukan persetujuan ketua sebelum diverifikasi.');
|
||||
}
|
||||
}
|
||||
|
||||
if ($record->amount > 2_000_000) {
|
||||
$vote = Vote::where('type', 'finance')
|
||||
->where('related_id', $record->id)
|
||||
->first();
|
||||
|
||||
$total = $vote?->items()->count() ?? 0;
|
||||
$approve = $vote?->items()->where('choice', 'approve')->count() ?? 0;
|
||||
|
||||
if (! $vote || $vote->status !== 'closed' || $total === 0 || ($approve / $total) <= 0.5) {
|
||||
throw new \Exception('Transaksi ini memerlukan voting dengan mayoritas setuju sebelum diverifikasi.');
|
||||
}
|
||||
}
|
||||
|
||||
ActivityLog::create([
|
||||
'user_id' => Auth::id(),
|
||||
'action' => 'verified',
|
||||
@@ -103,7 +75,13 @@ class CashRecordObserver
|
||||
public function deleting(CashRecord $record): void
|
||||
{
|
||||
if ($record->verified_at !== null) {
|
||||
throw new \Exception('Transaksi yang sudah diverifikasi tidak dapat dihapus.');
|
||||
\Filament\Notifications\Notification::make()
|
||||
->title('Tidak dapat dihapus')
|
||||
->body('Transaksi yang sudah diverifikasi tidak dapat dihapus.')
|
||||
->danger()
|
||||
->send();
|
||||
|
||||
abort(403);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user