diff --git a/app/models/derived_variables/sales_log_variables.rb b/app/models/derived_variables/sales_log_variables.rb index 5fff0900d..c9675d84a 100644 --- a/app/models/derived_variables/sales_log_variables.rb +++ b/app/models/derived_variables/sales_log_variables.rb @@ -7,5 +7,8 @@ module DerivedVariables::SalesLogVariables self.exyear = exdate.year end self.deposit = value if outright_sale? && mortgage_not_used? + if mscharge_known.present? && mscharge_known.zero? + self.mscharge = 0 + end end end diff --git a/app/models/form/sales/pages/leasehold_charges.rb b/app/models/form/sales/pages/leasehold_charges.rb new file mode 100644 index 000000000..7aed92db9 --- /dev/null +++ b/app/models/form/sales/pages/leasehold_charges.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::LeaseholdCharges < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::LeaseholdChargesKnown.new(nil, nil, self), + Form::Sales::Questions::LeaseholdCharges.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/leasehold_charges.rb b/app/models/form/sales/questions/leasehold_charges.rb new file mode 100644 index 000000000..eb19a7377 --- /dev/null +++ b/app/models/form/sales/questions/leasehold_charges.rb @@ -0,0 +1,13 @@ +class Form::Sales::Questions::LeaseholdCharges < ::Form::Question + def initialize(id, hsh, page) + super + @id = "mscharge" + @check_answer_label = "Monthly leasehold charges" + @header = "Enter the total monthly charge" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + end +end diff --git a/app/models/form/sales/questions/leasehold_charges_known.rb b/app/models/form/sales/questions/leasehold_charges_known.rb new file mode 100644 index 000000000..a94e7f63e --- /dev/null +++ b/app/models/form/sales/questions/leasehold_charges_known.rb @@ -0,0 +1,27 @@ +class Form::Sales::Questions::LeaseholdChargesKnown < ::Form::Question + def initialize(id, hsh, page) + super + @id = "mscharge_known" + @check_answer_label = "Monthly leasehold charges known?" + @header = "Does the property have any monthly leasehold charges?" + @hint_text = "For example, service and management charges" + @type = "radio" + @answer_options = ANSWER_OPTIONS + @page = page + @conditional_for = { + "mscharge" => [1], + } + @hidden_in_check_answers = { + "depends_on" => [ + { + "mscharge_known" => 1, + }, + ], + } + end + + ANSWER_OPTIONS = { + "1" => { "value" => "Yes" }, + "0" => { "value" => "No" }, + }.freeze +end diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 9181e9c41..827ecf1de 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -16,6 +16,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_discounted_ownership", nil, self), Form::Sales::Pages::DepositValueCheck.new("discounted_ownership_deposit_value_check", nil, self), + Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_discounted_ownership", nil, self), ] end diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 2b38841ba..a751c6734 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -14,6 +14,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self), Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_outright_sale", nil, self), Form::Sales::Pages::DepositValueCheck.new("outright_sale_deposit_value_check", nil, self), + Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_outright_sale", nil, self), ] end diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index c40fa9441..043459adb 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -24,6 +24,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::AboutDepositWithoutDiscount.new("about_deposit_shared_ownership", nil, self), Form::Sales::Pages::DepositValueCheck.new("shared_ownership_deposit_value_check", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), + Form::Sales::Pages::LeaseholdCharges.new("leasehold_charges_shared_ownership", nil, self), ] end diff --git a/db/migrate/20230103112225_add_mscharge_known_to_sales.rb b/db/migrate/20230103112225_add_mscharge_known_to_sales.rb new file mode 100644 index 000000000..cf09e8a52 --- /dev/null +++ b/db/migrate/20230103112225_add_mscharge_known_to_sales.rb @@ -0,0 +1,8 @@ +class AddMschargeKnownToSales < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :mscharge_known, :integer + t.column :mscharge, :decimal, precision: 10, scale: 2 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 49f59a503..8812128eb 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -461,6 +461,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_05_103733) do t.integer "mortgageused" t.integer "wchair" t.integer "armedforcesspouse" + t.integer "mscharge_known" + t.decimal "mscharge", precision: 10, scale: 2 t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id" t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 22d7320f4..08f37b3bf 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -90,6 +90,8 @@ FactoryBot.define do mortgageused { 1 } wchair { 1 } armedforcesspouse { 5 } + mscharge_known { 1 } + mscharge { 100 } end end end diff --git a/spec/models/form/sales/pages/leasehold_charges_spec.rb b/spec/models/form/sales/pages/leasehold_charges_spec.rb new file mode 100644 index 000000000..d35d1076b --- /dev/null +++ b/spec/models/form/sales/pages/leasehold_charges_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::LeaseholdCharges, type: :model do + subject(:page) { described_class.new(page_id, page_definition, subsection) } + + let(:page_id) { nil } + let(:page_definition) { nil } + let(:subsection) { instance_double(Form::Subsection) } + + it "has correct subsection" do + expect(page.subsection).to eq(subsection) + end + + it "has correct questions" do + expect(page.questions.map(&:id)).to eq(%w[mscharge_known mscharge]) + end + + it "has the correct id" do + expect(page.id).to eq(nil) + end + + it "has the correct header" do + expect(page.header).to eq("") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to be_nil + end +end diff --git a/spec/models/form/sales/questions/leasehold_charges_known_spec.rb b/spec/models/form/sales/questions/leasehold_charges_known_spec.rb new file mode 100644 index 000000000..d47b535eb --- /dev/null +++ b/spec/models/form/sales/questions/leasehold_charges_known_spec.rb @@ -0,0 +1,60 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::LeaseholdChargesKnown, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("mscharge_known") + end + + it "has the correct header" do + expect(question.header).to eq("Does the property have any monthly leasehold charges?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Monthly leasehold charges known?") + end + + it "has the correct type" do + expect(question.type).to eq("radio") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct answer_options" do + expect(question.answer_options).to eq({ + "0" => { "value" => "No" }, + "1" => { "value" => "Yes" }, + }) + end + + it "has correct conditional for" do + expect(question.conditional_for).to eq({ + "mscharge" => [1], + }) + end + + it "has the correct hint" do + expect(question.hint_text).to eq("For example, service and management charges") + end + + it "has correct hidden_in_check_answers for" do + expect(question.hidden_in_check_answers).to eq({ + "depends_on" => [ + { + "mscharge_known" => 1, + }, + ], + }) + end +end diff --git a/spec/models/form/sales/questions/leasehold_charges_spec.rb b/spec/models/form/sales/questions/leasehold_charges_spec.rb new file mode 100644 index 000000000..a06fc9975 --- /dev/null +++ b/spec/models/form/sales/questions/leasehold_charges_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::LeaseholdCharges, type: :model do + subject(:question) { described_class.new(question_id, question_definition, page) } + + let(:question_id) { nil } + let(:question_definition) { nil } + let(:page) { instance_double(Form::Page) } + + it "has correct page" do + expect(question.page).to eq(page) + end + + it "has the correct id" do + expect(question.id).to eq("mscharge") + end + + it "has the correct header" do + expect(question.header).to eq("Enter the total monthly charge") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Monthly leasehold charges") + end + + it "has the correct type" do + expect(question.type).to eq("numeric") + end + + it "is not marked as derived" do + expect(question.derived?).to be false + end + + it "has the correct hint" do + expect(question.hint_text).to be_nil + end + + it "has the correct width" do + expect(question.width).to eq(5) + end + + it "has the correct min" do + expect(question.min).to eq(0) + end + + it "has the correct prefix" do + expect(question.prefix).to eq("£") + end +end diff --git a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb index f6c05aeb6..e30e5bfde 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -21,6 +21,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model mortgage_amount_discounted_ownership about_deposit_discounted_ownership discounted_ownership_deposit_value_check + leasehold_charges_discounted_ownership ], ) end diff --git a/spec/models/form/sales/subsections/outright_sale_spec.rb b/spec/models/form/sales/subsections/outright_sale_spec.rb index d39dee44c..06b394f27 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/spec/models/form/sales/subsections/outright_sale_spec.rb @@ -13,11 +13,14 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do it "has correct pages" do expect(outright_sale.pages.map(&:id)).to eq( - %w[purchase_price - mortgage_used_outright_sale - mortgage_amount_outright_sale - about_deposit_outright_sale - outright_sale_deposit_value_check], + %w[ + purchase_price + mortgage_used_outright_sale + mortgage_amount_outright_sale + about_deposit_outright_sale + outright_sale_deposit_value_check + leasehold_charges_outright_sale + ], ) end diff --git a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb index e95579df3..06f98ba09 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -29,6 +29,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do about_deposit_shared_ownership shared_ownership_deposit_value_check monthly_rent + leasehold_charges_shared_ownership ], ) end diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 7d5339806..4fef52c66 100644 --- a/spec/models/form_handler_spec.rb +++ b/spec/models/form_handler_spec.rb @@ -52,14 +52,14 @@ RSpec.describe FormHandler do it "is able to load a current sales form" do form = form_handler.get_form("current_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(122) + expect(form.pages.count).to eq(125) expect(form.name).to eq("2022_2023_sales") end it "is able to load a previous sales form" do form = form_handler.get_form("previous_sales") expect(form).to be_a(Form) - expect(form.pages.count).to eq(122) + expect(form.pages.count).to eq(125) expect(form.name).to eq("2021_2022_sales") end end