From 7c0b042e887f53d7be206d26f1a49311e195f822 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 16 Oct 2024 15:43:21 -0500 Subject: [PATCH 1/2] Initial work on printing room and judge assignment report Work on #77 --- .../Admin/PrintRoomAssignmentsController.php | 13 +++++++++++++ .../components/layout/navbar/menus/setup.blade.php | 2 ++ routes/admin.php | 4 ++++ 3 files changed, 19 insertions(+) create mode 100644 app/Http/Controllers/Admin/PrintRoomAssignmentsController.php diff --git a/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php b/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php new file mode 100644 index 0000000..dbdc8e9 --- /dev/null +++ b/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php @@ -0,0 +1,13 @@ +Run Draw Print Cards Print Sign-In Sheets + Print Room and Judge Assignments + diff --git a/routes/admin.php b/routes/admin.php index b38f4ab..0ab9b6c 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\PrintRoomAssignmentsController; use App\Http\Controllers\Admin\PrintSignInSheetsController; use App\Http\Controllers\Admin\RoomController; use App\Http\Controllers\Admin\SchoolController; @@ -177,4 +178,7 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> Route::get('/', 'index')->name('admin.signInSheets.index'); Route::post('/print', 'print')->name('admin.signInSheets.print'); }); + + // Print Room and Judge Assignment Report + Route::get('room_assignment_report', PrintRoomAssignmentsController::class)->name('admin.print_room_assignment_report'); }); -- 2.39.5 From 632be2cd4fb3bd00b3c401137a3ff2c366fc5c27 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Wed, 16 Oct 2024 17:56:35 -0500 Subject: [PATCH 2/2] Room and Judge Assignment Report Complete Closes #77 --- .../Admin/PrintRoomAssignmentsController.php | 93 ++++++++++++++++++- 1 file changed, 92 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php b/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php index dbdc8e9..66a3137 100644 --- a/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php +++ b/app/Http/Controllers/Admin/PrintRoomAssignmentsController.php @@ -3,11 +3,102 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; +use App\Models\Room; +use Codedge\Fpdf\Fpdf\Fpdf; + +use function auditionSetting; class PrintRoomAssignmentsController extends Controller { + private $pdf; + + /* TABLE DIMENSIONS */ + private $col1width = 1.7; + + private $col2width = 2.6; + + private $lineHeight = .2; + public function __invoke() { - echo 'Printing Room Assignments'; + $this->pdf = new reportPDF('P', 'in', 'letter'); + $this->pdf->SetMargins(.3, .3); + $this->pdf->SetAutoPageBreak(true, .5); + $this->pdf->AddPage(); + $this->pdf->SetFont('arial', 'B', '10'); + $headerText = auditionSetting('auditionName').' - Room and Judge Assignments'; + $this->pdf->Cell(0, .2, $headerText, 1, 1, 'C'); + $this->pdf->Ln(.1); + + $this->pdf->SetFont('arial', 'B', '10'); + + /* TABLE HEADER */ + $this->pdf->cell($this->col1width, $this->lineHeight, 'Room', 1); + $this->pdf->cell($this->col2width, $this->lineHeight, 'Auditions', 1); + $this->pdf->cell(0, $this->lineHeight, 'Judges', 1, 1); + + $rooms = Room::withCount('entries')->where('id', '>', 0)->with('auditions')->with('judges')->get(); + + foreach ($rooms as $room) { + $this->roomRow($room); + } + + $this->pdf->Output('D', 'JudgingAssignments.pdf'); + } + + private function roomRow(Room $room) + { + $this->pdf->SetFont('arial', '', '9'); + $roomDescription = $room->name.' ('.$room->entries_count.')'; + $judgingAssignments = $room->judges; + $auditions = $room->auditions()->withCount('entries')->get(); + $numLines = max([$judgingAssignments->count(), $auditions->count()]); + $rowHeight = $this->lineHeight * $numLines; + $auditionText = ''; + $judgeText = ''; + + foreach ($auditions as $audition) { + $auditionText .= $audition->name.' ('.$audition->entries_count.')'; + $auditionText .= PHP_EOL; + } + + foreach ($judgingAssignments as $ja) { + $judgeText .= $ja->full_name(); + $judgeText .= PHP_EOL; + } + + if ($this->pdf->GetY() + $rowHeight > $this->pdf->getPageBreakTrigger()) { + $this->pdf->AddPage(); + } + + $startx = $this->pdf->getX(); + $starty = $this->pdf->getY(); + + /* CELL BORDERS */ + $this->pdf->MultiCell($this->col1width, $rowHeight, ' ', 1, 'C'); + $this->pdf->SetXY($startx + $this->col1width, $starty); + $this->pdf->MultiCell($this->col2width, $rowHeight, ' ', 1); + $this->pdf->SetXY($startx + $this->col1width + $this->col2width, $starty); + $this->pdf->MultiCell(0, $rowHeight, ' ', 1); + + /* CELL CONTENTS */ + $this->pdf->SetXY($startx, $starty); + $this->pdf->MultiCell($this->col1width, $this->lineHeight, $roomDescription, 0, 'C'); + $this->pdf->SetXY($startx + $this->col1width, $starty); + $this->pdf->MultiCell($this->col2width, $this->lineHeight, $auditionText); + $this->pdf->SetXY($startx + $this->col1width + $this->col2width, $starty); + $this->pdf->MultiCell(0, $this->lineHeight, $judgeText, 0); + + /* SET LOCATION FOR NEXT ROW */ + $this->pdf->setXY($startx, $starty + $rowHeight); + + } +} + +class reportPDF extends FPDF +{ + public function getPageBreakTrigger() + { + return $this->PageBreakTrigger; } } -- 2.39.5