diff --git a/app/Actions/Tabulation/EnterNoShow.php b/app/Actions/Tabulation/EnterNoShow.php index 5d3e0d0..3bd1718 100644 --- a/app/Actions/Tabulation/EnterNoShow.php +++ b/app/Actions/Tabulation/EnterNoShow.php @@ -7,6 +7,7 @@ use App\Models\BonusScore; use App\Models\Entry; use App\Models\EntryTotalScore; use App\Models\ScoreSheet; +use Illuminate\Support\Facades\DB; class EnterNoShow { @@ -25,9 +26,9 @@ class EnterNoShow * @throws AuditionAdminException If an invalid flag type is provided, * or the action violates business rules. */ - public function __invoke(Entry $entry, string $flagType = 'no-show'): string + public function __invoke(Entry $entry, string $flagType = 'noshow'): string { - if ($flagType !== 'no-show' && $flagType !== 'failed-prelim') { + if ($flagType !== 'noshow' && $flagType !== 'failprelim') { throw new AuditionAdminException('Invalid flag type'); } @@ -42,7 +43,7 @@ class EnterNoShow ScoreSheet::where('entry_id', $entry->id)->delete(); BonusScore::where('entry_id', $entry->id)->delete(); EntryTotalScore::where('entry_id', $entry->id)->delete(); - if ($flagType == 'failed-prelim') { + if ($flagType == 'failprelim') { $msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; $entry->addFlag('failed_prelim'); } else { diff --git a/app/Http/Controllers/Tabulation/EntryFlagController.php b/app/Http/Controllers/Tabulation/EntryFlagController.php index d9c8aac..8154120 100644 --- a/app/Http/Controllers/Tabulation/EntryFlagController.php +++ b/app/Http/Controllers/Tabulation/EntryFlagController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Tabulation; +use App\Exceptions\AuditionAdminException; use App\Http\Controllers\Controller; use App\Models\BonusScore; use App\Models\Entry; @@ -69,28 +70,38 @@ class EntryFlagController extends Controller 'scores')); } + /** + * @throws AuditionAdminException + */ public function enterNoShow(Entry $entry) { - if ($entry->audition->hasFlag('seats_published')) { - return to_route('entry-flags.noShowSelect')->with('error', - 'Cannot enter a no-show for an entry in an audition where seats are published'); + $recorder = app('App\Actions\Tabulation\EnterNoShow'); + try { + $msg = $recorder($entry, request()->input('noshow-type')); + } catch (AuditionAdminException $e) { + return to_route('entry-flags.noShowSelect')->with('error', $e->getMessage()); } - if ($entry->audition->hasFlag('advancement_published')) { - return to_route('entry-flags.noShowSelect')->with('error', - 'Cannot enter a no-show for an entry in an audition where advancement is published'); - } - DB::table('score_sheets')->where('entry_id', $entry->id)->delete(); - ScoreSheet::where('entry_id', $entry->id)->delete(); - BonusScore::where('entry_id', $entry->id)->delete(); - EntryTotalScore::where('entry_id', $entry->id)->delete(); - if (request()->input('noshow-type') == 'failprelim') { - $msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; - $entry->addFlag('failed_prelim'); - } else { - $entry->addFlag('no_show'); - $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; - } + // if ($entry->audition->hasFlag('seats_published')) { + // return to_route('entry-flags.noShowSelect')->with('error', + // 'Cannot enter a no-show for an entry in an audition where seats are published'); + // } + // if ($entry->audition->hasFlag('advancement_published')) { + // return to_route('entry-flags.noShowSelect')->with('error', + // 'Cannot enter a no-show for an entry in an audition where advancement is published'); + // } + // DB::table('score_sheets')->where('entry_id', $entry->id)->delete(); + // + // ScoreSheet::where('entry_id', $entry->id)->delete(); + // BonusScore::where('entry_id', $entry->id)->delete(); + // EntryTotalScore::where('entry_id', $entry->id)->delete(); + // if (request()->input('noshow-type') == 'failprelim') { + // $msg = 'Failed prelim has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; + // $entry->addFlag('failed_prelim'); + // } else { + // $entry->addFlag('no_show'); + // $msg = 'No Show has been entered for '.$entry->audition->name.' #'.$entry->draw_number.' (ID: '.$entry->id.').'; + // } return to_route('entry-flags.noShowSelect')->with('success', $msg); }