Class: Nfe::Operations::Event

Inherits:
Base
  • Object
show all
Defined in:
lib/nfe/operations/event.rb

Direct Known Subclasses

CorrectionLetter, NfeCancel

Instance Attribute Summary

Attributes inherited from Base

#errors, #result

Instance Method Summary collapse

Methods inherited from Base

#execute

Constructor Details

#initialize(certificate, private_key, environment, nfe_key, sequential, date_time, detEvent, use_schema: true) ⇒ Event

Returns a new instance of Event.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nfe/operations/event.rb', line 6

def initialize(certificate, private_key, environment, nfe_key,
  sequential, date_time, detEvent, use_schema: true)
  super(certificate, private_key, use_schema: use_schema)

  @retEnvEvento = Services::Regress::RetEnvEvento.new
  @environment = environment
  @detEvent = detEvent
  @key = Helpers::NfeKey.parse(nfe_key)
  @date_time = date_time

  @object = object_to_send(nfe_key, sequential)

rescue NfeKeyError
  errors.add(:base, I18n.t("xml.invalid_nfe_key"))
end

Instance Method Details

#event_xmlObject



38
39
40
41
42
43
# File 'lib/nfe/operations/event.rb', line 38

def event_xml
  if success?
    procEventoNFe = Nfe::Models::ProcEventoNFe.new(@object.evento, @retEnvEvento.retEvento)
    procEventoNFe.to_xml
  end
end

#messageObject



34
35
36
# File 'lib/nfe/operations/event.rb', line 34

def message
  @retEnvEvento.retEvento.xMotivo if processed?
end

#processed?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/nfe/operations/event.rb', line 22

def processed?
  @retEnvEvento.cStat.to_i == processed_lot_code
end

#protocol_numberObject



45
46
47
# File 'lib/nfe/operations/event.rb', line 45

def protocol_number
  @retEnvEvento.retEvento.nProt if success?
end

#rejected?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/nfe/operations/event.rb', line 30

def rejected?
  @retEnvEvento.retEvento.cStat.to_i > 200
end

#success?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/nfe/operations/event.rb', line 26

def success?
  success_codes.include? @retEnvEvento.retEvento.cStat
end