Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

271 lines
8.6 KiB

module Validations::SoftValidations
include ChargesHelper
ALLOWED_INCOME_RANGES = {
1 => OpenStruct.new(soft_min: 143, soft_max: 730, hard_min: 90, hard_max: 1230),
2 => OpenStruct.new(soft_min: 67, soft_max: 620, hard_min: 50, hard_max: 950),
3 => OpenStruct.new(soft_min: 80, soft_max: 480, hard_min: 40, hard_max: 990),
4 => OpenStruct.new(soft_min: 50, soft_max: 370, hard_min: 10, hard_max: 450),
5 => OpenStruct.new(soft_min: 50, soft_max: 380, hard_min: 10, hard_max: 690),
6 => OpenStruct.new(soft_min: 53, soft_max: 540, hard_min: 10, hard_max: 890),
7 => OpenStruct.new(soft_min: 47, soft_max: 460, hard_min: 10, hard_max: 1300),
8 => OpenStruct.new(soft_min: 54, soft_max: 460, hard_min: 10, hard_max: 2000),
9 => OpenStruct.new(soft_min: 50, soft_max: 450, hard_min: 10, hard_max: 750),
0 => OpenStruct.new(soft_min: 50, soft_max: 580, hard_min: 10, hard_max: 1040),
10 => OpenStruct.new(soft_min: 47, soft_max: 730, hard_min: 10, hard_max: 2000),
}.freeze
def net_income_in_soft_max_range?
return unless weekly_net_income && ecstat1 && hhmemb
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max)
end
def net_income_in_soft_min_range?
return unless weekly_net_income && ecstat1 && hhmemb
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
end
def rent_in_soft_min_range?
return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(
start_year: collection_start_year,
la:,
beds: beds_for_la_rent_range,
lettype: get_lettype,
)
rent_range.present? && weekly_value(brent).between?(rent_range.hard_min, rent_range.soft_min)
end
def rent_in_soft_max_range?
return unless brent && weekly_value(brent) && startdate
rent_range = LaRentRange.find_by(
start_year: collection_start_year,
la:,
beds: beds_for_la_rent_range,
lettype: get_lettype,
)
if beds.present? && rent_range.present? && beds > LaRentRange::MAX_BEDS
weekly_value(brent) > rent_range.soft_max
elsif rent_range.present?
weekly_value(brent).between?(rent_range.soft_max, rent_range.hard_max)
end
end
(1..8).each do |person_num|
define_method("person_#{person_num}_retired_under_soft_min_age?") do
retired_under_soft_min_age?(person_num)
end
define_method("person_#{person_num}_not_retired_over_soft_max_age?") do
not_retired_over_soft_max_age?(person_num)
end
define_method("person_#{person_num}_partner_under_16?") do
partner_under_16?(person_num)
end
end
def all_male_tenants_in_a_pregnant_household?
all_male_tenants_in_the_household? && all_tenants_gender_information_completed? && preg_occ == 1
end
def female_in_pregnant_household_in_soft_validation_range?
all_tenants_age_and_gender_information_completed? && females_in_the_household? && !females_in_age_range(16, 50) && preg_occ == 1
end
def all_tenants_age_and_gender_information_completed?
person_count = hhmemb || 8
(1..person_count).all? do |n|
public_send("sex#{n}").present? && public_send("age#{n}").present? && details_known_or_lead_tenant?(n) && public_send("age#{n}_known").present? && public_send("age#{n}_known").zero?
end
end
def all_tenants_gender_information_completed?
person_count = hhmemb || 8
(1..person_count).all? do |n|
public_send("sex#{n}").present? && details_known_or_lead_tenant?(n)
end
end
TWO_YEARS_IN_DAYS = 730
TEN_YEARS_IN_DAYS = 3650
def major_repairs_date_in_soft_range?
mrcdate.present? && startdate.present? && mrcdate.between?(startdate.to_date - TEN_YEARS_IN_DAYS, startdate.to_date - TWO_YEARS_IN_DAYS)
end
def voiddate_in_soft_range?
voiddate.present? && startdate.present? && voiddate.between?(startdate.to_date - TEN_YEARS_IN_DAYS, startdate.to_date - TWO_YEARS_IN_DAYS)
end
CLDC-2248 Improve soft validations (#1584) * Update interruption screen page * Update routing and add flash * Only display routed to affected questions * Add affected_question_ids to pregnancy check * lint * Add skip link and lint * Move affected_question_ids to page, because we reuse questions so they might have different affected_question_ids * typo * Fix button wording * Update action href links * Change how we route back to interruption screen * Update affected_question_ids for lettings * Update sales soft validations * Update title texts * Update styling * Update is_referrer_interruption_screen? check and naming * Add interuption screen helper specs * Add request test for fixing soft validation * Add tests for geting soft validation page * Extract interruption screen banner * Update action_href to be reusable * Extract questions out of check answers summary list * Reuse check_answers_summary_list for interruption screen * refactor string parse * Rename attribute * fix test * Add tests for sales paths * typo * Update validation message: void date, major repairs date * Update validation message: rent_value_check, 2022 * Update validation message: buyer live in * Update validation message: staircase * Update validation message: purchase price * Update validation message: income * Update validation message: savings * Update validation message: extra borrowing * Update validation message: extra borrowing * Update validation message: wheelchair * Update validation message: monthly charge * Update validation message: mortgage * Update validation message: old persons shared ownership * Update validation message: discount * Update validation: min retirement * Wording in tests and time test * Update missing question * Refactor is referrer methods * Update validation message: net income * Update validation message: deposit and savings * Update validation message: mortgage, discount and deposit * Fix test validation messages * Fix the retirement check showing on the card 8, fix tests * test * return the user back to the check_your_answers after fixing a validation from check_your_anwers * pr comments
2 years ago
def net_income_higher_or_lower_text
net_income_in_soft_max_range? ? "higher" : "lower"
end
def scharge_in_soft_max_range?
return unless scharge && period && needstype && owning_organisation
return if weekly_value(scharge).blank?
soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35
else
owning_organisation.provider_type == "LA" ? 100 : 200
end
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:scharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_scharge = weekly_value(scharge)
weekly_scharge > soft_max && weekly_scharge <= hard_max
end
def pscharge_in_soft_max_range?
return unless pscharge && period && needstype && owning_organisation
return if weekly_value(pscharge).blank?
soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35
else
owning_organisation.provider_type == "LA" ? 75 : 100
end
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:pscharge, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_pscharge = weekly_value(pscharge)
weekly_pscharge > soft_max && weekly_pscharge <= hard_max
end
def supcharg_in_soft_max_range?
return unless supcharg && period && needstype && owning_organisation
return if weekly_value(supcharg).blank?
soft_max = if needstype == 1
owning_organisation.provider_type == "LA" ? 25 : 35
else
owning_organisation.provider_type == "LA" ? 75 : 85
end
provider_type = owning_organisation.provider_type_before_type_cast
hard_max = CHARGE_MAXIMA_PER_WEEK.dig(:supcharg, PROVIDER_TYPE[provider_type], NEEDSTYPE_VALUES[needstype])
weekly_supcharg = weekly_value(supcharg)
weekly_supcharg > soft_max && weekly_supcharg <= hard_max
end
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY = [
"Decant",
"Decanted",
"Refugee",
"Asylum",
"Ukraine",
"Ukrainian",
"Army",
"Military",
"Domestic Abuse",
"Domestic Violence",
"DA",
"DV",
"Relationship breakdown",
"Overcrowding",
"Overcrowded",
"Too small",
"More space",
"Bigger property",
"Damp",
"Mould",
"Fire",
"Repossession",
"Death",
"Deceased",
"Passed away",
"Prison",
"Hospital",
].freeze
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX = Regexp.union(
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY.map { |phrase| Regexp.new("\\b[^[:alpha]]*#{phrase}[^[:alpha:]]*\\b", Regexp::IGNORECASE) },
)
def reasonother_might_be_existing_category?
PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother)
end
def multiple_partners?
return unless hhmemb
max_person_with_details = sales? ? [hhmemb, 6].min : [hhmemb, 8].min
(2..max_person_with_details).many? { |n| public_send("relat#{n}") == "P" }
end
private
def details_known_or_lead_tenant?(tenant_number)
return true if tenant_number == 1
public_send("details_known_#{tenant_number}").zero?
end
def females_in_age_range(min, max)
person_count = hhmemb || 8
(1..person_count).any? do |n|
public_send("sex#{n}") == "F" && public_send("age#{n}").present? && public_send("age#{n}").between?(min, max)
end
end
def females_in_the_household?
person_count = hhmemb || 8
(1..person_count).any? do |n|
public_send("sex#{n}") == "F" || public_send("sex#{n}").nil?
end
end
def all_male_tenants_in_the_household?
person_count = hhmemb || 8
(1..person_count).all? do |n|
public_send("sex#{n}") == "M"
end
end
def tenant_is_retired?(economic_status)
economic_status == 5
end
def tenant_prefers_not_to_say?(economic_status)
economic_status == 10
end
def retired_under_soft_min_age?(person_num)
age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}")
CLDC-2248 Improve soft validations (#1584) * Update interruption screen page * Update routing and add flash * Only display routed to affected questions * Add affected_question_ids to pregnancy check * lint * Add skip link and lint * Move affected_question_ids to page, because we reuse questions so they might have different affected_question_ids * typo * Fix button wording * Update action href links * Change how we route back to interruption screen * Update affected_question_ids for lettings * Update sales soft validations * Update title texts * Update styling * Update is_referrer_interruption_screen? check and naming * Add interuption screen helper specs * Add request test for fixing soft validation * Add tests for geting soft validation page * Extract interruption screen banner * Update action_href to be reusable * Extract questions out of check answers summary list * Reuse check_answers_summary_list for interruption screen * refactor string parse * Rename attribute * fix test * Add tests for sales paths * typo * Update validation message: void date, major repairs date * Update validation message: rent_value_check, 2022 * Update validation message: buyer live in * Update validation message: staircase * Update validation message: purchase price * Update validation message: income * Update validation message: savings * Update validation message: extra borrowing * Update validation message: extra borrowing * Update validation message: wheelchair * Update validation message: monthly charge * Update validation message: mortgage * Update validation message: old persons shared ownership * Update validation message: discount * Update validation: min retirement * Wording in tests and time test * Update missing question * Refactor is referrer methods * Update validation message: net income * Update validation message: deposit and savings * Update validation message: mortgage, discount and deposit * Fix test validation messages * Fix the retirement check showing on the card 8, fix tests * test * return the user back to the check_your_answers after fixing a validation from check_your_anwers * pr comments
2 years ago
return unless age && economic_status
tenant_is_retired?(economic_status) && age < 66
end
def not_retired_over_soft_max_age?(person_num)
age = public_send("age#{person_num}")
economic_status = public_send("ecstat#{person_num}")
return unless age && economic_status
return false if tenant_prefers_not_to_say?(economic_status)
!tenant_is_retired?(economic_status) && age > 66
end
def partner_under_16?(person_num)
age = public_send("age#{person_num}")
relationship = public_send("relat#{person_num}")
return unless age && relationship
age < 16 && relationship == "P"
end
end