Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
4.4 KB
Raw Blame
<%# locals: (series:, current_occurrence:, suggestion: nil, settled_occurrence: nil) %>

<%# INSPECT. What is going on with this bill, and what to do about it?

    The top of the bill's drawer. Its sections (Overview, Coming up, History
    and Notes) follow it in bills/_detail, loaded lazily. %>

<div class="space-y-4">
  <%= render "bills/cancelled_notice", series: series %>

  <%# Current state, at the size the payment drawer and a transaction's
      drawer give their headline figure. At text-lg it matched the bill's name
      above it, so the drawer had no figure to lead with. %>
  <% if current_occurrence %>
    <% expected = current_occurrence.resolved_expected_amount_money %>
    <% paid = current_occurrence.confirmed_allocated_money %>
    <div class="space-y-0.5">
      <p class="text-2xl font-medium text-primary privacy-sensitive">
        <% if current_occurrence.paid? %>
          <%= t("bills.summary.paid_headline", amount: format_money(paid)) %>
        <% else %>
          <%= t("bills.summary.remaining", amount: format_money(current_occurrence.remaining_amount_money)) %>
        <% end %>
      </p>
      <p class="text-sm <%= current_occurrence.overdue? ? "text-destructive" : "text-secondary" %>">
        <span class="privacy-sensitive"><%= t("bills.partial_progress", paid: format_money(paid), expected: format_money(expected)) %></span>
        &middot; <%= occurrence_due_label(current_occurrence) %>
      </p>
      <%# The row shows the range only from @lg, so on a phone this is where
          an estimate says how far it can swing. %>
      <% if occurrence_amount_estimated?(current_occurrence) && series.has_amount_variance? %>
        <p class="text-xs text-secondary privacy-sensitive">
          <%= t("bills.amount_range",
                min: format_money(series.expected_amount_min_money),
                max: format_money(series.expected_amount_max_money)) %>
        </p>
      <% end %>
    </div>
  <% else %>
    <div class="space-y-0.5">
      <p class="text-2xl font-medium text-primary privacy-sensitive">
        <%= "~" if series.has_amount_variance? %><%= format_money(Money.new(series.amount.abs, series.currency)) %>
      </p>
      <p class="text-sm text-secondary">
        <%= series.next_expected_date.present? ? t("bills.detail.around", date: bills_upcoming_date(series.next_expected_date)) : t("bills.detail.next_payment") %>
      </p>
    </div>
  <% end %>

  <%# Schedule, on one line rather than as a stack of labelled fields. %>
  <p class="text-xs text-secondary">
    <%= frequency_label(series) %>
    <% if (progress = bills_installment_progress(series)) %>
      &middot; <%= progress %>
    <% end %>
    <% unless series.active? %>&middot; <%= t("recurring_transactions.status.#{series.status}") %><% end %>
    <% if series.account %>&middot; <%= series.account.name %><% end %>
    <% if (autopay = bills_autopay_label(series)) %>&middot; <%= autopay %><% end %>
  </p>

  <%# Subscription state is state, not depth, so it stays here. %>
  <%= render "bills/state_chips", series: series %>

  <%# The next step, spelled out. The row shows it only when the bill needs you
      now, and never on a phone. Here it is always present, settled occurrences
      included, because the drawer is the only route in the app to unlinking a
      payment or reopening a cycle. %>
  <div class="flex flex-wrap items-center gap-2 pt-1">
    <% if current_occurrence %>
      <%= render "bills/row_action", occurrence: current_occurrence, suggestion: suggestion, drawer: true %>
    <% end %>

    <%# Pay and Add link keep a home here, so the portal never leaves Bills
        just because the row got quieter. %>
    <%= render "recurring_transactions/pay_action", recurring_transaction: series %>

    <%# The primary verb only reaches the cycle the drawer is showing. When
        that is a different cycle -- an open one, or a skipped/missed one whose
        own verb has no payment to manage -- offer the latest settled cycle
        here. When the drawer already shows it, the primary action covers it. %>
    <% if settled_occurrence.present? && settled_occurrence != current_occurrence %>
      <%= render DS::Link.new(
            text: t("bills.manage_payments"),
            icon: "receipt-text",
            variant: "outline",
            size: "md",
            href: recurring_occurrence_path(settled_occurrence),
            frame: :drawer
          ) %>
    <% end %>
  </div>
</div>