Print sign in sheets working

Closes #73
This commit is contained in:
Matt Young 2024-10-16 14:20:07 -05:00
parent 3015e264cc
commit 2a7623a091
7 changed files with 193 additions and 0 deletions

View File

@ -0,0 +1,96 @@
<?php
namespace App\Actions\Print;
use App\Models\Entry;
use App\Models\Room;
use Illuminate\Support\Collection;
class PrintSignInSheets
{
protected $pdf;
protected $margin = .5;
protected $roomOn;
protected $columnWidth = [
'id' => .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');
}
}

View File

@ -0,0 +1,35 @@
<?php
namespace App\Actions\Print;
use Codedge\Fpdf\Fpdf\Fpdf;
class signInPDF extends Fpdf
{
public $roomOn;
public $columnWidth = [
'id' => .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');
}
}

View File

@ -2,12 +2,26 @@
namespace App\Http\Controllers\Admin;
use App\Actions\Print\PrintSignInSheets;
use App\Http\Controllers\Controller;
use App\Models\Room;
use function array_keys;
use function request;
class PrintSignInSheetsController extends Controller
{
public function index()
{
$rooms = Room::where('id', '>', 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);
}
}

View File

@ -0,0 +1,23 @@
<x-layout.app>
<x-slot:page_title>Select Sign-In Sheets to Print</x-slot:page_title>
<x-form.form method="POST" action="{{route('admin.signInSheets.print')}}">
<x-card.card class="mb-5 mx-auto max-w-3xl" id="room-card" x-data="{ allChecked: false }">
<x-card.heading>
Rooms
<x-slot:right_side>
<button @click="allChecked = true" class="rounded bg-indigo-50 px-2 py-1 text-xs font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100 mr-3" type="button">Check All</button>
<button @click="allChecked = false" class="rounded bg-indigo-50 px-2 py-1 text-xs font-semibold text-indigo-600 shadow-sm hover:bg-indigo-100" type="button">Uncheck All</button>
</x-slot:right_side>
</x-card.heading>
<div class="grid gap-y-3 md:grid-cols-2 lg:grid-cols-3 px-5 my-3 pb-3 border-b border-gray-100">
@foreach($rooms as $room)
<div id="room-div-{{$room->id}}" class="flex align-middle">
<x-form.checkbox id="roomCheckbox-{{$room->id}}" name="room[{{$room->id}}]" x-bind:checked="allChecked"/>
{{$room->name}}
</div>
@endforeach
</div>
</x-card.card>
<x-form.button class="mt-5 mx-auto max-w-3xl" type="submit">Print Sign-In Sheets</x-form.button>
</x-form.form>
</x-layout.app>

View File

@ -31,6 +31,7 @@
<x-layout.navbar.menus.menu-item :href="route('admin.rooms.judgingAssignment')">Judges</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.draw.index')">Run Draw</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.cards.index')">Print Cards</x-layout.navbar.menus.menu-item>
<x-layout.navbar.menus.menu-item :href="route('admin.signInSheets.index')">Print Sign-In Sheets</x-layout.navbar.menus.menu-item>
</div>
</div>
</div>

View File

@ -175,5 +175,6 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
// 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');
});
});

View File

@ -1,5 +1,6 @@
<?php
use App\Models\Room;
use Illuminate\Foundation\Testing\RefreshDatabase;
use function Pest\Laravel\get;
@ -20,3 +21,25 @@ it('ignores requests from tabulation users', function () {
->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