The personal finance app for everyone (by everyone)
Ruby
<%# locals: (account:, projection:, as_of: Date.current) %>
<%# `as_of` is the page's one reference date: the chart above the tabs and
this table shade "past" against the same day. `projection` is the loan's
payoff projection for that date, built once for the page and shared with
the chart. %>
<% today = as_of %>
<% schedule = account.loan.amortization_schedule %>
<% payments = schedule.payments %>
<div class="space-y-4">
<div class="grid grid-cols-2 md:grid-cols-4 gap-2">
<%# A re-amortising loan has no single monthly payment, so the card says
which one this is rather than implying the figure holds for the term. %>
<%= summary_card title: schedule.re_amortising? ? t(".opening_payment") : t(".monthly_payment") do %>
<%= format_money schedule.periodic_payment %>
<% end %>
<%= summary_card title: t(".total_interest") do %>
<%= format_money schedule.total_interest %>
<% end %>
<%= summary_card title: t(".total_cost") do %>
<%= format_money schedule.total_paid %>
<% end %>
<%# When the loan will actually be paid off: the projection from today's
balance at the contract's repayment, as the chart above draws it. The
Overview tab has the contract's own date. A balance that repayment no
longer clears has no date to give. %>
<%= summary_card title: t(".forecasted_payoff_date") do %>
<% if projection.payoff_date %>
<%= l projection.payoff_date, format: :long %>
<% elsif projection.applicable? %>
<%= t(".forecasted_payoff_not_converged") %>
<% else %>
<%= t(".not_applicable") %>
<% end %>
<% end %>
</div>
<p class="text-sm text-secondary">
<%= t(".description", start_date: l(account.loan.origination_date, format: :long)) %>
</p>
<% if account.loan.variable_rate_type? %>
<p class="text-sm text-secondary"><%= t(".variable_rate_notice") %></p>
<% end %>
<%= render DS::Table.new(
rows: payments,
sticky_header: true,
label: t("accounts.show.tabs.schedule"),
row_class: ->(payment) { "bg-container-inset" if payment.date <= today }
) do |table| %>
<% table.with_column(t(".number"), class: "text-secondary tabular-nums") { |payment| payment.number.to_s } %>
<% table.with_column(t(".date")) { |payment| l(payment.date, format: :long) } %>
<% table.with_column(t(".payment"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.payment) } %>
<% table.with_column(t(".principal"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.principal) } %>
<% table.with_column(t(".interest"), numeric: true, class: "text-secondary privacy-sensitive") { |payment| format_money(payment.interest) } %>
<% table.with_column(t(".remaining_balance"), numeric: true, class: "privacy-sensitive") { |payment| format_money(payment.ending_balance) } %>
<% end %>
</div>