diff --git a/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php b/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php
index 79d6b52..7f92acf 100644
--- a/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php
+++ b/app/Http/Controllers/Tabulation/Seating/ShowAuditionSeatingPage.php
@@ -69,9 +69,14 @@ class ShowAuditionSeatingPage extends Controller
$query->where('flag_name', 'failed_prelim');
})
->with('student.school')
+ ->with('PrelimScoreSheets')
->orderBy('draw_number')
->get();
+ $failed_prelim_entries = $failed_prelim_entries->sortByDesc(function ($entry) {
+ return $entry->prelimTotalScore();
+ });
+
// Get Doublers
$doublerData = Doubler::where('event_id', $audition->event_id)
->whereIn('student_id', $scored_entries->pluck('student_id'))
diff --git a/app/Models/Entry.php b/app/Models/Entry.php
index f4207e2..a64e1cf 100644
--- a/app/Models/Entry.php
+++ b/app/Models/Entry.php
@@ -141,6 +141,18 @@ class Entry extends Model
return $this->hasMany(PrelimScoreSheet::class);
}
+ public function prelimTotalScore()
+ {
+ return once(function () {
+ $total = 0;
+ foreach ($this->prelimScoreSheets as $sheet) {
+ $total += $sheet->total;
+ }
+
+ return $total / $this->prelimScoreSheets->count();
+ });
+ }
+
public function prelimResult()
{
if ($this->hasFlag('passed_prelim')) {
diff --git a/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php b/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php
index 6f76da6..669a390 100644
--- a/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php
+++ b/resources/views/tabulation/seating-page/failed-prelim-entries.blade.php
@@ -6,6 +6,7 @@