38 lines
1.4 KiB
PHP
38 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\AppSetting;
|
|
use App\Models\ChecklistTemplate;
|
|
use App\Models\ReportingCycle;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
class ReportingCycleService
|
|
{
|
|
/**
|
|
* Bina atribut kitaran daripada tahun pembaharuan.
|
|
* Peraturan perniagaan:
|
|
* - reporting_year = renewal_year - 2 (cth: pembaharuan 2028 => pelaporan 2026)
|
|
* - tempoh pelaporan: 1 Jan - 31 Dis tahun pelaporan
|
|
* - tarikh tutup lalai: hari/bulan yang dikonfigur JPP, tahun (renewal_year - 1)
|
|
*/
|
|
public function buildAttributes(int $renewalYear, ?string $cutOffDate = null): array
|
|
{
|
|
$reportingYear = ReportingCycle::reportingYearFor($renewalYear);
|
|
|
|
$cutOffDay = (int) AppSetting::get('default_cut_off_day', 1);
|
|
$cutOffMonth = (int) AppSetting::get('default_cut_off_month', 12);
|
|
|
|
// Pembaharuan dibuat sebelum/pada 1 Disember tahun sebelum pembaharuan.
|
|
$defaultCutOff = Carbon::create($renewalYear - 1, $cutOffMonth, $cutOffDay);
|
|
|
|
return [
|
|
'reporting_year' => $reportingYear,
|
|
'period_start' => Carbon::create($reportingYear, 1, 1),
|
|
'period_end' => Carbon::create($reportingYear, 12, 31),
|
|
'cut_off_date' => $cutOffDate ? Carbon::parse($cutOffDate) : $defaultCutOff,
|
|
'checklist_template_id' => ChecklistTemplate::activeTemplate()?->id,
|
|
];
|
|
}
|
|
}
|