ensureCrmSubscription(); $scope = CustomerMaintenanceScopeService::forCurrentUser(); $stats = $scope->dashboardStats(); $upcomingServices = collect(); if ($scope->preventiveSchedulesAvailable()) { $upcomingServices = $scope->preventiveScheduleQuery() ->with(['equipment:id,name', 'project:id,name', 'productionLine:id,name']) ->where('is_active', true) ->whereNotNull('next_due_at') ->orderBy('next_due_at') ->limit(5) ->get(); } $recentWorkOrders = collect(); if ($scope->workOrdersAvailable()) { $recentWorkOrders = $scope->workOrderQuery() ->with(['equipment:id,name', 'assignedTechnician:id,first_name,last_name']) ->orderByDesc('updated_at') ->limit(5) ->get(); } return view('portal::customer.maintenance.index', compact('stats', 'upcomingServices', 'recentWorkOrders')); } }