From 428eae8c8f98a50e780a54969a1588202a5b9c56 Mon Sep 17 00:00:00 2001 From: Arthur Campbell Date: Thu, 2 Feb 2023 16:46:29 +0000 Subject: [PATCH] enable currency formatting of numbers for inserting into informative_text or title_text --- app/models/form/sales/pages/buyer1_income_value_check.rb | 3 ++- app/models/form/sales/pages/buyer2_income_value_check.rb | 3 ++- app/models/log.rb | 4 ++++ app/models/sales_log.rb | 8 +++++++- config/locales/en.yml | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/models/form/sales/pages/buyer1_income_value_check.rb b/app/models/form/sales/pages/buyer1_income_value_check.rb index 8debbb1f3..ab1edb936 100644 --- a/app/models/form/sales/pages/buyer1_income_value_check.rb +++ b/app/models/form/sales/pages/buyer1_income_value_check.rb @@ -10,7 +10,8 @@ class Form::Sales::Pages::Buyer1IncomeValueCheck < ::Form::Page "translation" => "soft_validations.income.under_soft_min_for_economic_status", "arguments" => [ { - "key" => "income1", + "key" => "field_formatted_as_currency", + "arguments_for_public_send" => "income1", "i18n_template" => "income", }, { diff --git a/app/models/form/sales/pages/buyer2_income_value_check.rb b/app/models/form/sales/pages/buyer2_income_value_check.rb index 0262a4283..8037dc20a 100644 --- a/app/models/form/sales/pages/buyer2_income_value_check.rb +++ b/app/models/form/sales/pages/buyer2_income_value_check.rb @@ -13,7 +13,8 @@ class Form::Sales::Pages::Buyer2IncomeValueCheck < ::Form::Page "translation" => "soft_validations.income.under_soft_min_for_economic_status", "arguments" => [ { - "key" => "income2", + "key" => "field_formatted_as_currency", + "arguments_for_public_send" => "income2", "i18n_template" => "income", }, { diff --git a/app/models/log.rb b/app/models/log.rb index 1b43fd1cb..05ef430ba 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -143,4 +143,8 @@ private self[is_inferred_key] = false self[postcode_key] = nil end + + def format_as_currency(num_string) + ActionController::Base.helpers.number_to_currency(num_string, unit: "£") + end end diff --git a/app/models/sales_log.rb b/app/models/sales_log.rb index ee9e6bef5..e0fc0a2fa 100644 --- a/app/models/sales_log.rb +++ b/app/models/sales_log.rb @@ -254,6 +254,12 @@ class SalesLog < Log return unless ALLOWED_INCOME_RANGES_SALES - ALLOWED_INCOME_RANGES_SALES[economic_status_code]&.soft_min + soft_min = ALLOWED_INCOME_RANGES_SALES[economic_status_code]&.soft_min + format_as_currency(soft_min) + end + + def field_formatted_as_currency(field_name) + field_value = public_send(field_name) + format_as_currency(field_value) end end diff --git a/config/locales/en.yml b/config/locales/en.yml index 195abd838..3d66010e3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -459,7 +459,7 @@ en: in_soft_max_range: message: "Net income is higher than expected based on the lead tenant’s working situation. Are you sure this is correct?" income: - under_soft_min_for_economic_status: "You said income was £%{income}, which is below this working situation's minimum (£%{minimum})" + under_soft_min_for_economic_status: "You said income was %{income}, which is below this working situation's minimum (%{minimum})" rent: outside_range_title: "You told us the rent is %{brent}" min_hint_text: "The minimum rent expected for this type of property in this local authority is £%{soft_min_for_period}."