The personal finance app for everyone (by everyone)
Ruby
<%# locals: (money_flow_data:, accounts:, accessible_account_ids:, view_params:, col_span: "single") %>
<%
pill_button_class = "inline-flex items-center gap-1.5 bg-container border border-secondary font-medium rounded-lg pl-3 pr-2 py-2 text-sm cursor-pointer text-primary hover:bg-container-inset-hover focus:outline-hidden focus:ring-0 whitespace-nowrap"
selected_account_ids = money_flow_data[:account_ids] || accounts.map { |a| a.id.to_s }
all_accounts_selected = selected_account_ids.size == accounts.size
# TransactionsController falls back to the user's full accessible-accounts
# set (broader than this widget's eligible accounts) when account_ids is
# absent, so we can only drop the param when that default matches this
# widget's selection exactly — otherwise the drill-down would silently show
# transactions outside what these totals represent.
drilldown_account_ids = selected_account_ids.sort == accessible_account_ids.sort ? nil : selected_account_ids
period = money_flow_data[:period]
# At full width the chart and summary sit side by side; at single/half width
# they stack so the chart gets the full column and the month labels don't crowd.
stacked = col_span != "full"
# The other widgets' months and filters, carried through this widget's
# links and form so changing it doesn't reset them.
other_view_params = view_params.except(:money_flow_month, :money_flow_account_ids)
%>
<div id="money-flow-section" class="px-4 space-y-4">
<div class="flex flex-col lg:flex-row lg:items-start lg:justify-between gap-3">
<p class="text-sm text-secondary">
<%= t(".date_range", start_date: l(period.date_range.begin, format: :long), end_date: l(period.date_range.end, format: :long)) %>
</p>
<div class="flex items-center gap-2">
<%= render DS::Tooltip.new(text: t(".period_scope_hint"), placement: "top-start") %>
<%= render DS::Menu.new(variant: :button, placement: "bottom-end", max_height: "18rem") do |menu| %>
<% menu.with_button(type: "button", class: pill_button_class, aria: { label: t(".month_picker_aria_label") }) do %>
<span class="capitalize"><%= I18n.l(money_flow_data[:month], format: :month_year) %></span>
<%= icon("chevron-down", size: "sm") %>
<% end %>
<% (0..11).each do |i| %>
<% month = Date.current.beginning_of_month - i.months %>
<% menu.with_item(
variant: :link,
text: I18n.l(month, format: :month_year).capitalize,
href: root_path(other_view_params.merge(money_flow_month: month.iso8601, money_flow_account_ids: money_flow_data[:account_ids]).compact),
frame: "dashboard_sections",
selected: month == money_flow_data[:month],
data: { turbo_action: "advance" }
) %>
<% end %>
<% end %>
<%= render layout: "pages/dashboard/filter_popover", locals: {
button_text: all_accounts_selected ? t(".filter_accounts_all") : t(".filter_accounts", count: selected_account_ids.size),
search_label: t(".search_accounts"),
apply_text: t(".apply"),
hidden_fields: other_view_params.merge(money_flow_month: money_flow_data[:month].iso8601)
} do %>
<% accounts.each do |account| %>
<%= render layout: "pages/dashboard/filter_popover_option", locals: {
name: "money_flow_account_ids[]",
value: account.id,
checked: selected_account_ids.include?(account.id.to_s),
filter_name: account.name
} do %>
<span class="text-sm text-primary truncate"><%= account.name %></span>
<% end %>
<% end %>
<% end %>
</div>
</div>
<div class="flex flex-col gap-6<%= " xl:flex-row" unless stacked %>">
<div class="w-full space-y-2<%= " xl:w-3/5" unless stacked %>">
<div class="flex items-center justify-between gap-4 px-1">
<div class="flex items-center gap-4">
<span class="flex items-center gap-1.5 text-xs text-secondary">
<span class="w-2 h-2 rounded-full bg-success"></span>
<%= t(".income") %>
</span>
<span class="flex items-center gap-1.5 text-xs text-secondary">
<span class="w-2 h-2 rounded-full bg-subdued"></span>
<%= t(".expenses") %>
</span>
</div>
<span class="text-xs text-secondary"><%= t(".chart_span", count: money_flow_data[:bars].size) %></span>
</div>
<div class="w-full h-44 privacy-sensitive"
data-controller="bar-chart"
data-bar-chart-data-value="<%= money_flow_data[:bars].to_json %>"
data-bar-chart-currency-value="<%= Current.family.currency %>"
data-bar-chart-income-label-value="<%= t(".income") %>"
data-bar-chart-expense-label-value="<%= t(".expenses") %>">
</div>
</div>
<div class="w-full space-y-4<%= " xl:w-2/5" unless stacked %>">
<p class="text-sm font-medium text-primary capitalize"><%= I18n.l(money_flow_data[:month], format: :month_year) %></p>
<div class="flex items-center justify-between text-sm">
<span class="text-secondary"><%= t(".balance") %></span>
<span class="font-medium text-lg tabular-nums privacy-sensitive <%= money_flow_data[:balance].negative? ? "text-destructive" : (money_flow_data[:balance].zero? ? "text-primary" : "text-success") %>">
<%= format_money money_flow_data[:balance] %>
</span>
</div>
<%= link_to transactions_path(q: { types: [ "income" ], status: [ "confirmed" ], start_date: period.date_range.begin, end_date: period.date_range.end, account_ids: drilldown_account_ids }.compact),
class: "flex items-center justify-between p-3 border border-secondary rounded-lg hover:bg-container-inset-hover transition-colors group",
data: { turbo_frame: "_top" } do %>
<span class="flex items-center gap-2 text-sm text-primary">
<span class="w-2.5 h-2.5 rounded-full bg-success"></span>
<%= t(".income") %>
</span>
<%# text-sm to match the row's own label and the equivalent figure in the
outflows widget. Without it these inherited the 16px base, which is
off the scale the dashboard uses (sm for rows, lg for a total, 3xl
for a hero) and left the amount larger than the label beside it. %>
<span class="flex items-center gap-2">
<span class="text-sm font-medium tabular-nums text-success privacy-sensitive"><%= format_money money_flow_data[:income] %></span>
<%= icon("chevron-right", size: "sm", class: "text-secondary group-hover:text-primary transition-colors") %>
</span>
<% end %>
<%= link_to transactions_path(q: { types: [ "expense" ], status: [ "confirmed" ], start_date: period.date_range.begin, end_date: period.date_range.end, account_ids: drilldown_account_ids }.compact),
class: "flex items-center justify-between p-3 border border-secondary rounded-lg hover:bg-container-inset-hover transition-colors group",
data: { turbo_frame: "_top" } do %>
<span class="flex items-center gap-2 text-sm text-primary">
<span class="w-2.5 h-2.5 rounded-full bg-subdued"></span>
<%= t(".expenses") %>
</span>
<span class="flex items-center gap-2">
<span class="text-sm font-medium tabular-nums text-primary privacy-sensitive"><%= format_money money_flow_data[:expense] %></span>
<%= icon("chevron-right", size: "sm", class: "text-secondary group-hover:text-primary transition-colors") %>
</span>
<% end %>
</div>
</div>
</div>