@php
$baseUrl = route('platform.mystery.shopper.allocate');
$pendingMysteryShopperCalls = $assignmentsByBusiness
->flatMap(fn ($assignment) => $assignment->calls ?? collect())
->filter(fn ($call) => empty($call->mystery_shopper_id))
->count();
$hasAssignments = $assignmentsByBusiness->isNotEmpty();
$selectedYear = preg_match('/^\d{4}-\d{2}$/', (string) $selectedMonth) ? substr((string) $selectedMonth, 0, 4) : '2026';
$selectedMonthNumber = preg_match('/^\d{4}-\d{2}$/', (string) $selectedMonth) ? substr((string) $selectedMonth, 5, 2) : now()->format('m');
$yearOptions = collect(range(2026, 2030));
$monthOptions = collect(range(1, 12))->mapWithKeys(fn ($month) => [
str_pad((string) $month, 2, '0', STR_PAD_LEFT) => \Carbon\Carbon::create()->month($month)->format('F'),
]);
@endphp
Sector
@foreach($sectors as $sector)
id)>{{ $sector->name }}
@endforeach
Year
@foreach($yearOptions as $year)
{{ $year }}
@endforeach
Month
@foreach($monthOptions as $monthValue => $monthLabel)
{{ $monthLabel }}
@endforeach
Select a sector and month, then assign one mystery shopper per call number. Saving applies that call selection to every company in the filtered assignment set.
@if($businesses->isEmpty())
No active businesses with monthly call volumes were found for this sector.
@elseif(! $hasAssignments)
Sector
{{ $sectors->firstWhere('id', $selectedSectorId)?->name ?? 'N/A' }}
Month
{{ $selectedMonth ? \Carbon\Carbon::createFromFormat('Y-m', $selectedMonth)->format('F Y') : 'N/A' }}
Businesses
{{ $businesses->count() }}
Max Calls
{{ $maxCallCount }}
No assignments were found for the selected sector and month.
@else
Sector
{{ $sectors->firstWhere('id', $selectedSectorId)?->name ?? 'N/A' }}
Month
{{ $selectedMonth ? \Carbon\Carbon::createFromFormat('Y-m', $selectedMonth)->format('F Y') : 'N/A' }}
Businesses
{{ $businesses->count() }}
Max Calls
{{ $maxCallCount }}
Pending Mystery Shoppers
{{ $pendingMysteryShopperCalls }}
@if($pendingMysteryShopperCalls === 0)
All allocation is done. If you assign again here, it will overwrite all existing mystery shopper allocations for this sector and month.
@endif
Assign Mystery Shoppers
Each dropdown below controls that call number for all companies in this sector and month.
@for($callNumber = 1; $callNumber <= $maxCallCount; $callNumber++)
Call {{ $callNumber }}
Select Mystery Shopper
@foreach($mysteryShoppers as $user)
{{ $user->name }}
@endforeach
@endfor
@endif