Browse Source

Update guidance partial and validation

pull/2547/head
Kat 2 years ago
parent
commit
a9a7b94ed9
  1. 2
      app/models/form/sales/questions/deposit_amount.rb
  2. 1
      app/models/form/sales/questions/mortgageused.rb
  3. 4
      app/models/validations/sales/sale_information_validations.rb
  4. 2
      app/views/form/_radio_question.html.erb
  5. 10
      app/views/form/guidance/_financial_calculations_dicsounted_ownership.html.erb
  6. 13
      app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb

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

@ -13,7 +13,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question
@ownershipsch = ownershipsch @ownershipsch = 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]
@optional = optional @optional = optional
@top_guidance_partial = "financial_calculations_shared_ownership" if ownershipsch == 1 @top_guidance_partial = top_guidance_partial
end end
def derived?(log) def derived?(log)

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

@ -8,6 +8,7 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@ownershipsch = ownershipsch @ownershipsch = 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
end end
def displayed_answer_options(log, _user = nil) def displayed_answer_options(log, _user = nil)

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

@ -53,12 +53,12 @@ module Validations::Sales::SaleInformationValidations
if over_tolerance?(record.mortgage_deposit_and_grant_total, record.value_with_discount, tolerance, strict: !record.discount.nil?) && record.discounted_ownership_sale? if over_tolerance?(record.mortgage_deposit_and_grant_total, record.value_with_discount, tolerance, strict: !record.discount.nil?) && record.discounted_ownership_sale?
%i[mortgageused mortgage value deposit ownershipsch discount grant].each do |field| %i[mortgageused mortgage value deposit ownershipsch discount grant].each do |field|
record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value", record.errors.add field, I18n.t("validations.sale_information.discounted_ownership_value",
mortgage: record.mortgage.present? ? " (#{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"),
grant: record.grant.present? ? " (#{record.field_formatted_as_currency('grant')})" : "", grant: record.grant.present? ? " (#{record.field_formatted_as_currency('grant')})" : "",
mortgage_deposit_and_grant_total: record.field_formatted_as_currency("mortgage_deposit_and_grant_total"), mortgage_deposit_and_grant_total: record.field_formatted_as_currency("mortgage_deposit_and_grant_total"),
discount_sentence: record.discount.present? ? " (#{record.field_formatted_as_currency('value')}) times by the discount (#{record.discount}%)" : "", discount_sentence: record.discount.present? ? " (#{record.field_formatted_as_currency('value')}) times by the discount (#{record.discount}%)" : "",
value_with_discount: record.field_formatted_as_currency("value_with_discount")) value_with_discount: record.field_formatted_as_currency("value_with_discount")).html_safe
end end
end end
end end

2
app/views/form/_radio_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %> <%= render partial: "form/guidance/#{question.top_guidance_partial}", locals: { log: @log } if question.top_guidance? %>
<% banner = question.notification_banner(@log) %> <% banner = question.notification_banner(@log) %>
<% if banner %> <% if banner %>
<%= govuk_notification_banner( <%= govuk_notification_banner(

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

@ -1,10 +0,0 @@
<%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body">
The mortgage amount (<%= govuk_link_to "Q105", send("#{log.class.name.underscore}_#{log.form.get_question('mortgage', log).page.id}_path", log) %>),
cash deposit (<%= govuk_link_to "Q109", send("#{log.class.name.underscore}_#{log.form.get_question('deposit', log).page.id}_path", log) %>)
and grant (<%= govuk_link_to "Q102", send("#{log.class.name.underscore}_#{log.form.get_question('grant', log).page.id}_path", log) %>)
added together must equal
the purchase price (<%= govuk_link_to "Q101", send("#{log.class.name.underscore}_#{log.form.get_question('value', log).page.id}_path", log) %>)
multiplied by the discount stake (<%= govuk_link_to "103", send("#{log.class.name.underscore}_#{log.form.get_question('discount', log).page.id}_path", log) %>)
</p>
<% end %>

13
app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb

@ -0,0 +1,13 @@
<% grant_page = log.form.get_question("grant", log).page %>
<% mortgage_page = log.form.get_question("mortgage", log).page %>
<% discount_page = log.form.get_question("discount", log).page %>
<%= govuk_details(summary_text: "How the financial values are calculated") do %>
<p class="govuk-body">
The mortgage amount <%= "(#{govuk_link_to 'Q105', send("#{log.class.name.underscore}_#{mortgage_page.id}_path", log)})".html_safe if mortgage_page.routed_to?(log, current_user) %>
cash deposit (<%= govuk_link_to "Q109", send("#{log.class.name.underscore}_#{log.form.get_question('deposit', log).page.id}_path", log) %>)
and grant <%= "(#{govuk_link_to 'Q102', send("#{log.class.name.underscore}_#{grant_page.id}_path", log)})".html_safe if grant_page.routed_to?(log, current_user) %>
added together must equal
the purchase price (<%= govuk_link_to "Q101", send("#{log.class.name.underscore}_#{log.form.get_question('value', log).page.id}_path", log) %>)
multiplied by the discount stake <%= "(#{govuk_link_to '103', send("#{log.class.name.underscore}_#{discount_page.id}_path", log)})".html_safe if discount_page.routed_to?(log, current_user) %>
</p>
<% end %>
Loading…
Cancel
Save