getCurrentMonth(); // Si no hay mes abierto, buscar el último mes if (!$currentMonth) { $currentMonth = $user->months() ->orderBy('year', 'desc') ->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre') DESC") ->first(); } $data = null; if ($currentMonth) { $data = CommissionCalculator::calculateForMonth($user, $currentMonth); } // Últimos meses del usuario $recentMonths = $user->months() ->orderBy('year', 'desc') ->orderByRaw("FIELD(name, 'Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Agosto', 'Septiembre', 'Octubre', 'Noviembre', 'Diciembre') DESC") ->limit(6) ->get(); return view('dashboard.index', compact('currentMonth', 'data', 'recentMonths')); } }