Admin can waive late fees #41

Merged
okorpheus merged 2 commits from auditionadmin-38 into master 2024-07-18 00:33:21 +00:00
6 changed files with 47 additions and 7 deletions
Showing only changes of commit 51436bda40 - Show all commits

View File

@ -16,9 +16,9 @@ class CreateEntry
/**
* @throws ManageEntryException
*/
public function __invoke(Student|int $student, Audition|int $audition, string|array|null $entry_for = null): void
public function __invoke(Student|int $student, Audition|int $audition, string|array|null $entry_for = null)
{
$this->createEntry($student, $audition, $entry_for);
return $this->createEntry($student, $audition, $entry_for);
}
/**

View File

@ -8,5 +8,5 @@ enum EntryFlags: string
case DECLINED = 'declined';
case NO_SHOW = 'no_show';
case FAILED_PRELIM = 'failed_prelim';
case LATE_FEE_WAIVED = 'late_fee_waived';
}

View File

@ -102,6 +102,7 @@ class EntryController extends Controller
$validData['for_seating'] = $request->get('for_seating') ? 1 : 0;
$validData['for_advancement'] = $request->get('for_advancement') ? 1 : 0;
$validData['late_fee_waived'] = $request->get('late_fee_waived') ? 1 : 0;
$enter_for = [];
if ($validData['for_seating']) {
$enter_for[] = 'seating';
@ -111,10 +112,13 @@ class EntryController extends Controller
}
try {
$creator($validData['student_id'], $validData['audition_id'], $enter_for);
$entry = $creator($validData['student_id'], $validData['audition_id'], $enter_for);
} catch (ManageEntryException $ex) {
return redirect()->route('admin.entries.index')->with('error', $ex->getMessage());
}
if ($validData['late_fee_waived']) {
$entry->addFlag('late_fee_waived');
}
return redirect(route('admin.entries.index'))->with('success', 'The entry has been added.');
}

View File

@ -91,6 +91,7 @@ class Entry extends Model
'declined' => EntryFlags::DECLINED,
'no_show' => EntryFlags::NO_SHOW,
'failed_prelim' => EntryFlags::FAILED_PRELIM,
'late_fee_waived' => EntryFlags::LATE_FEE_WAIVED,
};
$this->flags()->create(['flag_name' => $enum]);
$this->load('flags');

View File

@ -1,3 +1,4 @@
<!--suppress JSUnresolvedReference -->
<x-layout.app>
<x-card.card class="mx-auto max-w-2xl">
<x-card.heading>Create Entry</x-card.heading>
@ -8,7 +9,8 @@
<x-slot:label>Student</x-slot:label>
<option value="" disabled selected>Select a student</option>
<template x-for="student in students" :key="student.id">
<option :value="student.id" x-text="`${student.name} - ${student.school} - Grade ${student.grade}`"></option>
<option :value="student.id"
x-text="`${student.name} - ${student.school} - Grade ${student.grade}`"></option>
</template>
</x-form.select>
@ -34,6 +36,10 @@
@else
<input type="hidden" name="for_seating" value="on">
@endif
<div class="col-span-3 align-top">
<x-form.checkbox name="late_fee_waived"
label="Wave late fee if applicable"/>
</div>
</x-form.body-grid>
<x-form.footer class="mb-5">
<x-form.button>Create Entry</x-form.button>

View File

@ -1,6 +1,7 @@
<?php
use App\Models\Audition;
use App\Models\Entry;
use App\Models\Student;
use Illuminate\Foundation\Testing\RefreshDatabase;
@ -87,3 +88,31 @@ it('can create a late entry', function () {
'for_advancement' => 0,
]);
});
it('can mark a late fee waived for an entry', function () {
$audition = Audition::factory()->closed()->create(['maximum_grade' => 12, 'minimum_grade' => 7]);
$student = Student::factory()->create(['grade' => 9]);
actAsAdmin();
$response = $this->post(route('admin.entries.store'), [
'student_id' => $student->id,
'audition_id' => $audition->id,
'for_seating' => 'on',
'late_fee_waived' => 'on',
]);
$response->assertRedirect(route('admin.entries.index'))
->assertSessionDoesntHaveErrors()
->assertSessionMissing('error')
->assertSessionHas('success', 'The entry has been added.');
assertDatabaseHas('entries', [
'student_id' => $student->id,
'audition_id' => $audition->id,
'for_seating' => 1,
'for_advancement' => 0,
]);
$entry = Entry::where('student_id', $student->id)->where('audition_id', $audition->id)->first();
assertDatabaseHas('entry_flags', [
'entry_id' => 1,
'flag_name' => 'late_fee_waived',
]);
});