T-shirt by school for SCOBDA

This commit is contained in:
Matt Young 2025-03-06 20:04:24 -06:00
parent abc8b0bcb1
commit fb750aaea1
4 changed files with 94 additions and 31 deletions

View File

@ -5,6 +5,7 @@ namespace App\Http\Controllers\NominationEnsembles;
use App\Http\Controllers\Controller;
use App\Models\NominationEnsemble;
use App\Models\NominationEnsembleEntry;
use App\Models\School;
use App\Models\Student;
use function redirect;
@ -13,13 +14,16 @@ class ScobdaNominationSeatingController extends Controller implements Nomination
{
public function index()
{
$shirtReportType = request()->get('shirtReportType') || null;
$shirtReportType = request()->get('shirtReportType') ?? 'none';
$ensembles = NominationEnsemble::all();
$ensemble = null;
$shirtCounts = ($shirtReportType == 'full') ? $this->totalShirtCount() : null;
$schoolShirtCounts = ($shirtReportType == 'by_school') ? $this->schoolShirtCount() : null;
$shirtSizes = Student::$shirtSizes;
$schools = School::all();
return view('nomination_ensembles.scobda.admin.seating.index',
compact('ensembles', 'ensemble', 'shirtReportType', 'shirtCounts'));
compact('ensembles', 'ensemble', 'shirtReportType', 'shirtCounts', 'schoolShirtCounts', 'shirtSizes', 'schools'));
}
protected function totalShirtCount()
@ -38,6 +42,26 @@ class ScobdaNominationSeatingController extends Controller implements Nomination
return $shirtCounts;
}
/**
* @return array an array of school ids, each containing and array where the key is a shirt size and the value is the count
*/
protected function schoolShirtCount(): array
{
$acceptedNominationEntries = NominationEnsembleEntry::where('data->accepted', true)
->with('student.school')
->get();
$schoolShirtCounts = [];
foreach ($acceptedNominationEntries as $entry) {
if (! isset($schoolShirtCounts[$entry->student->school->id])) {
$schoolShirtCounts[$entry->student->school->id] = [];
}
$schoolShirtCounts[$entry->student->school->id][$entry->student->optional_data['shirt_size']] =
($schoolShirtCounts[$entry->student->school->id][$entry->student->optional_data['shirt_size']] ?? 0) + 1;
}
return $schoolShirtCounts;
}
public function show(NominationEnsemble $ensemble)
{
$ensembles = NominationEnsemble::all();

View File

@ -19,10 +19,17 @@
<p class="text-md/6 font-semibold text-gray-800 mb-3 mt-3">Shirts Needed</p>
<ul role="list" class="-mx2 space-y-1">
<li>
<a href="{{ route('nomination.admin.seating.index', ['shirtReportType'=>'full']) }}" class="group flex gap-x-3 rounded-md p-2 pl-3 text-sm/6 font-semibold text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
<a href="{{ route('nomination.admin.seating.index', ['shirtReportType'=>'full']) }}"
class="group flex gap-x-3 rounded-md p-2 pl-3 text-sm/6 font-semibold text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
Total Needed
</a>
</li>
<li>
<a href="{{ route('nomination.admin.seating.index', ['shirtReportType'=>'by_school']) }}"
class="group flex gap-x-3 rounded-md p-2 pl-3 text-sm/6 font-semibold text-gray-700 hover:bg-gray-50 hover:text-indigo-600">
By School
</a>
</li>
</ul>
</nav>
</div>
@ -31,27 +38,11 @@
@if($ensemble)
@include('nomination_ensembles.scobda.admin.seating.seating_card')
@endif
@if($shirtReportType ?? NULL == 'full')
<x-card.card>
<x-card.heading>Total Shirt Needs</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Shirt Size</x-table.th>
<x-table.th>Total Needed</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($shirtCounts as $size => $count)
<tr>
<x-table.td>{{ $size }}</x-table.td>
<x-table.td>{{ $count }}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>
@if($shirtReportType == 'full')
@include('nomination_ensembles.scobda.admin.seating.total_shirt_report')
@endif
@if($shirtReportType == 'by_school')
@include('nomination_ensembles.scobda.admin.seating.school_shirt_report')
@endif
</div>

View File

@ -0,0 +1,29 @@
<x-card.card>
<x-card.heading>Shirt Needs by School</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>School</x-table.th>
@foreach($shirtSizes as $shortSize => $size)
<x-table.th>{{ $shortSize }}</x-table.th>
@endforeach
<x-table.th>Total</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($schools as $school)
@php($total = 0)
<tr>
<x-table.td>{{ $school->name }}</x-table.td>
@foreach($shirtSizes as $shortSize => $size)
<x-table.td>
{{ $schoolShirtCounts[$school->id][$shortSize] ?? '-' }}
@php($total += $schoolShirtCounts[$school->id][$shortSize] ?? 0)
</x-table.td>
@endforeach
<td>{{ $total }}</td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>

View File

@ -0,0 +1,19 @@
<x-card.card>
<x-card.heading>Total Shirt Needs</x-card.heading>
<x-table.table>
<thead>
<tr>
<x-table.th>Shirt Size</x-table.th>
<x-table.th>Total Needed</x-table.th>
</tr>
</thead>
<x-table.body>
@foreach($shirtCounts as $size => $count)
<tr>
<x-table.td>{{ $size }}</x-table.td>
<x-table.td>{{ $count }}</x-table.td>
</tr>
@endforeach
</x-table.body>
</x-table.table>
</x-card.card>