feat: tambah budget kegiatan dengan alur threshold approval/voting
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\Observers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\Approval;
|
||||
use App\Models\Vote;
|
||||
use App\Services\NotificationService;
|
||||
use Filament\Notifications\Notification;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
@@ -42,6 +44,27 @@ class ActivityObserver
|
||||
NotificationService::toRole('ketua', 'Kegiatan Menunggu Persetujuan',
|
||||
"Kegiatan \"{$activity->title}\" diajukan untuk disetujui.", 'warning',
|
||||
route('filament.admin.resources.activities.edit', $activity));
|
||||
|
||||
// Threshold budget
|
||||
$budget = $activity->budget;
|
||||
if ($budget >= 500_000 && $budget <= 2_000_000) {
|
||||
Approval::create([
|
||||
'model_type' => Activity::class,
|
||||
'model_id' => $activity->id,
|
||||
'required_approvals' => 1,
|
||||
'status' => 'pending',
|
||||
]);
|
||||
} elseif ($budget > 2_000_000) {
|
||||
Vote::create([
|
||||
'title' => "Persetujuan Budget Kegiatan: {$activity->title}",
|
||||
'description' => "Budget kegiatan senilai Rp " . number_format($budget, 0, ',', '.') . " memerlukan persetujuan voting.",
|
||||
'type' => 'finance',
|
||||
'related_id' => $activity->id,
|
||||
'status' => 'open',
|
||||
'deadline' => now()->addDays(3),
|
||||
'created_by' => Auth::id() ?? $activity->created_by,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($new, ['approved', 'rejected']) && $activity->creator) {
|
||||
|
||||
Reference in New Issue
Block a user