fix invoice and enrollment fees
Deploy to Shared Hosting / Shared hosting deploy (push) Failing after 48s
Tests / PHPUnit (push) Failing after 1m19s

This commit is contained in:
root
2026-08-27 18:34:36 -04:00
parent 0ae9993d82
commit 38644b32ae
29 changed files with 1836 additions and 1555 deletions
+106 -20
View File
@@ -34,7 +34,7 @@ class ParentReportCardController extends BaseController
$schoolYearContext = $this->resolveSchoolYearContext();
$schoolYear = trim($schoolYearContext->yearName());
$semester = trim((string) ($this->request->getGet('semester') ?? getSemester() ?? ''));
$semesterOptions = $this->semesterOptions($schoolYear, '');
$builder = $this->db->table('students s')
->select('s.id, s.firstname, s.lastname, cs.class_section_name')
@@ -48,29 +48,42 @@ class ParentReportCardController extends BaseController
$builder->where('sc.school_year', $schoolYear);
}
$students = $builder->get()->getResultArray();
$students = $this->uniqueStudentRows($builder->get()->getResultArray());
$studentIds = array_values(array_filter(array_map(static fn ($s) => (int) ($s['id'] ?? 0), $students)));
$ackMap = [];
$reportAvailableMap = $this->reportAvailabilityMap($studentIds, $schoolYear, $semester);
$reportAvailableMap = $this->reportAvailabilityMap($studentIds, $schoolYear);
if (! empty($studentIds)) {
$rows = $this->ackModel
$ackQuery = $this->ackModel
->where('parent_id', $parentId)
->where('school_year', $schoolYear)
->where('semester', $semester)
->whereIn('student_id', $studentIds)
->findAll();
->whereIn('student_id', $studentIds);
$rows = $ackQuery->findAll();
foreach ($rows as $row) {
$ackMap[(int) $row['student_id']] = $row;
$semester = $this->selectedSemester($row['semester'] ?? '');
$ackMap[$this->semesterStudentKey((int) $row['student_id'], $semester)] = $row;
}
}
$reportRows = [];
foreach ($students as $student) {
foreach ($semesterOptions as $semester) {
$reportRows[] = [
'student' => $student,
'semester' => $semester,
'key' => $this->semesterStudentKey((int) ($student['id'] ?? 0), $semester),
];
}
}
return view('parent/report_cards', [
'students' => $students,
'reportRows' => $reportRows,
'ackMap' => $ackMap,
'reportAvailableMap' => $reportAvailableMap,
'schoolYear' => $schoolYear,
'semester' => $semester,
'semesterOptions' => $semesterOptions,
'isEditable' => ! $schoolYearContext->isReadonly(),
]);
}
@@ -89,7 +102,7 @@ class ParentReportCardController extends BaseController
$schoolYearContext = $this->resolveSchoolYearContext();
$schoolYear = trim($schoolYearContext->yearName());
$semester = trim((string) ($this->request->getGet('semester') ?? getSemester() ?? ''));
$semester = $this->selectedSemester($this->request->getGet('semester'));
if (! $this->reportExists((int) $studentId, $schoolYear, $semester)) {
return redirect()->to(site_url('parent/report-cards'))
@@ -142,7 +155,7 @@ class ParentReportCardController extends BaseController
}
$schoolYear = trim($schoolYearContext->yearName());
$semester = trim((string) (getSemester() ?? ''));
$semester = $this->selectedSemester($this->request->getPost('semester'));
if (! $this->reportExists((int) $studentId, $schoolYear, $semester)) {
return redirect()->to(site_url('parent/report-cards'))
@@ -160,6 +173,78 @@ class ParentReportCardController extends BaseController
return redirect()->to(site_url('parent/report-cards'))->with('success', 'Report card acknowledged.');
}
protected function selectedSemester($semester): string
{
$selected = trim((string) ($semester ?? ''));
if ($selected === '') {
$selected = trim((string) (getSemester() ?? ''));
}
$normalized = strtolower($selected);
if ($normalized === 'fall' || $normalized === 'first' || str_contains($normalized, 'fall') || str_contains($normalized, '1')) {
return 'Fall';
}
if ($normalized === 'spring' || $normalized === 'second' || str_contains($normalized, 'spring') || str_contains($normalized, '2')) {
return 'Spring';
}
return $selected !== '' ? $selected : 'Fall';
}
protected function uniqueStudentRows(array $students): array
{
$unique = [];
foreach ($students as $student) {
$studentId = (int) ($student['id'] ?? 0);
if ($studentId <= 0) {
continue;
}
if (! isset($unique[$studentId])) {
$unique[$studentId] = $student;
continue;
}
if (
empty($unique[$studentId]['class_section_name'])
&& ! empty($student['class_section_name'])
) {
$unique[$studentId]['class_section_name'] = $student['class_section_name'];
}
}
return array_values($unique);
}
protected function semesterOptions(string $schoolYear, string $selectedSemester): array
{
$options = ['Fall', 'Spring'];
if ($schoolYear !== '') {
$rows = $this->db->table('semester_scores')
->select('DISTINCT semester', false)
->where('school_year', $schoolYear)
->where('semester IS NOT NULL', null, false)
->where('semester !=', '')
->orderBy('semester', 'ASC')
->get()
->getResultArray();
foreach ($rows as $row) {
$semester = $this->selectedSemester($row['semester'] ?? '');
if ($semester !== '' && ! in_array($semester, $options, true)) {
$options[] = $semester;
}
}
}
if ($selectedSemester !== '' && ! in_array($selectedSemester, $options, true)) {
$options[] = $selectedSemester;
}
return array_values(array_unique($options));
}
protected function resolvePrimaryParentId(): ?int
{
$parentId = (int) (session()->get('user_id') ?? 0);
@@ -186,7 +271,7 @@ class ParentReportCardController extends BaseController
return $parentId ?: null;
}
protected function reportAvailabilityMap(array $studentIds, string $schoolYear, string $semester): array
protected function reportAvailabilityMap(array $studentIds, string $schoolYear): array
{
$studentIds = array_values(array_filter(array_map('intval', $studentIds), static fn ($id) => $id > 0));
if (empty($studentIds) || $schoolYear === '') {
@@ -194,17 +279,12 @@ class ParentReportCardController extends BaseController
}
$builder = $this->db->table('semester_scores')
->select('student_id')
->select('student_id, semester')
->whereIn('student_id', $studentIds)
->where('school_year', $schoolYear);
$semesterVariants = $this->semesterVariants($semester);
if (! empty($semesterVariants)) {
$builder->whereIn('semester', $semesterVariants);
}
$rows = $builder
->groupBy('student_id')
->groupBy('student_id, semester')
->get()
->getResultArray();
@@ -212,13 +292,19 @@ class ParentReportCardController extends BaseController
foreach ($rows as $row) {
$sid = (int) ($row['student_id'] ?? 0);
if ($sid > 0) {
$map[$sid] = true;
$semester = $this->selectedSemester($row['semester'] ?? '');
$map[$this->semesterStudentKey($sid, $semester)] = true;
}
}
return $map;
}
protected function semesterStudentKey(int $studentId, string $semester): string
{
return $studentId . '|' . $this->selectedSemester($semester);
}
protected function reportExists(int $studentId, string $schoolYear, string $semester): bool
{
if ($studentId <= 0 || $schoolYear === '') {