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.
46 lines
1.5 KiB
46 lines
1.5 KiB
3 years ago
|
module Validations::SoftValidations
|
||
3 years ago
|
def has_no_unresolved_soft_errors?
|
||
|
soft_errors.empty? || soft_errors_overridden?
|
||
|
end
|
||
|
|
||
|
def soft_errors
|
||
|
{}.merge(net_income_validations)
|
||
|
end
|
||
|
|
||
|
def soft_errors_overridden?
|
||
3 years ago
|
public_send(soft_errors.keys.first) == "Yes" if soft_errors.present?
|
||
3 years ago
|
end
|
||
|
|
||
|
private
|
||
|
|
||
|
def net_income_validations
|
||
|
net_income_errors = {}
|
||
|
if net_income_in_soft_min_range?
|
||
|
net_income_errors["override_net_income_validation"] = OpenStruct.new(
|
||
|
message: "Net income is lower than expected based on the main tenant's working situation. Are you sure this is correct?",
|
||
3 years ago
|
hint_text: "This is based on the tenant's work situation: #{ecstat1}",
|
||
3 years ago
|
)
|
||
|
elsif net_income_in_soft_max_range?
|
||
|
net_income_errors["override_net_income_validation"] = OpenStruct.new(
|
||
|
message: "Net income is higher than expected based on the main tenant's working situation. Are you sure this is correct?",
|
||
3 years ago
|
hint_text: "This is based on the tenant's work situation: #{ecstat1}",
|
||
3 years ago
|
)
|
||
|
else
|
||
|
update_column(:override_net_income_validation, nil)
|
||
|
end
|
||
|
net_income_errors
|
||
|
end
|
||
|
|
||
|
def net_income_in_soft_max_range?
|
||
3 years ago
|
return unless weekly_net_income && ecstat1
|
||
3 years ago
|
|
||
|
weekly_net_income.between?(applicable_income_range.soft_max, applicable_income_range.hard_max)
|
||
|
end
|
||
|
|
||
|
def net_income_in_soft_min_range?
|
||
3 years ago
|
return unless weekly_net_income && ecstat1
|
||
3 years ago
|
|
||
3 years ago
|
weekly_net_income.between?(applicable_income_range.hard_min, applicable_income_range.soft_min)
|
||
3 years ago
|
end
|
||
|
end
|