Class: EventDispatchers::InvalidInvoiceEventDispatcher

Inherits:
BaseEventDispatcher show all
Defined in:
app/notifications/event_dispatchers/invalid_invoice_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
# File 'app/notifications/event_dispatchers/invalid_invoice_event_dispatcher.rb', line 5

def dispatch
  EdiInvoice.where(company_id: company_id, status: '03').find_each do |edi_invoice|
    ReferenceEvent.find_or_create_by!(
      slug: ReferenceEvent::Slugs::INVALID_INVOICE,
      level: ReferenceEvent::Levels::ERROR,
      company_id: company_id,
      reference: edi_invoice,
      end_at: nil
    ).tap do |reference_event|
      reference_event.update!(
        last_verified_at: Time.current
      )
    end
  end
end