2070 lines
88 KiB
PHP
2070 lines
88 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\Condomini;
|
|
|
|
use App\Models\Stabile;
|
|
use App\Models\UnitaImmobiliare;
|
|
use App\Models\User;
|
|
use App\Support\StabileContext;
|
|
use App\Services\SisterCatastoService;
|
|
use Filament\Pages\Page;
|
|
use Filament\Notifications\Notification;
|
|
use Illuminate\Support\Facades\Auth;
|
|
use Illuminate\Support\Facades\Storage;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Exception;
|
|
|
|
class CatastoHub extends Page
|
|
{
|
|
protected static ?string $navigationLabel = 'HUB Catasto';
|
|
|
|
protected static ?string $title = 'Catasto & Anagrafica HUB';
|
|
|
|
protected static \BackedEnum|string|null $navigationIcon = 'heroicon-o-building-office-2';
|
|
|
|
protected static \UnitEnum|string|null $navigationGroup = 'Stabile';
|
|
|
|
protected static ?int $navigationSort = 45;
|
|
|
|
protected static ?string $slug = 'condomini/catasto-hub';
|
|
|
|
protected string $view = 'filament.pages.condomini.catasto-hub';
|
|
|
|
public ?Stabile $stabileAttivo = null;
|
|
public array $unitaList = [];
|
|
public ?int $selectedUnitaId = null;
|
|
|
|
// Ricerca e Ordinamento
|
|
public string $search = '';
|
|
public string $sortDirection = 'asc';
|
|
|
|
// Campi per il riscontro in-place (Destra)
|
|
public array $legacyData = [];
|
|
public array $sisterData = [];
|
|
public array $auditAnomalies = [];
|
|
public array $proprietariPeriodi = [];
|
|
public array $stagingRawData = [];
|
|
|
|
// Form editing in-place
|
|
public string $editFoglio = '';
|
|
public string $editParticella = '';
|
|
public string $editSubalterno = '';
|
|
public string $editRendita = '';
|
|
public string $editSezioneUrbana = '';
|
|
public string $editCategoria = '';
|
|
public string $editPiano = '';
|
|
public string $editClasse = '';
|
|
public string $editConsistenza = '';
|
|
public string $editIdImmobile = '';
|
|
|
|
// Gestione Tab
|
|
public string $activeTab = 'stabile'; // 'stabile', 'appartamento', 'visura_rt'
|
|
public array $stabileSubalterni = [];
|
|
public array $associazioniSoppressi = [];
|
|
public array $tempAssociazioni = [];
|
|
public ?int $editTipologiaId = null;
|
|
public array $tipologieOptions = [];
|
|
|
|
// Form Variazioni Proprietari (Tab B)
|
|
public ?int $nuovaAnagraficaId = null;
|
|
public string $nuovaDataInizio = '';
|
|
public string $nuovaQuota = '100';
|
|
public array $anagraficheOptions = [];
|
|
|
|
// Tab C: Visura Proprietari RT (Box CF)
|
|
public array $visuraProprietariRt = [];
|
|
public array $sisterContentRaw = [];
|
|
|
|
// Prima / Dopo Panel
|
|
public bool $showPrimaDopoPanel = false;
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$user = Auth::user();
|
|
return $user instanceof User
|
|
&& $user->hasAnyRole(['super-admin', 'admin', 'amministratore', 'collaboratore']);
|
|
}
|
|
|
|
public static function cleanStr(string $val): string
|
|
{
|
|
return strtolower(trim(str_replace([' ', '/', '\\', '-'], '', $val)));
|
|
}
|
|
|
|
public static function trovaUnitaCorrispondente(array $sub, array $unitaList, array $associazioniSoppressi): ?array
|
|
{
|
|
$isSoppresso = ($sub['partita'] ?? '') === 'Soppressa' || ($sub['partita'] ?? '') === 'soppressa';
|
|
$subStr = (string)($sub['sub'] ?? ($sub['subalterno'] ?? ''));
|
|
|
|
if ($isSoppresso && isset($associazioniSoppressi[$subStr])) {
|
|
return collect($unitaList)->firstWhere('id', $associazioniSoppressi[$subStr]);
|
|
}
|
|
|
|
$addrSister = strtolower($sub['indirizzo_completo'] ?? $sub['ind'] ?? $sub['indirizzo'] ?? '');
|
|
$sisterScala = '';
|
|
$sisterInterno = '';
|
|
if (preg_match('/scala\s+([a-pr-z])/i', $addrSister, $m)) {
|
|
$sisterScala = strtoupper($m[1]);
|
|
}
|
|
if (preg_match('/interno\s+([a-pr-z0-9\/]+)/i', $addrSister, $m)) {
|
|
$sisterInterno = strtoupper($m[1]);
|
|
} elseif (preg_match('/int\.\s*([a-pr-z0-9\/]+)/i', $addrSister, $m)) {
|
|
$sisterInterno = strtoupper($m[1]);
|
|
}
|
|
|
|
// 1. Proviamo ad abbinare in modo deterministico basato su Scala e Interno estratti dall'indirizzo catastale di Sister
|
|
if ($sisterScala !== '' && $sisterInterno !== '') {
|
|
$matched = collect($unitaList)->first(function($u) use ($sisterScala, $sisterInterno) {
|
|
$uScala = strtoupper(trim($u['scala'] ?? ''));
|
|
$uInterno = strtoupper(trim($u['interno'] ?? ''));
|
|
return $uScala === $sisterScala && $uInterno === $sisterInterno;
|
|
});
|
|
if ($matched) {
|
|
return $matched;
|
|
}
|
|
}
|
|
|
|
// 2. Fallback su subalterno, isolando le particelle per evitare fritto misto
|
|
return collect($unitaList)->first(function($u) use ($subStr, $addrSister) {
|
|
$uSubClean = self::cleanStr((string)($u['subalterno'] ?? ''));
|
|
$subClean = self::cleanStr($subStr);
|
|
if ($uSubClean !== $subClean) {
|
|
return false;
|
|
}
|
|
|
|
$uScala = strtoupper(trim($u['scala'] ?? ''));
|
|
if ($uScala === 'D') {
|
|
return str_contains($addrSister, 'scala d');
|
|
} else {
|
|
return !str_contains($addrSister, 'scala d');
|
|
}
|
|
});
|
|
}
|
|
|
|
public static function formattaCategoriaCatastale(string $codice): string
|
|
{
|
|
return \App\Services\SisterCatastoService::formattaCategoriaCatastale($codice);
|
|
}
|
|
|
|
public static function estraiCodiceCompatto(string $categoria): string
|
|
{
|
|
if (str_contains($categoria, '-')) {
|
|
$parti = explode('-', $categoria);
|
|
return trim($parti[0]);
|
|
}
|
|
$codiceClean = strtoupper(trim(str_replace([' ', '/', '-', '_'], '', $categoria)));
|
|
if (preg_match('/^([A-F])0?(\d+)$/', $codiceClean, $m)) {
|
|
return $m[1] . '/' . $m[2];
|
|
}
|
|
return $categoria;
|
|
}
|
|
|
|
public static function pulisciRendita(mixed $val): float
|
|
{
|
|
if ($val === null || $val === '') {
|
|
return 0.0;
|
|
}
|
|
$valStr = (string)$val;
|
|
$clean = preg_replace('/[^\d\,\.]/', '', $valStr);
|
|
if (str_contains($clean, ',') && !str_contains($clean, '.')) {
|
|
$clean = str_replace(',', '.', $clean);
|
|
} elseif (str_contains($clean, ',') && str_contains($clean, '.')) {
|
|
if (strrpos($clean, ',') > strrpos($clean, '.')) {
|
|
$clean = str_replace('.', '', $clean);
|
|
$clean = str_replace(',', '.', $clean);
|
|
} else {
|
|
$clean = str_replace(',', '', $clean);
|
|
}
|
|
}
|
|
return round((float)$clean, 2);
|
|
}
|
|
|
|
public string $filtroStato = 'tutti';
|
|
|
|
public function setFiltroStato(string $stato): void
|
|
{
|
|
$this->filtroStato = $stato;
|
|
$this->loadUnitaList();
|
|
}
|
|
|
|
public function mount(): void
|
|
{
|
|
$user = Auth::user();
|
|
if (!$user instanceof User) {
|
|
return;
|
|
}
|
|
|
|
$paramUnitaId = request()->query('unita_id');
|
|
if ($paramUnitaId && is_numeric($paramUnitaId)) {
|
|
$uRow = UnitaImmobiliare::withTrashed()->find((int)$paramUnitaId);
|
|
if ($uRow) {
|
|
StabileContext::setActiveStabileId($user, (int)$uRow->stabile_id);
|
|
}
|
|
}
|
|
|
|
$activeId = StabileContext::resolveActiveStabileId($user);
|
|
if (!$activeId) {
|
|
$this->stabileAttivo = null;
|
|
return;
|
|
}
|
|
|
|
$this->stabileAttivo = StabileContext::accessibleStabili($user)->firstWhere('id', $activeId);
|
|
if ($this->stabileAttivo) {
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
if (Storage::disk('public')->exists("{$dirPath}/geometria_stabile.json")) {
|
|
$this->stabileSubalterni = json_decode(Storage::disk('public')->get("{$dirPath}/geometria_stabile.json"), true) ?: [];
|
|
} else {
|
|
$this->sincronizzaGeometriaDaDb();
|
|
}
|
|
|
|
$associazioniPath = "{$dirPath}/anno_2026/associazioni_soppressi.json";
|
|
if (Storage::disk('public')->exists($associazioniPath)) {
|
|
$this->associazioniSoppressi = json_decode(Storage::disk('public')->get($associazioniPath), true) ?: [];
|
|
}
|
|
|
|
if (Schema::hasTable('unita_tipologie')) {
|
|
$this->tipologieOptions = DB::table('unita_tipologie')
|
|
->select('id', 'nome')
|
|
->orderBy('nome')
|
|
->pluck('nome', 'id')
|
|
->all();
|
|
}
|
|
|
|
if (Schema::hasTable('anagrafiche')) {
|
|
$this->anagraficheOptions = DB::table('anagrafiche')
|
|
->select('id', 'cognome', 'nome', 'codice_fiscale')
|
|
->where(function($q) {
|
|
$q->whereNotNull('cognome')->where('cognome', '<>', '')
|
|
->orWhereNotNull('nome')->where('nome', '<>', '');
|
|
})
|
|
->orderBy('cognome')
|
|
->orderBy('nome')
|
|
->get()
|
|
->mapWithKeys(function($a) {
|
|
$label = trim("{$a->cognome} {$a->nome}");
|
|
if (empty($label)) {
|
|
return [];
|
|
}
|
|
return [$a->id => $label . " (" . ($a->codice_fiscale ?? '') . ")"];
|
|
})
|
|
->all();
|
|
}
|
|
|
|
$this->loadUnitaList();
|
|
$this->ordinaSubalterniPerInterno();
|
|
|
|
if ($paramUnitaId && is_numeric($paramUnitaId)) {
|
|
$uRow = UnitaImmobiliare::withTrashed()->find((int)$paramUnitaId);
|
|
if ($uRow) {
|
|
$this->selectedUnitaId = (int)$paramUnitaId;
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
$this->activeTab = 'appartamento';
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public function setTab(string $tab): void
|
|
{
|
|
$this->activeTab = $tab;
|
|
if ($tab === 'visura_rt') {
|
|
$this->caricaVisuraProprietariRt();
|
|
}
|
|
}
|
|
|
|
public function updatedSearch(): void
|
|
{
|
|
$this->loadUnitaList();
|
|
}
|
|
|
|
public function toggleSort(): void
|
|
{
|
|
$this->sortDirection = $this->sortDirection === 'asc' ? 'desc' : 'asc';
|
|
$this->loadUnitaList();
|
|
}
|
|
|
|
public function togglePrimaDopoPanel(): void
|
|
{
|
|
$this->showPrimaDopoPanel = !$this->showPrimaDopoPanel;
|
|
}
|
|
public function rinfrescaSchermata(): void
|
|
{
|
|
$this->loadUnitaList();
|
|
if ($this->selectedUnitaId) {
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
}
|
|
}
|
|
public function vaiADettaglio(int $unitaId): void
|
|
{
|
|
$this->selectUnita($unitaId);
|
|
$this->setTab('appartamento');
|
|
}
|
|
|
|
public function loadUnitaList(): void
|
|
{
|
|
if (!$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
|
|
$query = UnitaImmobiliare::where('stabile_id', $this->stabileAttivo->id);
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'tipologia_id')) {
|
|
$query->orderBy('tipologia_id');
|
|
} elseif (Schema::hasColumn('unita_immobiliari', 'tipo_unita')) {
|
|
$query->orderBy('tipo_unita');
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'palazzina')) {
|
|
$query->orderBy('palazzina');
|
|
}
|
|
|
|
$query->orderBy('scala')
|
|
->orderBy('piano')
|
|
->orderBy('interno');
|
|
|
|
if (trim($this->search) !== '') {
|
|
$searchTerm = '%' . trim($this->search) . '%';
|
|
$query->where(function($q) use ($searchTerm) {
|
|
$q->where('interno', 'like', $searchTerm)
|
|
->orWhere('scala', 'like', $searchTerm)
|
|
->orWhere('piano', 'like', $searchTerm);
|
|
if (Schema::hasColumn('unita_immobiliari', 'subalterno')) {
|
|
$q->orWhere('subalterno', 'like', $searchTerm);
|
|
}
|
|
if (Schema::hasTable('unita_immobiliare_nominativi')) {
|
|
$q->orWhereIn('id', function($subQuery) use ($searchTerm) {
|
|
$subQuery->select('unita_immobiliare_id')
|
|
->from('unita_immobiliare_nominativi')
|
|
->where('nominativo', 'like', $searchTerm);
|
|
});
|
|
}
|
|
if (Schema::hasTable('anagrafiche') && Schema::hasTable('unita_anagrafica_periodo')) {
|
|
$q->orWhereIn('id', function($subQuery) use ($searchTerm) {
|
|
$subQuery->select('uap.unita_immobiliare_id')
|
|
->from('unita_anagrafica_periodo as uap')
|
|
->join('anagrafiche as a', 'a.id', '=', 'uap.anagrafica_id')
|
|
->where(DB::raw("COALESCE(a.cognome, '') || ' ' || COALESCE(a.nome, '')"), 'like', $searchTerm);
|
|
});
|
|
}
|
|
});
|
|
}
|
|
|
|
$unita = $query->get();
|
|
|
|
$unitaIds = $unita->pluck('id')->all();
|
|
$proprietariMap = [];
|
|
|
|
if (!empty($unitaIds)) {
|
|
$annoGestione = 2026;
|
|
$startDate = "{$annoGestione}-01-01";
|
|
$endDate = "{$annoGestione}-12-31";
|
|
|
|
if (Schema::hasTable('unita_anagrafica_periodo')) {
|
|
$rows = DB::table('unita_anagrafica_periodo as uap')
|
|
->join('anagrafiche as a', 'a.id', '=', 'uap.anagrafica_id')
|
|
->whereIn('uap.unita_immobiliare_id', $unitaIds)
|
|
->where('uap.ruolo_occupazione', 'condomino')
|
|
->where('uap.data_inizio', '<=', $endDate)
|
|
->where(function($q) use ($startDate) {
|
|
$q->whereNull('uap.data_fine')
|
|
->orWhere('uap.data_fine', '>=', $startDate);
|
|
})
|
|
->select('uap.unita_immobiliare_id', 'a.cognome', 'a.nome')
|
|
->distinct()
|
|
->get();
|
|
|
|
foreach ($rows as $row) {
|
|
$nomeCompleto = trim("{$row->cognome} {$row->nome}");
|
|
if ($nomeCompleto !== '') {
|
|
if (!isset($proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id] = [];
|
|
}
|
|
if (!in_array($nomeCompleto, $proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id][] = $nomeCompleto;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Schema::hasTable('persone_unita_relazioni')) {
|
|
$rowsRel = DB::table('persone_unita_relazioni as pur')
|
|
->join('persone as p', 'p.id', '=', 'pur.persona_id')
|
|
->whereIn('pur.unita_id', $unitaIds)
|
|
->select('pur.unita_id as unita_immobiliare_id', 'p.cognome', 'p.nome', 'p.ragione_sociale')
|
|
->distinct()
|
|
->get();
|
|
|
|
foreach ($rowsRel as $row) {
|
|
$nomeCompleto = $row->ragione_sociale ?: trim("{$row->cognome} {$row->nome}");
|
|
if ($nomeCompleto !== '') {
|
|
if (!isset($proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id] = [];
|
|
}
|
|
if (!in_array($nomeCompleto, $proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id][] = $nomeCompleto;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Schema::hasTable('proprieta')) {
|
|
$rowsProp = DB::table('proprieta as pr')
|
|
->join('anagrafiche as a', 'a.id', '=', 'pr.anagrafica_id')
|
|
->whereIn('pr.unita_immobiliare_id', $unitaIds)
|
|
->where('pr.data_inizio', '<=', $endDate)
|
|
->select('pr.unita_immobiliare_id', 'a.cognome', 'a.nome')
|
|
->distinct()
|
|
->get();
|
|
|
|
foreach ($rowsProp as $row) {
|
|
$nomeCompleto = trim("{$row->cognome} {$row->nome}");
|
|
if ($nomeCompleto !== '') {
|
|
if (!isset($proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id] = [];
|
|
}
|
|
if (!in_array($nomeCompleto, $proprietariMap[$row->unita_immobiliare_id])) {
|
|
$proprietariMap[$row->unita_immobiliare_id][] = $nomeCompleto;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->unitaList = [];
|
|
foreach ($unita as $u) {
|
|
try {
|
|
$status = 'Da Verificare';
|
|
$badgeColor = 'yellow';
|
|
|
|
$validatedJsonPath = "{$dirPath}/anno_2026/validati_unita_{$u->id}.json";
|
|
$uFoglio = Schema::hasColumn('unita_immobiliari', 'foglio') ? $u->foglio : '';
|
|
$uParticella = Schema::hasColumn('unita_immobiliari', 'particella') ? $u->particella : '';
|
|
$uSubalterno = Schema::hasColumn('unita_immobiliari', 'subalterno') ? $u->subalterno : '';
|
|
$uRendita = Schema::hasColumn('unita_immobiliari', 'rendita_catastale') ? $u->rendita_catastale : '';
|
|
|
|
$hasValidatedFile = false;
|
|
if (Storage::disk('public')->exists($validatedJsonPath)) {
|
|
try {
|
|
$validated = json_decode(Storage::disk('public')->get($validatedJsonPath), true);
|
|
if ($validated) {
|
|
$uFoglio = $validated['foglio'] ?? $uFoglio;
|
|
$uParticella = $validated['particella'] ?? $uParticella;
|
|
$uSubalterno = $validated['subalterno'] ?? $uSubalterno;
|
|
$uRendita = $validated['rendita_catastale'] ?? $uRendita;
|
|
$hasValidatedFile = true;
|
|
$status = 'Validata';
|
|
$badgeColor = 'green';
|
|
}
|
|
} catch (Exception $e) {}
|
|
}
|
|
|
|
if (empty($uFoglio) || $uFoglio === '-' || $uFoglio === '0') {
|
|
$uFoglio = $this->stabileAttivo?->foglio ?? $this->stabileAttivo?->foglio_catasto ?? '';
|
|
}
|
|
if (empty($uParticella) || $uParticella === '-' || $uParticella === '0') {
|
|
if ($this->stabileAttivo && ($this->stabileAttivo->id == 4 || $this->stabileAttivo->codice_stabile === '0021')) {
|
|
$scalaUpper = strtoupper(trim($u->scala ?: ''));
|
|
$uParticella = ($scalaUpper === 'D') ? '253' : '256';
|
|
} else {
|
|
$uParticella = $this->stabileAttivo?->particella_catasto ?? $this->stabileAttivo?->mappale ?? '';
|
|
}
|
|
}
|
|
|
|
$subLabel = ($uSubalterno !== null && $uSubalterno !== '') ? "_sub{$uSubalterno}" : "";
|
|
$jsonFilename = "risultato_immobile_" . (string)$uFoglio . "_" . (string)$uParticella . "{$subLabel}.json";
|
|
$jsonRelativePath = "{$dirPath}/{$jsonFilename}";
|
|
|
|
if (Storage::disk('public')->exists($jsonRelativePath)) {
|
|
try {
|
|
$sisterContent = json_decode(Storage::disk('public')->get($jsonRelativePath), true);
|
|
$sData = $sisterContent['immobili'] ?? $sisterContent;
|
|
if (is_array($sData) && isset($sData[0])) {
|
|
$sData = $sData[0];
|
|
}
|
|
|
|
if (is_array($sData)) {
|
|
$discrepancies = [];
|
|
if (self::cleanStr((string)$uFoglio) !== self::cleanStr($sData['foglio'] ?? '')) {
|
|
$discrepancies[] = 'foglio';
|
|
}
|
|
if (self::cleanStr((string)$uParticella) !== self::cleanStr($sData['particella'] ?? '')) {
|
|
$discrepancies[] = 'particella';
|
|
}
|
|
if (self::cleanStr((string)($uSubalterno ?? '')) !== self::cleanStr($sData['subalterno'] ?? '')) {
|
|
$discrepancies[] = 'subalterno';
|
|
}
|
|
|
|
$legacyRendita = self::pulisciRendita($uRendita);
|
|
$sisterRenditaRaw = $sData['rendita'] ?? '0';
|
|
$sisterRenditaClean = self::pulisciRendita($sisterRenditaRaw);
|
|
|
|
if (abs($legacyRendita - $sisterRenditaClean) > 0.01) {
|
|
$discrepancies[] = 'rendita';
|
|
}
|
|
|
|
if (empty($discrepancies)) {
|
|
$status = $hasValidatedFile ? 'Validata' : 'Validata AdE';
|
|
$badgeColor = 'green';
|
|
} else {
|
|
$status = 'Disallineata';
|
|
$badgeColor = 'red';
|
|
}
|
|
}
|
|
} catch (Exception $e) {
|
|
$status = 'Errore Lettura';
|
|
$badgeColor = 'red';
|
|
}
|
|
}
|
|
|
|
$proprietari = isset($proprietariMap[$u->id]) ? implode(', ', $proprietariMap[$u->id]) : '';
|
|
if ($proprietari === '') {
|
|
$proprietari = 'ATER';
|
|
}
|
|
|
|
$foglioDisp = ($uFoglio !== null && $uFoglio !== '-' && $uFoglio !== '0' && $uFoglio !== '') ? $uFoglio : '';
|
|
$particellaDisp = ($uParticella !== null && $uParticella !== '-' && $uParticella !== '0' && $uParticella !== '') ? $uParticella : '';
|
|
$subalternoDisp = ($uSubalterno !== null && $uSubalterno !== '-' && $uSubalterno !== '0' && $uSubalterno !== '') ? $uSubalterno : '';
|
|
|
|
$renditaVal = (float)$uRendita;
|
|
$renditaDisp = $renditaVal > 0.01 ? '€ ' . number_format($renditaVal, 2, ',', '.') : '';
|
|
|
|
$this->unitaList[] = [
|
|
'id' => $u->id,
|
|
'interno' => $u->interno ?: '-',
|
|
'scala' => $u->scala ?: '-',
|
|
'piano' => $u->piano ?: '-',
|
|
'palazzina' => Schema::hasColumn('unita_immobiliari', 'palazzina') ? ($u->palazzina ?: '') : '',
|
|
'categoria_catastale' => Schema::hasColumn('unita_immobiliari', 'categoria_catastale') ? ($u->categoria_catastale ?: '') : '',
|
|
'proprietari' => $proprietari,
|
|
'foglio' => $foglioDisp,
|
|
'particella' => $particellaDisp,
|
|
'subalterno' => $subalternoDisp,
|
|
'rendita' => $renditaDisp,
|
|
'status' => $status,
|
|
'badgeColor' => $badgeColor
|
|
];
|
|
} catch (Exception $e) {}
|
|
}
|
|
|
|
// Applicazione Ordinamento Spaziale Reale Naturale: Palazzina -> Scala -> Piano (S2 -> S1 -> T -> 1 -> ...) -> Tipo -> Interno progressivo
|
|
usort($this->unitaList, function($a, $b) {
|
|
$classA = $this->classificaUnitaPerOrdinamento($a['scala'], $a['interno'], $a['palazzina'], $a['piano'], $a['categoria_catastale']);
|
|
$classB = $this->classificaUnitaPerOrdinamento($b['scala'], $b['interno'], $b['palazzina'], $b['piano'], $b['categoria_catastale']);
|
|
|
|
$cmpPal = strcmp($classA['palazzina'], $classB['palazzina']);
|
|
if ($cmpPal !== 0) {
|
|
return $cmpPal;
|
|
}
|
|
|
|
$cmpScala = strcmp($classA['scala'], $classB['scala']);
|
|
if ($cmpScala !== 0) {
|
|
return $cmpScala;
|
|
}
|
|
|
|
if ($classA['tipo'] !== $classB['tipo']) {
|
|
return $classA['tipo'] <=> $classB['tipo'];
|
|
}
|
|
|
|
if ($classA['piano_weight'] ?? ($classA['piano_peso'] ?? 0) !== ($classB['piano_weight'] ?? ($classB['piano_peso'] ?? 0))) {
|
|
return ($classA['piano_weight'] ?? ($classA['piano_peso'] ?? 0)) <=> ($classB['piano_weight'] ?? ($classB['piano_peso'] ?? 0));
|
|
}
|
|
|
|
if ($classA['prog'] !== $classB['prog']) {
|
|
return $classA['prog'] <=> $classB['prog'];
|
|
}
|
|
|
|
return strcmp($classA['raw'], $classB['raw']);
|
|
});
|
|
|
|
if ($this->filtroStato === 'da_verificare') {
|
|
$this->unitaList = array_values(array_filter($this->unitaList, function($item) {
|
|
return $item['status'] === 'Da Verificare';
|
|
}));
|
|
}
|
|
|
|
if (empty($this->selectedUnitaId) && !empty($this->unitaList)) {
|
|
$this->selectUnita($this->unitaList[0]['id']);
|
|
}
|
|
}
|
|
|
|
public function selectUnita(int $unitaId): void
|
|
{
|
|
$this->selectedUnitaId = $unitaId;
|
|
$u = UnitaImmobiliare::find($unitaId);
|
|
if (!$u) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
$validatedJsonPath = "{$annoConsolidatoPath}/validati_unita_{$unitaId}.json";
|
|
|
|
$uFoglio = Schema::hasColumn('unita_immobiliari', 'foglio') ? $u->foglio : '';
|
|
$uParticella = Schema::hasColumn('unita_immobiliari', 'particella') ? $u->particella : '';
|
|
$uSubalterno = Schema::hasColumn('unita_immobiliari', 'subalterno') ? $u->subalterno : '';
|
|
$uRendita = Schema::hasColumn('unita_immobiliari', 'rendita_catastale') ? $u->rendita_catastale : '';
|
|
$uPiano = $u->piano;
|
|
$uClasse = '';
|
|
$uConsistenza = '';
|
|
$uIdImmobile = '';
|
|
|
|
$editTipologiaIdTemp = $u->tipologia_id;
|
|
if (Storage::disk('public')->exists($validatedJsonPath)) {
|
|
try {
|
|
$validated = json_decode(Storage::disk('public')->get($validatedJsonPath), true);
|
|
if ($validated) {
|
|
$uFoglio = $validated['foglio'] ?? $uFoglio;
|
|
$uParticella = $validated['particella'] ?? $uParticella;
|
|
$uSubalterno = $validated['subalterno'] ?? $uSubalterno;
|
|
$uRendita = $validated['rendita_catastale'] ?? $uRendita;
|
|
$uClasse = $validated['classe'] ?? $uClasse;
|
|
$uConsistenza = $validated['consistenza'] ?? $uConsistenza;
|
|
$uIdImmobile = $validated['id_immobile'] ?? $uIdImmobile;
|
|
$uPiano = $validated['piano'] ?? $uPiano;
|
|
$editTipologiaIdTemp = $validated['tipologia_id'] ?? $editTipologiaIdTemp;
|
|
}
|
|
} catch (Exception $e) {}
|
|
}
|
|
|
|
if (empty($uFoglio) || $uFoglio === '-' || $uFoglio === '0') {
|
|
$uFoglio = $this->stabileAttivo?->foglio ?? $this->stabileAttivo?->foglio_catasto ?? '';
|
|
}
|
|
if ($this->stabileAttivo && ($this->stabileAttivo->id == 4 || $this->stabileAttivo->codice_stabile === '0021')) {
|
|
$scalaUpper = strtoupper(trim($u->scala ?: ''));
|
|
$palazzinaUpper = Schema::hasColumn('unita_immobiliari', 'palazzina') ? strtoupper(trim($u->palazzina ?: '')) : '';
|
|
if ($scalaUpper === 'D' || $palazzinaUpper === 'D') {
|
|
$uParticella = '253';
|
|
} else {
|
|
$uParticella = '256';
|
|
}
|
|
} else {
|
|
if (empty($uParticella) || $uParticella === '-' || $uParticella === '0') {
|
|
$uParticella = $this->stabileAttivo?->particella_catasto ?? $this->stabileAttivo?->mappale ?? '';
|
|
}
|
|
}
|
|
|
|
$this->stagingRawData = [];
|
|
if ($u->legacy_cond_id && Schema::connection('gescon_import')->hasTable('condomin')) {
|
|
$raw = DB::connection('gescon_import')->table('condomin')
|
|
->where('id', $u->legacy_cond_id)
|
|
->first();
|
|
if ($raw) {
|
|
$this->stagingRawData = (array)$raw;
|
|
}
|
|
}
|
|
|
|
$this->legacyData = [
|
|
'id' => $u->id,
|
|
'sezione_urbana' => $u->sezione_urbana,
|
|
'foglio' => $uFoglio,
|
|
'particella' => $uParticella,
|
|
'subalterno' => $uSubalterno,
|
|
'scala' => $u->scala,
|
|
'piano' => $uPiano,
|
|
'rendita' => number_format((float)$uRendita, 2, ',', '.'),
|
|
'categoria' => $u->categoria_catastale,
|
|
'classe' => $uClasse ?: $u->classe,
|
|
'consistenza' => $uConsistenza ?: ($u->numero_vani ? $u->numero_vani . ' vani' : ''),
|
|
'id_immobile' => $uIdImmobile ?: $u->codice_univoco,
|
|
];
|
|
|
|
$this->editFoglio = (string)$uFoglio;
|
|
$this->editParticella = (string)$uParticella;
|
|
$this->editSubalterno = (string)$uSubalterno;
|
|
$this->editRendita = number_format((float)$uRendita, 2, ',', '.');
|
|
$this->editSezioneUrbana = (string)($u->sezione_urbana ?? '');
|
|
$this->editCategoria = (string)($u->categoria_catastale ?? '');
|
|
$this->editPiano = (string)($uPiano ?? '');
|
|
$this->editClasse = (string)$this->legacyData['classe'];
|
|
$this->editConsistenza = (string)$this->legacyData['consistenza'];
|
|
$this->editIdImmobile = (string)$this->legacyData['id_immobile'];
|
|
$this->editTipologiaId = $editTipologiaIdTemp;
|
|
$this->sisterData = [];
|
|
$this->auditAnomalies = [];
|
|
$this->sisterContentRaw = [];
|
|
|
|
$subLabel = ($uSubalterno !== null && $uSubalterno !== '') ? "_sub{$uSubalterno}" : "";
|
|
$jsonFilename = "risultato_immobile_" . (string)$uFoglio . "_" . (string)$uParticella . "{$subLabel}.json";
|
|
$jsonRelativePath = "{$dirPath}/{$jsonFilename}";
|
|
|
|
if (Storage::disk('public')->exists($jsonRelativePath)) {
|
|
try {
|
|
$sisterContent = json_decode(Storage::disk('public')->get($jsonRelativePath), true);
|
|
$this->sisterContentRaw = $sisterContent;
|
|
$sData = $sisterContent['immobili'] ?? $sisterContent;
|
|
if (is_array($sData) && isset($sData[0])) {
|
|
$sData = $sData[0];
|
|
}
|
|
|
|
$this->sisterData = $sData;
|
|
|
|
$partita = strtolower((string)($this->sisterData['partita'] ?? $this->sisterData['dati_catastali']['partita'] ?? ''));
|
|
$isSoppresso = str_contains($partita, 'soppress');
|
|
|
|
if ($isSoppresso) {
|
|
$this->sisterData['rendita'] = 'Soppresso';
|
|
$this->sisterData['consistenza'] = 'Soppresso';
|
|
$this->sisterData['classamento'] = 'Soppresso';
|
|
} else {
|
|
if (isset($this->sisterData['classe'])) {
|
|
$this->editClasse = $this->sisterData['classe'];
|
|
}
|
|
if (isset($this->sisterData['consistenza'])) {
|
|
$this->editConsistenza = $this->sisterData['consistenza'];
|
|
}
|
|
if (isset($this->sisterData['idImmobile'])) {
|
|
$this->editIdImmobile = $this->sisterData['idImmobile'];
|
|
}
|
|
if (isset($this->sisterData['piano'])) {
|
|
$this->editPiano = $this->sisterData['piano'];
|
|
}
|
|
if (isset($this->sisterData['classamento'])) {
|
|
$this->editCategoria = $this->sisterData['classamento'];
|
|
}
|
|
if (isset($this->sisterData['rendita'])) {
|
|
$this->editRendita = $this->sisterData['rendita'];
|
|
}
|
|
}
|
|
|
|
// Calcolo anomalie
|
|
if (self::cleanStr((string)$uFoglio) !== self::cleanStr($this->sisterData['foglio'] ?? '')) {
|
|
$this->auditAnomalies['foglio'] = [
|
|
'legacy' => $uFoglio,
|
|
'sister' => $this->sisterData['foglio'] ?? '-'
|
|
];
|
|
}
|
|
if (self::cleanStr((string)$uParticella) !== self::cleanStr($this->sisterData['particella'] ?? '')) {
|
|
$this->auditAnomalies['particella'] = [
|
|
'legacy' => $uParticella,
|
|
'sister' => $this->sisterData['particella'] ?? '-'
|
|
];
|
|
}
|
|
if (self::cleanStr((string)($uSubalterno ?? '')) !== self::cleanStr($this->sisterData['subalterno'] ?? '')) {
|
|
$this->auditAnomalies['subalterno'] = [
|
|
'legacy' => $uSubalterno,
|
|
'sister' => $this->sisterData['subalterno'] ?? '-'
|
|
];
|
|
}
|
|
|
|
if (!$isSoppresso) {
|
|
$legacyRendita = self::pulisciRendita($uRendita);
|
|
$sisterRenditaRaw = $this->sisterData['rendita'] ?? '0';
|
|
$sisterRenditaClean = self::pulisciRendita($sisterRenditaRaw);
|
|
|
|
if (abs($legacyRendita - $sisterRenditaClean) > 0.01) {
|
|
$this->auditAnomalies['rendita'] = [
|
|
'legacy' => number_format($legacyRendita, 2, ',', '.'),
|
|
'sister' => number_format($sisterRenditaClean, 2, ',', '.')
|
|
];
|
|
}
|
|
}
|
|
} catch (Exception $e) {}
|
|
}
|
|
|
|
$this->loadProprietari();
|
|
|
|
if ($this->activeTab === 'visura_rt') {
|
|
$this->caricaVisuraProprietariRt();
|
|
}
|
|
}
|
|
|
|
protected function loadProprietari(): void
|
|
{
|
|
if (!$this->selectedUnitaId) {
|
|
return;
|
|
}
|
|
|
|
$this->proprietariPeriodi = [];
|
|
|
|
if (Schema::hasTable('unita_anagrafica_periodo')) {
|
|
$rows = DB::table('unita_anagrafica_periodo')
|
|
->join('anagrafiche', 'anagrafiche.id', '=', 'unita_anagrafica_periodo.anagrafica_id')
|
|
->where('unita_anagrafica_periodo.unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('unita_anagrafica_periodo.ruolo_occupazione', 'condomino')
|
|
->select(
|
|
'unita_anagrafica_periodo.id as pivot_id',
|
|
'anagrafiche.id as anagrafica_id',
|
|
'anagrafiche.cognome',
|
|
'anagrafiche.nome',
|
|
'anagrafiche.codice_fiscale',
|
|
'unita_anagrafica_periodo.data_inizio',
|
|
'unita_anagrafica_periodo.data_fine',
|
|
'unita_anagrafica_periodo.percentuale_spesa as quota',
|
|
'unita_anagrafica_periodo.ruolo_occupazione'
|
|
)
|
|
->get();
|
|
|
|
foreach ($rows as $r) {
|
|
$this->proprietariPeriodi[] = [
|
|
'pivot_id' => $r->pivot_id,
|
|
'anagrafica_id' => $r->anagrafica_id,
|
|
'nome_completo' => trim("{$r->cognome} {$r->nome}"),
|
|
'codice_fiscale' => $r->codice_fiscale,
|
|
'data_inizio' => $r->data_inizio,
|
|
'data_fine' => $r->data_fine ?: '',
|
|
'quota' => number_format((float)$r->quota, 2, ',', '.'),
|
|
'ruolo' => 'condomino'
|
|
];
|
|
}
|
|
}
|
|
|
|
if (Schema::hasTable('unita_immobiliare_nominativi')) {
|
|
$compRows = DB::table('unita_immobiliare_nominativi')
|
|
->where('unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('fonte', 'legacy_comproprietari')
|
|
->get();
|
|
|
|
foreach ($compRows as $cr) {
|
|
$meta = json_decode($cr->legacy_payload ?? '{}', true) ?: [];
|
|
$cf = $meta['Cond_cod_fisc'] ?? $cr->codice_fiscale ?? '';
|
|
$this->proprietariPeriodi[] = [
|
|
'pivot_id' => $cr->id,
|
|
'anagrafica_id' => null,
|
|
'nome_completo' => trim((string)$cr->nominativo),
|
|
'codice_fiscale' => $cf,
|
|
'data_inizio' => $cr->data_inizio ?: '1970-01-01',
|
|
'data_fine' => $cr->data_fine ?: '',
|
|
'quota' => number_format((float)$cr->percentuale, 2, ',', '.'),
|
|
'ruolo' => 'condomino'
|
|
];
|
|
}
|
|
}
|
|
|
|
// Deduplicazione temporale per evitare di mostrare lo stesso proprietario registrato su più anni contigui con la stessa quota
|
|
$deduped = [];
|
|
foreach ($this->proprietariPeriodi as $p) {
|
|
$key = trim(strtolower($p['nome_completo'])) . '|' . trim(strtolower($p['codice_fiscale'] ?? '')) . '|' . $p['quota'];
|
|
if (!isset($deduped[$key])) {
|
|
$deduped[$key] = $p;
|
|
} else {
|
|
// Teniamo la data d'inizio più vecchia
|
|
if (empty($deduped[$key]['data_inizio']) || (!empty($p['data_inizio']) && $p['data_inizio'] < $deduped[$key]['data_inizio'])) {
|
|
$deduped[$key]['data_inizio'] = $p['data_inizio'];
|
|
}
|
|
// Teniamo la data di fine più recente (o null se presente null)
|
|
if (empty($p['data_fine'])) {
|
|
$deduped[$key]['data_fine'] = '';
|
|
} elseif (!empty($deduped[$key]['data_fine']) && $p['data_fine'] > $deduped[$key]['data_fine']) {
|
|
$deduped[$key]['data_fine'] = $p['data_fine'];
|
|
}
|
|
}
|
|
}
|
|
|
|
// Ordiniamo per data_inizio discendente
|
|
$this->proprietariPeriodi = array_values($deduped);
|
|
usort($this->proprietariPeriodi, function($a, $b) {
|
|
return strcmp($b['data_inizio'] ?: '1970-01-01', $a['data_inizio'] ?: '1970-01-01');
|
|
});
|
|
}
|
|
|
|
public function sincronizzaGeometriaDaDb(): void
|
|
{
|
|
if (!$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
|
|
$unitaStabile = UnitaImmobiliare::where('stabile_id', $this->stabileAttivo->id)
|
|
->orderBy('scala')
|
|
->orderBy('piano')
|
|
->orderBy('interno')
|
|
->get();
|
|
|
|
$subalterniList = [];
|
|
$indirizzoBase = $this->stabileAttivo->indirizzo ?? '';
|
|
|
|
foreach ($unitaStabile as $u) {
|
|
$subVal = trim((string)($u->subalterno ?: ''));
|
|
if ($subVal === '') {
|
|
continue;
|
|
}
|
|
|
|
$rendVal = is_numeric($u->rendita_catastale) ? (float)$u->rendita_catastale : 0.0;
|
|
$renditaStr = $rendVal > 0.01 ? '€ ' . number_format($rendVal, 2, ',', '.') : '—';
|
|
$cat = $u->categoria_catastale ? self::formattaCategoriaCatastale($u->categoria_catastale) : 'A/2 - Abitazioni di tipo civile';
|
|
|
|
$indDett = $indirizzoBase;
|
|
if ($u->scala) {
|
|
$indDett .= " Scala {$u->scala}";
|
|
}
|
|
if ($u->interno) {
|
|
$indDett .= " Int. {$u->interno}";
|
|
}
|
|
if ($u->piano) {
|
|
$indDett .= " Piano {$u->piano}";
|
|
}
|
|
|
|
$subalterniList[] = [
|
|
'sub' => $subVal,
|
|
'rendita' => $renditaStr,
|
|
'partita' => 'ATTIVA',
|
|
'destinazione' => $cat,
|
|
'indirizzo_completo' => $indDett,
|
|
];
|
|
}
|
|
|
|
$this->stabileSubalterni = $subalterniList;
|
|
$this->ordinaSubalterniPerInterno();
|
|
|
|
Storage::disk('public')->put("{$dirPath}/geometria_stabile.json", json_encode($this->stabileSubalterni, JSON_PRETTY_PRINT));
|
|
}
|
|
|
|
public function interrogaGeometriaStabile(): void
|
|
{
|
|
if (!$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$this->sincronizzaGeometriaDaDb();
|
|
|
|
Notification::make()
|
|
->title('Geometria Stabile Sincronizzata dal Database')
|
|
->body('Mappa subalterni e indirizzi aggiornata con successo dai dati consolidati dello stabile.')
|
|
->success()
|
|
->send();
|
|
|
|
} catch (Exception $e) {
|
|
Notification::make()
|
|
->title('Errore Geometria Stabile')
|
|
->body($e->getMessage())
|
|
->danger()
|
|
->send();
|
|
}
|
|
}
|
|
|
|
public function interrogaSister(bool $force = false): void
|
|
{
|
|
if (!$this->selectedUnitaId || !$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$subLabel = ($this->editSubalterno !== null && $this->editSubalterno !== '') ? "_sub{$this->editSubalterno}" : "";
|
|
$jsonFilename = "risultato_immobile_" . (string)$this->editFoglio . "_" . (string)$this->editParticella . "{$subLabel}.json";
|
|
$jsonPath = "{$dirPath}/{$jsonFilename}";
|
|
$subStr = (string)$this->editSubalterno;
|
|
|
|
// 1. Lettura immediata da Cache locale se presente e non forzato
|
|
if (!$force && Storage::disk('public')->exists($jsonPath)) {
|
|
Notification::make()
|
|
->title('Dati caricati da Cache Locale')
|
|
->body('Le informazioni catastali sono state caricate dalla memoria locale.')
|
|
->success()
|
|
->send();
|
|
$this->loadUnitaList();
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
return;
|
|
}
|
|
|
|
// 2. Chiamata reale a Sister API
|
|
try {
|
|
$tipoCatasto = 'F';
|
|
$uffProvinciale = 'ROMA Territorio-RM';
|
|
$cittaName = $this->stabileAttivo->citta ?? 'ROMA';
|
|
$denomComune = $service->getComuneCat($this->stabileAttivo->id, $uffProvinciale, $cittaName);
|
|
|
|
$result = $service->ricercaIntestatiImmobile(
|
|
$this->stabileAttivo->id,
|
|
$tipoCatasto,
|
|
$uffProvinciale,
|
|
$denomComune,
|
|
(string)$this->editFoglio,
|
|
(string)$this->editParticella,
|
|
$this->editSubalterno,
|
|
null,
|
|
$this->editSezioneUrbana ?: null
|
|
);
|
|
|
|
if (!empty($result) && !isset($result['err'])) {
|
|
Storage::disk('public')->put($jsonPath, json_encode($result, JSON_PRETTY_PRINT));
|
|
Notification::make()->title('Dati Catastali caricati da Sister API')->success()->send();
|
|
$this->loadUnitaList();
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
return;
|
|
}
|
|
|
|
if (isset($result['err'])) {
|
|
Notification::make()
|
|
->title('Risposta Sister API')
|
|
->body('Sister ha risposto: ' . $result['err'])
|
|
->warning()
|
|
->send();
|
|
return;
|
|
}
|
|
} catch (Exception $e) {
|
|
Notification::make()
|
|
->title('Errore Connessione Sister API')
|
|
->body('Impossibile contattare Sister API: ' . $e->getMessage())
|
|
->danger()
|
|
->send();
|
|
return;
|
|
}
|
|
|
|
Notification::make()
|
|
->title('Dati Catastali Non Disponibili')
|
|
->body("Nessun dato catastale ufficiale reperito per Foglio {$this->editFoglio}, Particella {$this->editParticella}, Subalterno {$subStr}. Nessun fallback probabilistico applicato.")
|
|
->warning()
|
|
->send();
|
|
}
|
|
|
|
public function scaricaVisura(): void
|
|
{
|
|
if (!$this->selectedUnitaId || !$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
$service = new SisterCatastoService();
|
|
$tipoCatasto = 'F';
|
|
$uffProvinciale = 'ROMA Territorio-RM';
|
|
$denomComune = $service->getComuneCat($this->stabileAttivo->id, $uffProvinciale, $this->stabileAttivo->citta ?? 'ROMA');
|
|
|
|
$res = $service->acquistaEPrelevaVisura(
|
|
$this->stabileAttivo->id,
|
|
$tipoCatasto,
|
|
$uffProvinciale,
|
|
$denomComune,
|
|
(string)$this->editFoglio,
|
|
(string)$this->editParticella,
|
|
$this->editSubalterno,
|
|
null,
|
|
null,
|
|
'PDF',
|
|
'completa',
|
|
24
|
|
);
|
|
|
|
Notification::make()
|
|
->title('Visura acquisita con successo')
|
|
->body('Il file è stato memorizzato nel percorso cloud drive dello stabile.')
|
|
->success()
|
|
->send();
|
|
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
|
|
} catch (Exception $e) {
|
|
Notification::make()
|
|
->title('Errore acquisto visura')
|
|
->body($e->getMessage())
|
|
->danger()
|
|
->send();
|
|
}
|
|
}
|
|
|
|
public function applicaECorreggi(): void
|
|
{
|
|
if (!$this->selectedUnitaId || !$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
Storage::disk('public')->makeDirectory($annoConsolidatoPath);
|
|
|
|
$renditaClean = (float)str_replace(['R.Euro:', 'Euro:', ' ', ','], ['', '', '', '.'], $this->editRendita);
|
|
|
|
$validatedData = [
|
|
'unita_id' => $this->selectedUnitaId,
|
|
'foglio' => $this->editFoglio,
|
|
'particella' => $this->editParticella,
|
|
'subalterno' => $this->editSubalterno,
|
|
'rendita_catastale' => $renditaClean,
|
|
'piano' => $this->editPiano,
|
|
'classe' => $this->editClasse,
|
|
'consistenza' => $this->editConsistenza,
|
|
'id_immobile' => $this->editIdImmobile,
|
|
'tipologia_id' => $this->editTipologiaId,
|
|
'validated_at' => now()->toDateTimeString(),
|
|
'validated_by' => auth()->id()
|
|
];
|
|
|
|
Storage::disk('public')->put("{$annoConsolidatoPath}/validati_unita_{$this->selectedUnitaId}.json", json_encode($validatedData, JSON_PRETTY_PRINT));
|
|
|
|
$u = UnitaImmobiliare::find($this->selectedUnitaId);
|
|
if ($u) {
|
|
$updatePayload = [];
|
|
|
|
$addrAde = $this->sisterData['indirizzo_completo'] ?? $this->sisterData['indirizzo'] ?? '';
|
|
$scomp = self::scomponeIndirizzoAde($addrAde, $this->sisterData['piano'] ?? $this->editPiano ?? '');
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_via') && !empty($scomp['catasto_via'])) {
|
|
$updatePayload['catasto_via'] = $scomp['catasto_via'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_scala') && !empty($scomp['catasto_scala'])) {
|
|
$updatePayload['catasto_scala'] = $scomp['catasto_scala'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_interno') && !empty($scomp['catasto_interno'])) {
|
|
$updatePayload['catasto_interno'] = $scomp['catasto_interno'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_piano') && !empty($scomp['catasto_piano'])) {
|
|
$updatePayload['catasto_piano'] = $scomp['catasto_piano'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_piano_livello') && !empty($scomp['catasto_piano_livello'])) {
|
|
$updatePayload['catasto_piano_livello'] = $scomp['catasto_piano_livello'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_piano_fisico') && !empty($scomp['catasto_piano_fisico'])) {
|
|
$updatePayload['catasto_piano_fisico'] = $scomp['catasto_piano_fisico'];
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'indirizzo') && !empty($scomp['catasto_via'])) {
|
|
$updatePayload['indirizzo'] = $scomp['catasto_via'];
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'foglio') && !empty($this->editFoglio)) {
|
|
$updatePayload['foglio'] = $this->editFoglio;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'particella') && !empty($this->editParticella)) {
|
|
$updatePayload['particella'] = $this->editParticella;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'subalterno')) {
|
|
$updatePayload['subalterno'] = $this->editSubalterno;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'rendita_catastale')) {
|
|
$updatePayload['rendita_catastale'] = $renditaClean;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'sezione_urbana') && !empty($this->editSezioneUrbana)) {
|
|
$updatePayload['sezione_urbana'] = $this->editSezioneUrbana;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'categoria_catastale') && !empty($this->editCategoria)) {
|
|
$updatePayload['categoria_catastale'] = self::estraiCodiceCompatto($this->editCategoria);
|
|
}
|
|
$pianoFinale = $this->editPiano;
|
|
if (empty($pianoFinale)) {
|
|
$pianoRaw = $scomp['catasto_piano'] ?? '';
|
|
if (!empty($pianoRaw)) {
|
|
if (!empty($scomp['catasto_piano_fisico'])) {
|
|
$pianoFinale = 'Piano ' . $scomp['catasto_piano_fisico'];
|
|
} else {
|
|
$pianoFinale = 'Piano ' . $pianoRaw;
|
|
}
|
|
}
|
|
|
|
if (str_contains(strtolower($addrAde), 'piano') && empty($scomp['catasto_piano'])) {
|
|
Notification::make()
|
|
->title('Alert Critico: Rilevamento Piano Ambiguo')
|
|
->body('Impossibile interpretare in modo deterministico il piano dall\'indirizzo catastale. Si prega di confermare o digitare il piano corretto prima di procedere.')
|
|
->danger()
|
|
->persistent()
|
|
->send();
|
|
$pianoFinale = null;
|
|
}
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'piano') && !empty($pianoFinale)) {
|
|
$updatePayload['piano'] = $pianoFinale;
|
|
}
|
|
|
|
$consistenzaInt = 0;
|
|
if (preg_match('/(\d+)/', $this->editConsistenza, $matches)) {
|
|
$consistenzaInt = (int)$matches[1];
|
|
}
|
|
|
|
$catCompact = self::estraiCodiceCompatto($this->editCategoria);
|
|
if (str_starts_with($catCompact, 'C') && $consistenzaInt > 0) {
|
|
if (Schema::hasColumn('unita_immobiliari', 'superficie')) {
|
|
$updatePayload['superficie'] = $consistenzaInt;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'numero_vani')) {
|
|
$updatePayload['numero_vani'] = null;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'vani')) {
|
|
$updatePayload['vani'] = null;
|
|
}
|
|
|
|
if ($this->editParticella === '253') {
|
|
if (Schema::hasColumn('unita_immobiliari', 'ha_cantina_assegnata')) {
|
|
$updatePayload['ha_cantina_assegnata'] = 1;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'note_tecniche')) {
|
|
$updatePayload['note_tecniche'] = trim("Cantina / Pertinenza Scala D. " . ($updatePayload['note_tecniche'] ?? $u->note_tecniche ?? ''));
|
|
}
|
|
}
|
|
} else {
|
|
if ($consistenzaInt > 0) {
|
|
if (Schema::hasColumn('unita_immobiliari', 'numero_vani')) {
|
|
$updatePayload['numero_vani'] = $consistenzaInt;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'vani')) {
|
|
$updatePayload['vani'] = $consistenzaInt;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'codice_univoco') && !empty($this->editIdImmobile)) {
|
|
$updatePayload['codice_univoco'] = $this->editIdImmobile;
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'tipologia_id')) {
|
|
$updatePayload['tipologia_id'] = $this->editTipologiaId;
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'note_tecniche')) {
|
|
$updatePayload['note_tecniche'] = "Classe: " . $this->editClasse . " | Consistenza: " . $this->editConsistenza . " | idImmobile: " . $this->editIdImmobile;
|
|
}
|
|
|
|
if (!empty($updatePayload)) {
|
|
$u->update($updatePayload);
|
|
}
|
|
}
|
|
}
|
|
|
|
public function confermaPertinenza525(): void
|
|
{
|
|
if (!$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$u = UnitaImmobiliare::find(1551);
|
|
if ($u) {
|
|
$u->update([
|
|
'ha_cantina_assegnata' => 1,
|
|
'subalterno' => '16 e 525',
|
|
'note_tecniche' => trim("Abbinata pertinenza cantina Sub 525 (Piano S1) - Variazione 2026. " . $u->note_tecniche)
|
|
]);
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
Storage::disk('public')->makeDirectory($annoConsolidatoPath);
|
|
|
|
$this->associazioniSoppressi['525'] = 1551;
|
|
Storage::disk('public')->put("{$annoConsolidatoPath}/associazioni_soppressi.json", json_encode($this->associazioniSoppressi, JSON_PRETTY_PRINT));
|
|
|
|
$validatedData = [
|
|
'unita_id' => 1551,
|
|
'foglio' => $u->foglio ?: '405',
|
|
'particella' => $u->particella ?: '256',
|
|
'subalterno' => '16 e 525',
|
|
'rendita_catastale' => (float)$u->rendita_catastale,
|
|
'piano' => 'Piano 1',
|
|
'validated_at' => now()->toDateTimeString(),
|
|
'validated_by' => auth()->id()
|
|
];
|
|
Storage::disk('public')->put("{$annoConsolidatoPath}/validati_unita_1551.json", json_encode($validatedData, JSON_PRETTY_PRINT));
|
|
|
|
Notification::make()
|
|
->title('Variazione 2026 Consolidata')
|
|
->body('Pertinenza Sub 525 abbinata con successo all\'Interno 16 della Scala A.')
|
|
->success()
|
|
->send();
|
|
|
|
$this->loadUnitaList();
|
|
$this->selectUnita(1551);
|
|
}
|
|
}
|
|
|
|
public function salvaQuotaProprietario(int $pivotId, string $quotaString): void
|
|
{
|
|
if (!$this->selectedUnitaId || !$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$quotaClean = (float)str_replace([' ', ','], ['', '.'], $quotaString);
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
Storage::disk('public')->makeDirectory($annoConsolidatoPath);
|
|
|
|
$jsonPath = "{$annoConsolidatoPath}/quote_unita_{$this->selectedUnitaId}.json";
|
|
$quotes = [];
|
|
if (Storage::disk('public')->exists($jsonPath)) {
|
|
$quotes = json_decode(Storage::disk('public')->get($jsonPath), true) ?: [];
|
|
}
|
|
|
|
$quotes[$pivotId] = $quotaClean;
|
|
|
|
Storage::disk('public')->put($jsonPath, json_encode($quotes, JSON_PRETTY_PRINT));
|
|
|
|
Notification::make()
|
|
->title('Quota storicizzata (Sola Lettura DB)')
|
|
->body('La quota è stata memorizzata nel cloud dell\'anno consolidato 2026.')
|
|
->success()
|
|
->send();
|
|
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
}
|
|
|
|
public function approvaVariazione(): void
|
|
{
|
|
if (!$this->selectedUnitaId || !$this->nuovaAnagraficaId) {
|
|
return;
|
|
}
|
|
|
|
$annoGestione = 2026;
|
|
$dataInizio = $this->nuovaDataInizio ?: "{$annoGestione}-01-01";
|
|
$nuovaQuota = (float)$this->nuovaQuota;
|
|
|
|
if (Schema::hasTable('unita_anagrafica_periodo')) {
|
|
// Utilizziamo updateOrCreate per evitare righe ridondanti nell'anno 2026
|
|
$recordPeriodo = DB::table('unita_anagrafica_periodo')
|
|
->where('unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('anagrafica_id', $this->nuovaAnagraficaId)
|
|
->where('data_inizio', '>=', "{$annoGestione}-01-01")
|
|
->where('data_inizio', '<=', "{$annoGestione}-12-31")
|
|
->first();
|
|
|
|
if ($recordPeriodo) {
|
|
DB::table('unita_anagrafica_periodo')
|
|
->where('id', $recordPeriodo->id)
|
|
->update([
|
|
'percentuale_spesa' => $nuovaQuota,
|
|
'updated_at' => now(),
|
|
]);
|
|
} else {
|
|
DB::table('unita_anagrafica_periodo')->insert([
|
|
'unita_immobiliare_id' => $this->selectedUnitaId,
|
|
'anagrafica_id' => $this->nuovaAnagraficaId,
|
|
'ruolo_occupazione' => 'condomino',
|
|
'data_inizio' => $dataInizio,
|
|
'percentuale_spesa' => $nuovaQuota,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
|
|
// Stessa logica per la tabella proprieta
|
|
if (Schema::hasTable('proprieta')) {
|
|
$recordProp = DB::table('proprieta')
|
|
->where('unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('anagrafica_id', $this->nuovaAnagraficaId)
|
|
->where('data_inizio', '>=', "{$annoGestione}-01-01")
|
|
->where('data_inizio', '<=', "{$annoGestione}-12-31")
|
|
->first();
|
|
|
|
if ($recordProp) {
|
|
DB::table('proprieta')
|
|
->where('id', $recordProp->id)
|
|
->update([
|
|
'percentuale_possesso' => $nuovaQuota,
|
|
'updated_at' => now(),
|
|
]);
|
|
} else {
|
|
DB::table('proprieta')->insert([
|
|
'unita_immobiliare_id' => $this->selectedUnitaId,
|
|
'anagrafica_id' => $this->nuovaAnagraficaId,
|
|
'tipo_diritto' => 'proprieta',
|
|
'percentuale_possesso' => $nuovaQuota,
|
|
'data_inizio' => $dataInizio,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
// Ricalcolo e ridistribuzione delle quote per garantire il 100% matematico esatto per la timeline 2026
|
|
$altriPeriodi = DB::table('unita_anagrafica_periodo')
|
|
->where('unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('anagrafica_id', '<>', $this->nuovaAnagraficaId)
|
|
->where('data_inizio', '>=', "{$annoGestione}-01-01")
|
|
->where('data_inizio', '<=', "{$annoGestione}-12-31")
|
|
->get();
|
|
|
|
if ($altriPeriodi->isNotEmpty()) {
|
|
$residuo = 100.00 - $nuovaQuota;
|
|
$quotaDivisa = round($residuo / $altriPeriodi->count(), 2);
|
|
foreach ($altriPeriodi as $ap) {
|
|
DB::table('unita_anagrafica_periodo')
|
|
->where('id', $ap->id)
|
|
->update([
|
|
'percentuale_spesa' => $quotaDivisa,
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|
|
|
|
if (Schema::hasTable('proprieta')) {
|
|
$altreProp = DB::table('proprieta')
|
|
->where('unita_immobiliare_id', $this->selectedUnitaId)
|
|
->where('anagrafica_id', '<>', $this->nuovaAnagraficaId)
|
|
->where('data_inizio', '>=', "{$annoGestione}-01-01")
|
|
->where('data_inizio', '<=', "{$annoGestione}-12-31")
|
|
->get();
|
|
|
|
if ($altreProp->isNotEmpty()) {
|
|
$residuo = 100.00 - $nuovaQuota;
|
|
$quotaDivisa = round($residuo / $altreProp->count(), 2);
|
|
foreach ($altreProp as $ap) {
|
|
DB::table('proprieta')
|
|
->where('id', $ap->id)
|
|
->update([
|
|
'percentuale_possesso' => $quotaDivisa,
|
|
'updated_at' => now(),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
$this->loadProprietari();
|
|
}
|
|
}
|
|
|
|
public function applicaEApprovaTutto(): void
|
|
{
|
|
if (!$this->selectedUnitaId) {
|
|
return;
|
|
}
|
|
|
|
$this->applicaECorreggi();
|
|
|
|
if ($this->nuovaAnagraficaId) {
|
|
$this->approvaVariazione();
|
|
Notification::make()
|
|
->title('Allineamento e Variazione completati')
|
|
->body('Tutti i parametri catastali e anagrafici sono stati consolidati a database.')
|
|
->success()
|
|
->send();
|
|
} else {
|
|
Notification::make()
|
|
->title('Allineamento catastale completato')
|
|
->body('I parametri catastali sono stati aggiornati. Nessuna variazione anagrafica inserita.')
|
|
->success()
|
|
->send();
|
|
}
|
|
|
|
$this->loadUnitaList();
|
|
$this->selectUnita($this->selectedUnitaId);
|
|
}
|
|
|
|
public function associaUnitaSoppressa(string $sub, int $unitaId): void
|
|
{
|
|
$this->associazioniSoppressi[$sub] = $unitaId;
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
Storage::disk('public')->makeDirectory($annoConsolidatoPath);
|
|
Storage::disk('public')->put("{$annoConsolidatoPath}/associazioni_soppressi.json", json_encode($this->associazioniSoppressi, JSON_PRETTY_PRINT));
|
|
|
|
$u = UnitaImmobiliare::find($unitaId);
|
|
if ($u && Schema::hasColumn('unita_immobiliari', 'subalterno')) {
|
|
$u->update(['subalterno' => $sub]);
|
|
}
|
|
|
|
Notification::make()
|
|
->title('Associazione registrata')
|
|
->body("L'unità NetGescon è stata associata al subalterno soppresso {$sub}.")
|
|
->success()
|
|
->send();
|
|
|
|
$this->loadUnitaList();
|
|
}
|
|
|
|
public function confermaAssociazione(string $sub): void
|
|
{
|
|
$unitaId = $this->tempAssociazioni[$sub] ?? null;
|
|
if (!$unitaId) {
|
|
return;
|
|
}
|
|
$u = UnitaImmobiliare::find($unitaId);
|
|
if (!$u) {
|
|
return;
|
|
}
|
|
|
|
// Troviamo il subalterno reale tra quelli in cache
|
|
$subData = collect($this->stabileSubalterni)->firstWhere('sub', $sub);
|
|
$renditaReal = 0.0;
|
|
$classeReal = '';
|
|
$consistenzaReal = '';
|
|
$idImmobileReal = '';
|
|
$pianoReal = 'Piano T';
|
|
$sezioneReal = '';
|
|
|
|
if ($subData) {
|
|
$renditaStr = $subData['rendita'] ?? '';
|
|
$renditaReal = (float)str_replace(['R.Euro:', 'Euro:', ' ', ',', '€'], ['', '', '', '.', ''], $renditaStr);
|
|
|
|
$foglioVal = $this->stabileAttivo?->foglio_catasto ?? $this->stabileAttivo?->foglio ?? '405';
|
|
$particellaVal = $this->stabileAttivo?->particella_catasto ?? $this->stabileAttivo?->mappale ?? '256';
|
|
if ($this->stabileAttivo && ($this->stabileAttivo->id == 4 || $this->stabileAttivo->codice_stabile === '0021')) {
|
|
$scalaUpper = strtoupper(trim($u->scala ?: ''));
|
|
$palazzinaUpper = Schema::hasColumn('unita_immobiliari', 'palazzina') ? strtoupper(trim($u->palazzina ?: '')) : '';
|
|
if ($scalaUpper === 'D' || $palazzinaUpper === 'D') {
|
|
$particellaVal = '253';
|
|
} else {
|
|
$particellaVal = '256';
|
|
}
|
|
}
|
|
|
|
$subLabel = ($sub !== null && $sub !== '') ? "_sub{$sub}" : "";
|
|
$jsonFilename = "risultato_immobile_" . (string)$foglioVal . "_" . (string)$particellaVal . "{$subLabel}.json";
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$jsonRelativePath = "{$dirPath}/{$jsonFilename}";
|
|
|
|
if (Storage::disk('public')->exists($jsonRelativePath)) {
|
|
try {
|
|
$sisterContent = json_decode(Storage::disk('public')->get($jsonRelativePath), true);
|
|
$sData = $sisterContent['immobili'] ?? $sisterContent;
|
|
if (is_array($sData) && isset($sData[0])) {
|
|
$sData = $sData[0];
|
|
}
|
|
$classeReal = $sData['classe'] ?? '';
|
|
$consistenzaReal = $sData['consistenza'] ?? '';
|
|
$idImmobileReal = $sData['idImmobile'] ?? '';
|
|
$pianoReal = $sData['piano'] ?? 'Piano T';
|
|
$sezioneReal = $sData['sezione'] ?? ($sData['sezioneUrbana'] ?? '');
|
|
} catch (\Exception $e) {}
|
|
}
|
|
}
|
|
|
|
// Registriamo prima l'associazione soppresso/attivo a livello di stabile
|
|
$this->associaUnitaSoppressa($sub, (int)$unitaId);
|
|
|
|
// Ora creiamo il file JSON validato sotto anno_2026 per impostarlo come "Validata"
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
$annoConsolidatoPath = "{$dirPath}/anno_2026";
|
|
Storage::disk('public')->makeDirectory($annoConsolidatoPath);
|
|
|
|
$foglioVal = $this->stabileAttivo?->foglio_catasto ?? $this->stabileAttivo?->foglio ?? '405';
|
|
$particellaVal = $this->stabileAttivo?->particella_catasto ?? $this->stabileAttivo?->mappale ?? '256';
|
|
if ($this->stabileAttivo && ($this->stabileAttivo->id == 4 || $this->stabileAttivo->codice_stabile === '0021')) {
|
|
$scalaUpper = strtoupper(trim($u->scala ?: ''));
|
|
$palazzinaUpper = Schema::hasColumn('unita_immobiliari', 'palazzina') ? strtoupper(trim($u->palazzina ?: '')) : '';
|
|
if ($scalaUpper === 'D' || $palazzinaUpper === 'D') {
|
|
$particellaVal = '253';
|
|
} else {
|
|
$particellaVal = '256';
|
|
}
|
|
}
|
|
|
|
$validatedData = [
|
|
'unita_id' => $unitaId,
|
|
'foglio' => $foglioVal,
|
|
'particella' => $particellaVal,
|
|
'subalterno' => $sub,
|
|
'rendita_catastale' => $renditaReal,
|
|
'classe' => $classeReal,
|
|
'consistenza' => $consistenzaReal,
|
|
'id_immobile' => $idImmobileReal,
|
|
'piano' => $pianoReal,
|
|
'validated_at' => now()->toDateTimeString(),
|
|
'validated_by' => auth()->id()
|
|
];
|
|
Storage::disk('public')->put("{$annoConsolidatoPath}/validati_unita_{$unitaId}.json", json_encode($validatedData, JSON_PRETTY_PRINT));
|
|
|
|
// Aggiorniamo a DB l'unità NetGescon
|
|
if ($u) {
|
|
$updatePayload = [];
|
|
|
|
$addrAde = $subData['indirizzo_completo'] ?? '';
|
|
$scomp = self::scomponeIndirizzoAde($addrAde);
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_via') && !empty($scomp['catasto_via'])) {
|
|
$updatePayload['catasto_via'] = $scomp['catasto_via'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_scala') && !empty($scomp['catasto_scala'])) {
|
|
$updatePayload['catasto_scala'] = $scomp['catasto_scala'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_interno') && !empty($scomp['catasto_interno'])) {
|
|
$updatePayload['catasto_interno'] = $scomp['catasto_interno'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'catasto_piano') && !empty($scomp['catasto_piano'])) {
|
|
$updatePayload['catasto_piano'] = $scomp['catasto_piano'];
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'scala') && !empty($scomp['catasto_scala'])) {
|
|
$updatePayload['scala'] = $scomp['catasto_scala'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'interno') && !empty($scomp['catasto_interno'])) {
|
|
$updatePayload['interno'] = $scomp['catasto_interno'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'piano') && !empty($pianoReal)) {
|
|
$updatePayload['piano'] = $pianoReal;
|
|
} elseif (Schema::hasColumn('unita_immobiliari', 'piano') && !empty($scomp['catasto_piano'])) {
|
|
$updatePayload['piano'] = $scomp['catasto_piano'];
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'indirizzo') && !empty($scomp['catasto_via'])) {
|
|
$updatePayload['indirizzo'] = $scomp['catasto_via'];
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'subalterno')) {
|
|
$updatePayload['subalterno'] = $sub;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'rendita_catastale') && $renditaReal > 0.01) {
|
|
$updatePayload['rendita_catastale'] = $renditaReal;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'codice_univoco') && !empty($idImmobileReal)) {
|
|
$updatePayload['codice_univoco'] = $idImmobileReal;
|
|
}
|
|
|
|
$consistenzaInt = 0;
|
|
if (preg_match('/(\d+)/', $consistenzaReal, $matches)) {
|
|
$consistenzaInt = (int)$matches[1];
|
|
}
|
|
|
|
$catCompact = '';
|
|
if ($subData) {
|
|
$destVal = $subData['destinazione'] ?? '';
|
|
if (preg_match('/\(([A-F]\/?\d+)\)/i', $destVal, $m)) {
|
|
$catCompact = self::estraiCodiceCompatto($m[1]);
|
|
}
|
|
}
|
|
|
|
if (Schema::hasColumn('unita_immobiliari', 'categoria_catastale') && !empty($catCompact)) {
|
|
$updatePayload['categoria_catastale'] = $catCompact;
|
|
}
|
|
if (empty($sezioneReal) && $this->stabileAttivo) {
|
|
$sezioneReal = $this->stabileAttivo->sezione ?? '';
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'sezione_urbana') && !empty($sezioneReal)) {
|
|
$updatePayload['sezione_urbana'] = $sezioneReal;
|
|
}
|
|
|
|
if (str_starts_with($catCompact, 'C') && $consistenzaInt > 0) {
|
|
if (Schema::hasColumn('unita_immobiliari', 'superficie')) {
|
|
$updatePayload['superficie'] = $consistenzaInt;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'numero_vani')) {
|
|
$updatePayload['numero_vani'] = null;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'vani')) {
|
|
$updatePayload['vani'] = null;
|
|
}
|
|
} else {
|
|
if ($consistenzaInt > 0) {
|
|
if (Schema::hasColumn('unita_immobiliari', 'numero_vani')) {
|
|
$updatePayload['numero_vani'] = $consistenzaInt;
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'vani')) {
|
|
$updatePayload['vani'] = $consistenzaInt;
|
|
}
|
|
}
|
|
}
|
|
if (Schema::hasColumn('unita_immobiliari', 'note_tecniche')) {
|
|
$updatePayload['note_tecniche'] = "Classe: " . $classeReal . " | Consistenza: " . $consistenzaReal . " | idImmobile: " . $idImmobileReal;
|
|
}
|
|
|
|
if (!empty($updatePayload)) {
|
|
$u->update($updatePayload);
|
|
}
|
|
}
|
|
|
|
Notification::make()
|
|
->title('Associazione e Validazione Real-time')
|
|
->body("L'unità è stata associata al subalterno {$sub}, i dati reali di Sister sono stati iniettati a DB e lo stato è passato a VALIDATA.")
|
|
->success()
|
|
->send();
|
|
|
|
$this->loadUnitaList();
|
|
$this->selectUnita((int)$unitaId);
|
|
}
|
|
|
|
public function caricaVisuraProprietariRt(): void
|
|
{
|
|
if (!$this->stabileAttivo) {
|
|
return;
|
|
}
|
|
|
|
$service = new SisterCatastoService();
|
|
$dirPath = $service->getStoragePath($this->stabileAttivo->id);
|
|
|
|
$soggetti = [];
|
|
|
|
// 1. Lettura dai file JSON Sister presenti per lo stabile attivo
|
|
$files = Storage::disk('public')->files($dirPath);
|
|
foreach ($files as $file) {
|
|
if (str_contains($file, 'risultato_immobile_') && str_ends_with($file, '.json')) {
|
|
try {
|
|
$content = json_decode(Storage::disk('public')->get($file), true);
|
|
$sData = $content['immobili'] ?? $content;
|
|
if (is_array($sData) && isset($sData[0])) {
|
|
$sData = $sData[0];
|
|
}
|
|
|
|
$sub = $sData['subalterno'] ?? '';
|
|
$foglio = $sData['foglio'] ?? '';
|
|
$particella = $sData['particella'] ?? '';
|
|
$unitaDesc = "Foglio {$foglio} Part. {$particella} Sub. {$sub}";
|
|
|
|
$uCore = collect($this->unitaList)->first(function($u) use ($sub) {
|
|
$uSubClean = self::cleanStr((string)($u['subalterno'] ?? ''));
|
|
$subClean = self::cleanStr((string)($sub ?? ''));
|
|
return $uSubClean === $subClean;
|
|
});
|
|
|
|
if ($uCore) {
|
|
$unitaDesc = "Scala {$uCore['scala']} · Int. {$uCore['interno']}";
|
|
}
|
|
|
|
$intestati = $content['intestati'] ?? [];
|
|
if (empty($intestati) && isset($sData['intestati'])) {
|
|
$intestati = $sData['intestati'];
|
|
}
|
|
|
|
foreach ($intestati as $i) {
|
|
$cf = strtoupper(trim($i['codiceFiscale'] ?? $i['cf'] ?? ''));
|
|
if (empty($cf)) {
|
|
continue;
|
|
}
|
|
$nome = trim(($i['nome'] ?? '') . ' ' . ($i['cognome'] ?? $i['denominazione'] ?? ''));
|
|
$titolo = $i['titoloDiritto'] ?? $i['diritto'] ?? 'Proprietà';
|
|
$quota = $i['percentuale'] ?? $i['quota'] ?? '1000/1000';
|
|
|
|
if (!isset($soggetti[$cf])) {
|
|
$soggetti[$cf] = [
|
|
'cf' => $cf,
|
|
'nominativo' => $nome,
|
|
'unita' => []
|
|
];
|
|
}
|
|
|
|
$soggetti[$cf]['unita'][] = [
|
|
'descrizione' => $unitaDesc,
|
|
'dettagli' => "Foglio {$foglio} Part. {$particella} Sub. {$sub}",
|
|
'titolo' => $titolo,
|
|
'quota' => $quota
|
|
];
|
|
}
|
|
} catch (Exception $e) {}
|
|
}
|
|
}
|
|
|
|
// 2. Integrazione da anagrafiche e titolarità consolidate a DB per lo stabile attivo
|
|
if (Schema::hasTable('unita_anagrafica_periodo') && Schema::hasTable('anagrafiche')) {
|
|
$unitaIds = collect($this->unitaList)->pluck('id')->all();
|
|
$dbOwners = DB::table('unita_anagrafica_periodo as uap')
|
|
->join('anagrafiche as a', 'a.id', '=', 'uap.anagrafica_id')
|
|
->join('unita_immobiliari as u', 'u.id', '=', 'uap.unita_immobiliare_id')
|
|
->whereIn('uap.unita_immobiliare_id', $unitaIds)
|
|
->whereIn('uap.ruolo_occupazione', ['condomino', 'comproprietario', 'proprietario', 'nudo_proprietario', 'usufruttuario'])
|
|
->select(
|
|
'a.codice_fiscale',
|
|
'a.cognome',
|
|
'a.nome',
|
|
'u.id as unita_id',
|
|
'u.scala',
|
|
'u.interno',
|
|
'u.subalterno',
|
|
'uap.ruolo_occupazione',
|
|
'uap.percentuale_spesa'
|
|
)
|
|
->get();
|
|
|
|
$foglioDef = $this->stabileAttivo->foglio ?? $this->stabileAttivo->foglio_catasto ?? '—';
|
|
$partDef = $this->stabileAttivo->particella_catasto ?? $this->stabileAttivo->mappale ?? '—';
|
|
|
|
foreach ($dbOwners as $row) {
|
|
$cf = strtoupper(trim($row->codice_fiscale ?? ''));
|
|
if (empty($cf)) {
|
|
continue;
|
|
}
|
|
$nome = trim("{$row->cognome} {$row->nome}");
|
|
if (!isset($soggetti[$cf])) {
|
|
$soggetti[$cf] = [
|
|
'cf' => $cf,
|
|
'nominativo' => $nome,
|
|
'unita' => []
|
|
];
|
|
}
|
|
|
|
$unitaDesc = "Scala {$row->scala} · Int. {$row->interno}";
|
|
$subLabel = $row->subalterno ?: 'ND';
|
|
$soggetti[$cf]['unita'][] = [
|
|
'descrizione' => $unitaDesc,
|
|
'dettagli' => "Foglio {$foglioDef} Part. {$partDef} Sub. {$subLabel}",
|
|
'titolo' => ucfirst($row->ruolo_occupazione),
|
|
'quota' => ((float)$row->percentuale_spesa > 0 ? number_format((float)$row->percentuale_spesa, 2, ',', '.') . '%' : '1000/1000')
|
|
];
|
|
}
|
|
}
|
|
|
|
ksort($soggetti);
|
|
$this->visuraProprietariRt = array_values($soggetti);
|
|
|
|
foreach ($this->visuraProprietariRt as &$sog) {
|
|
$cf = strtoupper(trim($sog['cf']));
|
|
$decodificato = self::decodeCodiceFiscale($cf);
|
|
if ($decodificato && !empty($decodificato['data_nascita']) && !str_contains(strtolower($sog['nominativo']), 'nata a') && !str_contains(strtolower($sog['nominativo']), 'nato a')) {
|
|
$partici = ($decodificato['sesso'] === 'F') ? 'nata' : 'nato';
|
|
$sog['nominativo'] .= " ({$partici} a " . $decodificato['luogo_nascita'] . " il " . $decodificato['data_nascita'] . ")";
|
|
}
|
|
|
|
$uniqueUnita = [];
|
|
foreach ($sog['unita'] as $un) {
|
|
$uniqueUnita[$un['descrizione'] . '|' . $un['dettagli']] = $un;
|
|
}
|
|
$sog['unita'] = array_values($uniqueUnita);
|
|
}
|
|
unset($sog);
|
|
}
|
|
|
|
public static function decodeCodiceFiscale(string $cf): ?array
|
|
{
|
|
$cf = strtoupper(trim($cf));
|
|
if (strlen($cf) !== 16) {
|
|
return null;
|
|
}
|
|
|
|
$annoStr = substr($cf, 6, 2);
|
|
$meseLettera = substr($cf, 8, 1);
|
|
$giornoStr = substr($cf, 9, 2);
|
|
$comuneCodice = substr($cf, 11, 4);
|
|
|
|
$mesi = [
|
|
'A' => '01', 'B' => '02', 'C' => '03', 'D' => '04', 'E' => '05',
|
|
'H' => '06', 'L' => '07', 'M' => '08', 'P' => '09', 'R' => '10',
|
|
'S' => '11', 'T' => '12'
|
|
];
|
|
|
|
if (!isset($mesi[$meseLettera])) {
|
|
return null;
|
|
}
|
|
|
|
$anno = (int)$annoStr;
|
|
$correnteAnno = (int)date('y');
|
|
if ($anno <= $correnteAnno) {
|
|
$annoCompleto = 2000 + $anno;
|
|
} else {
|
|
$annoCompleto = 1900 + $anno;
|
|
}
|
|
|
|
$giornoNum = (int)$giornoStr;
|
|
$sesso = 'M';
|
|
if ($giornoNum > 40) {
|
|
$sesso = 'F';
|
|
$giornoNum = $giornoNum - 40;
|
|
}
|
|
|
|
$giorno = str_pad((string)$giornoNum, 2, '0', STR_PAD_LEFT);
|
|
$mese = $mesi[$meseLettera];
|
|
$dataNascita = "{$giorno}/{$mese}/{$annoCompleto}";
|
|
|
|
$comuneNome = '';
|
|
try {
|
|
$comune = DB::table('comuni_italiani')
|
|
->where('codice_catastale', $comuneCodice)
|
|
->first(['denominazione', 'provincia_codice']);
|
|
if ($comune) {
|
|
$comuneNome = trim($comune->denominazione) . " (" . trim($comune->provincia_codice) . ")";
|
|
}
|
|
} catch (\Exception $e) {}
|
|
|
|
return [
|
|
'data_nascita' => $dataNascita,
|
|
'luogo_nascita' => $comuneNome ?: $comuneCodice,
|
|
'sesso' => $sesso
|
|
];
|
|
}
|
|
|
|
public static function scomponeIndirizzoAde(string $indirizzoCompleto, string $pianoStringa = ''): array
|
|
{
|
|
$via = '';
|
|
$scala = '';
|
|
$interno = '';
|
|
$piano = '';
|
|
$pianoLivello = '';
|
|
$pianoFisico = '';
|
|
|
|
if (preg_match('/Piano\s+(.+)$/i', $indirizzoCompleto, $m)) {
|
|
$piano = trim($m[1]);
|
|
}
|
|
if (preg_match('/Interno\s+(\d+)/i', $indirizzoCompleto, $m)) {
|
|
$interno = trim($m[1]);
|
|
}
|
|
if (preg_match('/Scala\s+([A-Z])/i', $indirizzoCompleto, $m)) {
|
|
$scala = trim($m[1]);
|
|
}
|
|
$parti = preg_split('/(Scala|Interno|Piano)/i', $indirizzoCompleto);
|
|
if (isset($parti[0])) {
|
|
$via = trim(rtrim(trim($parti[0]), ','));
|
|
}
|
|
|
|
if (empty($piano) && !empty($pianoStringa)) {
|
|
$piano = trim(str_ireplace('Piano', '', $pianoStringa));
|
|
}
|
|
|
|
if (!empty($piano)) {
|
|
if (preg_match('/(\d+|S\d+|T|PT|Terra)\s*-\s*(\d+|S\d+|T|PT|Terra)/i', $piano, $m)) {
|
|
$val1 = strtoupper(trim($m[1]));
|
|
$val2 = strtoupper(trim($m[2]));
|
|
if (str_starts_with($val1, 'S')) {
|
|
$pianoLivello = $val1;
|
|
$pianoFisico = $val2;
|
|
} elseif (str_starts_with($val2, 'S')) {
|
|
$pianoLivello = $val2;
|
|
$pianoFisico = $val1;
|
|
} else {
|
|
$pianoLivello = $val1;
|
|
$pianoFisico = $val2;
|
|
}
|
|
} else {
|
|
$pUpper = strtoupper(trim($piano));
|
|
if (str_starts_with($pUpper, 'S')) {
|
|
$pianoLivello = $pUpper;
|
|
$pianoFisico = '';
|
|
} else {
|
|
$pianoLivello = '';
|
|
$pianoFisico = $pUpper;
|
|
}
|
|
}
|
|
}
|
|
|
|
return [
|
|
'catasto_via' => $via,
|
|
'catasto_scala' => $scala,
|
|
'catasto_interno' => $interno,
|
|
'catasto_piano' => $piano,
|
|
'catasto_piano_livello' => $pianoLivello,
|
|
'catasto_piano_fisico' => $pianoFisico
|
|
];
|
|
}
|
|
|
|
private function calcolaPesoPiano(string $piano): int
|
|
{
|
|
$p = strtoupper(trim($piano));
|
|
if (str_contains($p, 'S2')) return -2;
|
|
if (str_contains($p, 'S1')) return -1;
|
|
if (str_contains($p, 'S')) return -1;
|
|
if (str_contains($p, 'T') || str_contains($p, 'TERRA') || str_contains($p, 'PT')) return 0;
|
|
if (preg_match('/(\d+)/', $p, $m)) {
|
|
return (int)$m[1];
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
private function classificaUnitaPerOrdinamento(string $scala, string $interno, string $palazzina = '', string $piano = '', string $categoria = ''): array
|
|
{
|
|
$palazzinaClean = strtoupper(trim($palazzina ?: ''));
|
|
if ($palazzinaClean === '') {
|
|
$palazzinaClean = 'A';
|
|
}
|
|
|
|
$scalaClean = strtoupper(trim($scala ?: '-'));
|
|
if ($scalaClean === '' || $scalaClean === '-') {
|
|
$scalaClean = 'ZZZ';
|
|
}
|
|
|
|
$internoClean = strtoupper(trim($interno ?: ''));
|
|
$catClean = strtoupper(trim($categoria ?: ''));
|
|
|
|
// 1=Appartamenti, 2=Cantine/Pertinenze, 3=Soffitte, 4=Negozi, 5=Box
|
|
$tipoPriorita = 1;
|
|
if (str_contains($internoClean, 'CAN') || str_contains($internoClean, 'CANT') || str_contains($internoClean, 'MAG') || str_contains($catClean, 'C/2') || str_contains($catClean, 'C02')) {
|
|
$tipoPriorita = 2;
|
|
} elseif (str_contains($internoClean, 'SOF') || str_contains($internoClean, 'SOFF') || str_contains($internoClean, 'SOTTO') || str_contains($catClean, 'C/3') || str_contains($catClean, 'C03')) {
|
|
$tipoPriorita = 3;
|
|
} elseif (str_contains($internoClean, 'NEG') || str_contains($catClean, 'C/1') || str_contains($catClean, 'C01')) {
|
|
$tipoPriorita = 4;
|
|
} elseif (str_contains($internoClean, 'BOX') || str_contains($internoClean, 'AUTO') || str_contains($internoClean, 'GAR') || str_contains($catClean, 'C/6') || str_contains($catClean, 'C06')) {
|
|
$tipoPriorita = 5;
|
|
}
|
|
|
|
$pesoPiano = $this->calcolaPesoPiano($piano ?: '');
|
|
|
|
$numProgressivo = 999;
|
|
if (preg_match('/(\d+)/', $internoClean, $matches)) {
|
|
$numProgressivo = (int)$matches[1];
|
|
}
|
|
|
|
return [
|
|
'palazzina' => $palazzinaClean,
|
|
'scala' => $scalaClean,
|
|
'tipo' => $tipoPriorita,
|
|
'piano_peso' => $pesoPiano,
|
|
'prog' => $numProgressivo,
|
|
'raw' => $internoClean
|
|
];
|
|
}
|
|
|
|
private function ordinaSubalterniPerInterno(): void
|
|
{
|
|
if (empty($this->stabileSubalterni) || empty($this->unitaList)) {
|
|
return;
|
|
}
|
|
|
|
$unitaListCollect = collect($this->unitaList);
|
|
|
|
foreach ($this->stabileSubalterni as &$sub) {
|
|
$subVal = (string)($sub['sub'] ?? '');
|
|
$isSoppresso = ($sub['partita'] ?? '') === 'Soppressa';
|
|
|
|
$matched = self::trovaUnitaCorrispondente($sub, $this->unitaList, $this->associazioniSoppressi);
|
|
|
|
$presuntaScala = '-';
|
|
$presuntoInterno = '-';
|
|
if (!$matched && (!is_numeric($subVal) || ((int)$subVal <= 500 || (int)$subVal === 503 || (int)$subVal === 507))) {
|
|
$addr = strtolower($sub['indirizzo_completo'] ?? '');
|
|
|
|
if (preg_match('/scala\s+([a-pr-z])/i', $addr, $m)) {
|
|
$presuntaScala = strtoupper($m[1]);
|
|
}
|
|
if (preg_match('/interno\s+([a-pr-z0-9\/]+)/i', $addr, $m)) {
|
|
$presuntoInterno = strtoupper($m[1]);
|
|
} elseif (preg_match('/int\.\s*([a-pr-z0-9\/]+)/i', $addr, $m)) {
|
|
$presuntoInterno = strtoupper($m[1]);
|
|
}
|
|
|
|
if ($presuntaScala === '-' || $presuntoInterno === '-') {
|
|
if ($sub['sub'] === '41') {
|
|
$presuntaScala = 'B';
|
|
$presuntoInterno = '12';
|
|
} elseif ($sub['sub'] === '3' || $sub['sub'] === '503') {
|
|
$presuntaScala = 'A';
|
|
$presuntoInterno = '3';
|
|
} elseif ($sub['sub'] === '7' || $sub['sub'] === '507') {
|
|
$presuntaScala = 'A';
|
|
$presuntoInterno = '7';
|
|
} elseif ($sub['sub'] === '56' || $sub['sub'] === '520' || $sub['sub'] === '521') {
|
|
$presuntaScala = 'B';
|
|
$presuntoInterno = '27';
|
|
}
|
|
}
|
|
}
|
|
|
|
$scala = $matched ? ($matched['scala'] ?? '') : $presuntaScala;
|
|
$interno = $matched ? ($matched['interno'] ?? '') : $presuntoInterno;
|
|
$palazzina = $matched ? ($matched['palazzina'] ?? '') : '';
|
|
$piano = $matched ? ($matched['piano'] ?? '') : '';
|
|
$categoria = ($matched && !empty($matched['categoria_catastale'])) ? $matched['categoria_catastale'] : ($sub['destinazione'] ?? '');
|
|
|
|
$class = $this->classificaUnitaPerOrdinamento($scala, $interno, $palazzina, $piano, $categoria);
|
|
$sub['sort_palazzina'] = $class['palazzina'];
|
|
$sub['sort_scala'] = $class['scala'];
|
|
$sub['sort_tipo'] = $class['tipo'];
|
|
$sub['sort_piano_peso'] = $class['piano_peso'];
|
|
$sub['sort_prog'] = $class['prog'];
|
|
$sub['sort_raw'] = $class['raw'];
|
|
}
|
|
unset($sub);
|
|
|
|
usort($this->stabileSubalterni, function($a, $b) {
|
|
$cmpPal = strcmp($a['sort_palazzina'], $b['sort_palazzina']);
|
|
if ($cmpPal !== 0) {
|
|
return $cmpPal;
|
|
}
|
|
|
|
$cmpScala = strcmp($a['sort_scala'], $b['sort_scala']);
|
|
if ($cmpScala !== 0) {
|
|
return $cmpScala;
|
|
}
|
|
|
|
if ($a['sort_tipo'] !== $b['sort_tipo']) {
|
|
return $a['sort_tipo'] <=> $b['sort_tipo'];
|
|
}
|
|
|
|
if ($a['sort_piano_peso'] !== $b['sort_piano_peso']) {
|
|
return $a['sort_piano_peso'] <=> $b['sort_piano_peso'];
|
|
}
|
|
|
|
if ($a['sort_prog'] !== $b['sort_prog']) {
|
|
return $a['sort_prog'] <=> $b['sort_prog'];
|
|
}
|
|
|
|
return strcmp($a['sort_raw'], $b['sort_raw']);
|
|
});
|
|
}
|
|
}
|