feat: tambah budget kegiatan dengan alur threshold approval/voting
This commit is contained in:
@@ -17,6 +17,8 @@ class ActivityForm
|
|||||||
Textarea::make('description')->label('Deskripsi')->rows(3)->columnSpanFull(),
|
Textarea::make('description')->label('Deskripsi')->rows(3)->columnSpanFull(),
|
||||||
DatePicker::make('start_date')->label('Mulai')->required(),
|
DatePicker::make('start_date')->label('Mulai')->required(),
|
||||||
DatePicker::make('end_date')->label('Selesai')->required(),
|
DatePicker::make('end_date')->label('Selesai')->required(),
|
||||||
|
TextInput::make('budget')->label('Estimasi Budget (Rp)')->numeric()
|
||||||
|
->helperText('Kosongkan jika tidak ada budget. < Rp500.000: langsung | Rp500.000–2.000.000: approval ketua | > Rp2.000.000: voting'),
|
||||||
DateTimePicker::make('executed_at')->label('Waktu Pelaksanaan')
|
DateTimePicker::make('executed_at')->label('Waktu Pelaksanaan')
|
||||||
->visible(fn ($record) => $record?->status === 'approved'),
|
->visible(fn ($record) => $record?->status === 'approved'),
|
||||||
Textarea::make('execution_notes')->label('Catatan Pelaksanaan')->rows(3)->columnSpanFull()
|
Textarea::make('execution_notes')->label('Catatan Pelaksanaan')->rows(3)->columnSpanFull()
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Filament\Resources\CashRecords\Schemas;
|
namespace App\Filament\Resources\CashRecords\Schemas;
|
||||||
|
|
||||||
|
use App\Models\Activity;
|
||||||
use App\Models\CashCategory;
|
use App\Models\CashCategory;
|
||||||
use Filament\Forms\Components\DatePicker;
|
use Filament\Forms\Components\DatePicker;
|
||||||
use Filament\Forms\Components\Placeholder;
|
use Filament\Forms\Components\Placeholder;
|
||||||
@@ -27,6 +28,9 @@ class CashRecordForm
|
|||||||
->live(),
|
->live(),
|
||||||
Textarea::make('description')->label('Keterangan')->required()->columnSpanFull(),
|
Textarea::make('description')->label('Keterangan')->required()->columnSpanFull(),
|
||||||
DatePicker::make('date')->label('Tanggal')->required(),
|
DatePicker::make('date')->label('Tanggal')->required(),
|
||||||
|
Select::make('activity_id')->label('Kegiatan Terkait')
|
||||||
|
->options(Activity::whereIn('status', ['approved'])->pluck('title', 'id'))
|
||||||
|
->searchable()->nullable(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|||||||
class Activity extends Model
|
class Activity extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'title', 'description', 'start_date', 'end_date',
|
'title', 'description', 'budget', 'start_date', 'end_date',
|
||||||
'created_by', 'status', 'approved_by', 'approved_at',
|
'created_by', 'status', 'approved_by', 'approved_at',
|
||||||
'executed_at', 'execution_notes',
|
'executed_at', 'execution_notes',
|
||||||
];
|
];
|
||||||
@@ -44,4 +44,9 @@ class Activity extends Model
|
|||||||
return $this->belongsToMany(User::class, 'activity_member')
|
return $this->belongsToMany(User::class, 'activity_member')
|
||||||
->withPivot('status', 'notes');
|
->withPivot('status', 'notes');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cashRecords(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||||
|
{
|
||||||
|
return $this->hasMany(CashRecord::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ namespace App\Models;
|
|||||||
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
use Illuminate\Database\Eloquent\Model;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
|
use App\Models\Activity;
|
||||||
|
|
||||||
class CashRecord extends Model
|
class CashRecord extends Model
|
||||||
{
|
{
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'amount', 'category_id', 'description',
|
'amount', 'category_id', 'activity_id', 'description',
|
||||||
'date', 'created_by', 'verified_by', 'verified_at',
|
'date', 'created_by', 'verified_by', 'verified_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -29,6 +30,11 @@ class CashRecord extends Model
|
|||||||
return $this->belongsTo(CashCategory::class, 'category_id');
|
return $this->belongsTo(CashCategory::class, 'category_id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function activity(): BelongsTo
|
||||||
|
{
|
||||||
|
return $this->belongsTo(Activity::class);
|
||||||
|
}
|
||||||
|
|
||||||
public function creator(): BelongsTo
|
public function creator(): BelongsTo
|
||||||
{
|
{
|
||||||
return $this->belongsTo(User::class, 'created_by');
|
return $this->belongsTo(User::class, 'created_by');
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ namespace App\Observers;
|
|||||||
|
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Models\ActivityLog;
|
use App\Models\ActivityLog;
|
||||||
|
use App\Models\Approval;
|
||||||
|
use App\Models\Vote;
|
||||||
use App\Services\NotificationService;
|
use App\Services\NotificationService;
|
||||||
use Filament\Notifications\Notification;
|
use Filament\Notifications\Notification;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
@@ -42,6 +44,27 @@ class ActivityObserver
|
|||||||
NotificationService::toRole('ketua', 'Kegiatan Menunggu Persetujuan',
|
NotificationService::toRole('ketua', 'Kegiatan Menunggu Persetujuan',
|
||||||
"Kegiatan \"{$activity->title}\" diajukan untuk disetujui.", 'warning',
|
"Kegiatan \"{$activity->title}\" diajukan untuk disetujui.", 'warning',
|
||||||
route('filament.admin.resources.activities.edit', $activity));
|
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) {
|
if (in_array($new, ['approved', 'rejected']) && $activity->creator) {
|
||||||
|
|||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('activities', function (Blueprint $table) {
|
||||||
|
$table->unsignedBigInteger('budget')->nullable()->after('description');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('cash_records', function (Blueprint $table) {
|
||||||
|
$table->foreignId('activity_id')->nullable()->constrained('activities')->nullOnDelete()->after('category_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('cash_records', function (Blueprint $table) {
|
||||||
|
$table->dropForeignIdFor(\App\Models\Activity::class, 'activity_id');
|
||||||
|
$table->dropColumn('activity_id');
|
||||||
|
});
|
||||||
|
|
||||||
|
Schema::table('activities', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('budget');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user