diff --git a/app/models/form/sales/questions/deposit_amount.rb b/app/models/form/sales/questions/deposit_amount.rb index 8fba5a5c4..e7e78b5c0 100644 --- a/app/models/form/sales/questions/deposit_amount.rb +++ b/app/models/form/sales/questions/deposit_amount.rb @@ -13,7 +13,7 @@ class Form::Sales::Questions::DepositAmount < ::Form::Question @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] @optional = optional - @top_guidance_partial = "financial_calculations_shared_ownership" if ownershipsch == 1 + @top_guidance_partial = top_guidance_partial end def derived?(log) diff --git a/app/models/form/sales/questions/mortgageused.rb b/app/models/form/sales/questions/mortgageused.rb index 8dbe3a650..3c90a7856 100644 --- a/app/models/form/sales/questions/mortgageused.rb +++ b/app/models/form/sales/questions/mortgageused.rb @@ -8,6 +8,7 @@ class Form::Sales::Questions::Mortgageused < ::Form::Question @answer_options = ANSWER_OPTIONS @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] + @top_guidance_partial = "financial_calculations_discounted_ownership" if @ownershipsch == 2 end def displayed_answer_options(log, _user = nil) diff --git a/app/models/validations/sales/sale_information_validations.rb b/app/models/validations/sales/sale_information_validations.rb index 67ac52a48..d24e557ae 100644 --- a/app/models/validations/sales/sale_information_validations.rb +++ b/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? %i[mortgageused mortgage value deposit ownershipsch discount grant].each do |field| 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"), 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"), 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 diff --git a/app/views/form/_radio_question.html.erb b/app/views/form/_radio_question.html.erb index c15b31b58..41e98a1cc 100644 --- a/app/views/form/_radio_question.html.erb +++ b/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) %> <% if banner %> <%= govuk_notification_banner( diff --git a/app/views/form/guidance/_financial_calculations_dicsounted_ownership.html.erb b/app/views/form/guidance/_financial_calculations_dicsounted_ownership.html.erb deleted file mode 100644 index c16980b71..000000000 --- a/app/views/form/guidance/_financial_calculations_dicsounted_ownership.html.erb +++ /dev/null @@ -1,10 +0,0 @@ -<%= govuk_details(summary_text: "How the financial values are calculated") do %> -
- 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) %>) -
-<% end %> diff --git a/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb b/app/views/form/guidance/_financial_calculations_discounted_ownership.html.erb new file mode 100644 index 000000000..5c9db235d --- /dev/null +++ b/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 %> ++ 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) %> +
+<% end %>