Browse Source

Add outright sale guidance

pull/2549/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
565b75c658
  1. 1
      app/models/form/sales/questions/deposit_amount.rb
  2. 1
      app/models/form/sales/questions/mortgage_amount.rb
  3. 7
      app/models/form/sales/questions/purchase_price.rb
  4. 16
      app/models/validations/sales/sale_information_validations.rb
  5. 10
      app/views/form/guidance/_financial_calculations_outright_sale.html.erb

1
app/models/form/sales/questions/deposit_amount.rb

@ -36,5 +36,6 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
def top_guidance_partial def top_guidance_partial
return "financial_calculations_shared_ownership" if @ownershipsch == 1 return "financial_calculations_shared_ownership" if @ownershipsch == 1
return "financial_calculations_discounted_ownership" if @ownershipsch == 2 return "financial_calculations_discounted_ownership" if @ownershipsch == 2
return "financial_calculations_outright_sale" if @ownershipsch == 3
end end
end end

1
app/models/form/sales/questions/mortgage_amount.rb

@ -27,5 +27,6 @@ class Form::Sales::Questions::MortgageAmount < ::Form::Question
def top_guidance_partial def top_guidance_partial
return "financial_calculations_shared_ownership" if @ownershipsch == 1 return "financial_calculations_shared_ownership" if @ownershipsch == 1
return "financial_calculations_discounted_ownership" if @ownershipsch == 2 return "financial_calculations_discounted_ownership" if @ownershipsch == 2
return "financial_calculations_outright_sale" if @ownershipsch == 3
end end
end end

7
app/models/form/sales/questions/purchase_price.rb

@ -12,7 +12,7 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
@hint_text = hint_text @hint_text = hint_text
@ownership_sch = ownershipsch @ownership_sch = ownershipsch
@question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch] @question_number = QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.fetch(form.start_date.year, QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP.max_by { |k, _v| k }.last)[ownershipsch]
@top_guidance_partial = "financial_calculations_discounted_ownership" if ownershipsch == 2 @top_guidance_partial = top_guidance_partial
end end
QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = { QUESTION_NUMBER_FROM_YEAR_AND_OWNERSHIP = {
@ -25,4 +25,9 @@ class Form::Sales::Questions::PurchasePrice < ::Form::Question
"For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount" "For all schemes, including Right to Acquire (RTA), Right to Buy (RTB), Voluntary Right to Buy (VRTB) or Preserved Right to Buy (PRTB) sales, enter the full price of the property without any discount"
end end
def top_guidance_partial
return "financial_calculations_discounted_ownership" if @ownership_sch == 2
return "financial_calculations_outright_sale" if @ownership_sch == 3
end
end end

16
app/models/validations/sales/sale_information_validations.rb

@ -72,16 +72,16 @@ module Validations::Sales::SaleInformationValidations
if over_tolerance?(record.mortgage_and_deposit_total, record.value, 1) if over_tolerance?(record.mortgage_and_deposit_total, record.value, 1)
%i[mortgageused mortgage value deposit].each do |field| %i[mortgageused mortgage value deposit].each do |field|
record.errors.add field, I18n.t("validations.sale_information.outright_sale_value", record.errors.add field, I18n.t("validations.sale_information.outright_sale_value",
mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"),
mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "",
deposit: record.field_formatted_as_currency("deposit"), deposit: record.field_formatted_as_currency("deposit"),
value: record.field_formatted_as_currency("value")).html_safe value: record.field_formatted_as_currency("value")).html_safe
end end
record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value", record.errors.add :ownershipsch, :skip_bu_error, message: I18n.t("validations.sale_information.outright_sale_value",
mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"), mortgage_and_deposit_total: record.field_formatted_as_currency("mortgage_and_deposit_total"),
mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "", mortgage: record.mortgage&.positive? ? " (#{record.field_formatted_as_currency('mortgage')})" : "",
deposit: record.field_formatted_as_currency("deposit"), deposit: record.field_formatted_as_currency("deposit"),
value: record.field_formatted_as_currency("value")).html_safe value: record.field_formatted_as_currency("value")).html_safe
end end
end end

10
app/views/form/guidance/_financial_calculations_outright_sale.html.erb

@ -0,0 +1,10 @@
<% mortgage_page = log.form.get_question("mortgage", log).page %>
<% deposit_page = log.form.get_question("deposit", log).page %>
<%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body">
The mortgage amount <%= "(#{govuk_link_to 'Q113', send("#{log.class.name.underscore}_#{mortgage_page.id}_path", log)})".html_safe if mortgage_page.routed_to?(log, current_user) %>
and cash deposit <%= "(#{govuk_link_to 'Q116', send("#{log.class.name.underscore}_#{deposit_page.id}_path", log)})".html_safe if deposit_page.routed_to?(log, current_user) %>
added together must equal
the purchase price (<%= govuk_link_to "Q111", send("#{log.class.name.underscore}_#{log.form.get_question('value', log).page.id}_path", log) %>)
</p>
<% end %>
Loading…
Cancel
Save