get() ->filter(function ($producto) { return $producto->getStockEfectivo() <= $producto->stock_minimo; }) ->count(); $stats[] = Stat::make('Stock Bajo Global', $productosStockBajo) ->description('Productos bajo mínimo') ->descriptionIcon('heroicon-m-exclamation-triangle') ->color($productosStockBajo > 0 ? 'danger' : 'success'); // Productos con stock alto general $productosStockAlto = Producto::where('estado', true) ->whereNotNull('stock_maximo') ->get() ->filter(function ($producto) { return $producto->getStockEfectivo() > $producto->stock_maximo; }) ->count(); $stats[] = Stat::make('Stock Excesivo', $productosStockAlto) ->description('Productos sobre máximo') ->descriptionIcon('heroicon-m-arrow-trending-up') ->color($productosStockAlto > 0 ? 'warning' : 'success'); // Análisis por bodega crítica (si existe) $bodegaPrincipal = Bodega::where('nombre', 'Principal')->first(); if ($bodegaPrincipal) { $productosConStockCero = $bodegaPrincipal->productos() ->wherePivot('stock', 0) ->count(); $stats[] = Stat::make('Sin Stock en Principal', $productosConStockCero) ->description('Productos agotados') ->descriptionIcon('heroicon-m-x-circle') ->color($productosConStockCero > 0 ? 'danger' : 'success'); } return $stats; } catch (\Exception $e) { // En caso de error, devolver estadísticas básicas return [ Stat::make('Sistema de Alertas', 'Configurando...') ->description('Ejecute las migraciones necesarias') ->descriptionIcon('heroicon-m-cog-6-tooth') ->color('warning') ]; } } protected function getColumns(): int { return 3; } }