Class: BrNfe::Product::Response::Build::NfeAutorizacao

Inherits:
Base show all
Defined in:
lib/br_nfe/product/response/build/nfe_autorizacao.rb

Instance Attribute Summary

Attributes inherited from Base

#operation, #savon_response

Attributes inherited from ActiveModelBase

#reference

Instance Method Summary collapse

Methods inherited from Base

#body_xml, #doc_original_xml, #header_xml, #nf_xmlns, #original_xml, #response, #response_xml, #url_xmlns_retorno, #xml_version, #xml_version_str

Methods inherited from ActiveModelBase

#assign_attributes, #default_values, #initialize

Constructor Details

This class inherits a constructor from BrNfe::ActiveModelBase

Instance Method Details

#async_protocolObject



49
50
51
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 49

def async_protocol
	@async_protocol ||= body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:infRec/nf:nRec', nf: nf_xmlns, ret: url_xmlns_retorno).text
end

#manage_invoices!Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 57

def manage_invoices!
	if async_protocol.present?
		notas_fiscais.each do |nf| 
			nf.protocol = async_protocol
			nf.processed_at = request_processed_at
			nf.status_code = get_processing_status_code
			nf.status_motive = get_processing_status_motive
		end
	elsif node_prot_nfe.present?
		notas_fiscais.each do |nfe|
			prot_nfe = parse_nokogiri_xml( node_prot_nfe.to_xml )
			set_invoice_protocol!(nfe, prot_nfe)
		end
	end
end

#node_prot_nfeObject



53
54
55
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 53

def node_prot_nfe
	body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:protNFe', nf: nf_xmlns, ret: url_xmlns_retorno)
end

#notas_fiscaisObject



7
8
9
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 7

def notas_fiscais
	operation.notas_fiscais
end

#response_classObject

Responsável por definir qual classe será instânciada para setar os valores de retorno referentes a cada operação.

Type: Class



16
17
18
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 16

def response_class
	BrNfe::Product::Response::NfeAutorizacao
end

#set_invoice_protocol!(invoice, prot_nfe) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 73

def set_invoice_protocol! invoice, prot_nfe
	invoice.processed_at    = get_processed_at_from_prot_nfe(  prot_nfe )
	invoice.protocol        = get_protocol_from_prot_nfe(      prot_nfe )
	invoice.digest_value    = get_digest_value_from_prot_nfe(  prot_nfe )
	invoice.status_code     = get_status_code_from_prot_nfe(   prot_nfe )
	invoice.status_motive   = get_status_motive_from_prot_nfe( prot_nfe )
	invoice.chave_de_acesso = get_access_key_from_prot_nfe(    prot_nfe )
	
	# Seta o XML da respectiva NF-e no objeto já com a tag <nfeProc>
	# e a tag do protocolo(<protNFe>)
	set_invoice_xml_with_prot_nfe!( invoice, prot_nfe ) if invoice.status == :success
end

#specific_attributesObject

Responsável por setar os atributos específicos para cada tipo de operação.

Type: Hash



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/br_nfe/product/response/build/nfe_autorizacao.rb', line 25

def specific_attributes
	attrs = {
		environment:              body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:tpAmb',    nf: nf_xmlns, ret: url_xmlns_retorno).text,
		app_version:              body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:verAplic', nf: nf_xmlns, ret: url_xmlns_retorno).text,
		processed_at:             request_processed_at,

		processing_status_code:   get_processing_status_code,
		processing_status_motive: get_processing_status_motive,
	}

	if async_protocol.present?
		# Se entrar aqui é porque o lote é assíncrono e tem um protocolo
		attrs[:protocol]    = async_protocol
		attrs[:tempo_medio] = body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:infRec/nf:tMed', nf: nf_xmlns, ret: url_xmlns_retorno).text
	else
		attrs[:protocol] = body_xml.xpath('//ret:nfeAutorizacaoLoteResult/nf:retEnviNFe/nf:protNFe/nf:infProt/nf:nProt', nf: nf_xmlns, ret: url_xmlns_retorno).text
	end

	manage_invoices!
	attrs[:notas_fiscais] = notas_fiscais

	attrs
end