diff --git a/app/models/validations/sales/financial_validations.rb b/app/models/validations/sales/financial_validations.rb index 21f3743ca..4b9059250 100644 --- a/app/models/validations/sales/financial_validations.rb +++ b/app/models/validations/sales/financial_validations.rb @@ -70,6 +70,27 @@ module Validations::Sales::FinancialValidations end end + def validate_equity_in_range_for_year_and_type(record) + return unless record.type && record.equity && record.collection_start_year + + if record.collection_start_year == 2022 + ranges = EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR[2022] + elsif record.collection_start_year >= 2023 + ranges = EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR[2023] + end + + if ranges.key?(record.type) + range = ranges[record.type] + if record.equity < range["min"] + record.errors.add :type, I18n.t("validations.financial.equity.under_min", min_equity: range["min"]) + record.errors.add :equity, I18n.t("validations.financial.equity.under_min", min_equity: range["min"]) + elsif record.equity > range["max"] + record.errors.add :type, I18n.t("validations.financial.equity.over_max") + record.errors.add :equity, I18n.t("validations.financial.equity.over_max") + end + end + end + private def is_relationship_child?(relationship) @@ -79,4 +100,26 @@ private def is_economic_status_child?(economic_status) economic_status == 9 end + + EQUITY_RANGES_FOR_TYPES_BY_COLLECTION_START_YEAR = { + 2022 => { + 2 => { "min" => 25, "max" => 75 }, + 30 => { "min" => 10, "max" => 75 }, + 18 => { "min" => 25, "max" => 75 }, + 16 => { "min" => 10, "max" => 75 }, + 24 => { "min" => 25, "max" => 75 }, + # 28 => ranges don't apply + 31 => { "min" => 0, "max" => 75 }, + }, + 2023 => { + 2 => { "min" => 10, "max" => 75 }, + 30 => { "min" => 25, "max" => 75 }, + 18 => { "min" => 25, "max" => 75 }, + 16 => { "min" => 10, "max" => 75 }, + 24 => { "min" => 25, "max" => 75 }, + # 28 => ranges don't apply + 31 => { "min" => 0, "max" => 75 }, + 32 => { "min" => 0, "max" => 75 }, + }, + }.freeze end diff --git a/config/locales/en.yml b/config/locales/en.yml index c3762e259..dfc7ff822 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -297,6 +297,9 @@ en: staircasing: percentage_bought_must_be_greater_than_percentage_owned: "Total percentage buyer now owns must be more than percentage bought in this transaction" older_person_percentage_owned_maximum_75: "Percentage cannot be above 75% under Older Person's Shared Ownership" + equity: + under_min: "The minimum initial equity stake for this type of shared ownership sale is %{min_equity}%" + over_max: "The maximum initial equity stake is 75%" household: reasonpref: