The personal finance app for everyone (by everyone)
Ruby
<%# locals: (series:, history:, upcoming:, analytics:, payment_history:,
yearly_metrics:, last_account:) %>
<%# The sections under bills/_summary in a bill's drawer, collapsible like a
transaction's or a budget category's: why it matches and what it has
cost, what is coming, what settled and what paid it, and the notes. The
summary already states the current cycle and the subscription state, so
none of that repeats here. %>
<div class="space-y-4">
<%= render DS::Disclosure.new(title: t("bills.detail.overview"), open: true) do %>
<div class="space-y-4">
<%# Why this bill matches what it matches, in words rather than engine terms. %>
<div class="space-y-1.5">
<p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.rules") %></p>
<%# What the app has learned from corrections, prepared by
BillsHelper#bills_matcher_hints. %>
<% hints = bills_matcher_hints(series) %>
<div class="flex flex-wrap gap-1.5">
<%# A reference-only bill is not matched by its name, so the name is not offered as the rule. %>
<% unless hints[:reference_only] %>
<%= render DS::Pill.new(label: t("bills.detail.rule_named", name: series.merchant&.name.presence || series.name), tone: :neutral, marker: false) %>
<% end %>
<% amount_label = series.has_amount_variance? ?
t("bills.detail.rule_amount_range", min: format_money(series.expected_amount_min_money), max: format_money(series.expected_amount_max_money)) :
format_money(Money.new(series.amount.abs, series.currency)) %>
<span class="privacy-sensitive"><%= render DS::Pill.new(label: amount_label, tone: :neutral, marker: false) %></span>
<%= render DS::Pill.new(label: frequency_label(series), tone: :neutral, marker: false) %>
<% if series.account %>
<%= render DS::Pill.new(label: series.account.name, tone: :neutral, marker: false) %>
<% end %>
</div>
<% if hints[:reference].present? %>
<p class="text-xs text-secondary">
<%= t(hints[:reference_only] ? "bills.detail.rule_reference_only" : "bills.detail.rule_reference", reference: hints[:reference]) %>
</p>
<% end %>
<% if !hints[:reference_only] && hints[:aliases].any? %>
<p class="text-xs text-secondary">
<%= t("bills.detail.rule_aliases", names: hints[:aliases].to_sentence) %>
</p>
<% end %>
<% if !hints[:reference_only] && hints[:detected_name].present? && hints[:detected_name] != (series.merchant&.name.presence || series.name) %>
<p class="text-xs text-secondary">
<%= t("bills.detail.rule_detected", name: hints[:detected_name]) %>
</p>
<% end %>
<% if hints[:learned_pct].positive? %>
<p class="text-xs text-secondary">
<%= t("bills.detail.rule_learned_tolerance", percent: number_to_percentage(hints[:learned_pct], precision: 1, format: "%n%")) %>
</p>
<% end %>
<% if series.one_off? %>
<p class="text-xs text-secondary"><%= t("bills.detail.once_kind_hint") %></p>
<% end %>
</div>
<%# What it has actually cost: the shape over twelve months, then the figures. %>
<div class="border border-subdued rounded-lg divide-y divide-subdued">
<div class="px-3 py-3 flex flex-col justify-center">
<p class="text-xs font-medium text-secondary uppercase pb-1"><%= t("bills.detail.history_title") %></p>
<%= render DS::Sparkline.new(series: payment_history, aria_label: t("bills.detail.history_aria")) %>
</div>
<div class="px-3 py-3 space-y-2">
<% if analytics %>
<div class="grid <%= series.one_off? ? "grid-cols-2" : "grid-cols-3" %> gap-2">
<div>
<p class="text-xs text-secondary"><%= t("bills.detail.average") %></p>
<p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:average]) %></p>
<p class="text-xs text-subdued privacy-sensitive">
<%= t("bills.detail.range", min: format_money(analytics[:lowest]), max: format_money(analytics[:highest])) %>
</p>
</div>
<% unless series.one_off? %>
<div>
<p class="text-xs text-secondary"><%= t("bills.detail.annualized") %></p>
<p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:annualized]) %></p>
</div>
<% end %>
<div>
<p class="text-xs text-secondary"><%= t("bills.detail.ytd") %></p>
<p class="text-sm font-medium text-primary privacy-sensitive"><%= format_money(analytics[:ytd]) %></p>
</div>
</div>
<% end %>
<%# Per-year totals are reference material rather than something you read
every time, so they sit one click away instead of adding a table to
every bill you open. %>
<% if yearly_metrics.any? %>
<%= render DS::Disclosure.new(title: t("bills.detail.key_metrics"), align: "left") do %>
<div class="divide-y divide-subdued pt-1">
<div class="grid grid-cols-3 text-xs text-secondary pb-1">
<p><%= t("bills.detail.year") %></p>
<p class="text-right"><%= t("bills.detail.spent_per_year") %></p>
<p class="text-right"><%= t("bills.detail.avg_payment") %></p>
</div>
<% yearly_metrics.each do |row| %>
<div class="grid grid-cols-3 py-1.5 text-sm">
<p class="text-secondary"><%= row[:year] %></p>
<p class="text-right text-primary privacy-sensitive"><%= format_money(row[:total]) %></p>
<p class="text-right text-primary privacy-sensitive"><%= format_money(row[:average]) %></p>
</div>
<% end %>
</div>
<% end %>
<% end %>
<% if last_account %>
<div class="flex items-center justify-between gap-3">
<p class="text-xs text-secondary"><%= t("bills.detail.last_account") %></p>
<p class="text-sm text-primary truncate"><%= last_account.name %></p>
</div>
<% end %>
</div>
</div>
<%# What it used to cost. The twelve-month chart above shows the shape; this
names the moment it changed and by how much. %>
<% changes = series.recent_price_changes %>
<% if changes.any? %>
<div class="space-y-1">
<p class="text-xs font-medium text-secondary uppercase"><%= t("bills.detail.price_changes") %></p>
<div class="bg-container-inset rounded-lg divide-y divide-subdued">
<% changes.each do |change| %>
<div class="flex items-center justify-between gap-3 px-3 py-2">
<p class="text-sm text-primary"><%= l(change.effective_on, format: :long) %></p>
<p class="text-sm privacy-sensitive <%= change.new_amount > change.previous_amount ? "text-warning" : "text-success" %>">
<%= t("bills.detail.price_change_line",
from: format_money(change.previous_amount_money),
to: format_money(change.new_amount_money)) %>
</p>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
<% end %>
<% if upcoming.any? %>
<%= render DS::Disclosure.new(title: t("bills.detail.upcoming")) do %>
<div class="bg-container-inset rounded-lg divide-y divide-subdued">
<% upcoming.each do |date| %>
<div class="flex items-center justify-between px-3 py-2">
<p class="text-sm text-primary"><%= l(date, format: :long) %></p>
<p class="text-sm text-secondary privacy-sensitive">
~<%= format_money(Money.new(series.amount.abs, series.currency)) %>
</p>
</div>
<% end %>
</div>
<% end %>
<% end %>
<%# Settled cycles with what paid them: "did I pay it that month" and "which
transaction paid it" in one list, rather than a cycle list and a payment
list that mostly repeat each other. Every row opens its cycle's payment
drawer, which is the only place a payment can be unlinked. %>
<% if history.any? %>
<%= render DS::Disclosure.new(title: t("bills.detail.history")) do %>
<div class="bg-container-inset rounded-lg divide-y divide-subdued">
<% history.each do |occurrence| %>
<% payments = occurrence.allocations.select(&:allocation_confirmed?) %>
<%= link_to recurring_occurrence_path(occurrence),
data: { turbo_frame: :drawer, turbo_prefetch: false },
class: "flex items-center justify-between gap-3 px-3 py-2 hover:bg-surface-hover focus-ring -outline-offset-2" do %>
<div class="min-w-0">
<p class="text-sm text-primary"><%= l(occurrence.due_on, format: :long) %></p>
<p class="text-xs text-secondary truncate">
<%= t("recurring_occurrences.history_status.#{occurrence.status}") %>
<% if payments.size > 1 %>
· <%= t("bills.detail.payment_count", count: payments.size) %>
<% elsif (payment = payments.first) %>
· <%= payment.entry&.name.presence || t("bills.detail.manual_payment") %>
<% end %>
</p>
</div>
<span class="flex items-center gap-1.5 shrink-0">
<span class="text-sm text-primary privacy-sensitive">
<%= format_money(occurrence.confirmed_allocated_money) %>
</span>
<%= icon("chevron-right", size: "sm", class: "text-subdued") %>
</span>
<% end %>
<% end %>
</div>
<% end %>
<% end %>
<% if series.notes.present? %>
<%= render DS::Disclosure.new(title: t("bills.detail.notes")) do %>
<p class="text-sm text-primary px-3"><%= series.notes %></p>
<% end %>
<% end %>
</div>