fix financial and certificates
This commit is contained in:
@@ -281,50 +281,59 @@ class PromotionEligibilityService
|
||||
*/
|
||||
private function loadAcademicResult(int $studentId, string $schoolYear): array
|
||||
{
|
||||
$rows = DB::table('semester_scores')
|
||||
->select('semester', 'semester_score')
|
||||
$decision = DB::table('student_decisions')
|
||||
->where('student_id', $studentId)
|
||||
->where('school_year', $schoolYear)
|
||||
->get();
|
||||
->orderByDesc('updated_at')
|
||||
->orderByDesc('id')
|
||||
->first();
|
||||
|
||||
$fall = null;
|
||||
$spring = null;
|
||||
foreach ($rows as $row) {
|
||||
$semester = strtolower((string) ($row->semester ?? ''));
|
||||
$score = isset($row->semester_score) ? (float) $row->semester_score : null;
|
||||
if ($semester === 'fall') {
|
||||
$fall = $score;
|
||||
} elseif ($semester === 'spring') {
|
||||
$spring = $score;
|
||||
}
|
||||
}
|
||||
|
||||
$threshold = $this->passThreshold();
|
||||
|
||||
if ($fall === null && $spring === null) {
|
||||
if (!$decision) {
|
||||
return [
|
||||
'passed' => null,
|
||||
'final_average' => null,
|
||||
'notes' => 'Missing fall and spring scores',
|
||||
'has_data' => false,
|
||||
];
|
||||
}
|
||||
if ($fall === null || $spring === null) {
|
||||
$existing = $fall ?? $spring;
|
||||
return [
|
||||
'passed' => null,
|
||||
'final_average' => $existing,
|
||||
'notes' => 'Awaiting both fall and spring scores',
|
||||
'notes' => 'Missing student_decisions record for promotion eligibility',
|
||||
'has_data' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$rawDecision = strtolower(trim((string) ($decision->decision ?? '')));
|
||||
$score = $decision->year_score !== null ? round((float) $decision->year_score, 2) : null;
|
||||
|
||||
if (in_array($rawDecision, ['passed', 'pass', 'promoted', 'promote', 'eligible_to_continue'], true)) {
|
||||
return [
|
||||
'passed' => true,
|
||||
'final_average' => $score,
|
||||
'notes' => $score !== null
|
||||
? sprintf('student_decisions marked promoted with score %.2f', $score)
|
||||
: 'student_decisions marked promoted without a year_score',
|
||||
'has_data' => true,
|
||||
];
|
||||
}
|
||||
|
||||
if (in_array($rawDecision, ['failed', 'fail', 'retained', 'repeat', 'repeated_level'], true)) {
|
||||
return [
|
||||
'passed' => false,
|
||||
'final_average' => $score,
|
||||
'notes' => 'student_decisions marked failed/retained',
|
||||
'has_data' => true,
|
||||
];
|
||||
}
|
||||
|
||||
if ($rawDecision === '' || $rawDecision === 'pending' || $rawDecision === 'manual review' || $rawDecision === 'manual_review') {
|
||||
return [
|
||||
'passed' => null,
|
||||
'final_average' => $score,
|
||||
'notes' => 'student_decisions is pending or requires manual review',
|
||||
'has_data' => false,
|
||||
];
|
||||
}
|
||||
|
||||
$avg = round(($fall + $spring) / 2.0, 2);
|
||||
return [
|
||||
'passed' => $avg >= $threshold,
|
||||
'final_average' => $avg,
|
||||
'notes' => sprintf('Final average %.2f (threshold %.2f)', $avg, $threshold),
|
||||
'has_data' => true,
|
||||
'passed' => null,
|
||||
'final_average' => $score,
|
||||
'notes' => 'student_decisions has unrecognized decision: ' . $rawDecision,
|
||||
'has_data' => false,
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user