netgescon-day0/resources/views/filament/pages/gescon/rubrica-universale-scheda.blade.php

750 lines
44 KiB
PHP

<x-filament-panels::page>
@if($isInlineEditing)
<x-filament::section>
<x-slot name="heading">Modifica Contatto Inline</x-slot>
<x-slot name="description">Modifica i campi direttamente in pagina, senza modal.</x-slot>
<div class="grid grid-cols-1 gap-3 md:grid-cols-3">
<label class="text-sm">
<span class="mb-1 block text-gray-600">Nome</span>
<input type="text" wire:model.defer="inlineForm.nome" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Cognome</span>
<input type="text" wire:model.defer="inlineForm.cognome" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Ragione sociale</span>
<input type="text" wire:model.defer="inlineForm.ragione_sociale" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Tipo contatto</span>
<input type="text" wire:model.defer="inlineForm.tipo_contatto" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Categoria</span>
<input type="text" wire:model.defer="inlineForm.categoria" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Codice fiscale</span>
<input type="text" wire:model.defer="inlineForm.codice_fiscale" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Partita IVA</span>
<input type="text" wire:model.defer="inlineForm.partita_iva" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Sesso</span>
<select wire:model.defer="inlineForm.sesso" class="w-full rounded-md border-gray-300 text-sm">
<option value="">Seleziona</option>
<option value="M">M</option>
<option value="F">F</option>
</select>
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Data nascita</span>
<input type="date" wire:model.defer="inlineForm.data_nascita" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Luogo nascita</span>
<input type="text" wire:model.defer="inlineForm.luogo_nascita" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Provincia nascita</span>
<input type="text" wire:model.defer="inlineForm.provincia_nascita" maxlength="2" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Email</span>
<input type="text" wire:model.defer="inlineForm.email" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">PEC</span>
<input type="text" wire:model.defer="inlineForm.pec" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Telefono ufficio</span>
<input type="text" wire:model.defer="inlineForm.telefono_ufficio" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Cellulare</span>
<input type="text" wire:model.defer="inlineForm.telefono_cellulare" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Telefono casa</span>
<input type="text" wire:model.defer="inlineForm.telefono_casa" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm md:col-span-2">
<span class="mb-1 block text-gray-600">Indirizzo</span>
<input type="text" wire:model.defer="inlineForm.indirizzo" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Civico</span>
<input type="text" wire:model.defer="inlineForm.civico" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">CAP</span>
<input type="text" wire:model.defer="inlineForm.cap" maxlength="5" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Città</span>
<input type="text" wire:model.defer="inlineForm.citta" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Provincia</span>
<input type="text" wire:model.defer="inlineForm.provincia" maxlength="2" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm md:col-span-3">
<span class="mb-1 block text-gray-600">Indirizzo completo legacy</span>
<input type="text" wire:model.defer="inlineForm.indirizzo_completo" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Profilo chiamante</span>
<input type="text" wire:model.defer="inlineForm.tipo_utenza_call" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Rif. stabile</span>
<input type="text" wire:model.defer="inlineForm.riferimento_stabile" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm">
<span class="mb-1 block text-gray-600">Rif. unità</span>
<input type="text" wire:model.defer="inlineForm.riferimento_unita" class="w-full rounded-md border-gray-300 text-sm" />
</label>
<label class="text-sm md:col-span-3">
<span class="mb-1 block text-gray-600">Note</span>
<textarea wire:model.defer="inlineForm.note" rows="3" class="w-full rounded-md border-gray-300 text-sm"></textarea>
</label>
<label class="text-sm md:col-span-3">
<span class="mb-1 block text-gray-600">Note segreteria</span>
<textarea wire:model.defer="inlineForm.note_segreteria" rows="3" class="w-full rounded-md border-gray-300 text-sm"></textarea>
</label>
</div>
<div class="mt-4 flex flex-wrap gap-2">
<x-filament::button type="button" wire:click="saveInlineEdit">Salva modifiche</x-filament::button>
<x-filament::button type="button" color="gray" wire:click="cancelInlineEdit">Annulla</x-filament::button>
</div>
</x-filament::section>
@endif
<div class="flex flex-col gap-2">
<div class="flex items-center justify-between gap-3">
@php
$prevUrl = $this->getPrevUrl();
$nextUrl = $this->getNextUrl();
@endphp
@if($prevUrl)
<x-filament::button tag="a" href="{{ $prevUrl }}" color="gray">
</x-filament::button>
@else
<x-filament::button color="gray" disabled>
</x-filament::button>
@endif
<div class="flex items-center gap-3 text-sm text-gray-600">
<div>
Pagina {{ $this->navPage }} / {{ $this->navPages }}
</div>
<label class="flex items-center gap-2">
<span>Visualizzati</span>
<select class="rounded-md border-gray-300 text-sm" onchange="window.location.href=this.value">
@foreach([10,25,50,100] as $pp)
<option value="{{ $this->getPerPageUrl($pp) }}" @selected($this->navPerPage === $pp)>{{ $pp }}</option>
@endforeach
</select>
</label>
</div>
@if($nextUrl)
<x-filament::button tag="a" href="{{ $nextUrl }}" color="gray">
</x-filament::button>
@else
<x-filament::button color="gray" disabled>
</x-filament::button>
@endif
</div>
<div class="flex items-center justify-center gap-2">
@php
$prevPageUrl = $this->getPrevPageUrl();
$nextPageUrl = $this->getNextPageUrl();
@endphp
@if($prevPageUrl)
<x-filament::button tag="a" href="{{ $prevPageUrl }}" color="gray" size="sm">
Pagina precedente
</x-filament::button>
@else
<x-filament::button color="gray" size="sm" disabled>
Pagina precedente
</x-filament::button>
@endif
@if($nextPageUrl)
<x-filament::button tag="a" href="{{ $nextPageUrl }}" color="gray" size="sm">
Pagina successiva
</x-filament::button>
@else
<x-filament::button color="gray" size="sm" disabled>
Pagina successiva
</x-filament::button>
@endif
</div>
</div>
<div class="grid grid-cols-1 gap-4 lg:grid-cols-3">
<x-filament::section class="lg:col-span-2">
<div class="grid grid-cols-1 gap-4 md:grid-cols-2">
<div>
<div class="text-sm text-gray-500">Nominativo</div>
<div class="text-lg font-semibold">{{ $rubrica->nome_completo ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Titolo</div>
<div class="text-lg font-semibold">
{{ $rubrica->titolo?->sigla ?? $rubrica->titolo?->nome ?? '—' }}
</div>
</div>
<div>
<div class="text-sm text-gray-500">Codice univoco</div>
<div class="font-mono">{{ $rubrica->codice_univoco ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Tipologia</div>
<div class="text-lg font-semibold">{{ $rubrica->tipo_contatto ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Categoria</div>
<div class="text-lg font-semibold">{{ $rubrica->categoria ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Codice fiscale</div>
<div class="font-mono">{{ $rubrica->codice_fiscale ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Partita IVA</div>
<div class="font-mono">{{ $rubrica->partita_iva ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Sesso</div>
<div>{{ $rubrica->sesso ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Data nascita</div>
<div>{{ $rubrica->data_nascita?->format('d/m/Y') ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Luogo nascita</div>
<div>{{ $rubrica->luogo_nascita ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Provincia nascita</div>
<div>{{ $rubrica->provincia_nascita ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Email</div>
<div>{{ $rubrica->email ?? '—' }}</div>
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Email aggiuntive</div>
@if(empty($emailMultiple))
<div></div>
@else
<div class="flex flex-wrap gap-2">
@foreach($emailMultiple as $emailRow)
<span class="inline-flex items-center rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs font-semibold text-gray-800">
{{ $emailRow['email'] }}
<span class="ml-1 text-gray-500">· {{ $emailRow['tipo_email'] ?? 'secondaria' }}</span>
@if(empty($emailRow['attiva']))
<span class="ml-1 text-gray-500">· inattiva</span>
@endif
</span>
@endforeach
</div>
@endif
</div>
<div>
<div class="text-sm text-gray-500">PEC</div>
<div>{{ $rubrica->pec ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Telefono</div>
<div class="flex items-center gap-2">
<span>{{ $rubrica->telefono_ufficio ?? '—' }}</span>
@if(filled($rubrica->telefono_ufficio) && $this->canRequestClickToCall())
<x-filament::button size="xs" color="info" type="button" wire:click="richiediClickToCallRubrica('telefono_ufficio')">Chiama</x-filament::button>
@endif
</div>
</div>
<div>
<div class="text-sm text-gray-500">Cellulare</div>
<div class="flex items-center gap-2">
<span>{{ $rubrica->telefono_cellulare ?? '—' }}</span>
@if(filled($rubrica->telefono_cellulare) && $this->canRequestClickToCall())
<x-filament::button size="xs" color="info" type="button" wire:click="richiediClickToCallRubrica('telefono_cellulare')">Chiama</x-filament::button>
@endif
</div>
</div>
<div>
<div class="text-sm text-gray-500">Profilo chiamante</div>
<div>{{ $rubrica->tipo_utenza_call ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Riferimento stabile</div>
<div>{{ $rubrica->riferimento_stabile ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Riferimento unità</div>
<div>{{ $rubrica->riferimento_unita ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Telefono casa</div>
<div class="flex items-center gap-2">
<span>{{ $rubrica->telefono_casa ?? '—' }}</span>
@if(filled($rubrica->telefono_casa) && $this->canRequestClickToCall())
<x-filament::button size="xs" color="info" type="button" wire:click="richiediClickToCallRubrica('telefono_casa')">Chiama</x-filament::button>
@endif
</div>
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Indirizzo</div>
<div>{{ $rubrica->indirizzo_completo ?? '—' }}</div>
@if($rubrica->indirizzo || $rubrica->cap || $rubrica->citta || $rubrica->provincia)
<div class="mt-1 text-xs text-gray-500">
{{ $rubrica->indirizzo ?? '—' }}
@if($rubrica->civico)
, {{ $rubrica->civico }}
@endif
@if($rubrica->cap)
· {{ $rubrica->cap }}
@endif
@if($rubrica->citta)
· {{ $rubrica->citta }}
@endif
@if($rubrica->provincia)
({{ $rubrica->provincia }})
@endif
</div>
@endif
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Note</div>
<div class="whitespace-pre-wrap">{{ $rubrica->note ?? '—' }}</div>
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Note segreteria</div>
<div class="whitespace-pre-wrap">{{ $rubrica->note_segreteria ?? '—' }}</div>
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Ruoli (attivi)</div>
@if(empty($ruoliAttivi))
<div class="text-sm text-gray-700"></div>
@else
<div class="flex flex-wrap gap-2">
@foreach($ruoliAttivi as $r)
<span class="inline-flex items-center rounded-full border border-gray-200 bg-gray-50 px-2.5 py-1 text-xs font-semibold text-gray-800">
{{ $r['ruolo'] ?? '—' }}
@if(!empty($r['stabile_codice']))
<span class="ml-1 text-gray-500">· {{ $r['stabile_codice'] }}</span>
@endif
@if(!empty($r['unita_codice']))
<span class="ml-1 text-gray-500">· {{ $r['unita_codice'] }}</span>
@endif
@if(!empty($r['preferito']))
<span class="ml-1 text-gray-500">· preferito</span>
@endif
</span>
@endforeach
</div>
@endif
</div>
</div>
</x-filament::section>
<div class="space-y-4">
<div class="rounded-lg border border-gray-200 bg-white p-2">
<div class="flex flex-wrap gap-2">
<button type="button" wire:click="$set('sideTab', 'collegamenti')" class="rounded-md px-3 py-1.5 text-xs font-medium {{ $sideTab === 'collegamenti' ? 'bg-indigo-700 text-white' : 'bg-gray-100 text-gray-700 hover:bg-gray-200' }}">Collegamenti</button>
<button type="button" wire:click="$set('sideTab', 'studio')" class="rounded-md px-3 py-1.5 text-xs font-medium {{ $sideTab === 'studio' ? 'bg-indigo-700 text-white' : 'bg-gray-100 text-gray-700 hover:bg-gray-200' }}">Collaboratore studio</button>
<button type="button" wire:click="$set('sideTab', 'dipendenti')" class="rounded-md px-3 py-1.5 text-xs font-medium {{ $sideTab === 'dipendenti' ? 'bg-indigo-700 text-white' : 'bg-gray-100 text-gray-700 hover:bg-gray-200' }}">Dipendenti</button>
<button type="button" wire:click="$set('sideTab', 'autorizzazioni')" class="rounded-md px-3 py-1.5 text-xs font-medium {{ $sideTab === 'autorizzazioni' ? 'bg-indigo-700 text-white' : 'bg-gray-100 text-gray-700 hover:bg-gray-200' }}">Ruoli e autorizzazioni</button>
</div>
</div>
@if($sideTab === 'studio')
<x-filament::section>
<x-slot name="heading">Collegamento collaboratore studio</x-slot>
<x-slot name="description">Trasforma questo nominativo rubrica in collaboratore di studio senza perdere eventuali altri profili già esistenti sullo stesso utente.</x-slot>
<div class="space-y-4">
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
<div>
<div class="text-sm text-gray-500">Utente collegato</div>
<div class="font-medium">{{ $studioCollaboratoreUserName ?: ($rubrica->nome_completo ?? '—') }}</div>
<div class="text-xs text-gray-500">{{ $studioCollaboratoreUserEmail ?: 'Email non presente in rubrica' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Ruoli attuali utente</div>
<div class="text-sm text-gray-800">{{ count($studioCollaboratoreRoles) > 0 ? implode(', ', $studioCollaboratoreRoles) : 'Nessun ruolo applicativo rilevato' }}</div>
</div>
</div>
@if(filled($studioCollaboratoreGeneratedPassword))
<div class="rounded-md border border-amber-300 bg-amber-50 px-3 py-2 text-xs text-amber-900">
Ultima password temporanea generata: <span class="font-mono font-semibold">{{ $studioCollaboratoreGeneratedPassword }}</span>
</div>
@endif
<div class="grid grid-cols-1 gap-3 md:grid-cols-2">
<div>
<label class="mb-1 block text-xs font-semibold text-gray-600">Interno PBX collaboratore</label>
<input type="text" wire:model.defer="studioCollaboratorePbxExtension" class="w-full rounded-md border-gray-300 text-sm" placeholder="Es. 101" />
</div>
<div>
<div class="mb-1 block text-xs font-semibold text-gray-600">Stabili assegnati al collaboratore</div>
<div class="max-h-40 space-y-1 overflow-auto rounded-md border border-gray-200 bg-gray-50 p-2">
@forelse($studioCollaboratoreStabileOptions as $stabileId => $stabileLabel)
<label class="flex items-center gap-2 text-xs text-gray-700">
<input type="checkbox" value="{{ (int) $stabileId }}" wire:model.defer="studioCollaboratoreStabileIds" class="rounded border-gray-300" />
<span>{{ $stabileLabel }}</span>
</label>
@empty
<div class="text-xs text-gray-500">Nessuno stabile disponibile per l'amministratore attivo.</div>
@endforelse
</div>
</div>
</div>
<div class="flex flex-wrap gap-2">
<x-filament::button type="button" color="primary" wire:click="abilitaAccessoCollaboratoreStudio">
{{ $studioCollaboratoreUserId ? 'Riabilita / conferma collaboratore' : 'Abilita collaboratore studio' }}
</x-filament::button>
<x-filament::button type="button" color="gray" wire:click="salvaCollaboratoreStudio">Salva interno e stabili</x-filament::button>
</div>
<div class="rounded-md border border-slate-200 bg-slate-50 p-3 text-xs text-slate-700">
Questo collegamento usa come chiave l'email principale della rubrica o, se manca, la prima email aggiuntiva attiva. Se l'utente esiste già, aggiunge solo il ruolo <strong>collaboratore</strong> e sincronizza gli stabili dell'amministratore corrente senza rimuovere eventuali altri ruoli o profili già presenti.
</div>
</div>
</x-filament::section>
@endif
@if($sideTab === 'collegamenti')
<x-filament::section>
<x-slot name="heading">Collegamenti</x-slot>
<div class="space-y-4">
@if(empty($stabili) && !empty($collegamentoSuggerito))
<div class="rounded-lg border border-amber-200 bg-amber-50 p-4 text-sm text-amber-900">
<div class="font-semibold">Collegamento riconosciuto ma non ancora agganciato</div>
<div class="mt-1 text-xs text-amber-800">
La scheda contiene riferimenti a uno stabile coerente, ma manca ancora il legame strutturato che popola questo box.
</div>
<div class="mt-3 grid gap-2 text-xs md:grid-cols-3">
<div>
<div class="font-semibold text-amber-900">Stabile candidato</div>
<div>{{ $collegamentoSuggerito['stabile_label'] ?? '—' }}</div>
</div>
<div>
<div class="font-semibold text-amber-900">Unità candidata</div>
<div>{{ $collegamentoSuggerito['unita_reference'] ?? 'Non rilevata' }}</div>
</div>
<div>
<div class="font-semibold text-amber-900">Ruolo proposto</div>
<div>{{ $this::getRuoliLabels()[$collegamentoSuggerito['role_standard'] ?? 'altro'] ?? ($collegamentoSuggerito['role_standard'] ?? 'Altro') }}</div>
</div>
</div>
<div class="mt-3 flex flex-wrap gap-2">
<x-filament::button type="button" color="warning" wire:click="collegaCollegamentoSuggerito">
Aggancia collegamento suggerito
</x-filament::button>
<x-filament::button type="button" color="gray" wire:click="mountAction('ruoli_legami')">
Apri editor completo ruoli / legami
</x-filament::button>
</div>
</div>
@endif
<div class="rounded-lg border border-slate-200 bg-slate-50 p-4">
<div class="text-sm font-semibold text-slate-900">Collegamento rapido a stabile / unità</div>
<div class="mt-1 text-xs text-slate-600">
Usa questo blocco per agganciare manualmente una nuova anagrafica a uno stabile del tenant attivo oppure per completare un record importato che oggi ha solo riferimenti testuali.
</div>
<div class="mt-4 grid gap-3 md:grid-cols-3">
<div>
<label class="mb-1 block text-xs font-semibold text-slate-700">Stabile</label>
<select wire:model.live="collegamentoStabileId" class="w-full rounded-md border-gray-300 text-sm">
<option value="">Seleziona stabile</option>
@foreach($this->getStabiliOptions() as $stabileId => $stabileLabel)
<option value="{{ (int) $stabileId }}">{{ $stabileLabel }}</option>
@endforeach
</select>
</div>
<div>
<label class="mb-1 block text-xs font-semibold text-slate-700">Unità</label>
<select wire:model.live="collegamentoUnitaId" class="w-full rounded-md border-gray-300 text-sm">
<option value="">Nessuna unità specifica</option>
@foreach($this->getUnitaOptions($collegamentoStabileId) as $unitaId => $unitaLabel)
<option value="{{ (int) $unitaId }}">{{ $unitaLabel }}</option>
@endforeach
</select>
</div>
<div>
<label class="mb-1 block text-xs font-semibold text-slate-700">Ruolo</label>
<select wire:model.live="collegamentoRuolo" class="w-full rounded-md border-gray-300 text-sm">
@foreach($this::getRuoliLabels() as $ruoloKey => $ruoloLabel)
<option value="{{ $ruoloKey }}">{{ $ruoloLabel }}</option>
@endforeach
</select>
</div>
</div>
<div class="mt-3 grid gap-3 md:grid-cols-[1fr_auto]">
<div>
<label class="mb-1 block text-xs font-semibold text-slate-700">Ruolo custom</label>
<input type="text" wire:model.defer="collegamentoRuoloCustom" class="w-full rounded-md border-gray-300 text-sm" placeholder="Opzionale" />
</div>
<div class="flex items-end">
<x-filament::button type="button" color="primary" wire:click="salvaCollegamentoManuale">
Salva collegamento
</x-filament::button>
</div>
</div>
</div>
<div>
<div class="text-sm text-gray-500">Fornitori (ambiente attivo)</div>
@if(count($fornitori) > 0)
<ul class="mt-2 list-disc pl-5 text-sm">
@foreach($fornitori as $f)
<li>
<a class="text-primary-600 hover:underline" href="{{ \App\Filament\Pages\Gescon\FornitoreScheda::getUrl(['record' => $f['id']], panel: 'admin-filament') }}">
{{ $f['nome'] }}
</a>
<span class="text-xs text-gray-500">({{ $f['codice'] ?: '—' }})</span>
</li>
@endforeach
</ul>
@else
<div class="mt-1 text-sm text-gray-500"></div>
@endif
</div>
<div>
<div class="text-sm text-gray-500">Stabili (ambiente attivo)</div>
@if(count($stabili) > 0)
<ul class="mt-2 list-disc pl-5 text-sm">
@foreach($stabili as $s)
<li>
<a class="text-primary-600 hover:underline" href="{{ \App\Filament\Pages\Gescon\StabileScheda::getUrl(['record' => $s['id']], panel: 'admin-filament') }}">
{{ $s['codice'] }} - {{ $s['nome'] }}
</a>
</li>
@endforeach
</ul>
@else
<div class="mt-1 text-sm text-gray-500"></div>
@endif
</div>
</div>
</x-filament::section>
@endif
@if($sideTab === 'dipendenti')
<x-filament::section>
<x-slot name="heading">Collega o crea dipendenti fornitore</x-slot>
<x-slot name="description">Usa questa tab per agganciare un nominativo rubrica come dipendente o creare un nuovo dipendente manualmente.</x-slot>
<div class="space-y-4">
@forelse($fornitoriCollegati as $f)
<div class="rounded-lg border border-gray-200 p-3">
<div class="mb-2 text-sm font-semibold text-gray-800">{{ $f['nome'] }}</div>
<div class="mb-2 text-xs text-gray-500">Fornitore #{{ $f['id'] }} · Rubrica collegata: {{ $f['rubrica_id'] ?: '—' }}</div>
<div class="grid grid-cols-1 gap-2">
<div class="flex flex-wrap items-center gap-2">
<input type="number" min="1" wire:model.defer="dipendenteRubricaSelect.{{ (int) $f['id'] }}" class="w-40 rounded-md border-gray-300 text-xs" placeholder="ID rubrica dipendente" />
<x-filament::button size="xs" color="primary" type="button" wire:click="collegaRubricaDipendente({{ (int) $f['id'] }})">Collega da rubrica</x-filament::button>
</div>
<div class="grid grid-cols-1 gap-2 md:grid-cols-4">
<input type="text" wire:model.defer="dipendenteManualDraft.{{ (int) $f['id'] }}.nome" class="rounded-md border-gray-300 text-xs" placeholder="Nome" />
<input type="text" wire:model.defer="dipendenteManualDraft.{{ (int) $f['id'] }}.cognome" class="rounded-md border-gray-300 text-xs" placeholder="Cognome" />
<input type="email" wire:model.defer="dipendenteManualDraft.{{ (int) $f['id'] }}.email" class="rounded-md border-gray-300 text-xs" placeholder="Email" />
<input type="text" wire:model.defer="dipendenteManualDraft.{{ (int) $f['id'] }}.telefono" class="rounded-md border-gray-300 text-xs" placeholder="Telefono" />
</div>
<div>
<x-filament::button size="xs" color="gray" type="button" wire:click="creaDipendenteManuale({{ (int) $f['id'] }})">Crea dipendente</x-filament::button>
</div>
</div>
</div>
@empty
<div class="text-sm text-gray-500">Nessun fornitore collegato a questo nominativo rubrica.</div>
@endforelse
</div>
</x-filament::section>
@endif
@if($sideTab === 'autorizzazioni')
<x-filament::section>
<x-slot name="heading">Ruoli e autorizzazioni dipendenti</x-slot>
<x-slot name="description">Abilita accesso utente e assegna interno PBX per i dipendenti collegati ai fornitori.</x-slot>
<div class="overflow-x-auto">
<table class="min-w-full border-collapse border text-xs">
<thead>
<tr class="bg-slate-100 text-slate-700">
<th class="border px-2 py-1.5 text-left">Fornitore</th>
<th class="border px-2 py-1.5 text-left">Dipendente</th>
<th class="border px-2 py-1.5 text-left">Email</th>
<th class="border px-2 py-1.5 text-left">Ruoli utente</th>
<th class="border px-2 py-1.5 text-left">Interno PBX</th>
<th class="border px-2 py-1.5 text-left">Azioni</th>
</tr>
</thead>
<tbody>
@forelse($dipendentiFornitoreRows as $row)
<tr class="hover:bg-slate-50">
<td class="border px-2 py-1.5">{{ $row['fornitore_nome'] }}</td>
<td class="border px-2 py-1.5">{{ $row['nome'] }}</td>
<td class="border px-2 py-1.5">{{ $row['email'] !== '' ? $row['email'] : '-' }}</td>
<td class="border px-2 py-1.5">{{ count($row['ruoli']) > 0 ? implode(', ', $row['ruoli']) : '-' }}</td>
<td class="border px-2 py-1.5">
<input type="text" wire:model.defer="dipendentePbxExtension.{{ (int) $row['id'] }}" class="w-24 rounded-md border-gray-300 text-xs" placeholder="Es. 101" />
</td>
<td class="border px-2 py-1.5">
@if(! $row['user_id'])
<x-filament::button size="xs" color="primary" type="button" wire:click="abilitaAccessoDipendente({{ (int) $row['id'] }})">Abilita accesso</x-filament::button>
@endif
<x-filament::button size="xs" color="gray" type="button" wire:click="salvaInternoDipendente({{ (int) $row['id'] }})">Salva interno</x-filament::button>
</td>
</tr>
@empty
<tr>
<td colspan="6" class="border px-2 py-3 text-center text-gray-500">Nessun dipendente fornitore collegato.</td>
</tr>
@endforelse
</tbody>
</table>
</div>
</x-filament::section>
@endif
<x-filament::section>
<x-slot name="heading">Azioni</x-slot>
<div class="flex flex-col gap-2">
<x-filament::button type="button" color="gray" wire:click="mountAction('contatti')">
Contatti aggiuntivi
</x-filament::button>
<x-filament::button type="button" color="gray" wire:click="mountAction('ruoli_legami')">
Ruoli / legami
</x-filament::button>
</div>
</x-filament::section>
</div>
</div>
<x-filament::section>
<x-slot name="heading">Cronistoria ruoli / legami</x-slot>
<x-slot name="description">Storico collegamenti rubrica stabile/unità (con periodi).</x-slot>
@if(empty($cronistoriaRuoli))
<div class="text-sm text-gray-500">Nessun ruolo/legame registrato.</div>
@else
<div class="overflow-x-auto">
<table class="min-w-full text-sm">
<thead>
<tr class="border-b text-left text-gray-500">
<th class="py-2">Stabile</th>
<th class="py-2">Unità</th>
<th class="py-2">Ruolo</th>
<th class="py-2">Periodo</th>
<th class="py-2">Stato</th>
</tr>
</thead>
<tbody class="divide-y">
@foreach($cronistoriaRuoli as $r)
@php
$unitaUrl = $this->getUrlUnita(($r['unita_id'] ?? 0) ?: null);
$periodo = trim(($r['data_inizio'] ?? '—') . ' → ' . (($r['data_fine'] ?? null) ?: 'in corso'));
@endphp
<tr>
<td class="py-2 text-gray-900">
{{ !empty($r['stabile_codice']) ? $r['stabile_codice'] : '—' }}
@if(!empty($r['stabile_nome']))
<div class="text-xs text-gray-500">{{ $r['stabile_nome'] }}</div>
@endif
</td>
<td class="py-2">
@if($unitaUrl)
<a href="{{ $unitaUrl }}" class="inline-flex items-center rounded-full border border-primary-200 bg-primary-50 px-2 py-0.5 text-xs font-semibold text-primary-700 hover:bg-primary-100">
{{ $r['unita_codice'] ?? 'Unità' }}
</a>
@else
<span class="text-gray-900">{{ $r['unita_codice'] ?? '—' }}</span>
@endif
@if(!empty($r['unita_nome']))
<div class="text-xs text-gray-500">{{ $r['unita_nome'] }}</div>
@endif
</td>
<td class="py-2 text-gray-900">{{ $r['ruolo'] ?? '—' }}</td>
<td class="py-2 text-gray-900">{{ $periodo }}</td>
<td class="py-2 text-gray-900">
@if(!empty($r['attivo']))
<span class="text-xs text-gray-500">attivo</span>
@else
<span class="text-xs text-gray-500">chiuso</span>
@endif
@if(!empty($r['preferito']))
<span class="text-xs text-gray-500">· preferito</span>
@endif
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
@endif
</x-filament::section>
</x-filament-panels::page>