Files
sure/app/views/bills/index.html.erb
T
Brandon fe0d27471d feat(bills): the bills pages, calendar feed and in-page AI helpers (#3202)
* feat(bills): the bills pages, calendar feed and in-page AI helpers

Second of three chunks carved out of #3083, stacked on the schema and domain
core. This is everything a user sees and clicks. The whole surface sits behind
the preview flag, so it is unreachable until someone opts in.

Pages, all under one nav entry:

- the pay run, a month calendar, the full bills table, and the paycheck planner
- a detail drawer per bill, with payment history, price changes and cost
  analytics
- create and edit flows for bills, subscriptions, installment plans and income

The overview marks pay periods inside the month, so a weekly paycheck no longer
reads as one undifferentiated month of bills. Markers appear only when income
actually subdivides the month, which means monthly and undeclared income render
exactly as before and there is no new setting to configure.

Navigation and design system:

- one preview-gated nav item shared by the desktop rail and the mobile bar
- DS::Sparkline for payment-history charts, replacing raw SVG in views
- status badges render through DS::Pill rather than hand-rolled spans
- the suggestions panel is a disclosure that remembers being collapsed, per
  device, the way privacy mode and the sidebar width already do
- every surface reflows to phone widths without horizontal scroll

Calendar feed: a signed ICS feed per family, served sessionless by token, with a
reset that revokes previously shared URLs.

In-page AI helpers: smart fill on the bill form and a smart configuration
proposal on an existing bill, each reading a bounded slice of charge history.
Provider-side prompt assembly sits behind the existing LlmConcept interface,
with an implementation for each of the two providers. These belong here rather
than with the assistant tools because they are buttons on these pages and lean
on the provider suggester, not on the tool registry.

Suite 7,776 runs green apart from the pre-existing passkey-session flake, which passes standalone. Rubocop clean, eager loading verified. The hosting guide for the feature ships here rather than with the schema, since its instructions walk pages this PR introduces.

* Render the suggested strip through DS::Disclosure

The hand-rolled details pair predates the component. The card_inset
variant is the same shape, so the strip now inherits the design system
chrome, and the persisted-disclosure controller rides along unchanged.

* Route the remaining hand-rolled chips through the design system

The subscription-state chips, rule-match chips and match-reason chips
become DS::Pill, with the state chips extracted to one shared partial so
the drawer and the summary tab stop carrying copy-pasted markup. The AI
prompt chips become DS::Button and the bills-index filter becomes
DS::SearchInput, both of which this PR already uses elsewhere for the
same shapes.

* Fix erb_lint whitespace offenses in bills views

* Address the post-ready review round

* Require a writable destination account and gate the feed on preview

* Reject an unresolvable declared account out loud
2026-09-02 02:08:58 +02:00

182 lines
8.1 KiB
ERB

<%= content_for :page_title, t(".title") %>
<div class="space-y-4 pb-6 lg:pb-12">
<%= render "bills/view_switcher", active: "overview" %>
<div class="space-y-4 min-w-0">
<%# Nothing here was confirmed by anyone: detection built it from bank data.
Says so once, and stops as soon as the user works with any of it. %>
<% if @detected_awaiting_review.positive? %>
<div class="bg-container rounded-xl shadow-border-xs px-4 py-3 flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1">
<p class="text-sm text-primary">
<%= t(".detected_review", count: @detected_awaiting_review) %>
</p>
<%= link_to t(".detected_review_action"), bills_path(view: "all"),
class: "text-xs text-secondary hover:text-primary shrink-0" %>
</div>
<% end %>
<%= render "bills/month_pulse" %>
<%= render "bills/ai_prompts", prompts: %w[due_before_paycheck subscriptions_up monthly_subscriptions] %>
<%# Changes worth knowing about, ranked by whether you can still do anything.
Everything stays on the page: the quieter half collapses rather than
being capped, so nothing becomes a dead end and nothing pushes the
worklist off screen. %>
<% if @notices.any? %>
<% urgent, routine = @notices.partition(&:urgent?) %>
<div class="bg-container rounded-xl shadow-border-xs divide-y divide-subdued">
<% urgent.each do |notice| %>
<%= render "bills/notice", notice: notice, urgent: true %>
<% end %>
<% if routine.any? %>
<div class="px-4 py-2">
<% if urgent.any? %>
<%= render DS::Disclosure.new(title: t(".notices_routine", count: routine.size), align: "left") do %>
<div class="divide-y divide-subdued">
<% routine.each do |notice| %>
<%= render "bills/notice", notice: notice, urgent: false %>
<% end %>
</div>
<% end %>
<% else %>
<div class="divide-y divide-subdued">
<% routine.each do |notice| %>
<%= render "bills/notice", notice: notice, urgent: false %>
<% end %>
</div>
<% end %>
</div>
<% end %>
</div>
<% end %>
<% if @suggested_allocations.any? %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary uppercase">
<p><%= t(".needs_review") %></p>
<span class="text-subdued">&middot;</span>
<p><%= @suggested_allocations.size %></p>
</div>
<div class="bg-container rounded-lg shadow-border-xs divide-y divide-subdued">
<% @suggested_allocations.each do |suggestion| %>
<% series = suggestion.recurring_occurrence.recurring_transaction %>
<div class="flex items-center justify-between gap-4 px-4 py-3">
<div class="min-w-0">
<p class="text-sm text-primary truncate">
<%= t(".suggestion_line",
entry: suggestion.entry&.name.presence || t(".suggestion_unknown_entry"),
bill: series.display_name) %>
</p>
<%# The matcher stores WHY it proposed each of these. This line
used to show a bare percentage of that reasoning instead of
the reasoning, which told nobody anything they could judge. %>
<% reasons = bills_match_reasons(
suggestion.match_signals,
currency: suggestion.recurring_occurrence.currency,
expected: suggestion.recurring_occurrence.resolved_expected_amount,
actual: suggestion.entry&.amount&.abs,
due_on: suggestion.recurring_occurrence.effective_due_on,
paid_on: suggestion.paid_on
) %>
<p class="text-xs text-secondary privacy-sensitive">
<%= format_money(suggestion.allocated_amount_money) %>
&middot; <%= l(suggestion.paid_on, format: :short) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>
</p>
</div>
<div class="flex items-center gap-2 shrink-0">
<%= render DS::Link.new(
text: t("recurring_occurrences.show.link_payment"),
variant: "primary",
href: confirm_recurring_allocation_path(suggestion),
method: :post
) %>
<%= render DS::Link.new(
text: t("recurring_occurrences.show.not_this_one"),
variant: "ghost",
href: reject_recurring_allocation_path(suggestion),
method: :post
) %>
</div>
</div>
<% end %>
</div>
</div>
<% end %>
<%# Series-level review: detection found these, nobody confirmed them yet.
Distinct from the payment-match queue above. %>
<% if @suggested_series.any? %>
<%= render "recurring_transactions/suggested_series", suggested: @suggested_series %>
<% end %>
<% if [ @overdue, @month_rows, @later, @dormant ].all?(&:empty?) %>
<% if @suggested_series.none? %>
<div class="bg-container rounded-xl shadow-border-xs p-4">
<%= render DS::EmptyState.new(
icon: "receipt",
title: t(".empty.title"),
description: @has_transaction_history ? t(".empty.description") : t(".empty.no_history_description")
) do |empty| %>
<% empty.with_action do %>
<div class="flex flex-wrap items-center justify-center gap-2">
<% if @has_transaction_history %>
<%= render DS::Link.new(
text: t(".empty.action"),
icon: "search",
variant: "primary",
href: detect_bills_path,
method: :post
) %>
<%= render DS::Link.new(
text: t(".add_bill"),
icon: "plus",
variant: "outline",
href: new_recurring_transaction_path,
frame: :modal
) %>
<% else %>
<%# Detection over zero transactions finds nothing; offering it
would be a button that silently does nothing. %>
<%= render DS::Link.new(
text: t(".add_bill"),
icon: "plus",
variant: "primary",
href: new_recurring_transaction_path,
frame: :modal
) %>
<% end %>
</div>
<% end %>
<% end %>
</div>
<% end %>
<% else %>
<%# Anything late is pulled out of the chronological run. Inside it, an
overdue bill was distinguishable only by a word in the date column, so
the most urgent rows were the easiest ones to scroll past. %>
<% if @overdue.any? %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
<%# The section says how much is at stake, not just how many rows: a
count alone is alarming without being informative. %>
<%= render "bills/occurrence_section",
title: t(".needs_attention"),
occurrences: @overdue,
date_labels: true,
suggestions: @suggestions_by_occurrence,
meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %>
</div>
<% end %>
<div class="rounded-xl bg-container-inset space-y-1 p-1">
<%= render "bills/occurrence_section", title: t(".this_month"), occurrences: @month_rows, date_labels: true, suggestions: @suggestions_by_occurrence, pay_periods: @month_pay_periods %>
<%= render "bills/occurrence_section", title: t(".later"), occurrences: @later, suggestions: @suggestions_by_occurrence %>
<%= render "bills/occurrence_section", title: t(".dormant"), occurrences: @dormant, suggestions: @suggestions_by_occurrence %>
</div>
<% end %>
</div>
</div>