Class: EventDispatchers::EmployeesWithoutTimesheetsEventDispatcher

Inherits:
BaseEventDispatcher show all
Defined in:
app/notifications/event_dispatchers/employees_without_timesheets_event_dispatcher.rb

Instance Attribute Summary

Attributes inherited from BaseEventDispatcher

#company_id

Instance Method Summary collapse

Methods inherited from BaseEventDispatcher

#initialize

Constructor Details

This class inherits a constructor from EventDispatchers::BaseEventDispatcher

Instance Method Details

#dispatchObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'app/notifications/event_dispatchers/employees_without_timesheets_event_dispatcher.rb', line 5

def dispatch
  company = Company.find(company_id)

  payroll_period_id = company.current_ending_payroll_period(remaining_ratio: 0.5)&.payroll_period_id
  return unless payroll_period_id

  return unless company.employees.without_timesheets_for_period(payroll_period_id).exists?

  ReferenceEvent.find_or_create_by!(
    slug: ReferenceEvent::Slugs::EMPLOYEES_WITHOUT_TIMESHEETS,
    level: ReferenceEvent::Levels::ERROR,
    company_id: company_id,
    reference: company,
    end_at: nil
  ).tap do |reference_event|
    reference_event.update!(
      last_verified_at: Time.current
    )
  end
end