454 lines
19 KiB
PHP
Executable File
454 lines
19 KiB
PHP
Executable File
@extends('admin.layouts.netgescon')
|
|
|
|
@section('page-title', 'Dettagli Soggetto - Rubrica Unica')
|
|
|
|
@push('head')
|
|
<meta name="csrf-token" content="{{ csrf_token() }}">
|
|
@endpush
|
|
|
|
@section('content')
|
|
@php
|
|
$soggetto = $soggetto ?? $persona ?? null;
|
|
$isRubricaUniversale = $isRubricaUniversale ?? false;
|
|
$relazioniUnita = collect($relazioniUnita ?? []);
|
|
@endphp
|
|
|
|
@if(!$soggetto)
|
|
<div class="netgescon-card">
|
|
<div class="netgescon-card-header">
|
|
<h3 class="netgescon-card-title">
|
|
<i class="fas fa-triangle-exclamation mr-2"></i>
|
|
Soggetto non trovato
|
|
</h3>
|
|
</div>
|
|
<div class="p-4">
|
|
<p class="netgescon-text">Impossibile visualizzare la scheda: manca il soggetto da mostrare.</p>
|
|
<div class="mt-4">
|
|
<a href="{{ route('admin.rubrica.index') }}" class="netgescon-btn netgescon-btn-secondary">
|
|
<i class="fas fa-arrow-left mr-2"></i>
|
|
Torna alla Rubrica
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
@php return; @endphp
|
|
@endif
|
|
|
|
@php
|
|
$tipoRaw = strtolower($isRubricaUniversale
|
|
? ($soggetto->tipo_contatto ?? '')
|
|
: ($soggetto->tipologia ?? $soggetto->tipo ?? 'f'));
|
|
$isFisica = in_array($tipoRaw, ['f', 'fisica', 'persona_fisica'], true);
|
|
$nomeCompleto = $soggetto->nome_completo
|
|
?? ($isFisica
|
|
? trim(($soggetto->nome ?? '') . ' ' . ($soggetto->cognome ?? ''))
|
|
: ($soggetto->ragione_sociale ?? trim(($soggetto->nome ?? '') . ' ' . ($soggetto->cognome ?? ''))));
|
|
$codiceFiscale = $soggetto->codice_fiscale ?? null;
|
|
$partitaIva = $soggetto->partita_iva ?? null;
|
|
$emailPrincipale = $soggetto->email_principale ?? $soggetto->email ?? null;
|
|
$telefonoPrincipale = $soggetto->telefono_principale ?? $soggetto->telefono_ufficio ?? $soggetto->telefono_cellulare ?? $soggetto->telefono ?? null;
|
|
$indirizzoCompleto = trim(collect([
|
|
$soggetto->indirizzo ?? $soggetto->residenza_via ?? null,
|
|
$soggetto->civico ?? null,
|
|
trim(($soggetto->cap ?? '') . ' ' . ($soggetto->citta ?? '')),
|
|
$soggetto->provincia ? '(' . $soggetto->provincia . ')' : null,
|
|
])->filter()->join(' '));
|
|
@endphp
|
|
<div class="space-y-8 netgescon-fade-in">
|
|
<!-- Header -->
|
|
<div class="netgescon-card">
|
|
<div class="flex items-center justify-between">
|
|
<div>
|
|
<h2 class="netgescon-title">
|
|
<i class="fas fa-user text-purple-500 mr-3"></i>
|
|
Dettagli Soggetto
|
|
</h2>
|
|
<p class="netgescon-text mt-2">
|
|
Visualizza e gestisci i dati del soggetto
|
|
</p>
|
|
@if(!empty($primaryStabile))
|
|
<div class="flex flex-wrap items-center gap-2 mt-3 text-sm text-gray-600">
|
|
<i class="fas fa-city text-gray-400"></i>
|
|
<span class="font-medium">Stabile di riferimento:</span>
|
|
<span class="text-gray-800">{{ $primaryStabile['stabile_label'] ?? 'N/D' }}</span>
|
|
@if(!empty($primaryStabile['stabile_indirizzo']))
|
|
<span class="text-gray-500">· {{ $primaryStabile['stabile_indirizzo'] }}</span>
|
|
@endif
|
|
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[11px] bg-indigo-100 text-indigo-700">Ordinari</span>
|
|
<span class="inline-flex items-center px-2 py-0.5 rounded-full text-[11px] bg-amber-100 text-amber-700">Riscaldamento</span>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
<div class="flex space-x-3">
|
|
<a href="{{ route('admin.rubrica.edit', $soggetto) }}"
|
|
class="netgescon-btn netgescon-btn-primary">
|
|
<i class="fas fa-edit mr-2"></i>
|
|
Modifica
|
|
</a>
|
|
<a href="{{ route('admin.rubrica.index') }}"
|
|
class="netgescon-btn netgescon-btn-secondary">
|
|
<i class="fas fa-arrow-left mr-2"></i>
|
|
Torna alla Rubrica
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Informazioni Principali -->
|
|
<div class="netgescon-card">
|
|
<div class="netgescon-card-header">
|
|
<h3 class="netgescon-card-title">
|
|
<i class="fas fa-id-card mr-2"></i>
|
|
Informazioni Anagrafiche
|
|
</h3>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
|
|
<!-- Tipo Soggetto -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Tipo Soggetto</label>
|
|
<div class="flex items-center">
|
|
@if($isFisica)
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-blue-100 text-blue-800">
|
|
<i class="fas fa-user mr-2"></i>
|
|
Persona Fisica
|
|
</span>
|
|
@else
|
|
<span class="inline-flex items-center px-3 py-1 rounded-full text-sm font-medium bg-green-100 text-green-800">
|
|
<i class="fas fa-building mr-2"></i>
|
|
Persona Giuridica
|
|
</span>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Nome/Ragione Sociale -->
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">
|
|
@if($isFisica)
|
|
Nome Completo
|
|
@else
|
|
Ragione Sociale
|
|
@endif
|
|
</label>
|
|
<p class="text-lg font-semibold netgescon-text">
|
|
{{ $nomeCompleto ?: '—' }}
|
|
</p>
|
|
</div>
|
|
|
|
<!-- Codice Fiscale -->
|
|
@if($codiceFiscale)
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Codice Fiscale</label>
|
|
<p class="netgescon-text font-mono">{{ $codiceFiscale }}</p>
|
|
</div>
|
|
@endif
|
|
|
|
<!-- Partita IVA -->
|
|
@if($partitaIva)
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Partita IVA</label>
|
|
<p class="netgescon-text font-mono">{{ $partitaIva }}</p>
|
|
</div>
|
|
@endif
|
|
|
|
<!-- Email -->
|
|
@if($emailPrincipale)
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Email</label>
|
|
<p class="netgescon-text">
|
|
<a href="mailto:{{ $emailPrincipale }}" class="text-blue-600 hover:text-blue-800">
|
|
<i class="fas fa-envelope mr-2"></i>
|
|
{{ $emailPrincipale }}
|
|
</a>
|
|
</p>
|
|
</div>
|
|
@endif
|
|
|
|
<!-- Telefono -->
|
|
@if($telefonoPrincipale)
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Telefono</label>
|
|
<p class="netgescon-text">
|
|
<a href="tel:{{ $telefonoPrincipale }}" class="text-blue-600 hover:text-blue-800">
|
|
<i class="fas fa-phone mr-2"></i>
|
|
{{ $telefonoPrincipale }}
|
|
</a>
|
|
</p>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Indirizzo completo -->
|
|
@if($indirizzoCompleto)
|
|
<div class="mt-6 pt-6 border-t border-gray-200">
|
|
<label class="block text-sm font-medium text-gray-700 mb-2">Indirizzo</label>
|
|
<div class="netgescon-text">
|
|
<i class="fas fa-map-marker-alt mr-2 text-gray-500"></i>
|
|
{{ $indirizzoCompleto }}
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Unità Immobiliari Associate -->
|
|
<div class="netgescon-card">
|
|
<div class="netgescon-card-header">
|
|
<h3 class="netgescon-card-title">
|
|
<i class="fas fa-home mr-2"></i>
|
|
Unità Immobiliari Associate
|
|
<span class="text-sm font-normal text-gray-500 ml-2">
|
|
({{ $relazioniUnita->count() }} unità)
|
|
</span>
|
|
</h3>
|
|
</div>
|
|
|
|
@if($relazioniUnita->count() > 0)
|
|
<div class="overflow-x-auto">
|
|
<table class="min-w-full divide-y divide-gray-200">
|
|
<thead class="bg-gray-50">
|
|
<tr>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Stabile
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Scala/Interno
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Tipo Diritto
|
|
</th>
|
|
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">
|
|
Percentuale
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody class="bg-white divide-y divide-gray-200">
|
|
@foreach($relazioniUnita as $unita)
|
|
<tr class="hover:bg-gray-50">
|
|
<td class="px-6 py-4 whitespace-nowrap">
|
|
<div class="text-sm font-medium text-gray-900">
|
|
{{ $unita['stabile_label'] ?? 'N/D' }}
|
|
</div>
|
|
<div class="text-sm text-gray-500">
|
|
{{ $unita['stabile_indirizzo'] ?? '' }}
|
|
</div>
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
|
Scala {{ $unita['scala'] ?? '-' }} Int. {{ $unita['interno'] ?? '-' }}
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
|
@if(!empty($unita['ruolo_label']))
|
|
<span class="capitalize">{{ $unita['ruolo_label'] }}</span>
|
|
@else
|
|
<span class="text-gray-400">Non specificato</span>
|
|
@endif
|
|
</td>
|
|
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-900">
|
|
@if(!empty($unita['percentuale']))
|
|
{{ $unita['percentuale'] }}%
|
|
@else
|
|
<span class="text-gray-400">-</span>
|
|
@endif
|
|
</td>
|
|
</tr>
|
|
@endforeach
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
@else
|
|
<div class="text-center py-12">
|
|
<div class="text-gray-500">
|
|
<i class="fas fa-home text-4xl mb-4 opacity-50"></i>
|
|
<p class="text-lg font-medium">Nessuna unità immobiliare associata</p>
|
|
<p class="text-sm mt-2">Utilizza il pulsante "Collega Unità" nella rubrica per associare delle unità immobiliari</p>
|
|
</div>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<!-- Azioni Rapide -->
|
|
<div class="netgescon-card">
|
|
<div class="netgescon-card-header">
|
|
<h3 class="netgescon-card-title">
|
|
<i class="fas fa-tools mr-2"></i>
|
|
Azioni Rapide
|
|
</h3>
|
|
</div>
|
|
|
|
<div class="flex flex-wrap gap-3">
|
|
<a href="{{ route('admin.rubrica.edit', $soggetto) }}"
|
|
class="netgescon-btn netgescon-btn-primary">
|
|
<i class="fas fa-edit mr-2"></i>
|
|
Modifica Dati
|
|
</a>
|
|
|
|
<button onclick="collegaUnita({{ $soggetto->id }})"
|
|
class="netgescon-btn netgescon-btn-secondary">
|
|
<i class="fas fa-link mr-2"></i>
|
|
Collega Unità
|
|
</button>
|
|
|
|
@if($emailPrincipale)
|
|
<a href="mailto:{{ $emailPrincipale }}"
|
|
class="netgescon-btn netgescon-btn-secondary">
|
|
<i class="fas fa-envelope mr-2"></i>
|
|
Invia Email
|
|
</a>
|
|
@endif
|
|
|
|
@if($telefonoPrincipale)
|
|
<a href="tel:{{ $telefonoPrincipale }}"
|
|
class="netgescon-btn netgescon-btn-secondary">
|
|
<i class="fas fa-phone mr-2"></i>
|
|
Chiama
|
|
</a>
|
|
@endif
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- Modal per collegare unità immobiliare (riuso del modal dall'index) -->
|
|
<div id="collegaUnitaModal" class="fixed inset-0 bg-gray-600 bg-opacity-50 overflow-y-auto h-full w-full hidden">
|
|
<div class="relative top-20 mx-auto p-5 border w-11/12 md:w-1/2 shadow-lg rounded-md bg-white">
|
|
<div class="mt-3">
|
|
<div class="flex items-center justify-between mb-4">
|
|
<h3 class="text-lg font-medium text-gray-900">Collega Unità Immobiliare</h3>
|
|
<button onclick="chiudiModal()" class="text-gray-400 hover:text-gray-600">
|
|
<i class="fas fa-times"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<form id="collegaUnitaForm" method="POST">
|
|
@csrf
|
|
<div class="space-y-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Tipo di Diritto</label>
|
|
<select name="tipo_diritto" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm">
|
|
<option value="proprieta">Proprietà</option>
|
|
<option value="usufrutto">Usufrutto</option>
|
|
<option value="nuda_proprieta">Nuda Proprietà</option>
|
|
<option value="locazione">Locazione</option>
|
|
<option value="altro">Altro</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Percentuale Possesso (%)</label>
|
|
<input type="number" name="percentuale_possesso" min="0" max="100" step="0.01"
|
|
class="mt-1 block w-full border-gray-300 rounded-md shadow-sm">
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Unità Immobiliare</label>
|
|
<select name="unita_immobiliare_id" class="mt-1 block w-full border-gray-300 rounded-md shadow-sm" required>
|
|
<option value="">Seleziona un'unità immobiliare...</option>
|
|
</select>
|
|
</div>
|
|
|
|
<div class="grid grid-cols-2 gap-4">
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Data Inizio</label>
|
|
<input type="date" name="data_inizio"
|
|
class="mt-1 block w-full border-gray-300 rounded-md shadow-sm">
|
|
</div>
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Data Fine</label>
|
|
<input type="date" name="data_fine"
|
|
class="mt-1 block w-full border-gray-300 rounded-md shadow-sm">
|
|
</div>
|
|
</div>
|
|
|
|
<div>
|
|
<label class="block text-sm font-medium text-gray-700">Note</label>
|
|
<textarea name="note" rows="3"
|
|
class="mt-1 block w-full border-gray-300 rounded-md shadow-sm"></textarea>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="flex justify-end space-x-2 mt-6">
|
|
<button type="button" onclick="chiudiModal()"
|
|
class="px-4 py-2 text-sm font-medium text-gray-700 bg-gray-200 rounded-md hover:bg-gray-300">
|
|
Annulla
|
|
</button>
|
|
<button type="submit"
|
|
class="px-4 py-2 text-sm font-medium text-white bg-purple-600 rounded-md hover:bg-purple-700">
|
|
Collega Unità
|
|
</button>
|
|
</div>
|
|
</form>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script>
|
|
let soggettoSelezionato = null;
|
|
|
|
function collegaUnita(soggettoId) {
|
|
soggettoSelezionato = soggettoId;
|
|
document.getElementById('collegaUnitaModal').classList.remove('hidden');
|
|
|
|
// Carica le unità immobiliari disponibili
|
|
fetch(`/admin/rubrica/unita-disponibili`)
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
const select = document.querySelector('select[name="unita_immobiliare_id"]');
|
|
select.innerHTML = '<option value="">Seleziona un\'unità immobiliare...</option>';
|
|
|
|
data.forEach(unita => {
|
|
const option = document.createElement('option');
|
|
option.value = unita.id;
|
|
option.textContent = `${unita.stabile_nome} - Scala ${unita.scala || '-'} Int. ${unita.interno || '-'}`;
|
|
select.appendChild(option);
|
|
});
|
|
})
|
|
.catch(error => {
|
|
console.error('Errore nel caricamento delle unità:', error);
|
|
});
|
|
|
|
// Imposta l'action del form
|
|
document.getElementById('collegaUnitaForm').action = `/admin/rubrica/${soggettoId}/collega-unita`;
|
|
}
|
|
|
|
function chiudiModal() {
|
|
document.getElementById('collegaUnitaModal').classList.add('hidden');
|
|
soggettoSelezionato = null;
|
|
}
|
|
|
|
// Gestione submit del form
|
|
document.getElementById('collegaUnitaForm').addEventListener('submit', function(e) {
|
|
e.preventDefault();
|
|
|
|
const formData = new FormData(this);
|
|
|
|
fetch(this.action, {
|
|
method: 'POST',
|
|
body: formData,
|
|
headers: {
|
|
'X-CSRF-TOKEN': document.querySelector('meta[name="csrf-token"]').getAttribute('content')
|
|
}
|
|
})
|
|
.then(response => response.json())
|
|
.then(data => {
|
|
if (data.success) {
|
|
chiudiModal();
|
|
location.reload(); // Ricarica la pagina per mostrare i cambiamenti
|
|
} else {
|
|
alert('Errore nel collegamento: ' + (data.message || 'Errore sconosciuto'));
|
|
}
|
|
})
|
|
.catch(error => {
|
|
console.error('Errore:', error);
|
|
alert('Errore nel collegamento dell\'unità immobiliare');
|
|
});
|
|
});
|
|
|
|
// Chiudi modal cliccando fuori
|
|
document.getElementById('collegaUnitaModal').addEventListener('click', function(e) {
|
|
if (e.target === this) {
|
|
chiudiModal();
|
|
}
|
|
});
|
|
</script>
|
|
|
|
@endsection
|