class Nfe::Operations::Event

Public Class Methods

new(certificate, private_key, environment, nfe_key, sequential, date_time, detEvent, use_schema: true) click to toggle source
Calls superclass method Nfe::Operations::Base::new
# 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

Public Instance Methods

event_xml() click to toggle source
# 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
message() click to toggle source
# File lib/nfe/operations/event.rb, line 34
def message
  @retEnvEvento.retEvento.xMotivo if processed?
end
processed?() click to toggle source
# File lib/nfe/operations/event.rb, line 22
def processed?
  @retEnvEvento.cStat.to_i == processed_lot_code
end
protocol_number() click to toggle source
# File lib/nfe/operations/event.rb, line 45
def protocol_number
  @retEnvEvento.retEvento.nProt if success?
end
rejected?() click to toggle source
# File lib/nfe/operations/event.rb, line 30
def rejected?
  @retEnvEvento.retEvento.cStat.to_i > 200
end
success?() click to toggle source
# File lib/nfe/operations/event.rb, line 26
def success?
  success_codes.include? @retEnvEvento.retEvento.cStat
end

Protected Instance Methods

before_execute() click to toggle source
Calls superclass method Nfe::Operations::Base#before_execute
# File lib/nfe/operations/event.rb, line 50
def before_execute
  super

  sign @object.evento, @object.evento.id
end
handle_result(xml) click to toggle source
# File lib/nfe/operations/event.rb, line 56
def handle_result(xml)
  @retEnvEvento.parse! xml

  errors.add(:base, @retEnvEvento.xMotivo) if !processed?

  @retEnvEvento
end
schema_name() click to toggle source
# File lib/nfe/operations/event.rb, line 68
def schema_name
  ws_info.schema
end
ws_info() click to toggle source
# File lib/nfe/operations/event.rb, line 72
def ws_info
  Webservices::Wsinfo::Event.new(@environment, @key.uf, @detEvent.kind)
end
xpath() click to toggle source
# File lib/nfe/operations/event.rb, line 64
def xpath
  "//ns:retEnvEvento"
end

Private Instance Methods

default_lot() click to toggle source
# File lib/nfe/operations/event.rb, line 88
def default_lot
  1
end
event(nfe_key, sequential) click to toggle source
# File lib/nfe/operations/event.rb, line 92
def event(nfe_key, sequential)
  event = Nfe::Models::Evento.new

  event.versao = ws_info.version
  event.uf = @key.uf
  event.tpAmb = @environment
  event.tpEvento = @detEvent.tpEvent
  event.nSeqEvento = sequential
  event.cnpj = @key.cnpj
  event.chNFe = nfe_key
  event.dhEvento = @date_time
  event.detEvento = @detEvent

  event
end
object_to_send(nfe_key, sequential) click to toggle source
# File lib/nfe/operations/event.rb, line 77
def object_to_send(nfe_key, sequential)
  envEvento = Services::Dispatch::EnvEvento.new

  envEvento.versao = ws_info.version
  envEvento.idLote = default_lot
  @detEvent.versao = ws_info.version
  envEvento.evento = event(nfe_key, sequential)

  envEvento
end
processed_lot_code() click to toggle source
# File lib/nfe/operations/event.rb, line 108
def processed_lot_code
  128
end
success_codes() click to toggle source
# File lib/nfe/operations/event.rb, line 112
def success_codes
  [135, 136]
end