Class: PeopleGroup::Connectors::Hris

Inherits:
Object
  • Object
show all
Defined in:
lib/peoplegroup/connectors/hris.rb

Constant Summary collapse

EmployeeNotFoundError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initializeHris

Returns a new instance of Hris.



9
10
11
12
# File 'lib/peoplegroup/connectors/hris.rb', line 9

def initialize
  @workday = Workday::Client.new unless ENV.fetch('WORKDAY_SERVICE_URL', nil).nil?
  @bamboo = Bamboo.new
end

Instance Method Details

#accrued_days(employee_number) ⇒ Object



196
197
198
199
200
# File 'lib/peoplegroup/connectors/hris.rb', line 196

def accrued_days(employee_number)
  # Staying in bamboo for workday first release
  # Will need to have talks with pto by roots admin
  @bamboo.accrued_days(employee_number)
end

#active_and_current_employeesObject Also known as: active_and_current_team_members



27
28
29
30
31
32
# File 'lib/peoplegroup/connectors/hris.rb', line 27

def active_and_current_employees
  today = Date.current
  employees.select do |employee|
    employee['status'] == 'Active' && Date.parse(employee['hireDate']) <= today
  end
end

#active_employeesObject Also known as: active_team_members



22
23
24
# File 'lib/peoplegroup/connectors/hris.rb', line 22

def active_employees
  employees.select { |employee| employee['status'] == 'Active' }
end

#add_additional_data(employee_number, data) ⇒ Object



260
261
262
# File 'lib/peoplegroup/connectors/hris.rb', line 260

def add_additional_data(employee_number, data)
  @bamboo.add_additional_data(employee_number, data)
end

#add_bonus(employee_number, comment) ⇒ Object



268
269
270
# File 'lib/peoplegroup/connectors/hris.rb', line 268

def add_bonus(employee_number, comment)
  @workday.add_bonus(employee_number, comment)
end

#add_compensation_details(employee_number, data) ⇒ Object



163
164
165
# File 'lib/peoplegroup/connectors/hris.rb', line 163

def add_compensation_details(employee_number, data)
  @bamboo.add_compensation_details(employee_number, data)
end

#add_currency_conversion(employee_number, data) ⇒ Object



244
245
246
# File 'lib/peoplegroup/connectors/hris.rb', line 244

def add_currency_conversion(employee_number, data)
  @bamboo.add_currency_conversion(employee_number, data)
end

#add_employment_status(employee_number, data) ⇒ Object

Raises:

  • (NotImplementedError)


236
237
238
239
240
241
242
# File 'lib/peoplegroup/connectors/hris.rb', line 236

def add_employment_status(employee_number, data)
  # Only used in parental_pto_to_bamboo.rb
  # That integration adds the following statuses: Parental Leave, End of Parental Leave, Active
  # Asked what to do about this one on Slack: https://gitlab.slack.com/archives/C02FHJ9BYTZ/p1650666853127429

  raise NotImplementedError
end

#add_family_member(employee_number, data) ⇒ Object



256
257
258
# File 'lib/peoplegroup/connectors/hris.rb', line 256

def add_family_member(employee_number, data)
  @bamboo.add_family_member(employee_number, data)
end

#add_file(employee_number, file_name, file, folder_id) ⇒ Object



232
233
234
# File 'lib/peoplegroup/connectors/hris.rb', line 232

def add_file(employee_number, file_name, file, folder_id)
  @bamboo.add_file(employee_number, file_name, file, folder_id)
end

#add_job_details(employee_number, data) ⇒ Object



155
156
157
# File 'lib/peoplegroup/connectors/hris.rb', line 155

def add_job_details(employee_number, data)
  @bamboo.add_job_details(employee_number, data)
end

#add_on_target_earnings(employee_number, data) ⇒ Object



248
249
250
# File 'lib/peoplegroup/connectors/hris.rb', line 248

def add_on_target_earnings(employee_number, data)
  @bamboo.add_on_target_earnings(employee_number, data)
end

#add_signing_bonus(employee_number, data) ⇒ Object



252
253
254
# File 'lib/peoplegroup/connectors/hris.rb', line 252

def add_signing_bonus(employee_number, data)
  @bamboo.add_signing_bonus(employee_number, data)
end

#add_stock_options(employee_number, data) ⇒ Object



151
152
153
# File 'lib/peoplegroup/connectors/hris.rb', line 151

def add_stock_options(employee_number, data)
  @bamboo.add_stock_options(employee_number, data)
end

#add_time_off_policy(employee_number, time_off_policy_id, accrual_start_date) ⇒ Object



211
212
213
# File 'lib/peoplegroup/connectors/hris.rb', line 211

def add_time_off_policy(employee_number, time_off_policy_id, accrual_start_date)
  @bamboo.add_time_off_policy(employee_number, time_off_policy_id, accrual_start_date)
end

#additional_data(employee_number) ⇒ Object



264
265
266
# File 'lib/peoplegroup/connectors/hris.rb', line 264

def additional_data(employee_number)
  @bamboo.additional_data(employee_number)
end

#contract_folder_id(employee_number) ⇒ Object



228
229
230
# File 'lib/peoplegroup/connectors/hris.rb', line 228

def contract_folder_id(employee_number)
  @bamboo.contract_folder_id(employee_number)
end

#create_employee(employee_details_hash) ⇒ Object Also known as: create_team_member



136
137
138
# File 'lib/peoplegroup/connectors/hris.rb', line 136

def create_employee(employee_details_hash)
  @bamboo.create_employee(employee_details_hash)
end

#departmentsObject



272
273
274
# File 'lib/peoplegroup/connectors/hris.rb', line 272

def departments
  @workday.departments
end

#eligibility_status(eid, salary_min, salary_max) ⇒ Object



276
277
278
# File 'lib/peoplegroup/connectors/hris.rb', line 276

def eligibility_status(eid, salary_min, salary_max)
  @workday.eligibility_status(eid, salary_min, salary_max)
end

#employee_time_off_policies(employee_number) ⇒ Object Also known as: team_member_time_off_policies



206
207
208
# File 'lib/peoplegroup/connectors/hris.rb', line 206

def employee_time_off_policies(employee_number)
  @bamboo.employee_time_off_policies(employee_number)
end

#employeesObject Also known as: team_members



14
15
16
17
18
19
# File 'lib/peoplegroup/connectors/hris.rb', line 14

def employees
  @employees ||= Workday::Report.call(
    url: ENV.fetch('WORKDAY_WORKERS_REPORT', nil),
    password: ENV.fetch('WORKDAY_ISU_PASSWORD', nil)
  )
end

#employment_statuses(employee_number) ⇒ Object

Raises:

  • (NotImplementedError)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/peoplegroup/connectors/hris.rb', line 167

def employment_statuses(employee_number)
  # Terminated/Active in one field already. Those are the statuses we need to care about
  # Look for a hire date that is after the start date (not original hire date) to account for rehires
  # Affected: joining.rb

  # Probation period, CXC contract ending, temporary contract ending won't be needed
  # We can ignore garden leave (terminate access to systems without pausing benefits/stock vesting)
  # Affected:
  # - anniversary.rb
  # - cxc_contract_renewal_email.rb
  # - extension_netherlands_contract_email.rb
  # - probation_email.rb
  # - probation_status.rb

  raise NotImplementedError
end

#fetch_manager(team_member) ⇒ Object



114
115
116
# File 'lib/peoplegroup/connectors/hris.rb', line 114

def fetch_manager(team_member)
  active_team_members.find { |tm| tm['employeeNumber'] == team_member['supervisorId'] }
end

#fetch_manager!(team_member) ⇒ Object



118
119
120
121
122
123
# File 'lib/peoplegroup/connectors/hris.rb', line 118

def fetch_manager!(team_member)
  manager = fetch_manager(team_member)
  raise EmployeeNotFoundError, "Manager not found for employee #{team_member['employeeNumber']}" if manager.nil?

  manager
end

#fetch_second_level_manager(team_member) ⇒ Object



125
126
127
# File 'lib/peoplegroup/connectors/hris.rb', line 125

def fetch_second_level_manager(team_member)
  fetch_manager(fetch_manager(team_member))
end

#fetch_second_level_manager!(team_member) ⇒ Object



129
130
131
132
133
134
# File 'lib/peoplegroup/connectors/hris.rb', line 129

def fetch_second_level_manager!(team_member)
  manager = fetch_second_level_manager(team_member)
  raise EmployeeNotFoundError, "No second level manager found for employee #{team_member['employeeNumber']}" if manager.nil?

  manager
end

#get_employee_details(employee_number) ⇒ Object Also known as: get_team_member_details



35
36
37
# File 'lib/peoplegroup/connectors/hris.rb', line 35

def get_employee_details(employee_number)
  employees.find { |emp| emp['employeeNumber'] == employee_number.to_s }
end

#get_employee_details!(employee_number) ⇒ Object Also known as: get_team_member_details!



40
41
42
43
44
45
# File 'lib/peoplegroup/connectors/hris.rb', line 40

def get_employee_details!(employee_number)
  employee_details = get_employee_details(employee_number)
  raise EmployeeNotFoundError, "No team member found with employee number #{employee_number}" if employee_details.nil?

  employee_details
end

#job_details(employee_number) ⇒ Object



219
220
221
222
# File 'lib/peoplegroup/connectors/hris.rb', line 219

def job_details(employee_number)
  warn '[DEPRECATED] PeopleGroup::Connectors::Hris#job_details, use a custom workday report instead.'
  Workday::Report.call(url: ENV.fetch('WORKDAY_MANAGER_REPORT', nil))
end

#locationsObject



147
148
149
# File 'lib/peoplegroup/connectors/hris.rb', line 147

def locations
  @workday.locations
end

#remove_time_off_policy(employee_number, time_off_policy_id) ⇒ Object



215
216
217
# File 'lib/peoplegroup/connectors/hris.rb', line 215

def remove_time_off_policy(employee_number, time_off_policy_id)
  @bamboo.remove_time_off_policy(employee_number, time_off_policy_id)
end

#resumes_folder_id(employee_number) ⇒ Object



224
225
226
# File 'lib/peoplegroup/connectors/hris.rb', line 224

def resumes_folder_id(employee_number)
  @bamboo.resumes_folder_id(employee_number)
end

#search_employee(name) ⇒ Object Also known as: search_team_member



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/peoplegroup/connectors/hris.rb', line 48

def search_employee(name)
  return if name.empty?

  employees.find do |emp|
    [
      emp['displayName']&.downcase,
      "#{emp['firstName']&.downcase} #{emp['lastName']&.downcase}",
      "#{emp['preferredName']&.downcase} #{emp['lastName']&.downcase}",
      "#{emp['firstName']&.downcase} #{emp['customPreferredLastName']&.downcase}",
      "#{emp['preferredName']&.downcase} #{emp['customPreferredLastName']&.downcase}",
      emp['fullName5']&.downcase # this is firstName middleName lastName
    ].include?(name.downcase)
  end
end

#search_employee!(name) ⇒ Object Also known as: search_team_member!



64
65
66
67
68
69
# File 'lib/peoplegroup/connectors/hris.rb', line 64

def search_employee!(name)
  employee = search_employee(name)
  raise EmployeeNotFoundError, "No employee found with name #{name}" if employee.nil?

  employee
end

#search_employee_by_field(field:, value:) ⇒ Object Also known as: search_team_member_by_field



72
73
74
# File 'lib/peoplegroup/connectors/hris.rb', line 72

def search_employee_by_field(field:, value:)
  employees.find { |employee| employee[field] == value.to_s }
end

#search_employee_by_field!(field:, value:) ⇒ Object Also known as: search_team_member_by_field!



77
78
79
80
81
82
# File 'lib/peoplegroup/connectors/hris.rb', line 77

def search_employee_by_field!(field:, value:)
  employee = search_employee_by_field(field: field, value: value)
  raise EmployeeNotFoundError, "No employee found with #{field}: #{value}" if employee.nil?

  employee
end

#search_team_member_by_email(email) ⇒ Object Also known as: slack_email_lookup_with_fallback

Find the associated team member without checking case on their e-mail fields.



86
87
88
89
90
91
92
93
# File 'lib/peoplegroup/connectors/hris.rb', line 86

def search_team_member_by_email(email)
  return nil unless email

  team_members.find do |team_member|
    emails = [team_member['workEmail'], team_member['bestEmail'], team_member['homeEmail']]
    emails.compact.any? { |match| email.casecmp(match).zero? }
  end
end

#search_team_member_by_email!(email) ⇒ Object Also known as: slack_email_lookup_with_fallback!

Find the team member by email and raise error if not found.



97
98
99
100
101
102
103
# File 'lib/peoplegroup/connectors/hris.rb', line 97

def search_team_member_by_email!(email)
  team_member = search_team_member_by_email(email)

  return team_member if team_member

  raise EmployeeNotFoundError, "Could not find team member with the e-mail: #{email}"
end

#team_members_by_department(department) ⇒ Object



106
107
108
# File 'lib/peoplegroup/connectors/hris.rb', line 106

def team_members_by_department(department)
  active_and_current_team_members.select { |team_member| team_member['department'] == department }
end

#team_members_by_division(division) ⇒ Object



110
111
112
# File 'lib/peoplegroup/connectors/hris.rb', line 110

def team_members_by_division(division)
  active_and_current_team_members.select { |team_member| team_member['division'] == division }
end

#time_off_adjustment(employee_number, options) ⇒ Object



190
191
192
193
194
# File 'lib/peoplegroup/connectors/hris.rb', line 190

def time_off_adjustment(employee_number, options)
  # Staying in bamboo for workday first release
  # Will need to have talks with pto by roots admin
  @bamboo.time_off_adjustment(employee_number, options)
end

#time_off_policiesObject



202
203
204
# File 'lib/peoplegroup/connectors/hris.rb', line 202

def time_off_policies
  @bamboo.time_off_policies
end

#time_off_type(name) ⇒ Object



184
185
186
187
188
# File 'lib/peoplegroup/connectors/hris.rb', line 184

def time_off_type(name)
  # Staying in bamboo for workday first release
  # Will need to have talks with pto by roots admin
  @bamboo.time_off_type(name)
end

#update_employee(employee_number, employee_details_hash) ⇒ Object Also known as: update_team_member



141
142
143
144
# File 'lib/peoplegroup/connectors/hris.rb', line 141

def update_employee(employee_number, employee_details_hash)
  # Only used in activate_team_members.rb, which is not needed in Workday
  @bamboo.update_employee(employee_number, employee_details_hash)
end

#update_job_details(employee_number, data) ⇒ Object



159
160
161
# File 'lib/peoplegroup/connectors/hris.rb', line 159

def update_job_details(employee_number, data)
  @bamboo.update_job_details(employee_number, data)
end