fix attendance spring days

This commit is contained in:
root
2026-05-26 03:03:03 -04:00
parent 31976752da
commit cc0b83c1b9
3 changed files with 30 additions and 19 deletions
+12 -16
View File
@@ -1566,34 +1566,30 @@ class ReportCardsController extends PrintablesBaseController
$semRange = $this->semesterRangeService->getSemesterRange($refYear, ucfirst($normSemester));
if ($semRange) {
try {
$events = $this->calendarModel->getEventsBySchoolYearAndSemester($refYear, $normSemester);
// Fetch all events for the year (no semester filter) so that
// no-school events stored with a different semester label or
// NULL semester are still picked up. Date-range filtering below.
$events = $this->calendarModel->getEventsBySchoolYearAndSemester($refYear, null);
$noSchoolDays = [];
foreach ($events as $event) {
if (empty($event['no_school'])) {
continue;
}
$dateStr = substr((string)($event['date'] ?? ''), 0, 10);
if ($dateStr === '') {
continue;
}
try {
$eventDate = new \DateTime($dateStr);
} catch (\Throwable) {
continue;
}
if ($eventDate->format('N') !== '7') {
continue;
}
if ($dateStr < $semRange[0] || $dateStr > $semRange[1]) {
if ($dateStr === '' || $dateStr < $semRange[0] || $dateStr > $semRange[1]) {
continue;
}
$noSchoolDays[$dateStr] = true;
}
$sundays = $this->listSundays($semRange[0], $semRange[1]);
$anchor = $this->resolveAnchorSunday();
$limit = $semRange[1];
if ($anchor !== '' && $anchor >= $semRange[0]) {
$limit = min($anchor, $semRange[1]);
// Only cap at "today" while the semester is still in progress.
// Once the semester end date has passed, count all its Sundays.
if ($semRange[1] > date('Y-m-d')) {
$anchor = $this->resolveAnchorSunday();
if ($anchor !== '' && $anchor >= $semRange[0]) {
$limit = min($anchor, $semRange[1]);
}
}
$totalSemesterDays = 0;
foreach ($sundays as $date) {