From f68c67125b86940df6aecef88d89c4a44e0c8baa Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 5 Apr 2023 14:32:39 +0100 Subject: [PATCH] feat: combined income value check --- .../pages/combined_income_max_value_check.rb | 28 +++++++++++++++++++ .../questions/combined_income_value_check.rb | 25 +++++++++++++++++ .../income_benefits_and_savings.rb | 2 ++ app/models/sales_log.rb | 4 +++ config/locales/en.yml | 2 +- ...ombined_income_value_check_to_sales_log.rb | 5 ++++ db/schema.rb | 1 + 7 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 app/models/form/sales/pages/combined_income_max_value_check.rb create mode 100644 app/models/form/sales/questions/combined_income_value_check.rb create mode 100644 db/migrate/20230405132300_add_combined_income_value_check_to_sales_log.rb diff --git a/app/models/form/sales/pages/combined_income_max_value_check.rb b/app/models/form/sales/pages/combined_income_max_value_check.rb new file mode 100644 index 000000000..ae26ab4a8 --- /dev/null +++ b/app/models/form/sales/pages/combined_income_max_value_check.rb @@ -0,0 +1,28 @@ +class Form::Sales::Pages::CombinedIncomeMaxValueCheck < ::Form::Page + def initialize(id, hsh, subsection, buyer_index:) + super(id, hsh, subsection) + @depends_on = [ + { + "combined_income_over_soft_max?" => true, + }, + ] + @title_text = { + "translation" => "soft_validations.income.over_soft_max_for_la_combined", + "arguments" => [ + { + "key" => "field_formatted_as_currency", + "arguments_for_key" => "combined_income", + "i18n_template" => "combined_income", + } + ], + } + @informative_text = {} + @buyer_index = buyer_index + end + + def questions + @questions ||= [ + Form::Sales::Questions::CombinedIncomeValueCheck.new(nil, nil, self, buyer_index: @buyer_index), + ] + end +end diff --git a/app/models/form/sales/questions/combined_income_value_check.rb b/app/models/form/sales/questions/combined_income_value_check.rb new file mode 100644 index 000000000..b824e770d --- /dev/null +++ b/app/models/form/sales/questions/combined_income_value_check.rb @@ -0,0 +1,25 @@ +class Form::Sales::Questions::CombinedIncomeValueCheck < ::Form::Question + def initialize(id, hsh, page, buyer_index:) + super(id, hsh, page) + @id = "combined_income_value_check" + @check_answer_label = "Combined income confirmation" + @header = "Are you sure this is correct?" + @type = "interruption_screen" + @answer_options = { + "0" => { "value" => "Yes" }, + "1" => { "value" => "No" }, + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "combined_income_value_check" => 0, + }, + { + "combined_income_value_check" => 1, + }, + ], + } + @check_answers_card_number = buyer_index + @page = page + end +end diff --git a/app/models/form/sales/subsections/income_benefits_and_savings.rb b/app/models/form/sales/subsections/income_benefits_and_savings.rb index e2728b6e2..b52c444d3 100644 --- a/app/models/form/sales/subsections/income_benefits_and_savings.rb +++ b/app/models/form/sales/subsections/income_benefits_and_savings.rb @@ -11,6 +11,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::Buyer1Income.new(nil, nil, self), Form::Sales::Pages::Buyer1IncomeMinValueCheck.new("buyer_1_income_min_value_check", nil, self), Form::Sales::Pages::Buyer1IncomeMaxValueCheck.new("buyer_1_income_max_value_check", nil, self), + Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("buyer_1_combined_income_max_value_check", nil, self, buyer_index: 1), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_income_mortgage_value_check", nil, self, 1), Form::Sales::Pages::Buyer1Mortgage.new(nil, nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_1_mortgage_value_check", nil, self, 1), @@ -18,6 +19,7 @@ class Form::Sales::Subsections::IncomeBenefitsAndSavings < ::Form::Subsection Form::Sales::Pages::MortgageValueCheck.new("buyer_2_income_mortgage_value_check", nil, self, 2), Form::Sales::Pages::Buyer2IncomeMinValueCheck.new("buyer_2_income_min_value_check", nil, self), Form::Sales::Pages::Buyer2IncomeMaxValueCheck.new("buyer_2_income_max_value_check", nil, self), + Form::Sales::Pages::CombinedIncomeMaxValueCheck.new("buyer_2_combined_income_max_value_check", nil, self, buyer_index: 2), Form::Sales::Pages::Buyer2Mortgage.new(nil, nil, self), Form::Sales::Pages::MortgageValueCheck.new("buyer_2_mortgage_value_check", nil, self, 2), Form::Sales::Pages::HousingBenefits.new("housing_benefits_joint_purchase", nil, self, joint_purchase: true), diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index b0aed712a..0ab964bb6 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -349,4 +349,8 @@ class SalesLog < Log def beds_for_la_sale_range beds.nil? ? nil : [beds, LaSaleRange::MAX_BEDS].min end + + def combined_income + income1 + income2 + end end diff --git a/config/locales/en.yml b/config/locales/en.yml index d2941e9eb..5976a1fae 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -511,7 +511,7 @@ en: income: under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" over_soft_max_for_la: "You told us the income of this buyer is %{income}, which seems high." - over_soft_max_for_la_combined: "You told us the income of this household is %{income}, which seems high." + over_soft_max_for_la_combined: "You told us the income of this household is %{combined_income}, which seems high." rent: outside_range_title: "You told us the rent is %{brent}" min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}." diff --git a/db/migrate/20230405132300_add_combined_income_value_check_to_sales_log.rb b/db/migrate/20230405132300_add_combined_income_value_check_to_sales_log.rb new file mode 100644 index 000000000..bdf052288 --- /dev/null +++ b/db/migrate/20230405132300_add_combined_income_value_check_to_sales_log.rb @@ -0,0 +1,5 @@ +class AddCombinedIncomeValueCheckToSalesLog < ActiveRecord::Migration[7.0] + def change + add_column :sales_logs, :combined_income_value_check, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index 2c00fb921..55b733a6a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -572,6 +572,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_03_31_094840) do t.integer "nationalbuy2" t.integer "discounted_sale_value_check" t.integer "student_not_child_value_check" + t.integer "combined_income_value_check" t.index ["bulk_upload_id"], name: "index_sales_logs_on_bulk_upload_id" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["old_id"], name: "index_sales_logs_on_old_id", unique: true