Module: EmployeeTimeOffDeductions

Extended by:
ActiveSupport::Concern
Included in:
EmployeeTimeOffAccruals
Defined in:
app/models/concerns/employee_time_off_deductions.rb

Overview

Time-off request deductions and non-accruable balance adjustments.

Instance Method Summary collapse

Instance Method Details

#process_time_off_requestsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/models/concerns/employee_time_off_deductions.rb', line 7

def process_time_off_requests
  time_off_requests.approved.where(start_date: ..Date.current).find_each do |request|
    next if request.banked_time_request?
    next if time_off_balances.exists?(time_off_request_id: request.id, category: 'deduction')

    create_balance(
      time_off_type: request.time_off_type,
      date: request.start_date,
      amount: -request.amount,
      note: "#{request.time_off_type.name} Time off used for #{request.start_date} to #{request.end_date}",
      time_off_request_id: request.id,
      category: 'deduction'
    )
  end
end