@php $existingMap = collect(($tabelleFieldMapping ?? []))->keyBy('legacy'); $legacyCode = request('legacy_code'); $importConn = \App\Models\UserSetting::get('gescon.import_conn', 'gescon_import'); $humanize = static function ($value) { $value = trim((string) $value); if ($value === '') { return ''; } $value = str_replace(['_', '-', '.'], ' ', $value); $value = preg_replace('/\s+/', ' ', $value ?? '') ?? ''; return (string) \Illuminate\Support\Str::of($value)->squish()->title(); }; $legacyFields = []; $seenKeys = []; $stagingHeaders = []; try { $connection = $importConn ?: config('database.default'); if ($connection) { $schema = \Illuminate\Support\Facades\Schema::connection($connection); $probeTables = [ 'dett_tab', 'tabelle_millesimali_righe', 'tabelle_millesimali', 'millesimi', 'milles', ]; foreach ($probeTables as $table) { if ($schema->hasTable($table)) { $stagingHeaders = $schema->getColumnListing($table); if (!empty($stagingHeaders)) { break; } } } } } catch (\Throwable $e) { $stagingHeaders = []; } $preferredFields = [ [ 'key' => 'tabella', 'label' => 'Codice tabella', 'group' => 'Identificativi', 'description' => 'Codice tabella millesimale (campo TAB in dett_tab).', 'default_target' => 'tabella', ], [ 'key' => 'voce', 'label' => 'Descrizione voce', 'group' => 'Identificativi', 'description' => 'Descrizione o voce della riga millesimale.', 'default_target' => 'voce', ], [ 'key' => 'millesimi', 'label' => 'Millesimi', 'group' => 'Valori millesimali', 'description' => 'Valore millesimale principale (campo MILLESIMI).', 'default_target' => 'valore', ], [ 'key' => 'valore_prev', 'label' => 'Valore previsto', 'group' => 'Valori millesimali', 'description' => 'Valore previsto o preventivo della tabella.', 'default_target' => 'valore_prev', ], [ 'key' => 'valore_cons', 'label' => 'Valore consuntivo', 'group' => 'Valori millesimali', 'description' => 'Valore consuntivo della tabella.', 'default_target' => 'valore_cons', ], [ 'key' => 'importo_prev', 'label' => 'Importo previsto (€)', 'group' => 'Importi', 'description' => 'Importo previsto espresso in euro.', 'default_target' => 'importo_prev', ], [ 'key' => 'importo_cons', 'label' => 'Importo consuntivo (€)', 'group' => 'Importi', 'description' => 'Importo consuntivo espresso in euro.', 'default_target' => 'importo_cons', ], [ 'key' => 'nord', 'label' => 'NORD / Ordine', 'group' => 'Coordinate', 'description' => 'Numero d’ordine della riga (NORD).', 'default_target' => 'nord', ], [ 'key' => 'scala', 'label' => 'Scala', 'group' => 'Coordinate', 'description' => 'Indicazione scala o blocco di riferimento.', 'default_target' => 'scala', ], [ 'key' => 'piano', 'label' => 'Piano', 'group' => 'Coordinate', 'description' => 'Piano dell’unità associata alla tabella.', 'default_target' => 'piano', ], [ 'key' => 'unita_codice', 'label' => 'Codice unità', 'group' => 'Coordinate', 'description' => 'Codice unità/condòmino legato alla riga.', 'default_target' => 'unita_codice', ], [ 'key' => 'note', 'label' => 'Note', 'group' => 'Metadati', 'description' => 'Annotazioni e commenti legacy.', 'default_target' => 'note', ], [ 'key' => 'flag_unico', 'label' => 'Flag unico', 'group' => 'Metadati', 'description' => 'Indicatore legacy importato per logiche speciali.', 'default_target' => 'flag_unico', ], [ 'key' => 'provenienza', 'label' => 'Provenienza', 'group' => 'Metadati', 'description' => 'Origine o file di provenienza della riga.', 'default_target' => 'provenienza', ], [ 'key' => 'straordinaria_codice', 'label' => 'Codice straordinaria', 'group' => 'Metadati', 'description' => 'Identifica riparti straordinari legacy.', 'default_target' => 'straordinaria_codice', ], [ 'key' => 'ruolo_quota', 'label' => 'Ruolo / quota', 'group' => 'Metadati', 'description' => 'Ruolo, quota o profilo legacy collegato.', 'default_target' => 'ruolo_quota', ], ]; foreach ($preferredFields as $item) { $key = (string) ($item['key'] ?? ''); if ($key === '' || isset($seenKeys[$key])) { continue; } if (empty($item['label'])) { $item['label'] = $humanize($key); } $legacyFields[] = $item; $seenKeys[$key] = true; } foreach ($stagingHeaders as $header) { $key = (string) $header; if ($key === '' || isset($seenKeys[$key])) { continue; } $legacyFields[] = [ 'key' => $key, 'label' => $humanize($key), 'group' => null, 'description' => null, 'default_target' => null, ]; $seenKeys[$key] = true; } foreach ($existingMap->keys() as $legacyKey) { $key = (string) $legacyKey; if ($key === '' || isset($seenKeys[$key])) { continue; } $legacyFields[] = [ 'key' => $key, 'label' => $humanize($key), 'group' => null, 'description' => null, 'default_target' => null, ]; $seenKeys[$key] = true; } $legacyFieldMeta = []; foreach ($legacyFields as $field) { $legacyFieldMeta[$field['key']] = [ 'label' => $field['label'], 'group' => $field['group'] ?? null, 'description' => $field['description'] ?? null, 'default_target' => $field['default_target'] ?? null, ]; } $targetFields = [ 'voce', 'tabella', 'valore', 'valore_prev', 'valore_cons', 'importo_prev', 'importo_cons', 'nord', 'scala', 'piano', 'unita_codice', 'note', 'flag_unico', 'provenienza', 'straordinaria_codice', 'ruolo_quota', ]; @endphp

Mapping Campi Tabelle Millesimali (Legacy → Archivi)

Campi Legacy (tabelle)
Tabella: Righe trovate: 0
@php $currentGroup = null; @endphp @forelse($legacyFields as $field) @if(($field['group'] ?? null) && $field['group'] !== $currentGroup)
{{ $field['group'] }}
@php $currentGroup = $field['group']; @endphp @endif
{{ $field['label'] }}
{{ $field['key'] }}
@if(!empty($field['description']))
{{ $field['description'] }}
@endif
@if(!empty($field['default_target']))
Suggerito → {{ $field['default_target'] }}
@endif
@empty
Nessun campo legacy rilevato.
@endforelse
Anteprima dati legacy
In attesa selezione…
Seleziona un codice legacy per vedere le prime righe da dett_tab / milles*.
Associazione a Campi Target
@forelse($legacyFields as $field) @php $legacyKey = $field['key']; $prefill = $existingMap->get($legacyKey)['target'] ?? ($field['default_target'] ?? null); @endphp
{{ $field['label'] }}
{{ $legacyKey }}
Anteprima →
@empty
Nessun mapping configurabile.
@endforelse @foreach($targetFields as $tf) @endforeach
Suggerimento: lascia vuoto il campo target se non vuoi importare quel campo legacy. Collega in seguito le UI alla tabella corretta.