diff --git a/app/Actions/Tabulation/EnterScore.php b/app/Actions/Tabulation/EnterScore.php index 9745e39..17b87fa 100644 --- a/app/Actions/Tabulation/EnterScore.php +++ b/app/Actions/Tabulation/EnterScore.php @@ -71,8 +71,10 @@ class EnterScore // Check the validity of submitted subscores, format array for storage, and sum score $subscoresRequired = $entry->audition->scoringGuide->subscores; $subscoresStorageArray = []; - $scoreSheetTotal = 0; - $maxPossible = 0; + $seatingTotal = 0; + $seatingMaxPossible = 0; + $advancementTotal = 0; + $advancementMaxPossible = 0; if ($scores->count() !== $subscoresRequired->count()) { throw new ScoreEntryException('Invalid number of scores'); } @@ -93,12 +95,20 @@ class EnterScore 'subscore_name' => $subscore->name, ]; - // Multiply subscore by weight and add to the total - $scoreSheetTotal += ($subscore->weight * $scores[$subscore->id]); + // If included in seating, multiply by weight and add to the total and max possible + if ($subscore->for_seating) { + $seatingTotal += ($subscore->weight * $scores[$subscore->id]); + $seatingMaxPossible += ($subscore->weight * $subscore->max_score); + } - // Add weight to total weights - $maxPossible += ($subscore->weight * $subscore->max_score); + // If included in advancement, multiply by weight and add to the total and max possible + if ($subscore->for_advance) { + $advancementTotal += ($subscore->weight * $scores[$subscore->id]); + $advancementMaxPossible += ($subscore->weight * $subscore->max_score); + } } + $finalSeatingTotal = ($seatingMaxPossible === 0) ? 0 : (($seatingTotal / $seatingMaxPossible) * 100); + $finalAdvancementTotal = ($advancementMaxPossible === 0) ? 0 : (($advancementTotal / $advancementMaxPossible) * 100); $entry->removeFlag('no_show'); if ($scoreSheet instanceof ScoreSheet) { @@ -106,15 +116,16 @@ class EnterScore 'user_id' => $user->id, 'entry_id' => $entry->id, 'subscores' => $subscoresStorageArray, - 'sheet_total' => ($scoreSheetTotal / $maxPossible) * 100, + 'seating_total' => $finalSeatingTotal, + 'advancement_total' => $finalAdvancementTotal, ]); } else { - $finalTotal = ($scoreSheetTotal / $maxPossible) * 100; $scoreSheet = ScoreSheet::create([ 'user_id' => $user->id, 'entry_id' => $entry->id, 'subscores' => $subscoresStorageArray, - 'sheet_total' => $finalTotal, + 'seating_total' => $finalSeatingTotal, + 'advancement_total' => $finalAdvancementTotal, ]); } @@ -124,7 +135,8 @@ class EnterScore foreach ($scoreSheet->subscores as $subscore) { $log_message .= $subscore['subscore_name'].': '.$subscore['score'].'
'; } - $log_message .= 'Total: '.$scoreSheet->sheet_total; + $log_message .= 'Seating Total: '.$scoreSheet->seating_total.'
'; + $log_message .= 'Advancement Total: '.$scoreSheet->advancement_total.'
'; AuditLogEntry::create([ 'user' => auth()->user()->email ?? 'no user', 'ip_address' => request()->ip(), diff --git a/app/Models/ScoreSheet.php b/app/Models/ScoreSheet.php index 7b9076e..a5b7dd8 100644 --- a/app/Models/ScoreSheet.php +++ b/app/Models/ScoreSheet.php @@ -13,7 +13,8 @@ class ScoreSheet extends Model 'user_id', 'entry_id', 'subscores', - 'sheet_total', + 'seating_total', + 'advancement_total', ]; protected $casts = ['subscores' => 'json']; diff --git a/database/migrations/2025_06_11_043508_add_sheet_total_column_to_score_sheets_table.php b/database/migrations/2025_06_11_043508_add_sheet_total_column_to_score_sheets_table.php index 9714f66..16a372a 100644 --- a/database/migrations/2025_06_11_043508_add_sheet_total_column_to_score_sheets_table.php +++ b/database/migrations/2025_06_11_043508_add_sheet_total_column_to_score_sheets_table.php @@ -12,7 +12,10 @@ return new class extends Migration public function up(): void { Schema::table('score_sheets', function (Blueprint $table) { - $table->decimal('sheet_total', 9, 6)->after('subscores'); + $table->decimal('seating_total', 9, 6)->after('subscores'); + }); + Schema::table('score_sheets', function (Blueprint $table) { + $table->decimal('advancement_total', 9, 6)->after('seating_total'); }); } @@ -22,7 +25,8 @@ return new class extends Migration public function down(): void { Schema::table('score_sheets', function (Blueprint $table) { - $table->dropColumn('sheet_total'); + $table->dropColumn('seating_total'); + $table->dropColumn('advancement_total'); }); } };