campagna = $campagna; } public function render() { // Assignments counted for this campaign: linked via campaign_id and // flagged as counted — the same set used by the percentage // (Campagna::percentuale_percorrenza). Which campaign is offered on // return is decided by Assegnazione::campagnaApplicabile(). $conteggiate = $this->campagna->assegnazioniConteggiate() ->with(['territorio', 'proclamatore']) ->orderBy('returned_at') ->get(); // Open assignments can still be counted for this campaign only while // no later campaign has started: on return the most recent one is // offered (see Assegnazione::campagnaApplicabile()). $superata = Campagna::where('start_date', '>', $this->campagna->start_date) ->where('start_date', '<=', now()->toDateString()) ->exists(); $inCorso = $superata ? null : $this->campagna->assegnazioniInCorso() ->with(['territorio', 'proclamatore']) ->orderBy('assigned_at') ->get(); // All assignments that were active during this campaign range $assegnateNelRange = Assegnazione::where('assigned_at', '<=', $this->campagna->end_date) ->where(function ($q) { $q->whereNull('returned_at') ->orWhere('returned_at', '>=', $this->campagna->start_date); }) ->count(); return view('livewire.campagne.campagna-show', [ 'conteggiate' => $conteggiate, 'inCorso' => $inCorso, 'assegnateNelRange' => $assegnateNelRange, ]); } }