*/ protected function getStats(): array { $tenant = static::resolveTenantContextForCurrentPanel(); if (! $tenant instanceof Tenant) { return [ Stat::make('Total items', 0), Stat::make('Covered types', '—')->description('Select a tenant to load coverage truth.'), Stat::make('Need follow-up', '—')->description('Select a tenant to review follow-up types.'), Stat::make('Coverage basis', '—')->description('Select a tenant to see the latest coverage basis.'), Stat::make('Active ops', 0), ]; } $truth = app(TenantCoverageTruthResolver::class)->resolve($tenant); $activeOps = (int) OperationRun::query() ->where('tenant_id', (int) $tenant->getKey()) ->active() ->count(); $inventoryOps = (int) OperationRun::query() ->where('tenant_id', (int) $tenant->getKey()) ->where('type', 'inventory_sync') ->active() ->count(); return [ Stat::make('Total items', $truth->observedItemTotal) ->description(sprintf('Observed across %d supported types.', $truth->observedTypeCount())), Stat::make('Covered types', sprintf('%d / %d', $truth->succeededTypeCount, $truth->supportedTypeCount)) ->description(new HtmlString(InventoryKpiBadges::coverageBreakdown( $truth->failedTypeCount, $truth->skippedTypeCount, $truth->unknownTypeCount, ))), Stat::make('Need follow-up', $truth->followUpTypeCount) ->description(new HtmlString(InventoryKpiBadges::followUpSummary( $truth->topPriorityFollowUpRow(), $truth->observedItemTotal, $truth->observedTypeCount(), ))), $this->coverageBasisStat($truth, $tenant), Stat::make('Active ops', $activeOps) ->description($inventoryOps > 0 ? 'A tenant inventory sync is queued or running.' : 'No inventory sync is currently active.'), ]; } private function coverageBasisStat(TenantCoverageTruth $truth, Tenant $tenant): Stat { $user = auth()->user(); if (! $truth->basisRun instanceof OperationRun) { return Stat::make('Coverage basis', 'No current result') ->description($user instanceof User && $user->can(Capabilities::TENANT_INVENTORY_SYNC_RUN, $tenant) ? 'Run Inventory Sync from Inventory Items to establish current coverage truth.' : 'A tenant operator with inventory sync permission must establish current coverage truth.'); } $outcomeBadge = BadgeRenderer::spec(BadgeDomain::OperationRunOutcome, (string) $truth->basisRun->outcome); $canViewRun = $user instanceof User && Gate::forUser($user)->allows('view', $truth->basisRun); $description = Blade::render(<<<'BLADE'
{{ $statusLabel }} @if ($canViewRun && $viewUrl) Open basis run @else Latest run detail is not available with your current role. @endif
BLADE, [ 'badgeColor' => $outcomeBadge->color, 'statusLabel' => $outcomeBadge->label, 'canViewRun' => $canViewRun, 'viewUrl' => $canViewRun ? OperationRunLinks::view($truth->basisRun, $tenant) : null, ]); return Stat::make('Coverage basis', $truth->basisCompletedAtLabel() ?? 'Completed') ->description(new HtmlString($description)); } }