Module: Validations::Sales::SoftValidations
- Includes:
- SaleInformationValidations
- Defined in:
- sales/soft_validations.rb
Constant Summary collapse
- ALLOWED_INCOME_RANGES_SALES =
{ 1 => OpenStruct.new(soft_min: 5000), 2 => OpenStruct.new(soft_min: 1500), 3 => OpenStruct.new(soft_min: 1000), 5 => OpenStruct.new(soft_min: 2000), 0 => OpenStruct.new(soft_min: 2000), }.freeze
Instance Method Summary collapse
- #buyer1_livein_wrong_for_ownership_type? ⇒ Boolean
- #buyer2_livein_wrong_for_ownership_type? ⇒ Boolean
- #combined_income_over_soft_max? ⇒ Boolean
- #deposit_over_soft_max? ⇒ Boolean
- #discounted_ownership_value_invalid? ⇒ Boolean
- #extra_borrowing_expected_but_not_reported? ⇒ Boolean
- #grant_outside_common_range? ⇒ Boolean
- #hodate_3_years_or_more_saledate? ⇒ Boolean
- #income1_over_soft_max? ⇒ Boolean
- #income1_under_soft_min? ⇒ Boolean
- #income2_over_soft_max? ⇒ Boolean
- #income2_under_soft_min? ⇒ Boolean
- #monthly_charges_over_soft_max? ⇒ Boolean
- #mortgage_over_soft_max? ⇒ Boolean
- #mortgage_plus_deposit_less_than_discounted_value? ⇒ Boolean
- #percentage_discount_invalid? ⇒ Boolean
- #purchase_price_higher_or_lower_text ⇒ Object
- #purchase_price_out_of_soft_range? ⇒ Boolean
- #purchase_price_soft_min_or_soft_max ⇒ Object
- #savings_over_soft_max? ⇒ Boolean
- #shared_ownership_deposit_invalid? ⇒ Boolean
- #staircase_bought_above_fifty? ⇒ Boolean
- #staircase_owned_out_of_soft_range? ⇒ Boolean
- #wheelchair_when_not_disabled? ⇒ Boolean
Instance Method Details
#buyer1_livein_wrong_for_ownership_type? ⇒ Boolean
152 153 154 155 156 |
# File 'sales/soft_validations.rb', line 152 def buyer1_livein_wrong_for_ownership_type? return unless ownershipsch && buy1livein (discounted_ownership_sale? || shared_ownership_scheme?) && buy1livein == 2 end |
#buyer2_livein_wrong_for_ownership_type? ⇒ Boolean
158 159 160 161 162 163 |
# File 'sales/soft_validations.rb', line 158 def buyer2_livein_wrong_for_ownership_type? return unless ownershipsch && buy2livein return unless joint_purchase? (discounted_ownership_sale? || shared_ownership_scheme?) && buy2livein == 2 end |
#combined_income_over_soft_max? ⇒ Boolean
36 37 38 39 40 |
# File 'sales/soft_validations.rb', line 36 def combined_income_over_soft_max? return unless income1 && income2 && la && discounted_ownership_sale? income_over_soft_max?(income1 + income2) end |
#deposit_over_soft_max? ⇒ Boolean
64 65 66 67 68 |
# File 'sales/soft_validations.rb', line 64 def deposit_over_soft_max? return unless savings && deposit && mortgage_used? deposit > savings * 4 / 3 end |
#discounted_ownership_value_invalid? ⇒ Boolean
143 144 145 146 147 148 149 150 |
# File 'sales/soft_validations.rb', line 143 def discounted_ownership_value_invalid? return unless saledate && collection_start_year <= 2023 return unless value && deposit && ownershipsch return unless mortgage || mortgageused == 2 || mortgageused == 3 return unless discount || grant || type == 29 mortgage_deposit_and_grant_total != value_with_discount && discounted_ownership_sale? end |
#extra_borrowing_expected_but_not_reported? ⇒ Boolean
70 71 72 73 74 |
# File 'sales/soft_validations.rb', line 70 def extra_borrowing_expected_but_not_reported? return unless extrabor && mortgage && deposit && value && discount extrabor != 1 && mortgage + deposit > value - value * discount / 100 end |
#grant_outside_common_range? ⇒ Boolean
118 119 120 121 122 123 |
# File 'sales/soft_validations.rb', line 118 def grant_outside_common_range? return unless grant && type && saledate return if form.start_year_after_2024? && (type == 21 || type == 8) !grant.between?(9_000, 16_000) end |
#hodate_3_years_or_more_saledate? ⇒ Boolean
104 105 106 107 108 |
# File 'sales/soft_validations.rb', line 104 def hodate_3_years_or_more_saledate? return unless hodate && saledate saledate - hodate >= 3.years end |
#income1_over_soft_max? ⇒ Boolean
24 25 26 27 28 |
# File 'sales/soft_validations.rb', line 24 def income1_over_soft_max? return unless income1 && la && discounted_ownership_sale? income_over_soft_max?(income1) end |
#income1_under_soft_min? ⇒ Boolean
12 13 14 15 16 |
# File 'sales/soft_validations.rb', line 12 def income1_under_soft_min? return false unless ecstat1 && income1 && ALLOWED_INCOME_RANGES_SALES[ecstat1] income1 < ALLOWED_INCOME_RANGES_SALES[ecstat1][:soft_min] end |
#income2_over_soft_max? ⇒ Boolean
30 31 32 33 34 |
# File 'sales/soft_validations.rb', line 30 def income2_over_soft_max? return unless income2 && la && discounted_ownership_sale? income_over_soft_max?(income2) end |
#income2_under_soft_min? ⇒ Boolean
18 19 20 21 22 |
# File 'sales/soft_validations.rb', line 18 def income2_under_soft_min? return false unless ecstat2 && income2 && ALLOWED_INCOME_RANGES_SALES[ecstat2] income2 < ALLOWED_INCOME_RANGES_SALES[ecstat2][:soft_min] end |
#monthly_charges_over_soft_max? ⇒ Boolean
125 126 127 128 129 130 |
# File 'sales/soft_validations.rb', line 125 def monthly_charges_over_soft_max? return unless type && mscharge && proptype soft_max = old_persons_shared_ownership? ? 550 : 300 mscharge > soft_max end |
#mortgage_over_soft_max? ⇒ Boolean
46 47 48 49 50 51 52 |
# File 'sales/soft_validations.rb', line 46 def mortgage_over_soft_max? return false unless mortgage && inc1mort && (inc2mort || not_joint_purchase?) return false if income1_used_for_mortgage? && income1.blank? || income2_used_for_mortgage? && income2.blank? income_used_for_mortgage = (income1_used_for_mortgage? ? income1 : 0) + (income2_used_for_mortgage? ? income2 : 0) mortgage > income_used_for_mortgage * 5 end |
#mortgage_plus_deposit_less_than_discounted_value? ⇒ Boolean
97 98 99 100 101 102 |
# File 'sales/soft_validations.rb', line 97 def mortgage_plus_deposit_less_than_discounted_value? return unless mortgage && deposit && value && discount discounted_value = value * (100 - discount) / 100 mortgage + deposit < discounted_value end |
#percentage_discount_invalid? ⇒ Boolean
165 166 167 168 169 170 171 172 173 174 |
# File 'sales/soft_validations.rb', line 165 def percentage_discount_invalid? return unless discount && proptype case proptype when 1, 2 discount > 50 when 3, 4, 9 discount > 35 end end |
#purchase_price_higher_or_lower_text ⇒ Object
110 111 112 |
# File 'sales/soft_validations.rb', line 110 def purchase_price_higher_or_lower_text value < sale_range.soft_min ? "lower" : "higher" end |
#purchase_price_out_of_soft_range? ⇒ Boolean
76 77 78 79 80 |
# File 'sales/soft_validations.rb', line 76 def purchase_price_out_of_soft_range? return unless value && beds && la && sale_range !value.between?(sale_range.soft_min, sale_range.soft_max) end |
#purchase_price_soft_min_or_soft_max ⇒ Object
114 115 116 |
# File 'sales/soft_validations.rb', line 114 def purchase_price_soft_min_or_soft_max value < sale_range.soft_min ? sale_range.soft_min : sale_range.soft_max end |
#savings_over_soft_max? ⇒ Boolean
60 61 62 |
# File 'sales/soft_validations.rb', line 60 def savings_over_soft_max? savings && savings > 100_000 end |
#shared_ownership_deposit_invalid? ⇒ Boolean
88 89 90 91 92 93 94 95 |
# File 'sales/soft_validations.rb', line 88 def shared_ownership_deposit_invalid? return unless saledate && collection_start_year <= 2023 return unless mortgage || mortgageused == 2 || mortgageused == 3 return unless cashdis || ! return unless deposit && value && equity over_tolerance?(mortgage_deposit_and_discount_total, value * equity / 100, 1) end |
#staircase_bought_above_fifty? ⇒ Boolean
42 43 44 |
# File 'sales/soft_validations.rb', line 42 def staircase_bought_above_fifty? stairbought && stairbought > 50 end |
#staircase_owned_out_of_soft_range? ⇒ Boolean
82 83 84 85 86 |
# File 'sales/soft_validations.rb', line 82 def staircase_owned_out_of_soft_range? return unless type && stairowned type == 24 && stairowned.between?(76, 100) end |
#wheelchair_when_not_disabled? ⇒ Boolean
54 55 56 57 58 |
# File 'sales/soft_validations.rb', line 54 def wheelchair_when_not_disabled? return unless disabled && wheel wheel == 1 && disabled == 2 end |