diff --git a/app/Actions/Print/PrintSignInSheets.php b/app/Actions/Print/PrintSignInSheets.php new file mode 100644 index 0000000..738c57c --- /dev/null +++ b/app/Actions/Print/PrintSignInSheets.php @@ -0,0 +1,96 @@ + .5, + 'instrument' => 1.25, + 'drawNumber' => .3, + 'name' => 1.8, + 'school' => 1.4, + ]; + + protected $headerRowHeight = .25; + + protected $bodyRowHeight = .3125; + + protected $blankLinesPerRoom = 10; + + protected $addBlankLinesAuditionFactor = .1; + + public function __construct() + { + } + + public function __invoke(Collection $rooms): void + { + $this->print($rooms); + } + + /** + * @param Collection|Room[] $rooms + */ + public function print(Collection $rooms) + { + $this->pdf = new signInPDF('P', 'in', 'letter'); + $this->pdf->columnWidth = $this->columnWidth; + $this->pdf->headerRowHeight = $this->headerRowHeight; + $this->pdf->SetMargins($this->margin, $this->margin); + $this->pdf->SetAutoPageBreak(true, .5); + //$this->pdf->SetFont('arial', '', '10'); + foreach ($rooms as $room) { + $this->pdf->roomOn = $room->name; + $auditions = $room->auditions; + $this->pdf->AddPage(); + foreach ($auditions as $audition) { + $entries = $audition->entries()->orderBy('draw_number')->get(); + foreach ($entries as $entry) { + $this->addEntryRow($entry); + } + // Add extra rows for audition + $extraRowCount = ceil($audition->entries()->count() * $this->addBlankLinesAuditionFactor); + for ($n = 0; $n < $extraRowCount; $n++) { + $this->addBlankRow($audition); + } + } + for ($n = 0; $n < $this->blankLinesPerRoom; $n++) { + $this->addBlankRow(); + } + } + $this->pdf->Output('D', 'SignInSheets.pdf'); + } + + public function addEntryRow(Entry $entry) + { + $this->pdf->Cell($this->columnWidth['id'], $this->bodyRowHeight, $entry->id, 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['instrument'], $this->bodyRowHeight, $entry->audition->name, 1, 0, + 'L'); + $this->pdf->Cell($this->columnWidth['drawNumber'], $this->bodyRowHeight, $entry->draw_number, 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['name'], $this->bodyRowHeight, $entry->student->full_name(), 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['school'], $this->bodyRowHeight, $entry->student->school->name, 1, 0, 'L'); + $this->pdf->Cell(0, $this->bodyRowHeight, ' ', 1, 1, 'L'); + } + + public function addBlankRow($audition = null) + { + $a = ($audition ? $audition->name : ' '); + $this->pdf->Cell($this->columnWidth['id'], $this->bodyRowHeight, ' ', 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['instrument'], $this->bodyRowHeight, $a, 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['drawNumber'], $this->bodyRowHeight, ' ', 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['name'], $this->bodyRowHeight, ' ', 1, 0, 'L'); + $this->pdf->Cell($this->columnWidth['school'], $this->bodyRowHeight, ' ', 1, 0, 'L'); + $this->pdf->Cell(0, $this->bodyRowHeight, ' ', 1, 1, 'L'); + } +} diff --git a/app/Actions/Print/signInPDF.php b/app/Actions/Print/signInPDF.php new file mode 100644 index 0000000..4dbabd6 --- /dev/null +++ b/app/Actions/Print/signInPDF.php @@ -0,0 +1,35 @@ + .5, + 'instrument' => 1.25, + 'drawNumber' => .3, + 'name' => 1.8, + 'school' => 1.4, + ]; + + public $headerRowHeight = .25; + + public function Header() + { + $this->SetFont('arial', '', '10'); + $headerText = auditionSetting('auditionName').' - Student Sign In - Room: '; + $headerText .= $this->roomOn; + $this->Cell(0, .3, $headerText, 1, 0, 'C'); + $this->Ln(.4); + $this->Cell($this->columnWidth['id'], $this->headerRowHeight, 'I.D.', 1, 0, 'L'); + $this->Cell($this->columnWidth['instrument'], $this->headerRowHeight, 'Instrument', 1, 0, 'L'); + $this->Cell($this->columnWidth['drawNumber'], $this->headerRowHeight, '#', 1, 0, 'L'); + $this->Cell($this->columnWidth['name'], $this->headerRowHeight, 'Name (D) = Doubler', 1, 0, 'L'); + $this->Cell($this->columnWidth['school'], $this->headerRowHeight, 'School', 1, 0, 'L'); + $this->Cell(0, $this->headerRowHeight, 'Signature', 1, 1, 'L'); + } +} diff --git a/app/Http/Controllers/Admin/PrintSignInSheetsController.php b/app/Http/Controllers/Admin/PrintSignInSheetsController.php new file mode 100644 index 0000000..e348106 --- /dev/null +++ b/app/Http/Controllers/Admin/PrintSignInSheetsController.php @@ -0,0 +1,27 @@ +', 0)->get(); + + return view('admin.print_sign_in_sheets.index', compact('rooms')); + } + + public function print(PrintSignInSheets $printer) + { + $selectedRoomIds = array_keys(request()->room); + $rooms = Room::whereIn('id', $selectedRoomIds)->get(); + $printer->print($rooms); + } +} diff --git a/resources/views/admin/print_sign_in_sheets/index.blade.php b/resources/views/admin/print_sign_in_sheets/index.blade.php new file mode 100644 index 0000000..81c3576 --- /dev/null +++ b/resources/views/admin/print_sign_in_sheets/index.blade.php @@ -0,0 +1,23 @@ + + Select Sign-In Sheets to Print + + + + Rooms + + + + + +
+ @foreach($rooms as $room) +
+ + {{$room->name}} +
+ @endforeach +
+
+ Print Sign-In Sheets +
+
diff --git a/resources/views/components/layout/navbar/menus/setup.blade.php b/resources/views/components/layout/navbar/menus/setup.blade.php index 3f51ab8..47998b7 100644 --- a/resources/views/components/layout/navbar/menus/setup.blade.php +++ b/resources/views/components/layout/navbar/menus/setup.blade.php @@ -31,6 +31,7 @@ Judges Run Draw Print Cards + Print Sign-In Sheets diff --git a/routes/admin.php b/routes/admin.php index 53de58b..b38f4ab 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -9,6 +9,7 @@ use App\Http\Controllers\Admin\EnsembleController; use App\Http\Controllers\Admin\EntryController; use App\Http\Controllers\Admin\EventController; use App\Http\Controllers\Admin\PrintCards; +use App\Http\Controllers\Admin\PrintSignInSheetsController; use App\Http\Controllers\Admin\RoomController; use App\Http\Controllers\Admin\SchoolController; use App\Http\Controllers\Admin\ScoringGuideController; @@ -170,4 +171,10 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> Route::get('/', 'index')->name('admin.cards.index'); Route::post('/print', 'print')->name('admin.cards.print'); }); + + // Admin SignIn Sheet Routes + Route::prefix('signInSheets')->controller(PrintSignInSheetsController::class)->group(function () { + Route::get('/', 'index')->name('admin.signInSheets.index'); + Route::post('/print', 'print')->name('admin.signInSheets.print'); + }); }); diff --git a/tests/Feature/Pages/Admin/PrintSigninSheetsTest.php b/tests/Feature/Pages/Admin/PrintSigninSheetsTest.php new file mode 100644 index 0000000..63ac4d1 --- /dev/null +++ b/tests/Feature/Pages/Admin/PrintSigninSheetsTest.php @@ -0,0 +1,45 @@ +assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); +}); +it('ignores requests from tabulation users', function () { + // Arrange + actAsTab(); + get(route('admin.signInSheets.index')) + ->assertRedirect(route('dashboard')) + ->assertSessionHas('error', 'You are not authorized to perform this action'); +}); +it('ignores requests from guests', function () { + // Arrange + get(route('admin.signInSheets.index')) + ->assertRedirect(route('home')); +}); +it('allows access to admin users', function () { + // Arrange + actAsAdmin(); + // Act and Assert + get(route('admin.signInSheets.index')) + ->assertOk() + ->assertViewIs('admin.print_sign_in_sheets.index') + ->assertSessionHasNoErrors(); +}); +it('shows rooms', function () { + $room = Room::factory()->create(); + actAsAdmin(); + get(route('admin.signInSheets.index')) + ->assertSee($room->name); +}); + +// Process the form and print the sheets