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

498 lines
27 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">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-3">
<span class="mb-1 block text-gray-600">Indirizzo completo</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">Email</div>
<div>{{ $rubrica->email ?? '—' }}</div>
</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>{{ $rubrica->telefono_ufficio ?? '—' }}</div>
</div>
<div>
<div class="text-sm text-gray-500">Cellulare</div>
<div>{{ $rubrica->telefono_cellulare ?? '—' }}</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>{{ $rubrica->telefono_casa ?? '—' }}</div>
</div>
<div class="md:col-span-2">
<div class="text-sm text-gray-500">Indirizzo</div>
<div>{{ $rubrica->indirizzo_completo ?? '—' }}</div>
</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', '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 === 'collegamenti')
<x-filament::section>
<x-slot name="heading">Collegamenti</x-slot>
<div class="space-y-4">
<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>