@php $rows = $simulateResult['rows'] ?? []; $summary = $simulateResult['summary'] ?? []; $fieldLabels = [ 'i_company_id' => 'Empresa interna (ID)', 'group_id' => 'Grupo (ID)', 'name' => 'Nome fantasia', 'business_name' => 'Razão social', 'opening_date' => 'Data de abertura', 'document' => 'CNPJ (máscara na BD)', 'type' => 'Tipo legal (1=Filial, 2=Matriz)', 'company_characteristic_id' => 'Característica', 'url' => 'Site', 'zip_code' => 'CEP', 'address' => 'Endereço', 'number' => 'Número', 'complement' => 'Complemento', 'neighborhood' => 'Bairro', 'city' => 'Cidade', 'state' => 'UF', 'company_size' => 'Porte', 'is_active' => 'Ativa', 'relationship_level' => 'Nível relacionamento', 'company_capital' => 'Capital', 'company_origin' => 'Origem país', 'has_contract_pj' => 'Contrato PJ', 'has_invoice_pj' => 'NF PJ', 'flexible_benefits' => 'Benefícios flexíveis', 'platform_flexible_benefits' => 'Plataforma benefícios', 'company_payroll' => 'Empresa folha', 'has_outpost' => 'Posto avançado', 'has_doctor_company' => 'Médico na empresa', 'doctor_company' => 'Qtd. médicos', 'has_nursing_company' => 'Enfermagem', 'nursing_company' => 'Qtd. enfermagem', 'has_outpatient_company' => 'Ambulatório', 'outpatient_company' => 'Qtd. ambulatório', 'system_payroll' => 'Sistema folha', 'type_visit' => 'Tipo visita', 'frequency_visit' => 'Frequência visitas', 'slug' => 'Slug (apelido)', 'email' => 'E-mail', 'phone' => 'Telefone', 'nivel_planilha' => 'NIVEL (planilha)', 'role' => 'Cargo (planilha)', 'role_level' => 'Nível cargo (BD)', 'hobbie' => 'Hobbie', 'birth_date' => 'Aniversário', 'company_id' => 'Empresa (ID)', 'group_curve' => 'Curva do grupo (1–4)', ]; @endphp
{{ $summary['total'] ?? 0 }} Linhas
{{ $summary['would_create'] ?? 0 }} Criariam
{{ $summary['would_update'] ?? 0 }} Atualizariam
{{ $summary['skipped'] ?? 0 }} Ignoradas
{{ $summary['errors'] ?? 0 }} Erros

Ordem de gravação: groupscompaniescompany_type_indexcompany_contacts

@foreach($rows as $idx => $row) @php $status = $row['status'] ?? ''; $preview = $row['preview'] ?? null; $payloadDb = $preview['payload_gravar_banco'] ?? null; $debug = $preview['integracao_debug'] ?? null; $companyReg = data_get($payloadDb, 'companies.registro', []); $searchBlob = mb_strtolower(implode(' ', array_filter([ (string) ($row['line'] ?? ''), (string) ($row['cnpj'] ?? ''), (string) ($row['cnpj_digitos'] ?? ''), (string) ($companyReg['name'] ?? ''), (string) ($companyReg['business_name'] ?? ''), (string) data_get($payloadDb, 'groups.registro.name', ''), (string) ($row['message'] ?? ''), ]))); $action = $row['action'] ?? $status; $warnings = $row['warnings'] ?? []; @endphp
L{{ $row['line'] ?? '?' }} @if($status === 'preview') {{ $action === 'would_update' ? 'ATUALIZAR' : 'CRIAR' }} {{ $row['cnpj'] ?? '—' }} {{ $companyReg['name'] ?? '—' }} {{ data_get($payloadDb, 'groups.registro.name', '') }} @if(count($warnings)) ⚠ {{ count($warnings) }} @endif @elseif($status === 'error') ERRO {{ $row['message'] ?? 'Falha' }} @elseif($status === 'skipped') IGNORADA {{ $row['message'] ?? '' }} @else {{ $status }} @endif @if($status === 'preview' && $payloadDb)
@if(count($warnings))
Avisos
    @foreach($warnings as $w)
  • {{ $w }}
  • @endforeach
@endif @php $g = $payloadDb['groups'] ?? []; @endphp

Tabela groups

@php $gOp = $g['operacao'] ?? 'nenhuma'; @endphp {{ strtoupper(str_replace('_', ' ', $gOp)) }}
@if(($g['sera_criado_novo_grupo'] ?? false))

Novo grupo será criado antes da empresa.

@elseif(($g['group_id_existente'] ?? null))

Grupo já existe — ID {{ $g['group_id_existente'] }}{{ $gOp !== 'nenhuma' ? ', curva será atualizada' : '' }}.

@endif @foreach(($g['registro'] ?? []) as $col => $val) @endforeach
{{ $fieldLabels[$col] ?? $col }} @include('imports.partials.companies-simulate-cell', ['value' => $val])

Tabela companies

{{ str_contains($action, 'update') ? 'UPDATE' : 'INSERT' }}
@foreach($companyReg as $col => $val) in_array($col, ['document', 'opening_date', 'slug', 'group_id'], true)])> @endforeach
{{ $fieldLabels[$col] ?? $col }} @if($col === 'document' && !empty($row['cnpj'])) {{ $row['cnpj'] }} ({{ $val }}) @else @include('imports.partials.companies-simulate-cell', ['value' => $val]) @endif
@php $ct = $payloadDb['company_type_index'] ?? []; @endphp

Tabela company_type_index (N:N com company_types)

SYNC
@php $typeIds = $ct['company_type_ids'] ?? []; @endphp @if($typeIds === [])

Nenhum tipo associado nesta linha.

@else

Após gravar a empresa, serão ligados os IDs:

@foreach($typeIds as $tid) company_type_id = {{ $tid }} @endforeach
@if($debug['company_types_origem_planilha'] ?? null) @php $orig = $debug['company_types_origem_planilha']; @endphp
Segmento (planilha){{ $orig['tipo_negocio_segmento'] ?: '—' }}
Ramo (planilha){{ $orig['ramo_atividade'] ?: '—' }}
@endif @endif
@php $contact = $payloadDb['company_contacts'] ?? null; @endphp

Tabela company_contacts

@if($contact) INSERT / UPDATE @else @endif
@if($contact) @if(!empty($contact['nota']))

{{ $contact['nota'] }}

@endif @php $inferenciaCargo = $contact['inferencia_role_level'] ?? null; @endphp @if($inferenciaCargo)
{{ $fieldLabels['nivel_planilha'] }} {{ $inferenciaCargo['nivel_planilha'] ?? '—' }}
Inferência → role_level {{ $inferenciaCargo['role_level_exibicao'] ?? '—' }} @if(!empty($inferenciaCargo['fonte'])) via coluna {{ $inferenciaCargo['fonte'] }} @endif
@endif @foreach(($contact['registro'] ?? []) as $col => $val) @endforeach
{{ $fieldLabels[$col] ?? $col }} @include('imports.partials.companies-simulate-cell', [ 'value' => $val, 'column' => $col, 'inferencia' => $inferenciaCargo, ])
@else

Sem nome de contacto na planilha — nada gravado em company_contacts.

@endif
@if($debug)
Integrações e debug (Localize, data abertura)
@if($debug['data_abertura'] ?? null) @php $da = $debug['data_abertura']; @endphp

Data de abertura

Valor que vai para opening_date{{ $da['valor_resolvido'] ?? '—' }}
Planilha{{ $da['planilha_data_abertura'] ?: '—' }}
Localize (candidatos){{ implode(', ', $da['candidatos_localize'] ?? []) ?: '—' }}
@endif @if(!empty($debug['localize_basic']['founding_date']))

Localize basic.founding_date: {{ $debug['localize_basic']['founding_date'] }}

@endif
JSON completo (integracao_debug)
@json($debug, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)
@endif
@endif
@endforeach
Ver JSON bruto completo da simulação
@json($simulateResult, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE)