@php
$grades_str = '';
$head_marks_array = json_decode($assignedMarksHead->first(), true);
$head_id_array = array_keys($head_marks_array);
$subject_head_marks = $assignedMarksHead;
$highest_grand_total_obtain = 0;
// Calculate grand total obtained for each student
$students_with_grand_total = [];
foreach ($students as $student) {
$grand_total_obtain = 0;
$examRecords = $student?->examRecords ?? '';
if ($examRecords->isNotEmpty()) {
foreach ($examRecords as $record) {
$head_wise_marks_record = json_decode($record->head_wise_marks);
$head_marks_data = $subject_head_marks[$record->subject->id];
$head_marks_array = json_decode($head_marks_data);
$total_marks_obtain = 0;
foreach ($markHeads as $head) {
if (in_array($head->id, $head_id_array)) {
$total_marks_obtain += $head_wise_marks_record?->{$head->id} ?? 0;
}
}
$grand_total_obtain += $total_marks_obtain;
}
}
// Add student and their total obtained marks
$students_with_grand_total[] = [
'student' => $student,
'grand_total_obtain' => $grand_total_obtain
];
// Update highest total if this student's grand_total_obtain is higher
if ($grand_total_obtain > $highest_grand_total_obtain) {
$highest_grand_total_obtain = $grand_total_obtain;
}
}
// Sort students by grand_total_obtain in descending order
usort($students_with_grand_total, function ($a, $b) {
return $b['grand_total_obtain'] <=> $a['grand_total_obtain'];
});
$position = 1; // To assign position based on sorted order
@endphp
Student ID |
Name |
Class |
Section |
Roll |
Full Marks |
Total Obt. |
Obt. Percentage |
Position |
Highest Marks |
GPA |
Grade |
@foreach ($students_with_grand_total as $data)
@php
$student = $data['student'];
$grand_total_obtain = $data['grand_total_obtain'];
$grand_total = 0;
$fail_count = 0;
$examRecords = $student?->examRecords ?? '';
$section = $sections[$student->section_id] ?? '';
$class = $studentClasses[$student->student_class_id] ?? '';
$academicYear = $academicYears[$academic_year] ?? '';
@endphp
@if ($examRecords->isNotEmpty())
@foreach ($examRecords as $record)
@php
$full_marks = 0;
$head_wise_total_obtain = [];
$total_marks_obtain = 0;
$head_wise_marks_record = json_decode($record->head_wise_marks);
$head_marks_data = $subject_head_marks[$record->subject->id];
$head_marks_array = json_decode($head_marks_data);
@endphp
@if (isset($head_wise_marks_record))
@foreach ($markHeads as $head)
@if (in_array($head->id, $head_id_array))
@php
$full_marks += $head_marks_array->{$head?->id};
$total_marks_obtain += $head_wise_marks_record?->{$head?->id} ?? 0;
@endphp
@endif
@endforeach
@php
$grand_total += $full_marks;
@endphp
@endif
@endforeach
@endif
{{ $student->student_id_no }} |
{{ $student->first_name }} |
{{ $class }} |
{{ $section }} |
{{ $student->class_roll }} |
{{ $grand_total }} |
{{ $grand_total_obtain }} |
@php
$grade_name = '';
$grade_point = '';
$grade_name_remarks = '';
$grand_total_percentage = $grand_total_obtain > 0 && $grand_total > 0
? round(($grand_total_obtain * 100) / $grand_total)
: 0;
foreach ($grades as $grade) {
if ($grade->mark_from <= $grand_total_percentage && $grade->mark_to >= $grand_total_percentage) {
$grade_name = $grade->name;
$grade_point = $grade;
$grade_name_remarks = $grade->remark;
}
}
@endphp
{{ round($grand_total_percentage, 2) }}% |
{{ $position++ }} |
|
{{ $grade_point->gpa }} |
@if ($fail_count > 0)
F
@else
{{ $grade_name }}
@endif
|
@endforeach