2025-01-16 14:36:37 -05:00
|
|
|
class BudgetsController < ApplicationController
|
|
|
|
before_action :set_budget, only: %i[show edit update]
|
|
|
|
|
|
|
|
def index
|
|
|
|
redirect_to_current_month_budget
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
render layout: "wizard"
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@budget.update!(budget_params)
|
|
|
|
redirect_to budget_budget_categories_path(@budget)
|
|
|
|
end
|
|
|
|
|
|
|
|
def picker
|
|
|
|
render partial: "budgets/picker", locals: {
|
|
|
|
family: Current.family,
|
|
|
|
year: params[:year].to_i || Date.current.year
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2025-02-25 10:14:07 -06:00
|
|
|
|
2025-01-16 14:36:37 -05:00
|
|
|
def budget_create_params
|
|
|
|
params.require(:budget).permit(:start_date)
|
|
|
|
end
|
|
|
|
|
|
|
|
def budget_params
|
|
|
|
params.require(:budget).permit(:budgeted_spending, :expected_income)
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_budget
|
2025-02-21 11:57:59 -05:00
|
|
|
start_date = Budget.param_to_date(params[:month_year])
|
|
|
|
@budget = Budget.find_or_bootstrap(Current.family, start_date: start_date)
|
|
|
|
raise ActiveRecord::RecordNotFound unless @budget
|
2025-01-16 14:36:37 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def redirect_to_current_month_budget
|
2025-02-21 11:57:59 -05:00
|
|
|
current_budget = Budget.find_or_bootstrap(Current.family, start_date: Date.current)
|
2025-01-16 14:36:37 -05:00
|
|
|
redirect_to budget_path(current_budget)
|
|
|
|
end
|
|
|
|
end
|