'dashboard', 'domains/admission/seo.admission_schedule.title' => 'admission-schedules.index', '{admissionTrack.name} {term.name}' => ''], context: 'admissionSchedule')] class extends Component { use HasLayoutDataAttributes; use HasSeoAttributes; use WithToast; #[Locked] public string $id; public function mount($id): void { $this->id = $id; } #[Computed] public function admissionSchedule(): AdmissionSchedule { return AdmissionSchedule::with(['admissionTrack', 'term']) ->where('ulid', $this->id)->first(); } #[Computed] public function studyPrograms(): Collection { return StudyProgram::all(['id', 'name', 'ulid']); } #[Computed] public function academicPrograms(): Collection { return AcademicProgram::all(['id', 'name', 'ulid']); } #[Computed] public function feeTypes(): Collection { return FeeType::all(['id', 'name', 'ulid']); } #[Computed] public function feeRates(): Collection { return FeeRate::where('admission_schedule_id', $this->admissionSchedule->id) ->get() ->mapWithKeys(function (FeeRate $rate) { $key = "{$rate->study_program_id}_{$rate->academic_program_id}_{$rate->fee_type_id}"; $amount = $rate->amount; return [ $key => $amount, ]; }); } public function checkFeeSetup($studyId): bool { $requiredCount = count($this->academicPrograms) * count($this->feeTypes); if ($requiredCount === 0) { return false; } $filledCount = 0; foreach ($this->academicPrograms as $program) { foreach ($this->feeTypes as $fee) { $lookupKey = "{$studyId}_{$program->id}_{$fee->id}"; $amount = $this->feeRates[$lookupKey] ?? '0'; if ($amount instanceof Money) { $amount = $amount->toFloat(); } if ($amount !== '0' && $amount !== 0 && ! empty($amount)) { $filledCount++; } } } return $filledCount === $requiredCount; } public function setBadgeVariant(mixed $amount): string { if (is_int($amount) && $amount !== 0) { return 'success'; } if ($amount instanceof Money && $amount->toFloat() != 0) { return 'success'; } return 'danger'; } public function updateFee(string $feeTypeId, string $programId, string $studyId, int $value, SetUpAdmissionFeeRates $setUpAdmissionFeeRates): true { $feeType = $this->feeTypes->where('ulid', $feeTypeId)->first(); $program = $this->academicPrograms->where('ulid', $programId)->first(); $study = $this->studyPrograms->where('ulid', $studyId)->first(); $setUpAdmissionFeeRates->execute(new AdmissionFeeRatesDTO( academicProgramId: $program->id, admissionScheduleId: $this->admissionSchedule->id, studyProgramId: $study->id, feeTypeId: $feeType->id, amount: $value )); $this->success(__('ui/crud.success.updated', ['resource' => __('ui/label.fee_type')])); $this->dispatch('$refresh'); return true; } };