fix close year and ignore not active students
This commit is contained in:
@@ -587,6 +587,9 @@ final class SchoolYearClosingService
|
||||
|
||||
$hasEventOnly = $this->db->fieldExists('is_event_only', 'student_class');
|
||||
$hasActive = $this->db->fieldExists('is_active', 'students');
|
||||
$hasEnrollments = $this->db->tableExists('enrollments');
|
||||
$hasEnrollmentStatus = $hasEnrollments && $this->db->fieldExists('enrollment_status', 'enrollments');
|
||||
$hasEnrollmentWithdrawn = $hasEnrollments && $this->db->fieldExists('is_withdrawn', 'enrollments');
|
||||
$hasDob = $this->db->fieldExists('dob', 'students');
|
||||
$hasRegistrationGrade = $this->db->fieldExists('registration_grade', 'students');
|
||||
|
||||
@@ -600,6 +603,14 @@ final class SchoolYearClosingService
|
||||
->where('sc.school_year', $schoolYear)
|
||||
->where('sc.class_section_id IS NOT NULL', null, false);
|
||||
|
||||
if ($hasEnrollments && ($hasEnrollmentStatus || $hasEnrollmentWithdrawn)) {
|
||||
$builder->join(
|
||||
'enrollments e',
|
||||
'e.student_id = sc.student_id AND e.school_year = ' . $this->db->escape($schoolYear),
|
||||
'left'
|
||||
);
|
||||
}
|
||||
|
||||
if ($hasDob) {
|
||||
$builder->select('s.dob');
|
||||
}
|
||||
@@ -619,6 +630,19 @@ final class SchoolYearClosingService
|
||||
$builder->where('s.is_active', 1);
|
||||
}
|
||||
|
||||
if ($hasEnrollmentStatus) {
|
||||
$inactiveStatuses = implode(',', array_map([$this->db, 'escape'], EnrollmentStatusService::INACTIVE_STATUSES));
|
||||
$builder->where(
|
||||
'(e.enrollment_status IS NULL OR LOWER(TRIM(e.enrollment_status)) NOT IN (' . $inactiveStatuses . '))',
|
||||
null,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
if ($hasEnrollmentWithdrawn) {
|
||||
$builder->where('(e.is_withdrawn IS NULL OR e.is_withdrawn != 1)', null, false);
|
||||
}
|
||||
|
||||
$assignmentRows = $builder
|
||||
->orderBy('sc.student_id', 'ASC')
|
||||
->orderBy('sc.updated_at', 'DESC')
|
||||
|
||||
Reference in New Issue
Block a user