@extends('../padre.padre') @section('contenido')
Módulo Metas Control & Rendimiento

INFORME DE CUMPLIMIENTO Y METAS

@include('menu.botonRegresar')
@include('../menu.bodegas')
@isset($productos) @php $totVentaGlobal = 0; $totPresupuestoGlobal = 0; $totVentaConPresupuestoGlobal = 0; // 1. Agrupación consolidada por Entidad (Vendedor o Bodega) para evitar gráficos sobrecargados por días $entidades = []; $diarios = []; foreach ($productos as $item) { $code = ($Tipo == "vendedor") ? ($item["codigoVendedor"] ?? '') : ($item["bodega"] ?? ''); $name = ($Tipo == "vendedor") ? ($item["nombrev"] ?? '') : ($item["nombreB"] ?? ''); $vReal = floatval($item["valor"] ?? 0); $vPres = floatval($item["valorPresup"] ?? 0); $totVentaGlobal += $vReal; $totPresupuestoGlobal += $vPres; if ($vPres > 0) { $totVentaConPresupuestoGlobal += $vReal; } // Agrupar por Entidad (Vendedor o Bodega) if (!isset($entidades[$code])) { $entidades[$code] = [ 'nombre' => $name, 'venta' => 0, 'presupuesto' => 0 ]; } $entidades[$code]['venta'] += $vReal; $entidades[$code]['presupuesto'] += $vPres; // Agrupar por Día (para el gráfico de tendencia temporal si es detallado) if ($Agrupado == "detallado" && isset($item["diaV"])) { $fechaKey = sprintf('%02d/%02d', $item["diaV"], $item["mesV"] ?? 1); if (!isset($diarios[$fechaKey])) { $diarios[$fechaKey] = [ 'venta' => 0, 'presupuesto' => 0 ]; } $diarios[$fechaKey]['venta'] += $vReal; $diarios[$fechaKey]['presupuesto'] += $vPres; } } $totDiferenciaGlobal = $totVentaGlobal - $totPresupuestoGlobal; $hasGlobalPresupuesto = ($totPresupuestoGlobal > 0); $cumplimientoGlobalPct = $hasGlobalPresupuesto ? round(($totVentaConPresupuestoGlobal / $totPresupuestoGlobal) * 100, 1) : 0; if (!$hasGlobalPresupuesto) { $kpiClassCumpl = 'kpi-cumplimiento-neutral'; } elseif ($cumplimientoGlobalPct >= 100) { $kpiClassCumpl = 'kpi-cumplimiento-success'; } elseif ($cumplimientoGlobalPct >= 80) { $kpiClassCumpl = 'kpi-cumplimiento-warning'; } else { $kpiClassCumpl = 'kpi-cumplimiento-danger'; } // Preparar datos para Gráficos Consolidados por Entidad $chartEntityLabels = []; $chartEntityVentas = []; $chartEntityPresupuestos = []; $chartEntityPct = []; foreach ($entidades as $ent) { $chartEntityLabels[] = strlen($ent['nombre']) > 22 ? substr($ent['nombre'], 0, 22) . '...' : $ent['nombre']; $chartEntityVentas[] = round($ent['venta'], 0); $chartEntityPresupuestos[] = round($ent['presupuesto'], 0); $pctEnt = ($ent['presupuesto'] > 0) ? round(($ent['venta'] / $ent['presupuesto']) * 100, 1) : 0; $chartEntityPct[] = $pctEnt; } // Preparar datos para Gráfico de Tendencia Diaria (si es detallado) ksort($diarios); $chartDailyLabels = array_keys($diarios); $chartDailyVentas = array_column($diarios, 'venta'); $chartDailyPresupuestos = array_column($diarios, 'presupuesto'); @endphp
Ventas Reales Totales
${{ number_format($totVentaGlobal, 0) }}
Presupuesto Meta Total
${{ number_format($totPresupuestoGlobal, 0) }}
Diferencia Total
${{ number_format($totDiferenciaGlobal, 0) }}
% Cumplimiento Global
@if($hasGlobalPresupuesto) {{ $cumplimientoGlobalPct > 999 ? '>999%' : number_format($cumplimientoGlobalPct, 1) . '%' }} @else N/A (Sin Meta) @endif
@if(count($entidades) > 0)
Consolidado por {{ ucfirst($Tipo) }}: Presupuesto vs Venta Real
Ranking de Cumplimiento (%) por {{ ucfirst($Tipo) }}
@if($Agrupado == "detallado" && count($chartDailyLabels) > 1)
Evolución Diaria del Periodo (Venta Real vs Presupuesto)
@endif @endif @endisset
Detalle de Cumplimiento
@include('../menu/exportar.exportarCumplimientos')
@isset($productos) @if(count($entidades) > 0) @endif @endisset @endsection