authorizeSupplyChain('supplychain.view'); $businessId = $this->supplyChainUtil->getBusinessId(); $stats = [ 'scorecards' => SupplierScorecard::forBusiness($businessId)->count(), 'forecasts' => DemandForecast::forBusiness($businessId)->count(), 'open_rfqs' => RfqRequest::forBusiness($businessId)->where('status', 'open')->count(), 'high_risk_suppliers' => SupplierScorecard::forBusiness($businessId) ->whereIn('risk_level', ['high', 'critical']) ->distinct('contact_id') ->count('contact_id'), ]; $recentScorecards = SupplierScorecard::forBusiness($businessId) ->with('contact') ->orderByDesc('period_end') ->limit(5) ->get(); $recentRfqs = RfqRequest::forBusiness($businessId) ->orderByDesc('id') ->limit(5) ->get(); return view('supplychain::dashboard.index', compact('stats', 'recentScorecards', 'recentRfqs')); } }