add test batches

This commit is contained in:
root
2026-06-08 23:45:55 -04:00
parent c792b8be05
commit 8d4d610b82
1480 changed files with 22587 additions and 10762 deletions
@@ -17,7 +17,8 @@ class AttendanceCaseQueryService
protected AttendanceTracking $attendanceTrackingModel,
protected ViolationRuleEngineService $violationRuleEngine,
protected AttendanceParentLookupService $parentLookupService
) {}
) {
}
public function getStudentCase(
int $studentId,
@@ -31,16 +32,16 @@ class AttendanceCaseQueryService
?string $defaultSemester = null
): array {
$student = $this->studentModel->query()->find($studentId);
if (! $student) {
if (!$student) {
return [
'success' => false,
'message' => 'Student not found',
'status' => 404,
'status' => 404,
];
}
$student = $student->toArray();
$student['name'] = trim(($student['firstname'] ?? '').' '.($student['lastname'] ?? ''));
$student['name'] = trim(($student['firstname'] ?? '') . ' ' . ($student['lastname'] ?? ''));
$codeParam = strtoupper((string) ($codeParam ?? ''));
$incidentDate = preg_match('/^\d{4}-\d{2}-\d{2}$/', (string) $incidentDate) ? (string) $incidentDate : '';
@@ -65,13 +66,13 @@ class AttendanceCaseQueryService
}
[$syStart, $syEnd] = $this->violationRuleEngine->deriveSchoolYearBounds($schoolYear ?: date('Y'));
$today = Carbon::today();
$start = Carbon::parse($syStart)->startOfDay();
$today = Carbon::today();
$start = Carbon::parse($syStart)->startOfDay();
$rangeEnd = Carbon::parse(min($syEnd, $today->format('Y-m-d')))->startOfDay();
$windowWeeks = $this->violationRuleEngine->windowWeeksForViolationCode($codeParam);
$endYmd = $incidentDate !== '' ? $incidentDate : date('Y-m-d');
$startYmd = $this->violationRuleEngine->activeWeekWindowStartYmd($endYmd, $windowWeeks, $schoolYear, $semester);
$endYmd = $incidentDate !== '' ? $incidentDate : date('Y-m-d');
$startYmd = $this->violationRuleEngine->activeWeekWindowStartYmd($endYmd, $windowWeeks, $schoolYear, $semester);
$studentIdValues = [(int) $studentId];
$studentCodeRaw = trim((string) ($student['student_code'] ?? $student['school_id'] ?? ''));
@@ -107,7 +108,7 @@ class AttendanceCaseQueryService
])
->where(function ($q) use ($studentIdValues, $studentCodeValues) {
$q->whereIn('student_id', $studentIdValues);
if (! empty($studentCodeValues)) {
if (!empty($studentCodeValues)) {
$q->orWhereIn('student_id', $studentCodeValues);
}
})
@@ -125,7 +126,7 @@ class AttendanceCaseQueryService
if ($pendingOnly) {
$this->violationRuleEngine->applyUnreportedAttendanceFilter($qb, $this->attendanceDataModel->getTable());
if (! $includeNotified) {
if (!$includeNotified) {
$qb->whereRaw("(LOWER(TRIM(COALESCE(is_notified, ''))) NOT IN ('yes','1'))");
}
}
@@ -141,21 +142,21 @@ class AttendanceCaseQueryService
$attendanceRows = $qb->orderByDesc('date')->get()->toArray();
$data = [
'student' => $student,
'attendance' => $attendanceRows,
'violation_code' => $codeParam !== '' ? $codeParam : null,
'violation_date' => $incidentDate,
'violation_notified' => null,
'student' => $student,
'attendance' => $attendanceRows,
'violation_code' => $codeParam !== '' ? $codeParam : null,
'violation_date' => $incidentDate,
'violation_notified' => null,
'show_violation_summary' => true,
'school_year' => $schoolYear,
'semester' => $semester,
'school_year' => $schoolYear,
'semester' => $semester,
];
if ($data['violation_date'] === '' && ! empty($data['attendance'][0]['date'])) {
if ($data['violation_date'] === '' && !empty($data['attendance'][0]['date'])) {
$data['violation_date'] = substr((string) $data['attendance'][0]['date'], 0, 10);
}
if (! empty($data['attendance'][0]['is_notified'])) {
if (!empty($data['attendance'][0]['is_notified'])) {
$data['violation_notified'] = $data['attendance'][0]['is_notified'];
}
@@ -171,7 +172,7 @@ class AttendanceCaseQueryService
return [
'success' => true,
'data' => $data,
'data' => $data,
];
}
@@ -182,7 +183,7 @@ class AttendanceCaseQueryService
?string $defaultSemester = null
): array {
$schoolYear = filled($schoolYearParam) ? (string) $schoolYearParam : (string) $defaultSchoolYear;
$semester = filled($semesterParam) ? (string) $semesterParam : (string) $defaultSemester;
$semester = filled($semesterParam) ? (string) $semesterParam : (string) $defaultSemester;
$trackingData = $this->attendanceTrackingModel->query()
->where('school_year', $schoolYear)
@@ -210,7 +211,7 @@ class AttendanceCaseQueryService
if ($latest) {
$schoolYear = (string) ($latest->school_year ?? $schoolYear);
$semester = (string) ($latest->semester ?? $semester);
$semester = (string) ($latest->semester ?? $semester);
$trackingData = $this->attendanceTrackingModel->query()
->where('school_year', $schoolYear)
@@ -228,9 +229,9 @@ class AttendanceCaseQueryService
if (empty($trackingData)) {
return [
'students' => [],
'school_year' => $schoolYear,
'semester' => $semester,
'students' => [],
'school_year' => $schoolYear,
'semester' => $semester,
'show_actions' => false,
];
}
@@ -257,9 +258,9 @@ class AttendanceCaseQueryService
if (empty($trackingData)) {
return [
'students' => [],
'school_year' => $schoolYear,
'semester' => $semester,
'students' => [],
'school_year' => $schoolYear,
'semester' => $semester,
'show_actions' => false,
];
}
@@ -288,12 +289,12 @@ class AttendanceCaseQueryService
foreach ($rows as $row) {
$sid = (int) ($row->student_id ?? 0);
if ($sid > 0 && ! isset($classByStudent[$sid])) {
if ($sid > 0 && !isset($classByStudent[$sid])) {
$classByStudent[$sid] = [
'class_section_id' => $row->class_section_id ?? null,
'class_section_id' => $row->class_section_id ?? null,
'class_section_name' => (string) ($row->class_section_name ?? ''),
'class_id' => $row->class_id ?? null,
'class_name' => (string) ($row->class_name ?? ''),
'class_id' => $row->class_id ?? null,
'class_name' => (string) ($row->class_name ?? ''),
];
}
}
@@ -303,7 +304,7 @@ class AttendanceCaseQueryService
$mergedData = [];
foreach ($trackingData as $row) {
$sid = (int) ($row['student_id'] ?? 0);
if (! isset($studentMap[$sid])) {
if (!isset($studentMap[$sid])) {
continue;
}
@@ -311,15 +312,15 @@ class AttendanceCaseQueryService
if (isset($classByStudent[$sid])) {
$merged['class_section_name'] = (string) ($classByStudent[$sid]['class_section_name'] ?? '');
$merged['class_name'] = (string) ($classByStudent[$sid]['class_name'] ?? '');
} elseif (! empty($merged['registration_grade'])) {
$merged['class_name'] = (string) ($classByStudent[$sid]['class_name'] ?? '');
} elseif (!empty($merged['registration_grade'])) {
$merged['grade'] = (string) $merged['registration_grade'];
}
try {
$p = $this->parentLookupService->getPrimaryParentForStudent($sid);
if ($p) {
$merged['parent_name'] = $p['parent_name'] ?? '';
$merged['parent_name'] = $p['parent_name'] ?? '';
$merged['parent_email'] = $p['email'] ?? '';
$merged['parent_phone'] = $p['phone'] ?? '';
}
@@ -330,9 +331,9 @@ class AttendanceCaseQueryService
}
return [
'students' => $mergedData,
'students' => $mergedData,
'school_year' => $schoolYear,
'semester' => $semester,
'semester' => $semester,
];
}
}
}