mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 23:01:26 +00:00
* feat(budgets): add per-user personal budgets with strict isolation Families can now opt into personal budgets (toggleable via family settings): each family member gets their own budget for a given period instead of sharing a single family-wide budget. - Add families.personal_budgets flag and budgets.user_id, with partial unique indexes so shared budgets (user_id IS NULL) and personal budgets (user_id IS NOT NULL) can't collide. - Budget.find_or_bootstrap scopes lookup/creation by user when the family has personal_budgets enabled. - Scope most_recent_initialized_budget (used to seed a new budget from the prior period) by user_id so one user's copy-forward never bleeds into another user's budget. - budgets.user_id cascades on user deletion so personal budgets don't outlive their owner. * feat(budgets): enforce user-specific budget ownership and cascade deletion * feat(budgets): display user name for personal budgets in budget card on the plan section * feat(budgets): enhance personal budgets display for admins with preview feature indication * feat(budgets): enforce user-specific budget and category visibility for personal budgets * feat(budgets): create budget section titles and add translations notice in preferences * feat(budgets): let household and personal budgets coexist with sharing Previously enabling personal_budgets made the shared household budget unreachable. Budget.find_or_bootstrap now takes an explicit household: flag so both can be resolved independently for the same period, with a new household_budget_enabled family setting to opt out of the household side and keep personal budgets only. Adds a BudgetShare model (read_only/read_write) so a member can grant another family member access to their personal budget, enforced via Budget#viewable_by?/editable_by? across BudgetsController, BudgetCategoriesController, PlansController, and the read-only API. Preferences gains a Budget sharing card (gated on preview access like the rest of the personal budgets UI) and an owner switcher pill ( Household / mine / shared-with-me) appears on the budget page and the Plan hub card. Also fixes personal budgets showing the same "actual spending" as the household budget: actual spending/income now scope to the budget owner's own accounts instead of the viewer's full accessible set, via a new accounts: override on IncomeStatement. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> * feat(budgets): enhance budget switcher with icons and improved styling * feat(budgets): remove user name display from budget card and header * feat(budgets): remove unique index on taggable_type and taggable_id in taggings * feat(budgets): enhance budget sharing functionality and improve UI elements * Collapse personal budget migrations --------- Signed-off-by: JulienGourmet <69808509+jubbakka@users.noreply.github.com> Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com> Co-authored-by: sure-admin <sure-admin@splashblot.com>
86 lines
3.4 KiB
ERB
86 lines
3.4 KiB
ERB
<div class="pb-6 lg:pb-12">
|
|
<%= render "budgets/budget_header",
|
|
budget: @budget,
|
|
previous_budget: @previous_budget,
|
|
next_budget: @next_budget,
|
|
latest_budget: @latest_budget %>
|
|
|
|
<div class="space-y-4">
|
|
<%# Top Section: Donut and Summary side by side %>
|
|
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
|
<%# Budget Donut %>
|
|
<div class="min-h-[300px] bg-container rounded-xl shadow-border-xs p-8">
|
|
<% if !@budget.initialized? && @source_budget.present? && @editable %>
|
|
<%= render "budgets/copy_previous_prompt", budget: @budget, source_budget: @source_budget %>
|
|
<% elsif @budget.initialized? && @budget.available_to_allocate.negative? %>
|
|
<%= render "budgets/over_allocation_warning", budget: @budget, editable: @editable %>
|
|
<% else %>
|
|
<%= render "budgets/budget_donut", budget: @budget, editable: @editable %>
|
|
<% end %>
|
|
</div>
|
|
|
|
<%# Actuals Summary %>
|
|
<% if @budget.initialized? && @budget.available_to_allocate.positive? %>
|
|
<%= render DS::Tabs.new(active_tab: params[:tab].presence || "budgeted") do |tabs| %>
|
|
<% tabs.with_nav do |nav| %>
|
|
<% nav.with_btn(id: "budgeted", label: t("budgets.show.tabs.budgeted")) %>
|
|
<% nav.with_btn(id: "actuals", label: t("budgets.show.tabs.actual")) %>
|
|
<% end %>
|
|
|
|
<% tabs.with_panel(tab_id: "budgeted") do %>
|
|
<div class="bg-container rounded-xl shadow-border-xs">
|
|
<%= render "budgets/budgeted_summary", budget: @budget %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<% tabs.with_panel(tab_id: "actuals") do %>
|
|
<div class="bg-container rounded-xl shadow-border-xs">
|
|
<%= render "budgets/actuals_summary", budget: @budget %>
|
|
</div>
|
|
<% end %>
|
|
<% end %>
|
|
<% else %>
|
|
<div class="bg-container rounded-xl shadow-border-xs">
|
|
<%= render "budgets/actuals_summary", budget: @budget %>
|
|
</div>
|
|
<% end %>
|
|
</div>
|
|
|
|
<%# Bottom Section: Categories full width %>
|
|
<% has_over_budget = budget_has_over_budget?(@budget) %>
|
|
<%= content_tag :div,
|
|
class: "w-full bg-container rounded-xl shadow-border-xs p-4",
|
|
data: (has_over_budget ? { controller: "budget-filter" } : {}) do %>
|
|
<div class="flex items-center mb-4 flex-nowrap justify-between">
|
|
<h2 class="text-lg font-medium shrink-0">
|
|
<%= t("budgets.show.categories.title") %>
|
|
</h2>
|
|
|
|
<% if has_over_budget %>
|
|
<div class="hidden lg:flex flex-1 min-w-0 px-1">
|
|
<%= render "budgets/budget_tabs" %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<div class="<%= has_over_budget ? "shrink-0 flex justify-end whitespace-nowrap" : "ml-auto" %>">
|
|
<% if @budget.initialized? && @editable %>
|
|
<%= render DS::Link.new(
|
|
text: t("budgets.show.categories.edit"),
|
|
variant: "secondary",
|
|
icon: "settings-2",
|
|
href: budget_budget_categories_path(@budget, **budget_owner_query)
|
|
) %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|
|
<% if has_over_budget %>
|
|
<div class="flex lg:hidden flex-1 min-w-0 mb-4">
|
|
<%= render "budgets/budget_tabs" %>
|
|
</div>
|
|
<% end %>
|
|
|
|
<%= render "budgets/budget_categories", budget: @budget %>
|
|
<% end %>
|
|
</div>
|
|
</div>
|