From 0f12080c580bdcbbb04d88c8f149d8e7da05b934 Mon Sep 17 00:00:00 2001 From: natdeanlewissoftwire Date: Wed, 4 Jan 2023 10:32:38 +0000 Subject: [PATCH] feat: add question and page and update db --- app/models/form/sales/pages/mortgage_amount.rb | 14 ++++++++++++++ app/models/form/sales/questions/mortgage_amount.rb | 14 ++++++++++++++ .../subsections/discounted_ownership_scheme.rb | 1 + app/models/form/sales/subsections/outright_sale.rb | 1 + .../sales/subsections/shared_ownership_scheme.rb | 1 + .../20230104093057_change_mortgage_to_float.rb | 13 +++++++++++++ db/schema.rb | 4 ++-- 7 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 app/models/form/sales/pages/mortgage_amount.rb create mode 100644 app/models/form/sales/questions/mortgage_amount.rb create mode 100644 db/migrate/20230104093057_change_mortgage_to_float.rb diff --git a/app/models/form/sales/pages/mortgage_amount.rb b/app/models/form/sales/pages/mortgage_amount.rb new file mode 100644 index 000000000..1c80b2f52 --- /dev/null +++ b/app/models/form/sales/pages/mortgage_amount.rb @@ -0,0 +1,14 @@ +class Form::Sales::Pages::MortgageAmount < ::Form::Page + def initialize(id, hsh, subsection) + super + @header = "Mortgage Amount" + @description = "" + @subsection = subsection + end + + def questions + @questions ||= [ + Form::Sales::Questions::MortgageAmount.new(nil, nil, self), + ] + end +end diff --git a/app/models/form/sales/questions/mortgage_amount.rb b/app/models/form/sales/questions/mortgage_amount.rb new file mode 100644 index 000000000..c385563c5 --- /dev/null +++ b/app/models/form/sales/questions/mortgage_amount.rb @@ -0,0 +1,14 @@ +class Form::Sales::Questions::MortgageAmount < ::Form::Question + def initialize(id, hsh, page) + super + @id = "mortgage" + @check_answer_label = "Mortgage amount" + @header = "What is the mortgage amount?" + @type = "numeric" + @page = page + @min = 0 + @width = 5 + @prefix = "£" + @hint_text = "" + 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 b1a485382..1fce2f1bf 100644 --- a/app/models/form/sales/subsections/discounted_ownership_scheme.rb +++ b/app/models/form/sales/subsections/discounted_ownership_scheme.rb @@ -12,6 +12,7 @@ class Form::Sales::Subsections::DiscountedOwnershipScheme < ::Form::Subsection Form::Sales::Pages::LivingBeforePurchase.new("living_before_purchase_discounted_ownership", nil, self), Form::Sales::Pages::AboutPriceRtb.new(nil, nil, self), Form::Sales::Pages::AboutPriceNotRtb.new(nil, nil, self), + Form::Sales::Pages::MortgageAmount.new("mortgage_amount_discounted_ownership", nil, self), Form::Sales::Pages::AboutDeposit.new("about_deposit_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 cc566c396..4b95d04c2 100644 --- a/app/models/form/sales/subsections/outright_sale.rb +++ b/app/models/form/sales/subsections/outright_sale.rb @@ -9,6 +9,7 @@ class Form::Sales::Subsections::OutrightSale < ::Form::Subsection def pages @pages ||= [ + Form::Sales::Pages::MortgageAmount.new("mortgage_amount_outright_sale", nil, self), Form::Sales::Pages::AboutDeposit.new("about_deposit_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 74dba4351..750d9de88 100644 --- a/app/models/form/sales/subsections/shared_ownership_scheme.rb +++ b/app/models/form/sales/subsections/shared_ownership_scheme.rb @@ -18,6 +18,7 @@ class Form::Sales::Subsections::SharedOwnershipScheme < ::Form::Subsection 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::MortgageAmount.new("mortgage_amount_shared_ownership", 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/20230104093057_change_mortgage_to_float.rb b/db/migrate/20230104093057_change_mortgage_to_float.rb new file mode 100644 index 000000000..201031288 --- /dev/null +++ b/db/migrate/20230104093057_change_mortgage_to_float.rb @@ -0,0 +1,13 @@ +class ChangeMortgageToFloat < ActiveRecord::Migration[7.0] + def self.up + change_table :sales_logs do |t| + t.change :mortgage, :decimal, precision: 10, scale: 2 + end + end + + def self.down + change_table :sales_logs do |t| + t.change :mortgage, :integer + end + end +end diff --git a/db/schema.rb b/db/schema.rb index 6a3ddbcdf..ee62f5656 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.0].define(version: 2023_01_03_094948) do +ActiveRecord::Schema[7.0].define(version: 2023_01_04_093057) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -408,7 +408,7 @@ ActiveRecord::Schema[7.0].define(version: 2023_01_03_094948) do t.bigint "updated_by_id" t.integer "details_known_1" t.integer "income1_value_check" - t.integer "mortgage" + t.decimal "mortgage", precision: 10, scale: 2 t.integer "inc2mort" t.integer "mortgage_value_check" t.integer "ecstat3"