console: billing accounts list says when past months show
The accounts page shows BDP-14 under the list while the stored history is shorter than the last complete month, as the overview does. The overview's condition moves into opBillingHistoryNote and both pages use it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4 files changed,
+62
−12
internal/console/opbilling.go+13 −9internal/console/opbilling_overview.go+12 −3internal/console/opbilling_test.go+36 −0internal/console/templates/ops_billing_accounts.html+1 −0
diff --git a/internal/console/opbilling.go b/internal/console/opbilling.go| index 1c187c774..106429e16 100644 |
| --- a/internal/console/opbilling.go |
| +++ b/internal/console/opbilling.go |
| @@ -34,15 +34,18 @@ type opBillingAccountsView struct { |
| RateNote string // BDP-5, when there are rates |
| MonthName string // the last complete month, as the overview names it |
| MonthNote string // BDP-117 |
| - Tabs opTabs |
| - Sort opTabs |
| - Fallback string |
| - Rows []opBillingAccountRow |
| - Empty string |
| - Whys []string |
| - PageLine string |
| - Prev string |
| - Next string |
| + // HistoryNote is BDP-14 while the stored history is shorter than the |
| + // month (opBillingHistoryNote); the handler sets it from the snapshots. |
| + HistoryNote string |
| + Tabs opTabs |
| + Sort opTabs |
| + Fallback string |
| + Rows []opBillingAccountRow |
| + Empty string |
| + Whys []string |
| + PageLine string |
| + Prev string |
| + Next string |
| // Figures is every figure the builder made, in order: the five |
| // counts, then the page's rows'. |
| Figures []opMoneyFigure |
| @@ -403,6 +406,7 @@ func (s *Server) handleOpBillingAccounts(w http.ResponseWriter, r *http.Request) |
| v := buildOpBillingAccounts(rows, in.Covered, in.Gate, in.Rates, billingGroup(q.Get("tab")), q.Get("sort"), page, q) |
| v.Header = opHeader{Title: billCopyAccounts, Sub: billCopyAccountsSub} |
| v.TestMode = s.billingTestMode() |
| + v.HistoryNote = opBillingHistoryNote(in.Snaps, in.LastMonth) |
| p := s.billingPage(addr, raw, billCopyAccounts) |
| p.OpBillingAccounts = &v |
| s.render(w, http.StatusOK, "ops_billing_accounts", p) |
diff --git a/internal/console/opbilling_overview.go b/internal/console/opbilling_overview.go| index dc7838d73..ec4d50c0e 100644 |
| --- a/internal/console/opbilling_overview.go |
| +++ b/internal/console/opbilling_overview.go |
| @@ -698,12 +698,21 @@ func opBillingPayingList(v *opBillingView, in opBillingInput, rows []accountMone |
| v.Paying = append(v.Paying, row) |
| } |
| v.PayingNote = fmt.Sprintf(billCopyPayingListNote, opBillingMonthLabel(in.LastMonth, in.Now)) |
| - if len(in.Snaps) == 0 || in.Snaps[0].Day > in.LastMonth+"-01" { |
| - v.HistoryNote = billCopyHistoryShort |
| - } |
| + v.HistoryNote = opBillingHistoryNote(in.Snaps, in.LastMonth) |
| v.PayingWhys = opBillingWhys(v.Figures[start:]) |
| } |
| +// opBillingHistoryNote is BDP-14 while the stored history is shorter than |
| +// month ("2006-01"): no snapshot, or the first (snaps oldest first) after |
| +// the month's first day; "" otherwise. It sits under every per-account |
| +// list. |
| +func opBillingHistoryNote(snaps []arrSnapshot, month string) string { |
| + if len(snaps) == 0 || snaps[0].Day > month+"-01" { |
| + return billCopyHistoryShort |
| + } |
| + return "" |
| +} |
| + |
| // opBillingPlanNote is an account's seats and packs: "2 seats, 3 packs"; |
| // "" with neither. |
| func opBillingPlanNote(f billingFact) string { |
diff --git a/internal/console/opbilling_test.go b/internal/console/opbilling_test.go| index 93346ee06..5a5611a62 100644 |
| --- a/internal/console/opbilling_test.go |
| +++ b/internal/console/opbilling_test.go |
| @@ -1175,4 +1175,40 @@ func TestBillingAccountsServed(t *testing.T) { |
| if strings.Contains(body, fmt.Sprintf(billCopySortFallback, "")) { |
| t.Error("page falls back from earns with October covered") |
| } |
| + if strings.Contains(body, billCopyHistoryShort) { |
| + t.Error("October covered, yet the page says the history is short") |
| + } |
| +} |
| + |
| +// With the stored history starting on 15 October, October is not covered: |
| +// earns fall back with the history reason and the page says when past |
| +// months show (BDP-14), as the overview does. |
| +func TestBillingAccountsHistoryShort(t *testing.T) { |
| + fx, acct := overviewFixture(t) |
| + for d := time.Date(2026, 10, 15, 0, 0, 0, 0, time.UTC); !d.After(overviewNow); d = d.AddDate(0, 0, 1) { |
| + day := d.Format(snapshotDayFormat) |
| + snap := arrSnapshot{Day: day, ARR: map[string]int64{"eur": 2400}, EUR: 2400, RateDay: "2026-11-06", Paying: 1, Complete: true} |
| + rows := []accountDay{{Day: day, AccountID: acct.ID, Annual: 2400, Currency: "eur", AnnualEUR: 2400, Paying: true, InARR: true}} |
| + if err := fx.st.PutDailySnapshot(snap, rows, day, d); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + c := signInOperator(t, fx) |
| + status, _, body := get(t, c, fx.ts.URL+"/fleet/billing/accounts?sort=earns") |
| + body = html.UnescapeString(body) |
| + if status != http.StatusOK { |
| + t.Fatalf("page = %d", status) |
| + } |
| + history := fmt.Sprintf(billCopyWhyHistory, "October 2026") |
| + for _, s := range []string{billCopyHistoryShort, fmt.Sprintf(billCopySortFallback, history)} { |
| + if !strings.Contains(body, s) { |
| + t.Errorf("page lacks %q", s) |
| + } |
| + } |
| + if got := opBillingHistoryNote(nil, "2026-10"); got != billCopyHistoryShort { |
| + t.Errorf("no snapshots: %q", got) |
| + } |
| + if got := opBillingHistoryNote([]arrSnapshot{{Day: "2026-10-01"}}, "2026-10"); got != "" { |
| + t.Errorf("history from 1 October: %q", got) |
| + } |
| } |
diff --git a/internal/console/templates/ops_billing_accounts.html b/internal/console/templates/ops_billing_accounts.html| index 4b2c92167..47ec9d370 100644 |
| --- a/internal/console/templates/ops_billing_accounts.html |
| +++ b/internal/console/templates/ops_billing_accounts.html |
| @@ -21,6 +21,7 @@ |
| {{- end}} |
| </div> |
| <p co-note>{{.MonthNote}}</p> |
| +{{with .HistoryNote}}<p co-note>{{.}}</p>{{end}} |
| {{template "op_bill_whys" .Whys}} |
| {{if .PageLine}}<nav rst-pagination aria-label="{{.PageLine}}"> |
| {{- if .Prev}}<a href="{{.Prev}}">{{$w.Prev}}</a>{{else}}<span rst-pagination-disabled>{{$w.Prev}}</span>{{end}} |