diff --git a/app/models/form/sales/pages/about_deposit.rb b/app/models/form/sales/pages/about_deposit.rb new file mode 100644 index 000000000..415908567 --- /dev/null +++ b/app/models/form/sales/pages/about_deposit.rb @@ -0,0 +1,15 @@ +class Form::Sales::Pages::AboutDeposit < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "About the deposit" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::DepositAmount.new(nil, nil, self), + Form::Sales::Questions::DepositDiscount.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb new file mode 100644 index 000000000..8252ad8d7 --- /dev/null +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::DepositAmount < ::Form::Question + def initialize(id, hsh, page) + super + @id = "deposit" + @check_answer_label = "Cash deposit" + @header = "How much cash deposit was paid on the property?" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + @hint_text = "Enter the total cash sum paid by the buyer towards the property that was not funded by the mortgage" + end +end diff --git a/app/models/form/sales/questions/deposit_discount.rb b/app/models/form/sales/questions/deposit_discount.rb new file mode 100644 index 000000000..9496f90fd --- /dev/null +++ b/app/models/form/sales/questions/deposit_discount.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::DepositDiscount < ::Form::Question + def initialize(id, hsh, page) + super + @id = "cashdis" + @check_answer_label = "Cash discount through SocialHomeBuy" + @header = "How much cash discount was given through Social HomeBuy?" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + @hint_text = "Enter the total cash discount given on the property being purchased through the Social HomeBuy scheme" + 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 ea67d3566..2ce30c5bd 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -8,7 +8,9 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection end def pages - @pages ||= [] + @pages ||= [ + Form::Sales::Pages::AboutDeposit.new("about_deposit_discounted_ownership", nil, self), + ] end def displayed_in_tasklist?(log) diff --git a/app/models/form/sales/subsections/outright_sale.rb b/app/models/form/sales/subsections/outright_sale.rb index 82f5bd055..cc566c396 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -8,7 +8,9 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection end def pages - @pages ||= [] + @pages ||= [ + Form::Sales::Pages::AboutDeposit.new("about_deposit_outright_sale", nil, self), + ] end def displayed_in_tasklist?(log) diff --git a/app/models/form/sales/subsections/shared_ownership_scheme.rb b/app/models/form/sales/subsections/shared_ownership_scheme.rb index 28abf2d87..03cb88de4 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -13,6 +13,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::AboutStaircase.new(nil, nil, self), Form::Sales::Pages::LaNominations.new(nil, nil, self), Form::Sales::Pages::PreviousBedrooms.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/db/migrate/20221221164308_add_deposit_fields_to_sales.rb b/db/migrate/20221221164308_add_deposit_fields_to_sales.rb new file mode 100644 index 000000000..82087110f --- /dev/null +++ b/db/migrate/20221221164308_add_deposit_fields_to_sales.rb @@ -0,0 +1,8 @@ +class AddDepositFieldsToSales < ActiveRecord::Migration[7.0] + def change + change_table :sales_logs, bulk: true do |t| + t.column :deposit, :decimal, precision: 10, scale: 2 + t.column :cashdis, :decimal, precision: 10, scale: 2 + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6fd6777a2..0b5b66908 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -405,12 +405,12 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_22_081402) do t.integer "savings" t.integer "prevown" t.string "sex3" - t.bigint "updated_by_id" t.integer "details_known_1" t.integer "income1_value_check" t.integer "mortgage" t.integer "inc2mort" t.integer "mortgage_value_check" + t.bigint "updated_by_id" t.integer "ecstat3" t.integer "ecstat4" t.integer "ecstat5" @@ -424,6 +424,8 @@ ActiveRecord::Schema[7.0].define(version: 2022_12_22_081402) do t.integer "exmonth" t.integer "exyear" t.integer "resale" + t.decimal "deposit", precision: 10, scale: 2 + t.decimal "cashdis", precision: 10, scale: 2 t.decimal "mrent", precision: 10, scale: 2 t.integer "lanomagr" t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id" diff --git a/spec/factories/sales_log.rb b/spec/factories/sales_log.rb index 69cc54d85..b2d07496c 100644 --- a/spec/factories/sales_log.rb +++ b/spec/factories/sales_log.rb @@ -67,6 +67,8 @@ FactoryBot.define do ecstat4 { 3 } ecstat5 { 2 } ecstat6 { 1 } + deposit { 10_000 } + cashdis { 1_000 } end end end diff --git a/spec/models/form/sales/pages/about_deposit_spec.rb b/spec/models/form/sales/pages/about_deposit_spec.rb new file mode 100644 index 000000000..e22cf1e76 --- /dev/null +++ b/spec/models/form/sales/pages/about_deposit_spec.rb @@ -0,0 +1,33 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Pages::AboutDeposit, 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[deposit cashdis]) + 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("About the deposit") + 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/deposit_amount_spec.rb b/spec/models/form/sales/questions/deposit_amount_spec.rb new file mode 100644 index 000000000..9eaa628cf --- /dev/null +++ b/spec/models/form/sales/questions/deposit_amount_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::DepositAmount, 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("deposit") + end + + it "has the correct header" do + expect(question.header).to eq("How much cash deposit was paid on the property?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Cash deposit") + 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 total cash sum paid by the buyer towards the property that was not funded by the mortgage") + 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/deposit_discount_spec.rb b/spec/models/form/sales/questions/deposit_discount_spec.rb new file mode 100644 index 000000000..b0f8899bf --- /dev/null +++ b/spec/models/form/sales/questions/deposit_discount_spec.rb @@ -0,0 +1,49 @@ +require "rails_helper" + +RSpec.describe Form::Sales::Questions::DepositDiscount, 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("cashdis") + end + + it "has the correct header" do + expect(question.header).to eq("How much cash discount was given through Social HomeBuy?") + end + + it "has the correct check_answer_label" do + expect(question.check_answer_label).to eq("Cash discount through SocialHomeBuy") + 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 total cash discount given on the property being purchased through the Social HomeBuy scheme") + 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 93b905b05..1a608031e 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,7 @@ RSpec.describe Form::Sales::Subsections::DiscountedOwnershipScheme, type: :model it "has correct pages" do expect(discounted_ownership_scheme.pages.map(&:id)).to eq( - %w[], + %w[about_deposit_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 7e29e7fac..75f47bbc0 100644 --- a/spec/models/form/sales/subsections/outright_sale_spec.rb +++ b/spec/models/form/sales/subsections/outright_sale_spec.rb @@ -13,7 +13,7 @@ RSpec.describe Form::Sales::Subsections::OutrightSale, type: :model do it "has correct pages" do expect(outright_sale.pages.map(&:id)).to eq( - %w[], + %w[about_deposit_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 cc951a8bd..c56e5d3a2 100644 --- a/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb +++ b/spec/models/form/sales/subsections/shared_ownership_scheme_spec.rb @@ -18,6 +18,7 @@ RSpec.describe Form::Sales::Subsections::SharedOwnershipScheme, type: :model do about_staircasing la_nominations previous_bedrooms + 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 3ac4681ff..e9ecc340e 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(74) + expect(form.pages.count).to eq(77) 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(74) + expect(form.pages.count).to eq(77) expect(form.name).to eq("2021_2022_sales") end end