@extends('layouts.app') @section('title', 'Estoque Externo VIMAN & Unificação de Vales') @section('topbar_title', '📦 Estoque Externo & Unificação de Vales') @section('topbar_extra_actions')
@if(!empty($metadadosCache['atualizado_em']))
Cache VIMAN: {{ \Carbon\Carbon::parse($metadadosCache['atualizado_em'])->format('d/m/Y H:i:s') }}
@endif Atualizar VIMAN Agora
@endsection @section('styles') @endsection @section('content') {{-- CABEÇALHO DO PAINEL --}}

Painel de Estoque Externo & Unificação de Vales

Auditoria de Estoque Externo por Empresa e Análise Canônica de Unificação de Vales.

⚖️ Regra de Unificação: 1 único vale na Empresa 1 para MG/ES (Filial 01), 1 único vale na Empresa 6 para SP (Filial 06) e 1 único vale na Empresa 8 para RJ (Filial 08). Os dados do VIMAN ficam em cache com atualização horária automática para resposta instantânea.
{{-- ALERTAS DE SESSÃO / ERRO --}} @if (session('status'))
{{ session('status') }}
@endif @if (session('error'))
{{ session('error') }}
@endif @if (!empty($erroConsulta))
{{ $erroConsulta }}
@endif {{-- GRID DE KPIS UNIFICADO (6 CARDS) --}}
Total Estoque Externo
{{ number_format($kpis['total_qtde'], 0, ',', '.') }} un
{{ number_format($kpis['total_registros'], 0, ',', '.') }} itens / lotes
Clientes / Hospitais
{{ number_format($kpis['total_clientes'], 0, ',', '.') }}
Em {{ number_format($kpis['total_vales'], 0, ',', '.') }} vales ativos
100% Unificado & Correto
{{ number_format($kpis['total_corretos'], 0, ',', '.') }} un
{{ $kpis['total_clientes_corretos'] }} clientes com 1 vale único
Divergências Gerais
{{ number_format($kpis['total_divergentes'], 0, ',', '.') }} un
{{ $kpis['total_clientes_divergentes'] }} clientes a corrigir
Múltiplos Vales (Duplicidade)
{{ number_format($kpis['total_multiplos_vales'], 0, ',', '.') }}
Clientes com > 1 vale ativo
Empresa 7 (Legado MG)
{{ number_format($kpis['total_empresa_7'], 0, ',', '.') }} un
A migrar para Empresa 1
{{-- FILTROS RÁPIDOS (CHIPS) --}}
Filtros: Todos ⚠️ Apenas Divergências 🏢 Empresa 7 (Legado) MG/ES fora da 1 SP fora da 6 RJ fora da 8 ✅ Apenas Corretos
{{-- CARD DE FORMULÁRIO COMPLETO DE FILTROS --}}
Limpar
{{-- ALTERNADOR DE ABAS DE VISUALIZAÇÃO --}}
Tabela Dinâmica / Agregação por Vales ({{ number_format($kpis['total_clientes'], 0, ',', '.') }} clientes) Lista Analítica Completa ({{ number_format($vales->total(), 0, ',', '.') }} registros)
{{-- VISÃO 1: TABELA DINÂMICA / HIERÁRQUICA --}} @if ($visao === 'dinamica')
Exibindo agregação hierárquica por UF → Cliente → Empresa/Vale → Produto (inicia recolhida para máxima performance).
@php $indexUf = 0; @endphp @forelse ($arvoreDinamica as $noUf) @php $indexUf++; $idUf = 'uf_'.$indexUf; @endphp @php $indexCli = 0; @endphp @foreach ($noUf['clientes'] as $noCli) @php $indexCli++; $idCli = $idUf.'_cli_'.$indexCli; $isDivergente = !$noCli['eh_correto']; $temMultiplos = $noCli['tem_multiplos_vales']; $classeCliente = $isDivergente ? ($temMultiplos ? 'multiplos-vales' : 'divergente') : ''; @endphp @php $indexEmpVale = 0; @endphp @foreach ($noCli['empresas_vales'] as $noEmpVale) @php $indexEmpVale++; $idEmpVale = $idCli.'_empvale_'.$indexEmpVale; $valeDivergente = !$noEmpVale['eh_correto']; @endphp @foreach ($noEmpVale['produtos'] as $noProd) @endforeach @endforeach @endforeach @empty @endforelse @if (!empty($arvoreDinamica)) @endif
Rótulos de Linha (UF → Cliente → Empresa/Vale → Produto) Soma de Qtde Empresa Correta Status da Alocação / Observação
+ {{ $noUf['uf'] }} {{ number_format($noUf['qtde'], 0, ',', '.') }} @if(in_array($noUf['uf'], ['MG', 'ES'])) Empresa 1 (ES/MG) @elseif($noUf['uf'] === 'SP') Empresa 6 (SP) @elseif($noUf['uf'] === 'RJ') Empresa 8 (RJ) @else Regional @endif {{ count($noUf['clientes']) }} cliente(s) nesta página
Nenhum registro de estoque externo encontrado com os filtros selecionados.
Total Geral (Consolidado) {{ number_format($kpis['total_qtde'], 0, ',', '.') }} {{ number_format($kpis['total_registros'], 0, ',', '.') }} itens em {{ number_format($kpis['total_clientes'], 0, ',', '.') }} clientes ({{ number_format($kpis['total_vales'], 0, ',', '.') }} vales)
@endif {{-- VISÃO 2: LISTA ANALÍTICA COMPLETA --}} @if ($visao === 'analitica') @php $inicioRegistro = $vales->total() === 0 ? 0 : (($vales->currentPage() - 1) * $vales->perPage()) + 1; $fimRegistro = $vales->total() === 0 ? 0 : min($vales->currentPage() * $vales->perPage(), $vales->total()); $janelaInicial = max(1, $vales->currentPage() - 2); $janelaFinal = min($vales->lastPage(), $vales->currentPage() + 2); $paginasVisiveis = $vales->lastPage() > 0 ? array_values(array_unique(array_merge([1], range($janelaInicial, $janelaFinal), [$vales->lastPage()]))) : []; $queryAtual = request()->query(); @endphp
@if ($vales->total() > 0 && $vales->hasPages())
Exibindo {{ $inicioRegistro }}-{{ $fimRegistro }} de {{ number_format($vales->total(), 0, ',', '.') }} registros (Página {{ $vales->currentPage() }} de {{ max($vales->lastPage(), 1) }})
@endif
@forelse ($vales as $item) @php $isDivergente = !($item['EH_CORRETO'] ?? false); @endphp @empty @endforelse
Empresa Atual Filial UF Cidade Cód. Cliente Cliente / Hospital Empresa Correta Status Alocação Nº Vale Situação Vale Data Cirurgia Paciente Segmento Grupo Cód. Interno Referência Produto Lote Lote Interno Qtde Vlr. Unitário Vlr. Total
{{ $item['EMPRESA'] ?? '-' }} {{ $item['FILIAL'] ?? '-' }} {{ $item['ESTADO'] ?? '-' }} {{ $item['CIDADE'] ?? '-' }} {{ $item['COD_CLIENTE'] ?? '-' }} {{ $item['CLIENTE'] ?? '-' }} {{ $item['EMPRESA_CORRETA'] ?? '-' }} @if ($isDivergente) {{ $item['STATUS_ALOCACAO'] ?? 'DIVERGENTE' }} @else {{ $item['STATUS_ALOCACAO'] ?? 'CORRETO' }} @endif {{ $item['NU_VALE'] ?? '-' }} {{ $item['SITUACAO_VALE_DESC'] ?? ($item['SITUACAO_VALE'] ?? '-') }} {{ $item['DT_CIRURGIA_FORMATADA'] ?? '-' }} {{ $item['PACIENTE'] ?? '-' }} {{ $item['SEGMENTO'] ?? '-' }} {{ $item['GRUPO'] ?? '-' }} {{ $item['CODIGO_INTERNO'] ?? '-' }} {{ $item['REFERENCIA'] ?? '-' }} {{ $item['PRODUTO'] ?? '-' }} {{ $item['LOTE'] ?? '-' }} {{ $item['LOTE_INTERNO'] ?? '-' }} {{ number_format((float) ($item['QTDE'] ?? 0), 0, ',', '.') }} {{ $item['VALOR_UNIT'] ? 'R$ '.number_format((float)$item['VALOR_UNIT'], 2, ',', '.') : '-' }} {{ $item['VALOR_TOTAL'] ? 'R$ '.number_format((float)$item['VALOR_TOTAL'], 2, ',', '.') : '-' }}
Nenhum registro de estoque externo encontrado.
@if ($vales->total() > 0)
Exibindo {{ $inicioRegistro }}-{{ $fimRegistro }} de {{ number_format($vales->total(), 0, ',', '.') }} registros (Página {{ $vales->currentPage() }} de {{ max($vales->lastPage(), 1) }})
@if ($vales->hasPages()) @endif
@endif
@endif @endsection @section('scripts') @endsection