> */ public array $rows = []; /** @var array */ public array $totals = [ 'tutte' => 0, 'ticket_amministratore' => 0, 'interne' => 0, ]; public static function canAccess(): bool { $user = Auth::user(); return $user instanceof User && $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'fornitore']); } public function mount(): void { $this->scope = (string) request()->query('scope', 'tutte'); [$fornitore] = $this->resolveOperatoreContext(allowAdminWithoutSupplier: true); if (! $fornitore instanceof Fornitore) { $this->missingAdminContext = true; return; } $this->fornitoreId = (int) $fornitore->id; $this->fornitoreLabel = $this->getFornitoreLabel($fornitore); $this->refreshData(); } public function updatedScope(): void { $this->refreshData(); } public function setScope(string $scope): void { $this->scope = $scope; $this->refreshData(); } public function refreshData(): void { if (! $this->fornitoreId) { $this->rows = []; return; } [$fornitore, $dipendente] = $this->resolveOperatoreContext($this->fornitoreId); $baseQuery = $this->buildBaseQuery($fornitore, $dipendente); $this->totals = [ 'tutte' => (clone $baseQuery)->count(), 'ticket_amministratore' => (clone $baseQuery)->count(), 'interne' => 0, ]; if ($this->scope === 'interne') { $this->rows = []; return; } $this->rows = $baseQuery ->limit(120) ->get() ->map(function (TicketIntervento $intervento): array { $base = $this->buildInterventoRow($intervento); return array_merge($base, [ 'id' => (int) $intervento->id, 'ticket_id' => (int) $intervento->ticket_id, 'titolo' => (string) ($intervento->ticket->titolo ?? '-'), 'stato' => (string) $intervento->stato, 'stabile' => (string) ($intervento->ticket->stabile->denominazione ?? '-'), 'operatore' => (string) $intervento->operatore_assegnato_label, 'tempo_minuti' => (int) ($intervento->tempo_minuti ?? 0), 'updated_at' => optional($intervento->updated_at)->format('d/m/Y H:i') ?: '-', 'origine' => 'Ticket amministratore', 'url' => TicketInterventoScheda::getUrl(['record' => (int) $intervento->id], panel: 'admin-filament'), ]); }) ->all(); } public function getTicketsUrl(): string { if ($this->fornitoreId) { return TicketOperativi::getUrl(['fornitore' => $this->fornitoreId], panel: 'admin-filament'); } return TicketOperativi::getUrl(panel: 'admin-filament'); } public function getCollaboratoriUrl(): string { if ($this->fornitoreId) { return Collaboratori::getUrl(['fornitore' => $this->fornitoreId], panel: 'admin-filament'); } return Collaboratori::getUrl(panel: 'admin-filament'); } public function getRubricaUrl(): string { if ($this->fornitoreId) { return RubricaClienti::getUrl(['fornitore' => $this->fornitoreId], panel: 'admin-filament'); } return RubricaClienti::getUrl(panel: 'admin-filament'); } public function getProdottiUrl(): string { if ($this->fornitoreId) { return ProdottiCatalogo::getUrl(['fornitore' => $this->fornitoreId], panel: 'admin-filament'); } return ProdottiCatalogo::getUrl(panel: 'admin-filament'); } protected function buildBaseQuery(Fornitore $fornitore, ?FornitoreDipendente $dipendente): Builder { $query = TicketIntervento::query() ->with(['ticket.stabile', 'ticket.unitaImmobiliare', 'ticket.soggettoRichiedente', 'eseguitoDaDipendente']) ->where('fornitore_id', (int) $fornitore->id) ->orderByDesc('created_at'); if ($dipendente instanceof FornitoreDipendente) { $query->where(function (Builder $builder) use ($dipendente): void { $builder->whereNull('eseguito_da_dipendente_id') ->orWhere('eseguito_da_dipendente_id', (int) $dipendente->id); }); } return $query; } }