fix: tambah notifikasi ke ketua saat transaksi butuh persetujuan, dan ke bendahara setelah disetujui/ditolak
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Models\Approval;
|
|||||||
use App\Models\ApprovalItem;
|
use App\Models\ApprovalItem;
|
||||||
use App\Models\CashCategory;
|
use App\Models\CashCategory;
|
||||||
use App\Models\CashRecord;
|
use App\Models\CashRecord;
|
||||||
|
use App\Services\NotificationService;
|
||||||
use Filament\Actions\Action;
|
use Filament\Actions\Action;
|
||||||
use Filament\Actions\BulkActionGroup;
|
use Filament\Actions\BulkActionGroup;
|
||||||
use Filament\Actions\DeleteBulkAction;
|
use Filament\Actions\DeleteBulkAction;
|
||||||
@@ -83,6 +84,14 @@ class CashRecordsTable
|
|||||||
'notes' => $data['notes'] ?? null,
|
'notes' => $data['notes'] ?? null,
|
||||||
]);
|
]);
|
||||||
$approval->update(['status' => 'approved']);
|
$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 500rb–2jt
|
// Ketua: tolak transaksi 500rb–2jt
|
||||||
@@ -108,6 +117,14 @@ class CashRecordsTable
|
|||||||
'notes' => $data['notes'],
|
'notes' => $data['notes'],
|
||||||
]);
|
]);
|
||||||
$approval->update(['status' => 'rejected']);
|
$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)
|
// Bendahara/ketua: verifikasi (hanya jika approval sudah selesai atau tidak diperlukan)
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ use App\Models\ActivityLog;
|
|||||||
use App\Models\Approval;
|
use App\Models\Approval;
|
||||||
use App\Models\CashRecord;
|
use App\Models\CashRecord;
|
||||||
use App\Models\Vote;
|
use App\Models\Vote;
|
||||||
|
use App\Services\NotificationService;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
class CashRecordObserver
|
class CashRecordObserver
|
||||||
@@ -20,17 +21,24 @@ class CashRecordObserver
|
|||||||
'description' => "Transaksi kas baru: {$record->description} sebesar Rp " . number_format($record->amount, 0, ',', '.'),
|
'description' => "Transaksi kas baru: {$record->description} sebesar Rp " . number_format($record->amount, 0, ',', '.'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Threshold: 500rb–2jt → buat approval ketua
|
// Threshold: 500rb–2jt → buat approval ketua + notif
|
||||||
if ($record->amount >= 500_000 && $record->amount <= 2_000_000) {
|
if ($record->amount >= 500_000 && $record->amount <= 2_000_000) {
|
||||||
Approval::create([
|
$approval = Approval::create([
|
||||||
'model_type' => CashRecord::class,
|
'model_type' => CashRecord::class,
|
||||||
'model_id' => $record->id,
|
'model_id' => $record->id,
|
||||||
'required_approvals' => 1,
|
'required_approvals' => 1,
|
||||||
'status' => 'pending',
|
'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) {
|
if ($record->amount > 2_000_000) {
|
||||||
Vote::create([
|
Vote::create([
|
||||||
'title' => "Persetujuan Transaksi: {$record->description}",
|
'title' => "Persetujuan Transaksi: {$record->description}",
|
||||||
@@ -41,6 +49,13 @@ class CashRecordObserver
|
|||||||
'deadline' => now()->addDays(3),
|
'deadline' => now()->addDays(3),
|
||||||
'created_by' => Auth::id(),
|
'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')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user