authorizeAbility($request, 'queues.view'); $owner = $this->ownerRef($request); $organization = $this->organization($request); $branchScope = app(OrganizationResolver::class)->branchScope($this->member($request)); $queues = ServiceQueue::owned($owner) ->where('organization_id', $organization->id) ->when($branchScope, fn ($q) => $q->where('branch_id', $branchScope)) ->where('is_active', true) ->with('branch') ->orderBy('name') ->get(); $waiting = Ticket::owned($owner) ->where('organization_id', $organization->id) ->where('status', 'waiting') ->when($branchScope, fn ($q) => $q->where('branch_id', $branchScope)) ->with('serviceQueue') ->orderBy('issued_at') ->limit(100) ->get(); $serving = Ticket::owned($owner) ->where('organization_id', $organization->id) ->whereIn('status', ['called', 'serving']) ->when($branchScope, fn ($q) => $q->where('branch_id', $branchScope)) ->with(['serviceQueue', 'counter']) ->orderByDesc('called_at') ->limit(20) ->get(); return view('qms.board.index', compact('organization', 'queues', 'waiting', 'serving')); } }