@using PowderCoating.Web.Controllers @using PowderCoating.Application.DTOs.Health @model List @{ ViewData["Title"] = "Company Health"; var showChurned = (bool)(ViewBag.ShowChurned ?? false); var churnedCount = (int)(ViewBag.ChurnedCount ?? 0); string RiskBadge(ChurnRisk r) => r switch { ChurnRisk.Healthy => "bg-success", ChurnRisk.AtRisk => "bg-warning text-dark", ChurnRisk.Critical => "bg-danger", ChurnRisk.NeverActivated => "bg-secondary", _ => "bg-secondary" }; string RiskLabel(ChurnRisk r) => r switch { ChurnRisk.Healthy => "Healthy", ChurnRisk.AtRisk => "At Risk", ChurnRisk.Critical => "Critical", ChurnRisk.NeverActivated => "Never Activated", _ => r.ToString() }; string RowClass(ChurnRisk r) => r switch { ChurnRisk.Critical => "table-danger", ChurnRisk.AtRisk => "table-warning", ChurnRisk.NeverActivated => "opacity-75", _ => "" }; string ScoreColor(int s) => s >= 75 ? "text-success" : s >= 45 ? "text-warning" : "text-danger"; string ConfigBadgeClass(CompanyConfigHealth ch) => ch.IsHealthy ? "bg-success" : ch.OverallSeverity == ConfigIssueSeverity.Critical ? "bg-danger" : "bg-warning text-dark"; string LoginLabel(int days) => days switch { -1 => "Never", 0 => "Today", 1 => "Yesterday", _ => $"{days}d ago" }; string LoginClass(int days) => days is -1 or >= 90 ? "text-danger" : days >= 30 ? "text-warning" : "text-success"; } @section Styles { }

Company Health

Churn risk signals across all tenants
@* Churned account visibility banner *@ @if (churnedCount > 0 && !showChurned) {
@churnedCount churned @(churnedCount == 1 ? "account" : "accounts") (expired or canceled 14+ days ago) hidden from scores and totals. Show churned
} else if (showChurned && churnedCount > 0) {
Showing all accounts including @churnedCount churned. Hide churned
} @* Summary stat cards *@ @* Config issues summary card *@ @* Search + filter bar *@
Clear
@* Table *@
@if (!Model.Any()) { } @foreach (var h in Model) { var manageUrl = Url.Action("Manage", "SubscriptionManagement", new { id = h.Id }); }
Company Plan Risk Score Last Login Jobs 30d Jobs 90d Total Engagement Signals Config
No companies match the current filter.
@h.CompanyName @if (h.IsComped) { Comped } @if (!h.IsActive) { Inactive }
@h.PrimaryContactEmail
@h.PlanDisplayName @RiskLabel(h.RiskLevel) @if (h.RiskLevel == ChurnRisk.NeverActivated) { } else { @h.HealthScore } @LoginLabel(h.DaysSinceLastLogin) @if (h.JobsLast30Days > 0) { @h.JobsLast30Days } else { 0 } @if (h.JobsLast90Days > 0) { @h.JobsLast90Days } else { 0 } @h.TotalJobs @if (h.RiskSignals.Any()) {
@foreach (var s in h.RiskSignals) { @s }
} else { All clear }
@if (h.ConfigHealth.IsHealthy) { OK } else { var configUrl = Url.Action("Details", "Companies", new { id = h.Id }); i.Title))"> @h.ConfigHealth.Issues.Count issue@(h.ConfigHealth.Issues.Count == 1 ? "" : "s") }
@if (!Model.Any(h => h.RiskLevel != ChurnRisk.Healthy) && Model.Any()) { }