Module: EmployeeTimeOffAccruals
Overview
Weekly/periodic time-off accrual processing for Employee.
Instance Method Summary
collapse
#process_policy_transitions, #process_rollover_and_expiry
#process_time_off_requests
Instance Method Details
#current_time_off_policy_for(time_off_type, as_of_date = Date.current) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
|
# File 'app/models/concerns/employee_time_off_accruals.rb', line 26
def current_time_off_policy_for(time_off_type, as_of_date = Date.current)
return nil if employee_record&.hire_date.blank?
tenure = (as_of_date - employee_record.hire_date).to_i / 365.25
time_off_type.time_off_policies
.joins(:time_off_policy_assignments)
.where(time_off_policy_assignments: { employee_id: id })
.where(min_tenure: ..tenure)
.where('max_tenure >= ? OR max_tenure IS NULL', tenure)
.order(min_tenure: :desc)
.first
end
|
#process_accruals(simulate_date: nil) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
|
# File 'app/models/concerns/employee_time_off_accruals.rb', line 12
def process_accruals(simulate_date: nil)
return if time_off_policy_assignments.blank?
effective_date = simulate_date || Date.current
active_assignment = active_policy_assignment(effective_date)
return unless active_assignment
policy = active_assignment.time_off_policy
time_off_type = policy.time_off_type
dispatch_accrual(active_assignment, policy, time_off_type, simulate_date:)
process_non_accruable_deductions(active_assignment.employee, simulate_date:)
end
|
#process_work_schedule_transitions ⇒ Object
40
41
42
|
# File 'app/models/concerns/employee_time_off_accruals.rb', line 40
def process_work_schedule_transitions
work_schedules.where(expiry_date: Date.current, state: 'approved').find_each(&:expire!)
end
|