diff --git a/app/models/form/sales/pages/about_price.rb b/app/models/form/sales/pages/about_price.rb new file mode 100644 index 000000000..f5641791d --- /dev/null +++ b/app/models/form/sales/pages/about_price.rb @@ -0,0 +1,18 @@ +class Form::Sales::Pages::AboutPrice < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "about_price" + @header = "About the price of the property" + @description = "" + @subsection = subsection + @depends_on = [{ + "soctenant" => 2, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::Value.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/pages/about_price_not_rtb.rb b/app/models/form/sales/pages/about_price_not_rtb.rb new file mode 100644 index 000000000..795ed9226 --- /dev/null +++ b/app/models/form/sales/pages/about_price_not_rtb.rb @@ -0,0 +1,19 @@ +class Form::Sales::Pages::AboutPriceNotRtb < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "about_price_not_rtb" + @header = "About the price of the property" + @description = "" + @subsection = subsection + @depends_on = [{ + "right_to_buy?" => false, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::Value.new(nil, nil, self), + Form::Sales::Questions::Grant.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/pages/about_price_rtb.rb b/app/models/form/sales/pages/about_price_rtb.rb new file mode 100644 index 000000000..ec90afa01 --- /dev/null +++ b/app/models/form/sales/pages/about_price_rtb.rb @@ -0,0 +1,19 @@ +class Form::Sales::Pages::AboutPriceRtb < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "about_price_rtb" + @header = "About the price of the property" + @description = "" + @subsection = subsection + @depends_on = [{ + "right_to_buy?" => true, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::Value.new(nil, nil, self), + Form::Sales::Questions::Discount.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/pages/about_price_social_housing.rb b/app/models/form/sales/pages/about_price_social_housing.rb new file mode 100644 index 000000000..bf8045f3d --- /dev/null +++ b/app/models/form/sales/pages/about_price_social_housing.rb @@ -0,0 +1,19 @@ +class Form::Sales::Pages::AboutPriceSocialHousing < ::Form::Page + def initialize(id, hsh, subsection) + super + @id = "about_price_social_housing" + @header = "About the price of the property" + @description = "" + @subsection = subsection + @depends_on = [{ + "soctenant" => 1, + }] + end + + def questions + @questions ||= [ + Form::Sales::Questions::Value.new(nil, nil, self), + Form::Sales::Questions::Equity.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/discount.rb b/app/models/form/sales/questions/discount.rb new file mode 100644 index 000000000..4172ba4f2 --- /dev/null +++ b/app/models/form/sales/questions/discount.rb @@ -0,0 +1,17 @@ +class Form::Sales::Questions::Discount < ::Form::Question + def initialize(id, hsh, page) + super + @id = "discount" + @check_answer_label = "Percentage discount" + @header = "What was the percentage discount?" + @type = "numeric" + @page = page + @min = 0 + @max = 100 + @width = 5 + @suffix = "%" + @hint_text = "For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB) + If discount capped, enter capped % + If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given." + end +end diff --git a/app/models/form/sales/questions/equity.rb b/app/models/form/sales/questions/equity.rb new file mode 100644 index 000000000..585a14c36 --- /dev/null +++ b/app/models/form/sales/questions/equity.rb @@ -0,0 +1,15 @@ +class Form::Sales::Questions::Equity < ::Form::Question + def initialize(id, hsh, page) + super + @id = "equity" + @check_answer_label = "Initial percentage equity stake" + @header = "What was the initial percentage equity stake purchased?" + @type = "numeric" + @page = page + @min = 0 + @max = 100 + @width = 5 + @suffix = "%" + @hint_text = "Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)" + end +end diff --git a/app/models/form/sales/questions/grant.rb b/app/models/form/sales/questions/grant.rb new file mode 100644 index 000000000..edab388ac --- /dev/null +++ b/app/models/form/sales/questions/grant.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::Grant < ::Form::Question + def initialize(id, hsh, page) + super + @id = "grant" + @check_answer_label = "Amount of any loan, grant or subsidy" + @header = "What was the amount of any loan, grant, discount or subsidy given?" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + @hint_text = "For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)" + end +end diff --git a/app/models/form/sales/questions/value.rb b/app/models/form/sales/questions/value.rb new file mode 100644 index 000000000..0686d6610 --- /dev/null +++ b/app/models/form/sales/questions/value.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::Value < ::Form::Question + def initialize(id, hsh, page) + super + @id = "value" + @check_answer_label = "Full purchase price" + @header = "What was the full purchase price?" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + @hint_text = "Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)" + end +end diff --git a/app/models/form/sales/subsections/discounted_ownership_scheme.rb b/app/models/form/sales/subsections/discounted_ownership_scheme.rb index 2ce30c5bd..b432e0700 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -10,6 +10,8 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection def pages @pages ||= [ Form::Sales::Pages::AboutDeposit.new("about_deposit_discounted_ownership", nil, self), + Form::Sales::Pages::AboutPriceRtb.new("about_deposit_discounted_ownership", nil, self), + Form::Sales::Pages::AboutPriceNotRtb.new("about_deposit_discounted_ownership", 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 1837e5399..b22adc11e 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -15,6 +15,8 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::LaNominations.new(nil, nil, self), Form::Sales::Pages::BuyerPrevious.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.new(nil, nil, self), + Form::Sales::Pages::AboutPrice.new(nil, nil, self), + Form::Sales::Pages::AboutPriceSocialHousing.new(nil, nil, self), Form::Sales::Pages::AboutDeposit.new("about_deposit_shared_ownership", nil, self), Form::Sales::Pages::MonthlyRent.new(nil, nil, self), Form::Sales::Pages::ExchangeDate.new(nil, nil, self), diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index d3066974f..cda76d10e 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -111,4 +111,8 @@ class SalesLog < Log def income2_used_for_mortgage? inc2mort == 1 end + + def right_to_buy? + [9, 14, 27].include?(type) + end end diff --git a/db/migrate/20221222133600_add_price_fields.rb b/db/migrate/20221222133600_add_price_fields.rb new file mode 100644 index 000000000..43cc73ca4 --- /dev/null +++ b/db/migrate/20221222133600_add_price_fields.rb @@ -0,0 +1,10 @@ +class AddPriceFields < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :value, :decimal, precision: 10, scale: 2 + t.column :equity, :decimal, precision: 10, scale: 2 + t.column :discount, :decimal, precision: 10, scale: 2 + t.column :grant, :decimal, precision: 10, scale: 2 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index fff720aa3..f79423818 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -430,6 +430,10 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_22_133600) do t.decimal "cashdis", precision: 10, scale: 2 t.integer "lanomagr" t.integer "soctenant" + t.decimal "value", precision: 10, scale: 2 + t.decimal "equity", precision: 10, scale: 2 + t.decimal "discount", precision: 10, scale: 2 + t.decimal "grant", 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 0f1ea063c..922e265e4 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -70,6 +70,8 @@ FactoryBot.define do disabled { 2 } deposit { 10_000 } cashdis { 1_000 } + value { 110_000 } + grant { 1_000 } end end end diff --git a/spec/models/form/sales/pages/about_price_not_rtb_spec.rb b/spec/models/form/sales/pages/about_price_not_rtb_spec.rb new file mode 100644 index 000000000..584455d25 --- /dev/null +++ b/spec/models/form/sales/pages/about_price_not_rtb_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutPriceNotRtb, 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[value grant]) + end + + it "has the correct id" do + expect(page.id).to eq("about_price_not_rtb") + end + + it "has the correct header" do + expect(page.header).to eq("About the price of the property") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "right_to_buy?" => false, + }]) + end +end diff --git a/spec/models/form/sales/pages/about_price_rtb_spec.rb b/spec/models/form/sales/pages/about_price_rtb_spec.rb new file mode 100644 index 000000000..29e59f52c --- /dev/null +++ b/spec/models/form/sales/pages/about_price_rtb_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutPriceRtb, 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[value discount]) + end + + it "has the correct id" do + expect(page.id).to eq("about_price_rtb") + end + + it "has the correct header" do + expect(page.header).to eq("About the price of the property") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "right_to_buy?" => true, + }]) + end +end diff --git a/spec/models/form/sales/pages/about_price_social_housing_spec.rb b/spec/models/form/sales/pages/about_price_social_housing_spec.rb new file mode 100644 index 000000000..acdcd7dd3 --- /dev/null +++ b/spec/models/form/sales/pages/about_price_social_housing_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutPriceSocialHousing, 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[value equity]) + end + + it "has the correct id" do + expect(page.id).to eq("about_price_social_housing") + end + + it "has the correct header" do + expect(page.header).to eq("About the price of the property") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "soctenant" => 1, + }]) + end +end diff --git a/spec/models/form/sales/pages/about_price_spec.rb b/spec/models/form/sales/pages/about_price_spec.rb new file mode 100644 index 000000000..d6c45cd4b --- /dev/null +++ b/spec/models/form/sales/pages/about_price_spec.rb @@ -0,0 +1,35 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutPrice, 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[value]) + end + + it "has the correct id" do + expect(page.id).to eq("about_price") + end + + it "has the correct header" do + expect(page.header).to eq("About the price of the property") + end + + it "has the correct description" do + expect(page.description).to eq("") + end + + it "has correct depends_on" do + expect(page.depends_on).to eq([{ + "soctenant" => 2, + }]) + end +end diff --git a/spec/models/form/sales/questions/discount_spec.rb b/spec/models/form/sales/questions/discount_spec.rb new file mode 100644 index 000000000..977585d7b --- /dev/null +++ b/spec/models/form/sales/questions/discount_spec.rb @@ -0,0 +1,55 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Discount, 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("discount") + end + + it "has the correct header" do + expect(question.header).to eq("What was the percentage discount?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Percentage discount") + 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 eq("For Right to Buy (RTB), Preserved Right to Buy (PRTB), and Voluntary Right to Buy (VRTB) + If discount capped, enter capped % + If the property is being sold to an existing tenant under the RTB, PRTB, or VRTB schemes, enter the % discount from the full market value that is being given.") + end + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct suffix" do + expect(question.suffix).to eq("%") + end + + it "has correct min" do + expect(question.min).to eq(0) + end + + it "has correct max" do + expect(question.max).to eq(100) + end +end diff --git a/spec/models/form/sales/questions/equity_spec.rb b/spec/models/form/sales/questions/equity_spec.rb new file mode 100644 index 000000000..91308c745 --- /dev/null +++ b/spec/models/form/sales/questions/equity_spec.rb @@ -0,0 +1,53 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Equity, 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("equity") + end + + it "has the correct header" do + expect(question.header).to eq("What was the initial percentage equity stake purchased?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Initial percentage equity stake") + 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 eq("Enter the amount of initial equity held by the purchaser (for example, 25% or 50%)") + end + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct suffix" do + expect(question.suffix).to eq("%") + end + + it "has correct min" do + expect(question.min).to eq(0) + end + + it "has correct max" do + expect(question.max).to eq(100) + end +end diff --git a/spec/models/form/sales/questions/grant_spec.rb b/spec/models/form/sales/questions/grant_spec.rb new file mode 100644 index 000000000..d4e92f703 --- /dev/null +++ b/spec/models/form/sales/questions/grant_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Grant, 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("grant") + end + + it "has the correct header" do + expect(question.header).to eq("What was the amount of any loan, grant, discount or subsidy given?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Amount of any loan, grant or subsidy") + 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 eq("For all schemes except Right to Buy (RTB), Preserved Right to Buy (PRTB), Voluntary Right to Buy (VRTB)") + end + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct prefix" do + expect(question.prefix).to eq("£") + end + + it "has correct min" do + expect(question.min).to eq(0) + end +end diff --git a/spec/models/form/sales/questions/value_spec.rb b/spec/models/form/sales/questions/value_spec.rb new file mode 100644 index 000000000..f9da45db0 --- /dev/null +++ b/spec/models/form/sales/questions/value_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::Value, 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("value") + end + + it "has the correct header" do + expect(question.header).to eq("What was the full purchase price?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Full purchase price") + 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 eq("Enter the full purchase price of the property before any discounts are applied. For shared ownership, enter the full purchase price paid for 100% equity (this is equal to the value of the share owned by the PRP plus the value bought by the purchaser)") + end + + it "has correct width" do + expect(question.width).to eq(5) + end + + it "has correct prefix" do + expect(question.prefix).to eq("£") + end + + it "has correct min" do + expect(question.min).to eq(0) + 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 1a608031e..c3220bb51 100644 --- a/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/discounted_ownership_scheme_spec.rb @@ -13,7 +13,9 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model it "has correct pages" do expect(discounted_ownership_scheme.pages.map(&:id)).to eq( - %w[about_deposit_discounted_ownership], + %w[about_deposit_discounted_ownership + about_price_rtb + about_price_not_rtb], ) 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 8edabca53..ecabae734 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -20,6 +20,8 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do la_nominations buyer_previous previous_bedrooms + about_price + about_price_social_housing about_deposit_shared_ownership monthly_rent exchange_contracts diff --git a/spec/models/form_handler_spec.rb b/spec/models/form_handler_spec.rb index 253481886..880068012 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(79) + expect(form.pages.count).to eq(83) 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(79) + expect(form.pages.count).to eq(83) expect(form.name).to eq("2021_2022_sales") end end