Class: EventDispatchers::PayrollPeriodWithoutTransactionEventDispatcher

Inherits:
BaseEventDispatcher show all
Defined in:
app/notifications/event_dispatchers/payroll_period_without_transaction_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
25
26
27
28
# File 'app/notifications/event_dispatchers/payroll_period_without_transaction_event_dispatcher.rb', line 5

def dispatch
  company = Company.find(company_id)

  previous_payroll_period = company.previous_payroll_period
  return unless previous_payroll_period

  previous_payroll_period_transaction_header = previous_payroll_period.payroll_transaction_header

  return if previous_payroll_period_transaction_header # if there is transaction, end the event
  return unless previous_payroll_period
  return if previous_payroll_period.run_payroll_deadline_passed? # end if the run payroll deadline has passed

  ReferenceEvent.find_or_create_by!(
    slug: ReferenceEvent::Slugs::PAYROLL_PERIOD_WITHOUT_TRANSACTION,
    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