Class: PayrollDeductionRate

Inherits:
ApplicationRecord show all
Includes:
HasProvince, PayrollDeductionRatesProcedures
Defined in:
app/models/payroll_deduction_rate.rb

Instance Method Summary collapse

Methods included from PayrollDeductionRatesProcedures

#create_or_update_procedure

Methods inherited from ApplicationRecord

define_decrypted_attribute, define_decrypted_attributes, #errors_in_bullet_points, primary_connection, special_connection

Instance Method Details

#no_overlapping_rangesObject



11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/payroll_deduction_rate.rb', line 11

def no_overlapping_ranges
  overlapping_rates = PayrollDeductionRate.where(province_id: province_id)
                                          .where.not(
                                            payroll_federal_provincial_deduction_rate_id:
                                            payroll_federal_provincial_deduction_rate_id
                                          )
                                          .where('from_amount < ? AND to_amount > ?', to_amount, from_amount)
  return unless overlapping_rates.exists?

  errors.add(:base, I18n.t('messages.overlapping_deduction_rates'))
end