update exam and attendance
This commit is contained in:
@@ -449,15 +449,38 @@ class AttendanceQueryService
|
||||
|
||||
public function buildDailyAttendanceData(string $termSemester, string $termYear): array
|
||||
{
|
||||
$classSections = $this->classSection
|
||||
->query()
|
||||
->select('classSection.id', 'classSection.class_id', 'classSection.class_section_id', 'classSection.class_section_name')
|
||||
->join('student_class as sc', 'sc.class_section_id', '=', 'classSection.class_section_id')
|
||||
->where('sc.school_year', $termYear)
|
||||
->groupBy('classSection.id', 'classSection.class_id', 'classSection.class_section_id', 'classSection.class_section_name')
|
||||
->get()
|
||||
->map(fn($row) => (array)$row)
|
||||
->all();
|
||||
$effectiveTermYear = $termYear;
|
||||
|
||||
$loadClassSections = function (string $schoolYear): array {
|
||||
if ($schoolYear === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->classSection
|
||||
->query()
|
||||
->select('classSection.id', 'classSection.class_id', 'classSection.class_section_id', 'classSection.class_section_name')
|
||||
->join('student_class as sc', 'sc.class_section_id', '=', 'classSection.class_section_id')
|
||||
->where('sc.school_year', $schoolYear)
|
||||
->groupBy('classSection.id', 'classSection.class_id', 'classSection.class_section_id', 'classSection.class_section_name')
|
||||
->get()
|
||||
->map(fn($row) => $row->toArray())
|
||||
->all();
|
||||
};
|
||||
|
||||
$classSections = $loadClassSections($effectiveTermYear);
|
||||
|
||||
if ($classSections === []) {
|
||||
$fallbackYear = (string) DB::table('student_class')
|
||||
->whereNotNull('school_year')
|
||||
->where('school_year', '<>', '')
|
||||
->orderByDesc('school_year')
|
||||
->value('school_year');
|
||||
|
||||
if ($fallbackYear !== '' && $fallbackYear !== $effectiveTermYear) {
|
||||
$effectiveTermYear = $fallbackYear;
|
||||
$classSections = $loadClassSections($effectiveTermYear);
|
||||
}
|
||||
}
|
||||
|
||||
$attendanceData = [];
|
||||
$attendanceRecord = [];
|
||||
@@ -466,7 +489,7 @@ class AttendanceQueryService
|
||||
$datesBySection = [];
|
||||
$studentSchoolMap = [];
|
||||
|
||||
$sectionCounts = $this->studentClass->getStudentCountsBySection($termYear);
|
||||
$sectionCounts = $this->studentClass->getStudentCountsBySection($effectiveTermYear);
|
||||
|
||||
foreach ($classSections as $classSection) {
|
||||
$secPk = (int)($classSection['id'] ?? 0);
|
||||
@@ -483,9 +506,9 @@ class AttendanceQueryService
|
||||
$countForPk = (int)($sectionCounts[$secPk] ?? 0);
|
||||
$sectionHasStudents = ($countForCode + $countForPk) > 0;
|
||||
|
||||
$students = $this->studentClass->getClassStudents($secCode, $termYear);
|
||||
$students = $this->studentClass->getClassStudents($secCode, $effectiveTermYear);
|
||||
if (!$students && $secPk && (string)$secPk !== (string)$secCode) {
|
||||
$students = $this->studentClass->getClassStudents($secPk, $termYear);
|
||||
$students = $this->studentClass->getClassStudents($secPk, $effectiveTermYear);
|
||||
}
|
||||
|
||||
if (!$sectionHasStudents || !$students) {
|
||||
@@ -522,7 +545,7 @@ class AttendanceQueryService
|
||||
}
|
||||
})
|
||||
->when($termSemester !== '', fn($q) => $q->where('semester', $termSemester))
|
||||
->when($termYear !== '', fn($q) => $q->where('school_year', $termYear))
|
||||
->when($effectiveTermYear !== '', fn($q) => $q->where('school_year', $effectiveTermYear))
|
||||
->orderBy('date')
|
||||
->get()
|
||||
->map(fn($row) => $row->toArray())
|
||||
@@ -547,7 +570,7 @@ class AttendanceQueryService
|
||||
}
|
||||
})
|
||||
->when($termSemester !== '', fn($q) => $q->where('semester', $termSemester))
|
||||
->when($termYear !== '', fn($q) => $q->where('school_year', $termYear))
|
||||
->when($effectiveTermYear !== '', fn($q) => $q->where('school_year', $effectiveTermYear))
|
||||
->first();
|
||||
|
||||
$attendanceRecord[$secCode][$studentId] = $summary?->toArray() ?? [
|
||||
@@ -581,11 +604,11 @@ class AttendanceQueryService
|
||||
|
||||
ksort($grades, SORT_NUMERIC);
|
||||
|
||||
[$rangeStart, $rangeEnd] = $this->semesterRangeService->getSchoolYearRange($termYear);
|
||||
[$rangeStart, $rangeEnd] = $this->semesterRangeService->getSchoolYearRange($effectiveTermYear);
|
||||
$semesterNorm = $this->semesterRangeService->normalizeSemester($termSemester);
|
||||
|
||||
if ($semesterNorm !== '') {
|
||||
$semRange = $this->semesterRangeService->getSemesterRange($termYear, $semesterNorm);
|
||||
$semRange = $this->semesterRangeService->getSemesterRange($effectiveTermYear, $semesterNorm);
|
||||
if ($semRange) {
|
||||
[$rangeStart, $rangeEnd] = $semRange;
|
||||
}
|
||||
@@ -621,7 +644,7 @@ class AttendanceQueryService
|
||||
|
||||
$totalPassedDays = count($passedDatesSet);
|
||||
|
||||
if ($totalPassedDays > 0 && $termYear !== '' && $termSemester !== '') {
|
||||
if ($totalPassedDays > 0 && $effectiveTermYear !== '' && $termSemester !== '') {
|
||||
foreach ($attendanceData as $secCode => $studentEntries) {
|
||||
foreach ($studentEntries as $studentId => $entries) {
|
||||
$statusByDate = [];
|
||||
@@ -663,7 +686,7 @@ class AttendanceQueryService
|
||||
[
|
||||
'student_id' => $studentId,
|
||||
'semester' => $termSemester,
|
||||
'school_year' => $termYear,
|
||||
'school_year' => $effectiveTermYear,
|
||||
],
|
||||
[
|
||||
'class_section_id' => $secCode,
|
||||
@@ -705,7 +728,7 @@ class AttendanceQueryService
|
||||
'noSchoolDays' => $noSchoolDays,
|
||||
'totalPassedDays' => $totalPassedDays,
|
||||
'semester' => $termSemester,
|
||||
'schoolYear' => $termYear,
|
||||
'schoolYear' => $effectiveTermYear,
|
||||
'currentAdminName' => $adminName,
|
||||
];
|
||||
}
|
||||
@@ -876,4 +899,4 @@ class AttendanceQueryService
|
||||
return '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user