Browse Source

validate staircasing percentage totals

pull/3001/head
Carolyn 2 months ago
parent
commit
cc2963b4e0
  1. 17
      app/models/validations/sales/financial_validations.rb
  2. 8
      config/locales/validations/sales/financial.en.yml

17
app/models/validations/sales/financial_validations.rb

@ -118,6 +118,23 @@ module Validations::Sales::FinancialValidations
end end
end end
def validate_staircase_difference_enough_for_numstair(record)
return unless record.equity && record.stairbought && record.stairowned && record.numstair
# We must use the lowest possible percentage for a staircasing transaction of any saletype, any year since 1980
minimum_percentage_per_staircasing_transaction = 1
percentage_left = record.stairowned - record.stairbought - record.equity
previous_staircasing_transactions = record.numstair - 1
if percentage_left < previous_staircasing_transactions * minimum_percentage_per_staircasing_transaction
equity_sum = record.stairowned - percentage_left + previous_staircasing_transactions * minimum_percentage_per_staircasing_transaction
record.errors.add :equity, I18n.t("validations.sales.financial.equity.more_than_stairowned_minus_stairbought_minus_prev_staircasing", equity: record.equity, bought: record.stairbought, numprevstair: previous_staircasing_transactions, equity_sum:, stair_total: record.stairowned)
record.errors.add :stairowned, I18n.t("validations.sales.financial.stairowned.less_than_stairbought_plus_equity_plus_prev_staircasing", equity: record.equity, bought: record.stairbought, numprevstair: previous_staircasing_transactions, equity_sum:, stair_total: record.stairowned)
record.errors.add :stairbought, I18n.t("validations.sales.financial.stairbought.more_than_stairowned_minus_equity_minus_prev_staircasing", equity: record.equity, bought: record.stairbought, numprevstair: previous_staircasing_transactions, equity_sum:, stair_total: record.stairowned)
record.errors.add :numstair, I18n.t("validations.sales.financial.numstair.too_high_for_stairowned_minus_stairbought_minus_equity", equity: record.equity, bought: record.stairbought, numprevstair: previous_staircasing_transactions, equity_sum:, stair_total: record.stairowned)
end
end
private private
def is_relationship_child?(relationship) def is_relationship_child?(relationship)

8
config/locales/validations/sales/financial.en.yml

@ -63,6 +63,7 @@ en:
equity_over_stairowned_minus_stairbought: equity_over_stairowned_minus_stairbought:
joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought." joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyers own minus the percentage bought."
not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought." not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought."
more_than_stairowned_minus_stairbought_minus_prev_staircasing: "The initial equity stake is %{equity}%, the percentage bought is %{bought}%, and there have been %{numprevstair}% previous staircasing transactions, totalling at least %{equity_sum}%, which is more than the total percentage owned by the buyers (%{stair_total}%). In a staircasing transaction, the total percentage owned must be at least the initial equity stake plus the percentage bought plus a minimum of 1% for each previous staircasing transaction."
stairowned: stairowned:
equity_over_stairowned_minus_stairbought: equity_over_stairowned_minus_stairbought:
@ -72,6 +73,7 @@ en:
joint_purchase: "Total percentage buyers now own must be more than percentage bought in this transaction." joint_purchase: "Total percentage buyers now own must be more than percentage bought in this transaction."
not_joint_purchase: "Total percentage buyer now owns must be more than percentage bought in this transaction." not_joint_purchase: "Total percentage buyer now owns must be more than percentage bought in this transaction."
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same." percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
less_than_stairbought_plus_equity_plus_prev_staircasing: "The initial equity stake is %{equity}%, the percentage bought is %{bought}%, and there have been %{numprevstair}% previous staircasing transactions, totalling at least %{equity_sum}%, which is more than the total percentage owned by the buyers (%{stair_total}%). In a staircasing transaction, the total percentage owned must be at least the initial equity stake plus the percentage bought plus a minimum of 1% for each previous staircasing transaction."
stairbought: stairbought:
equity_over_stairowned_minus_stairbought: equity_over_stairowned_minus_stairbought:
@ -79,7 +81,11 @@ en:
not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought." not_joint_purchase: "The initial equity stake is %{equity}% and the percentage owned in total minus the percentage bought is %{staircase_difference}%. In a staircasing transaction, the equity stake purchased cannot be larger than the percentage the buyer owns minus the percentage bought."
percentage_bought_must_be_at_least_threshold: "The minimum percentage share that can be bought in a staircasing transaction for %{shared_ownership_type} is %{threshold}%. Please change your answer or check that you have selected the correct shared ownership type." percentage_bought_must_be_at_least_threshold: "The minimum percentage share that can be bought in a staircasing transaction for %{shared_ownership_type} is %{threshold}%. Please change your answer or check that you have selected the correct shared ownership type."
percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same." percentage_bought_equal_percentage_owned: "The percentage bought is %{stairbought}% and the percentage owned in total is %{stairowned}%. These figures cannot be the same."
more_than_stairowned_minus_equity_minus_prev_staircasing: "The initial equity stake is %{equity}%, the percentage bought is %{bought}%, and there have been %{numprevstair}% previous staircasing transactions, totalling at least %{equity_sum}%, which is more than the total percentage owned by the buyers (%{stair_total}%). In a staircasing transaction, the total percentage owned must be at least the initial equity stake plus the percentage bought plus a minimum of 1% for each previous staircasing transaction."
numstair:
too_high_for_stairowned_minus_stairbought_minus_equity: "The initial equity stake is %{equity}%, the percentage bought is %{bought}%, and there have been %{numprevstair}% previous staircasing transactions, totalling at least %{equity_sum}%, which is more than the total percentage owned by the buyers (%{stair_total}%). In a staircasing transaction, the total percentage owned must be at least the initial equity stake plus the percentage bought plus a minimum of 1% for each previous staircasing transaction."
uprn_selection: uprn_selection:
outside_london_income_range: "Income must be between £0 and £90,000 for properties within a London local authority." outside_london_income_range: "Income must be between £0 and £90,000 for properties within a London local authority."
outside_non_london_income_range: "Income must be between £0 and £80,000 for properties in a non-London local authority." outside_non_london_income_range: "Income must be between £0 and £80,000 for properties in a non-London local authority."

Loading…
Cancel
Save