Files
sure/app/controllers/retirement/statements_controller.rb
Guillem Arias 26bb333c34 feat(retirement): PR2 CRUD for sources, statements, adjustments, bucket
Functional data-entry surface on the (still preview) /retirement page.
The polished combined-page UI is PR4; this ships plain forms + lists so
a preview user can populate a plan end to end.

- RetirementScoped concern: tier-1 preview gate + tier-2 family
  killswitch + per-owner plan bootstrap (Goal::Retirement.for_owner
  find-or-creates, so children always have a parent). RetirementController
  now uses it.
- Nested controllers under Retirement::: PensionSources (full CRUD),
  Statements (new/create + soft-delete destroy — append-only audit),
  Adjustments (full CRUD), Buckets (replace-all account selection,
  same-family filtered). All scoped to the current user's own plan, so
  cross-user access is impossible by construction.
- Routes nested under `resource :retirement` via `scope module:`.
- Views: show page rewritten into management sections (sources,
  adjustments, bucket checkboxes, statement journal) + plain
  styled_form_with forms. Money carries privacy-sensitive.
- Goal gains a target_amount_required? hook (true); Goal::Retirement
  overrides it false — the forecast owns the target (PR3), so a plan
  can exist before any target is set.
- EN locale for the new surface. 111 controller+model tests green.

Note: delete uses Turbo confirm for now; PR4 swaps in the skinned
DS::Dialog per the design.
2026-05-29 10:49:18 +02:00

43 lines
1.2 KiB
Ruby

class Retirement::StatementsController < ApplicationController
include RetirementScoped
before_action :set_statement, only: %i[destroy]
def new
@statement = @plan.statements.new(
received_on: Date.current,
projected_currency: Current.family.primary_currency_code
)
@pension_sources = @plan.pension_sources.order(:start_age)
end
def create
@statement = @plan.statements.new(statement_params)
if @statement.save
redirect_to retirement_path, notice: t(".created")
else
@pension_sources = @plan.pension_sources.order(:start_age)
render :new, status: :unprocessable_entity
end
end
# Append-only audit: deleting flips the soft-delete flag so history is kept.
def destroy
@statement.update!(deleted: true)
redirect_to retirement_path, notice: t(".deleted")
end
private
def set_statement
@statement = @plan.statements.find(params[:id])
end
def statement_params
params.require(:goal_retirement_statement).permit(
:pension_source_id, :received_on, :projected_monthly_amount,
:projected_currency, :projected_at_age, :current_points,
:raw_source_doc, :notes
)
end
end