+
+
+
+
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+ |
+
+ # File 'financial_validations.rb', line 27
+
+def validate_net_income(record)
+ if record.ecstat1 && record.hhmemb && record.weekly_net_income && record.startdate && record.form.start_date.year >= 2023
+ if record.weekly_net_income > record.applicable_income_range.hard_max
+ frequency = record.form.get_question("incfreq", record).label_from_value(record.incfreq).downcase
+ hard_max = format_as_currency(record.applicable_income_range.hard_max)
+ record.errors.add(
+ :earnings,
+ :over_hard_max,
+ message: I18n.t("validations.financial.earnings.over_hard_max", hard_max:),
+ )
+ record.errors.add(
+ :hhmemb,
+ :over_hard_max,
+ message: I18n.t("validations.financial.hhmemb.earnings.over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
+ )
+ (1..record.hhmemb).each do |n|
+ record.errors.add(
+ "ecstat#{n}",
+ :over_hard_max,
+ message: I18n.t("validations.financial.ecstat.over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
+ )
+ next unless record["ecstat#{n}"] == 9
+
+ record.errors.add(
+ "age#{n}",
+ :over_hard_max,
+ message: I18n.t("validations.financial.age.earnings_over_hard_max", earnings: format_as_currency(record.earnings), frequency:),
+ )
+ end
+ end
+
+ if record.weekly_net_income < record.applicable_income_range.hard_min
+ hard_min = format_as_currency(record.applicable_income_range.hard_min)
+ frequency = record.form.get_question("incfreq", record).label_from_value(record.incfreq).downcase
+ record.errors.add(
+ :earnings,
+ :under_hard_min,
+ message: I18n.t("validations.financial.earnings.under_hard_min", hard_min:),
+ )
+ record.errors.add(
+ :hhmemb,
+ :under_hard_min,
+ message: I18n.t("validations.financial.hhmemb.earnings.under_hard_min", earnings: format_as_currency(record.earnings), frequency:),
+ )
+ (1..record.hhmemb).each do |n|
+ record.errors.add(
+ "ecstat#{n}",
+ :under_hard_min,
+ message: I18n.t("validations.financial.ecstat.under_hard_min", earnings: format_as_currency(record.earnings), frequency:),
+ )
+ end
+ end
+ end
+
+ if record.earnings.present? && record.incfreq.blank?
+ record.errors.add :incfreq, I18n.t("validations.financial.earnings.freq_missing")
+ record.errors.add :earnings, I18n.t("validations.financial.earnings.freq_missing")
+ end
+
+ if record.incfreq.present? && record.earnings.blank?
+ record.errors.add :earnings, I18n.t("validations.financial.earnings.earnings_missing")
+ record.errors.add :incfreq, I18n.t("validations.financial.earnings.earnings_missing")
+ end
+end
+ |
+
+