78 lines
1.9 KiB
PHP
78 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Spatie\Activitylog\Support\LogOptions;
|
|
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
|
|
|
class ReportingCycle extends Model
|
|
{
|
|
use HasFactory, LogsActivity;
|
|
|
|
protected $fillable = [
|
|
'renewal_year',
|
|
'reporting_year',
|
|
'period_start',
|
|
'period_end',
|
|
'cut_off_date',
|
|
'licence_period_year',
|
|
'checklist_template_id',
|
|
'status',
|
|
'catatan',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'renewal_year' => 'integer',
|
|
'reporting_year' => 'integer',
|
|
'period_start' => 'date',
|
|
'period_end' => 'date',
|
|
'cut_off_date' => 'date',
|
|
'licence_period_year' => 'integer',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Peraturan perniagaan: tahun pelaporan = tahun pembaharuan - 2.
|
|
* Cth: pembaharuan 2028 => pelaporan 2026.
|
|
*/
|
|
public static function reportingYearFor(int $renewalYear): int
|
|
{
|
|
return $renewalYear - 2;
|
|
}
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logOnly(['renewal_year', 'reporting_year', 'cut_off_date', 'status'])
|
|
->logOnlyDirty()
|
|
->dontLogEmptyChanges()
|
|
->useLogName('kitaran_pelaporan');
|
|
}
|
|
|
|
public function checklistTemplate(): BelongsTo
|
|
{
|
|
return $this->belongsTo(ChecklistTemplate::class);
|
|
}
|
|
|
|
public function submissions(): HasMany
|
|
{
|
|
return $this->hasMany(Submission::class);
|
|
}
|
|
|
|
public function scopeAktif($query)
|
|
{
|
|
return $query->where('status', 'aktif');
|
|
}
|
|
|
|
public function isOverdue(): bool
|
|
{
|
|
return $this->cut_off_date && now()->startOfDay()->gt($this->cut_off_date);
|
|
}
|
|
}
|