Module: Validations::SoftValidations
- Includes:
- ChargesHelper
- Defined in:
- soft_validations.rb
Constant Summary collapse
- 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
- TWO_YEARS_IN_DAYS =
730
- TEN_YEARS_IN_DAYS =
3650
- 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) }, )
Instance Method Summary collapse
- #all_tenants_age_and_gender_information_completed? ⇒ Boolean
- #all_tenants_gender_information_completed? ⇒ Boolean
- #female_in_pregnant_household_in_soft_validation_range? ⇒ Boolean
- #major_repairs_date_in_soft_range? ⇒ Boolean
- #multiple_partners? ⇒ Boolean
- #net_income_higher_or_lower_text ⇒ Object
- #net_income_in_soft_max_range? ⇒ Boolean
- #net_income_in_soft_min_range? ⇒ Boolean
- #no_females_in_a_pregnant_household? ⇒ Boolean
- #pscharge_in_soft_max_range? ⇒ Boolean
- #reasonother_might_be_existing_category? ⇒ Boolean
- #rent_in_soft_max_range? ⇒ Boolean
- #rent_in_soft_min_range? ⇒ Boolean
- #scharge_in_soft_max_range? ⇒ Boolean
- #supcharg_in_soft_max_range? ⇒ Boolean
- #voiddate_in_soft_range? ⇒ Boolean
Instance Method Details
#all_tenants_age_and_gender_information_completed? ⇒ Boolean
78 79 80 81 82 83 84 |
# File 'soft_validations.rb', line 78 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 |
#all_tenants_gender_information_completed? ⇒ Boolean
86 87 88 89 90 91 92 |
# File 'soft_validations.rb', line 86 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 |
#female_in_pregnant_household_in_soft_validation_range? ⇒ Boolean
74 75 76 |
# File 'soft_validations.rb', line 74 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 |
#major_repairs_date_in_soft_range? ⇒ Boolean
97 98 99 |
# File 'soft_validations.rb', line 97 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 |
#multiple_partners? ⇒ Boolean
198 199 200 201 202 203 |
# File 'soft_validations.rb', line 198 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 |
#net_income_higher_or_lower_text ⇒ Object
105 106 107 |
# File 'soft_validations.rb', line 105 def net_income_higher_or_lower_text net_income_in_soft_max_range? ? "higher" : "lower" end |
#net_income_in_soft_max_range? ⇒ Boolean
18 19 20 21 22 |
# File 'soft_validations.rb', line 18 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 |
#net_income_in_soft_min_range? ⇒ Boolean
24 25 26 27 28 |
# File 'soft_validations.rb', line 24 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 |
#no_females_in_a_pregnant_household? ⇒ Boolean
70 71 72 |
# File 'soft_validations.rb', line 70 def no_females_in_a_pregnant_household? !females_in_the_household? && all_tenants_gender_information_completed? && preg_occ == 1 end |
#pscharge_in_soft_max_range? ⇒ Boolean
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'soft_validations.rb', line 126 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 |
#reasonother_might_be_existing_category? ⇒ Boolean
194 195 196 |
# File 'soft_validations.rb', line 194 def reasonother_might_be_existing_category? PHRASES_LIKELY_TO_INDICATE_EXISTING_REASON_CATEGORY_REGEX.match?(reasonother) end |
#rent_in_soft_max_range? ⇒ Boolean
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'soft_validations.rb', line 42 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 |
#rent_in_soft_min_range? ⇒ Boolean
30 31 32 33 34 35 36 37 38 39 40 |
# File 'soft_validations.rb', line 30 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 |
#scharge_in_soft_max_range? ⇒ Boolean
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'soft_validations.rb', line 109 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 |
#supcharg_in_soft_max_range? ⇒ Boolean
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'soft_validations.rb', line 143 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 |
#voiddate_in_soft_range? ⇒ Boolean
101 102 103 |
# File 'soft_validations.rb', line 101 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 |