74 lines
3.0 KiB
PHP
74 lines
3.0 KiB
PHP
<?php
|
|
|
|
namespace Database\Seeders;
|
|
|
|
use App\Models\ChecklistTemplate;
|
|
use App\Models\Consultant;
|
|
use App\Models\DataCentre;
|
|
use App\Models\DataCentreConsultantAssignment;
|
|
use App\Models\ReportingCycle;
|
|
use App\Models\User;
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class DemoDataSeeder extends Seeder
|
|
{
|
|
public function run(): void
|
|
{
|
|
$consultant = Consultant::where('emel', 'perunding@example.com')->first();
|
|
$officer = User::where('email', 'pegawai@mbip.gov.my')->first();
|
|
$template = ChecklistTemplate::activeTemplate();
|
|
|
|
if (! $consultant) {
|
|
return;
|
|
}
|
|
|
|
// Pusat data contoh.
|
|
$dataCentres = [
|
|
['nama_pusat_data' => 'Pusat Data Iskandar 1', 'tajuk_permohonan' => 'Permohonan Lesen Pusat Data Hyperscale Iskandar', 'lokasi_pusat_data' => 'Nusajaya', 'it_load' => 50.00, 'keluasan_tapak' => 12.50],
|
|
['nama_pusat_data' => 'Pusat Data Tebrau Tech Park', 'tajuk_permohonan' => 'Permohonan Lesen Pusat Data Tebrau', 'lokasi_pusat_data' => 'Tebrau', 'it_load' => 30.00, 'keluasan_tapak' => 8.20],
|
|
['nama_pusat_data' => 'Pusat Data Pasir Gudang', 'tajuk_permohonan' => 'Permohonan Lesen Pusat Data Industri', 'lokasi_pusat_data' => 'Pasir Gudang', 'it_load' => 20.00, 'keluasan_tapak' => 5.00],
|
|
];
|
|
|
|
foreach ($dataCentres as $data) {
|
|
$dc = DataCentre::firstOrCreate(
|
|
['nama_pusat_data' => $data['nama_pusat_data']],
|
|
array_merge($data, [
|
|
'alamat' => $data['lokasi_pusat_data'].', Johor',
|
|
'status' => 'aktif',
|
|
])
|
|
);
|
|
|
|
// Tugaskan perunding aktif jika belum ada.
|
|
if (! $dc->current_consultant_id) {
|
|
$dc->update(['current_consultant_id' => $consultant->id]);
|
|
DataCentreConsultantAssignment::firstOrCreate(
|
|
['data_centre_id' => $dc->id, 'consultant_id' => $consultant->id, 'is_active' => true],
|
|
[
|
|
'start_date' => Carbon::create(2026, 1, 1),
|
|
'reason' => 'Penugasan awal perunding.',
|
|
'assigned_by' => $officer?->id,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
|
|
// Kitaran pelaporan contoh: pembaharuan 2028 => pelaporan 2026.
|
|
foreach ([2027, 2028] as $renewalYear) {
|
|
$reportingYear = ReportingCycle::reportingYearFor($renewalYear);
|
|
ReportingCycle::firstOrCreate(
|
|
['renewal_year' => $renewalYear],
|
|
[
|
|
'reporting_year' => $reportingYear,
|
|
'period_start' => Carbon::create($reportingYear, 1, 1),
|
|
'period_end' => Carbon::create($reportingYear, 12, 31),
|
|
'cut_off_date' => Carbon::create($renewalYear - 1, 12, 1),
|
|
'licence_period_year' => 1,
|
|
'checklist_template_id' => $template?->id,
|
|
'status' => $renewalYear === 2028 ? 'aktif' : 'tutup',
|
|
]
|
|
);
|
|
}
|
|
}
|
|
}
|