Class: Employee::WorkAnniversaryMessage
Instance Method Summary
collapse
Methods inherited from BaseService
#initialize, #log_debug, #log_error, #log_info, #log_warning, #logger, #options, #tagged_logger
Constructor Details
This class inherits a constructor from BaseService
Instance Method Details
#create_praise(employee_record) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
# File 'app/services/employee/work_anniversary_message.rb', line 15
def create_praise(employee_record)
return if employee_record.years_at_work == 0
logger.info "Creating work anniversary praise for #{employee_record.employee.full_name}"
p = nil
Praise.transaction do
p = Praise.create!(
employee_records: [employee_record],
praise_type: "work_anniversary",
headline: "Happy #{employee_record.years_at_work.ordinalize} Anniversary #{employee_record.employee.first_name}!",
praise: "Happy #{employee_record.years_at_work.ordinalize} Anniversary From Your WarmlyYours Family!",
praise_date: Date.current, image_url: get_badge_attachment,
notify: true,
notify_staff: true
)
p.publish
end
p
end
|
#get_badge ⇒ Object
44
45
46
47
|
# File 'app/services/employee/work_anniversary_message.rb', line 44
def get_badge
Image.find_by(title: 'Anniversary Badge')&.attachment
end
|
#get_badge_attachment ⇒ Object
35
36
37
38
|
# File 'app/services/employee/work_anniversary_message.rb', line 35
def get_badge_attachment
Image.find_by(title: 'Anniversary Badge').image_url(width: 300, encode_format: :jpeg)
end
|
#load_overdue_employee_records ⇒ Object
40
41
42
|
# File 'app/services/employee/work_anniversary_message.rb', line 40
def load_overdue_employee_records
EmployeeRecord.active_employees.where(EmployeeRecord[:next_work_anniversary].lteq(Date.current)).where(disable_special_events_alerts: false)
end
|
#process ⇒ Object
2
3
4
5
6
7
8
9
10
11
12
13
|
# File 'app/services/employee/work_anniversary_message.rb', line 2
def process
praises = []
records = load_overdue_employee_records
logger.info "No work anniversaries to process" if records.blank?
records.each do |er|
praises << create_praise(er)
schedule_next_work_anniversary(er)
end
praises
end
|
#schedule_next_work_anniversary(employee_record) ⇒ Object
49
50
51
52
53
54
|
# File 'app/services/employee/work_anniversary_message.rb', line 49
def schedule_next_work_anniversary(employee_record)
next_year = (Date.current + 1.year).year
employee_record.next_work_anniversary = employee_record.next_work_anniversary.change(year: next_year)
logger.info "Advancing work anniversary to #{employee_record.next_work_anniversary} for #{employee_record.employee.full_name}"
employee_record.save!
end
|