mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 15:59:02 +00:00
- Add JSONB pension_params column to retirement_configs
- Add data JSONB column to pension_entries
- Create pension calculator strategy classes (Base, DeGrv, UsSocialSecurity, UkStatePension, FrRegimeGeneral, EsSocialSecurity)
- Update RetirementConfig model to delegate to calculators
- Make PensionEntry.current_points optional for non-points systems
- Update controller strong params (pension_params: {})
- Add Stimulus pension_system_controller for dynamic form fields
- Update views with per-country field groups and conditional points columns
- Expand i18n (EN, DE) and add ES, FR locale files
- Update fixtures and tests for new schema
Addresses review feedback from jjmata on PR #1057
95 lines
2.6 KiB
Ruby
95 lines
2.6 KiB
Ruby
class RetirementController < ApplicationController
|
|
before_action :set_retirement_config, only: %i[show edit update]
|
|
before_action :require_retirement_config, only: %i[add_pension_entry destroy_pension_entry]
|
|
|
|
def show
|
|
@pension_entries = @retirement_config.pension_entries_with_gains
|
|
end
|
|
|
|
def setup
|
|
@retirement_config = Current.family.retirement_config || Current.family.build_retirement_config(
|
|
birth_year: 1990,
|
|
currency: Current.family.currency
|
|
)
|
|
end
|
|
|
|
def create
|
|
# Guard against duplicate creation (unique index on family_id)
|
|
if Current.family.retirement_config
|
|
redirect_to retirement_path
|
|
return
|
|
end
|
|
|
|
@retirement_config = Current.family.build_retirement_config(retirement_config_params)
|
|
|
|
if @retirement_config.save
|
|
redirect_to retirement_path, notice: t(".created")
|
|
else
|
|
render :setup, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def edit
|
|
end
|
|
|
|
def update
|
|
if @retirement_config.update(retirement_config_params)
|
|
redirect_to retirement_path, notice: t(".updated")
|
|
else
|
|
render :edit, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def add_pension_entry
|
|
@pension_entry = @retirement_config.pension_entries.build(pension_entry_params)
|
|
|
|
if @pension_entry.save
|
|
redirect_to retirement_path, notice: t(".pension_entry_added")
|
|
else
|
|
@pension_entries = @retirement_config.pension_entries_with_gains
|
|
render :show, status: :unprocessable_entity
|
|
end
|
|
end
|
|
|
|
def destroy_pension_entry
|
|
@pension_entry = @retirement_config.pension_entries.find(params[:id])
|
|
@pension_entry.destroy!
|
|
redirect_to retirement_path, notice: t(".pension_entry_removed")
|
|
end
|
|
|
|
private
|
|
|
|
def set_retirement_config
|
|
@retirement_config = Current.family.retirement_config
|
|
|
|
unless @retirement_config
|
|
redirect_to setup_retirement_path
|
|
end
|
|
end
|
|
|
|
def require_retirement_config
|
|
@retirement_config = Current.family.retirement_config
|
|
|
|
unless @retirement_config
|
|
redirect_to setup_retirement_path, alert: t("retirement.show.setup_required")
|
|
end
|
|
end
|
|
|
|
def retirement_config_params
|
|
params.require(:retirement_config).permit(
|
|
:country, :pension_system, :birth_year, :retirement_age,
|
|
:target_monthly_income, :currency, :expected_return_pct,
|
|
:inflation_pct, :tax_rate_pct, :current_monthly_savings,
|
|
pension_params: {}
|
|
)
|
|
end
|
|
|
|
def pension_entry_params
|
|
params.require(:pension_entry).permit(
|
|
:recorded_at, :current_points, :current_monthly_pension,
|
|
:projected_monthly_pension, :notes,
|
|
data: {}
|
|
)
|
|
end
|
|
end
|