Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby
8.6 KB
Raw Blame
<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 p-4 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>
      <%= render DS::Link.new(
            text: t(".detected_review_action"),
            variant: :default,
            href: bills_path(view: "all"),
            class: "text-xs shrink-0"
          ) %>
    </div>
  <% end %>

  <% bill_rows_empty = [ @overdue, @month_rows, @later, @dormant ].all?(&:empty?) %>

  <%# With no bill rows the pulse is a card of dashes and zeros, and the
      prompts would start a chat about bills that don't exist. Suggestions
      don't count: they aren't bills yet, and the pulse can't total them.
      Nor do Dormant rows: paused bills owe nothing this month. %>
  <% unless [ @overdue, @month_rows, @later ].all?(&:empty?) %>
    <%= render "bills/month_pulse" %>

    <%= render "bills/ai_prompts", prompts: %w[due_before_paycheck subscriptions_up monthly_subscriptions] %>
  <% end %>

  <% if bill_rows_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 %>
    <%# One list, what is late first, the way Budgets leads its categories
        with Over budget. Anything late is still 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. It used to sit below the review queues and the
        notices, a screen down from the pulse that totals it. %>
    <%# The section says how much is at stake, not just how many rows: a
        count alone is alarming without being informative. %>
    <div class="rounded-xl bg-surface-inset space-y-1 p-1">
      <%= render "bills/occurrence_section",
                 title: t(".needs_attention"),
                 occurrences: @overdue,
                 suggestions: @suggestions_by_occurrence,
                 meta: (@past_due_total && @past_due_total.amount.positive? ? t(".attention_overdue_total", amount: format_money(@past_due_total)) : nil) %>
      <%= render "bills/occurrence_section", title: t(".this_month"), occurrences: @month_rows, suggestions: @suggestions_by_occurrence, pay_periods: @month_pay_periods, pay_period_occurrences: @paid_this_month + @open_upcoming %>
      <%= 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 %>

  <%# What is waiting on a yes or no sits under the bills it is about. A row
      with a match to review already says so and offers Review match, so
      nothing here is only reachable from up top. %>
  <% if @suggested_allocations.any? %>
    <%= render DS::Section.new(title: t(".needs_review"), count: @suggested_allocations.size) do %>
      <% @suggested_allocations.each do |suggestion| %>
        <% series = suggestion.recurring_occurrence.recurring_transaction %>
        <%= render DS::ReviewRow.new do |row| %>
          <% row.with_actions do %>
            <%= 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
                ) %>
          <% end %>
          <p class="text-sm text-primary @md: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_with_year) %><%= " · #{reasons.join(" · ")}" if reasons.any? %>
          </p>
        <% end %>
      <% end %>
    <% end %>
  <% 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 %>

  <%# Changes worth knowing about, ranked by whether you can still do anything.
      Last on the page: they inform rather than ask, so they follow the
      worklist instead of pushing it off screen. Everything stays on the page:
      the quieter half collapses rather than being capped, so nothing becomes
      a dead end. %>
  <% if @notices.any? %>
    <% urgent, routine = @notices.partition(&:urgent?) %>
    <%= render DS::Section.new(title: t(".notices_heading"), count: @notices.size) do %>
      <% urgent.each do |notice| %>
        <%= render "bills/notice", notice: notice, urgent: true %>
      <% end %>

      <% if routine.any? && urgent.any? %>
        <%# A row of the card like the notices around it. Its old grey
            summary read as a box inside the card. %>
        <%= render DS::Disclosure.new(variant: :inline, body_class: nil) do |disclosure| %>
          <% disclosure.with_summary_content do %>
            <div class="flex items-center gap-2 px-4 py-2.5 text-sm text-secondary">
              <%= disclosure_chevron %>
              <span><%= t(".notices_routine", count: routine.size) %></span>
            </div>
          <% end %>
          <div class="divide-y divide-subdued border-t border-subdued">
            <% routine.each do |notice| %>
              <%= render "bills/notice", notice: notice, urgent: false %>
            <% end %>
          </div>
        <% end %>
      <% else %>
        <% routine.each do |notice| %>
          <%= render "bills/notice", notice: notice, urgent: false %>
        <% end %>
      <% end %>
    <% end %>
  <% end %>
  </div>
</div>