Files
sure/app/views/bills/_month_pulse.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

113 lines
5.3 KiB
ERB
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<%# The month as one surface rather than a row of statistics.
It used to be a big number, two small ones, and a ring reading 0% -- a
generic KPI card that answered "how far along am I" (which nobody asked)
more loudly than "what do I owe" (which everybody does).
It now reads as one sentence: this month, this much left, this much late,
this much due soon, and here is what happens next. %>
<%# Slice math lives with BillsHelper#bills_month_progress: the bar reads
paid | overdue | still to come, overdue being a subset of what remains. %>
<% progress = bills_month_progress(
paid: @paid_this_month_total&.amount,
remaining: @remaining_this_month&.amount,
overdue: @past_due_total&.amount
) %>
<div class="bg-container rounded-xl shadow-border-xs p-5 space-y-4">
<div class="flex items-baseline justify-between gap-3">
<p class="text-xs font-medium uppercase tracking-wide text-secondary"><%= l(Date.current, format: "%B") %></p>
<p class="text-xs text-secondary"><%= t(".bill_count", count: @month_bill_count) %></p>
</div>
<%# The one figure the page exists to state. %>
<div>
<p class="text-3xl font-medium text-primary privacy-sensitive leading-tight">
<%= @remaining_this_month ? format_money(@remaining_this_month) : "" %>
</p>
<p class="text-sm text-secondary"><%= t(".left_to_pay") %></p>
</div>
<%# Supporting, not competing: one line of three, each a figure and a word. %>
<div class="flex flex-wrap items-center gap-x-5 gap-y-1 text-sm">
<p>
<span class="font-medium text-primary privacy-sensitive"><%= format_money(@paid_this_month_total || Money.new(0, Current.family.currency)) %></span>
<span class="text-secondary"><%= t(".pulse_paid") %></span>
</p>
<% if @past_due_total && @past_due_total.amount.positive? %>
<p class="text-destructive">
<span class="font-medium privacy-sensitive"><%= format_money(@past_due_total) %></span>
<%= t(".pulse_overdue") %>
</p>
<% end %>
<% if @due_next_seven && @due_next_seven.amount.positive? %>
<p>
<span class="font-medium text-primary privacy-sensitive"><%= format_money(@due_next_seven) %></span>
<span class="text-secondary"><%= t(".pulse_next_seven") %></span>
</p>
<% end %>
</div>
<%# Progress reports, it does not prompt: a 6px rule, not a centrepiece. %>
<% if progress[:total].positive? %>
<div class="flex h-1.5 rounded-full overflow-hidden bg-surface-inset"
role="img"
aria-label="<%= t(".pulse_bar_aria", percent: progress[:paid_pct].round) %>">
<% if progress[:paid_pct].positive? %>
<div class="bg-success" style="width: <%= progress[:paid_pct].round(2) %>%"></div>
<% end %>
<% if progress[:overdue_pct].positive? %>
<div class="bg-destructive" style="width: <%= progress[:overdue_pct].round(2) %>%"></div>
<% end %>
<% if progress[:upcoming_pct].positive? %>
<div class="bg-secondary opacity-30" style="width: <%= progress[:upcoming_pct].round(2) %>%"></div>
<% end %>
</div>
<% end %>
<% if @unconvertible_count.positive? %>
<p class="text-xs text-warning"><%= t(".unconvertible", count: @unconvertible_count) %></p>
<% end %>
<%# What happens next, which is what makes this header operational rather
than statistical. Items open the bill's page: the row expansion belongs
to a row, and expanding one further down the page while you are reading
the top of it would be a jump with no explanation. %>
<% if @next_up.any? %>
<div class="pt-3 border-t border-subdued space-y-2">
<div class="flex items-center justify-between gap-3">
<p class="text-xs font-medium uppercase tracking-wide text-secondary"><%= t(".next_up") %></p>
<%= link_to t(".view_upcoming"), bills_path(view: "calendar"),
class: "text-xs text-link hover:underline shrink-0" %>
</div>
<%# A horizontal strip where there is room, a scrollable one where there
is not. Four columns at 375px would be four unreadable slivers. %>
<div class="flex gap-2 overflow-x-auto no-scrollbar sm:grid sm:grid-cols-2 sm:overflow-visible lg:grid-cols-4">
<% @next_up.each do |occurrence| %>
<% series = occurrence.recurring_transaction %>
<%= link_to bill_path(series),
class: "shrink-0 w-36 sm:w-auto rounded-lg px-2 py-1.5 -mx-2 hover:bg-surface-hover group" do %>
<p class="text-xs text-secondary truncate">
<%= bills_next_up_date(occurrence) %>
<% if series.autopay? %>
&middot; <%= t("recurring_transactions.pay_action.autopay") %>
<% end %>
</p>
<p class="text-sm text-primary truncate group-hover:underline"><%= series.display_name %></p>
<p class="text-sm font-medium text-primary privacy-sensitive">
<% if occurrence.partially_paid? %>
<%= format_money(occurrence.remaining_amount_money) %>
<span class="text-xs font-normal text-secondary"><%= t("bills.remaining_label") %></span>
<% else %>
<%= "~" if occurrence_amount_estimated?(occurrence) %><%= format_money(occurrence.resolved_expected_amount_money) %>
<% end %>
</p>
<% end %>
<% end %>
</div>
</div>
<% end %>
</div>