Class: BrNfe::Response::Service::BuildResponse

Inherits:
ActiveModelBase show all
Defined in:
lib/br_nfe/response/service/build_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from ActiveModelBase

#assign_attributes, #default_values, #initialize

Constructor Details

This class inherits a constructor from BrNfe::ActiveModelBase

Instance Attribute Details

#body_xml_pathObject

4: Alguns Webservices trazem dentro do body da resposta SOAp outro XML com as informações necessárias. Quando isso aocntece é preciso converter esse XML para um HASH para que possamos encontrar os valores necessários.



19
20
21
# File 'lib/br_nfe/response/service/build_response.rb', line 19

def body_xml_path
  @body_xml_path
end

#cancelation_date_time_pathObject

data e hora do cancelamento da nf



41
42
43
# File 'lib/br_nfe/response/service/build_response.rb', line 41

def cancelation_date_time_path
  @cancelation_date_time_path
end

#invoice_base_calculation_pathObject

Valor da base de cálculo



79
80
81
# File 'lib/br_nfe/response/service/build_response.rb', line 79

def invoice_base_calculation_path
  @invoice_base_calculation_path
end

#invoice_cancelamento_cnpj_pathObject

CNPJ da NF cancelada



91
92
93
# File 'lib/br_nfe/response/service/build_response.rb', line 91

def invoice_cancelamento_cnpj_path
  @invoice_cancelamento_cnpj_path
end

#invoice_cancelamento_codigo_pathObject

Código do cancelamento da NFS



89
90
91
# File 'lib/br_nfe/response/service/build_response.rb', line 89

def invoice_cancelamento_codigo_path
  @invoice_cancelamento_codigo_path
end

#invoice_cancelamento_data_hora_pathObject

Data e hora do cancelamento



93
94
95
# File 'lib/br_nfe/response/service/build_response.rb', line 93

def invoice_cancelamento_data_hora_path
  @invoice_cancelamento_data_hora_path
end

#invoice_cancelamento_inscricao_municipal_pathObject

Inscrição municipal da nota cancelada



94
95
96
# File 'lib/br_nfe/response/service/build_response.rb', line 94

def invoice_cancelamento_inscricao_municipal_path
  @invoice_cancelamento_inscricao_municipal_path
end

#invoice_cancelamento_municipio_pathObject

Municipo da nota cancelada



92
93
94
# File 'lib/br_nfe/response/service/build_response.rb', line 92

def invoice_cancelamento_municipio_path
  @invoice_cancelamento_municipio_path
end

#invoice_cancelamento_numero_nf_pathObject

Número da NFS cancelada



90
91
92
# File 'lib/br_nfe/response/service/build_response.rb', line 90

def invoice_cancelamento_numero_nf_path
  @invoice_cancelamento_numero_nf_path
end

#invoice_cnae_code_pathObject

CNAE utilizado na nf



66
67
68
# File 'lib/br_nfe/response/service/build_response.rb', line 66

def invoice_cnae_code_path
  @invoice_cnae_code_path
end

#invoice_codigo_art_pathObject

Código art



97
98
99
# File 'lib/br_nfe/response/service/build_response.rb', line 97

def invoice_codigo_art_path
  @invoice_codigo_art_path
end

#invoice_codigo_municipio_pathObject

Código do municipio prestador do serviço



68
69
70
# File 'lib/br_nfe/response/service/build_response.rb', line 68

def invoice_codigo_municipio_path
  @invoice_codigo_municipio_path
end

#invoice_codigo_obra_pathObject

Código obra



96
97
98
# File 'lib/br_nfe/response/service/build_response.rb', line 96

def invoice_codigo_obra_path
  @invoice_codigo_obra_path
end

#invoice_codigo_verificacao_pathObject

código de verificação



48
49
50
# File 'lib/br_nfe/response/service/build_response.rb', line 48

def invoice_codigo_verificacao_path
  @invoice_codigo_verificacao_path
end

#invoice_competencia_pathObject

Competência da nf



59
60
61
# File 'lib/br_nfe/response/service/build_response.rb', line 59

def invoice_competencia_path
  @invoice_competencia_path
end

#invoice_data_emissao_pathObject

Data de emissão da NF



49
50
51
# File 'lib/br_nfe/response/service/build_response.rb', line 49

def invoice_data_emissao_path
  @invoice_data_emissao_path
end

#invoice_data_emissao_rps_pathObject

Data de emissão do RPS



58
59
60
# File 'lib/br_nfe/response/service/build_response.rb', line 58

def invoice_data_emissao_rps_path
  @invoice_data_emissao_rps_path
end

#invoice_deductions_pathObject

Valor das deduções



70
71
72
# File 'lib/br_nfe/response/service/build_response.rb', line 70

def invoice_deductions_path
  @invoice_deductions_path
end

#invoice_desconto_condicionado_pathObject

Valor do desconto condicionado



82
83
84
# File 'lib/br_nfe/response/service/build_response.rb', line 82

def invoice_desconto_condicionado_path
  @invoice_desconto_condicionado_path
end

#invoice_desconto_incondicionado_pathObject

Valor do desconto incondicionado



83
84
85
# File 'lib/br_nfe/response/service/build_response.rb', line 83

def invoice_desconto_incondicionado_path
  @invoice_desconto_incondicionado_path
end

#invoice_description_pathObject

Descrição da nf



67
68
69
# File 'lib/br_nfe/response/service/build_response.rb', line 67

def invoice_description_path
  @invoice_description_path
end

#invoice_destinatario_cnpj_pathObject

Cnpj do destinatário da NFS



112
113
114
# File 'lib/br_nfe/response/service/build_response.rb', line 112

def invoice_destinatario_cnpj_path
  @invoice_destinatario_cnpj_path
end

#invoice_destinatario_cpf_pathObject

Cpf do destinatário da NFS



111
112
113
# File 'lib/br_nfe/response/service/build_response.rb', line 111

def invoice_destinatario_cpf_path
  @invoice_destinatario_cpf_path
end

#invoice_destinatario_email_pathObject

Email do destinatário da NFS



118
119
120
# File 'lib/br_nfe/response/service/build_response.rb', line 118

def invoice_destinatario_email_path
  @invoice_destinatario_email_path
end

#invoice_destinatario_endereco_bairro_pathObject

Bairro do destinatário da NFS



122
123
124
# File 'lib/br_nfe/response/service/build_response.rb', line 122

def invoice_destinatario_endereco_bairro_path
  @invoice_destinatario_endereco_bairro_path
end

#invoice_destinatario_endereco_cep_pathObject

Cep do destinatário da NFS



125
126
127
# File 'lib/br_nfe/response/service/build_response.rb', line 125

def invoice_destinatario_endereco_cep_path
  @invoice_destinatario_endereco_cep_path
end

#invoice_destinatario_endereco_codigo_municipio_pathObject

Codigo_municipio do destinatário da NFS



123
124
125
# File 'lib/br_nfe/response/service/build_response.rb', line 123

def invoice_destinatario_endereco_codigo_municipio_path
  @invoice_destinatario_endereco_codigo_municipio_path
end

#invoice_destinatario_endereco_complemento_pathObject

Complemento do destinatário da NFS



121
122
123
# File 'lib/br_nfe/response/service/build_response.rb', line 121

def invoice_destinatario_endereco_complemento_path
  @invoice_destinatario_endereco_complemento_path
end

#invoice_destinatario_endereco_logradouro_pathObject

Logradouro do destinatário da NFS



119
120
121
# File 'lib/br_nfe/response/service/build_response.rb', line 119

def invoice_destinatario_endereco_logradouro_path
  @invoice_destinatario_endereco_logradouro_path
end

#invoice_destinatario_endereco_numero_pathObject

Numero do destinatário da NFS



120
121
122
# File 'lib/br_nfe/response/service/build_response.rb', line 120

def invoice_destinatario_endereco_numero_path
  @invoice_destinatario_endereco_numero_path
end

#invoice_destinatario_endereco_uf_pathObject

Uf do destinatário da NFS



124
125
126
# File 'lib/br_nfe/response/service/build_response.rb', line 124

def invoice_destinatario_endereco_uf_path
  @invoice_destinatario_endereco_uf_path
end

#invoice_destinatario_inscricao_estadual_pathObject

Inscricao estadual do destinatário da NFS



114
115
116
# File 'lib/br_nfe/response/service/build_response.rb', line 114

def invoice_destinatario_inscricao_estadual_path
  @invoice_destinatario_inscricao_estadual_path
end

#invoice_destinatario_inscricao_municipal_pathObject

Inscricao municipal do destinatário da NFS



113
114
115
# File 'lib/br_nfe/response/service/build_response.rb', line 113

def invoice_destinatario_inscricao_municipal_path
  @invoice_destinatario_inscricao_municipal_path
end

#invoice_destinatario_inscricao_suframa_pathObject

Inscricao suframa do destinatário da NFS



115
116
117
# File 'lib/br_nfe/response/service/build_response.rb', line 115

def invoice_destinatario_inscricao_suframa_path
  @invoice_destinatario_inscricao_suframa_path
end

#invoice_destinatario_razao_social_pathObject

Razao social do destinatário da NFS



116
117
118
# File 'lib/br_nfe/response/service/build_response.rb', line 116

def invoice_destinatario_razao_social_path
  @invoice_destinatario_razao_social_path
end

#invoice_destinatario_telefone_pathObject

Telefone do destinatário da NFS



117
118
119
# File 'lib/br_nfe/response/service/build_response.rb', line 117

def invoice_destinatario_telefone_path
  @invoice_destinatario_telefone_path
end

#invoice_emitente_cnpj_pathObject

Cnpj do emitente da NFS



98
99
100
# File 'lib/br_nfe/response/service/build_response.rb', line 98

def invoice_emitente_cnpj_path
  @invoice_emitente_cnpj_path
end

#invoice_emitente_email_pathObject

Email do emitente da NFS



103
104
105
# File 'lib/br_nfe/response/service/build_response.rb', line 103

def invoice_emitente_email_path
  @invoice_emitente_email_path
end

#invoice_emitente_endereco_bairro_pathObject

Bairro do emitente da NFS



107
108
109
# File 'lib/br_nfe/response/service/build_response.rb', line 107

def invoice_emitente_endereco_bairro_path
  @invoice_emitente_endereco_bairro_path
end

#invoice_emitente_endereco_cep_pathObject

Cep do emitente da NFS



110
111
112
# File 'lib/br_nfe/response/service/build_response.rb', line 110

def invoice_emitente_endereco_cep_path
  @invoice_emitente_endereco_cep_path
end

#invoice_emitente_endereco_codigo_municipio_pathObject

Codigo_municipio do emitente da NFS



108
109
110
# File 'lib/br_nfe/response/service/build_response.rb', line 108

def invoice_emitente_endereco_codigo_municipio_path
  @invoice_emitente_endereco_codigo_municipio_path
end

#invoice_emitente_endereco_complemento_pathObject

Complemento do emitente da NFS



106
107
108
# File 'lib/br_nfe/response/service/build_response.rb', line 106

def invoice_emitente_endereco_complemento_path
  @invoice_emitente_endereco_complemento_path
end

#invoice_emitente_endereco_logradouro_pathObject

Logradouro do emitente da NFS



104
105
106
# File 'lib/br_nfe/response/service/build_response.rb', line 104

def invoice_emitente_endereco_logradouro_path
  @invoice_emitente_endereco_logradouro_path
end

#invoice_emitente_endereco_numero_pathObject

Numero do emitente da NFS



105
106
107
# File 'lib/br_nfe/response/service/build_response.rb', line 105

def invoice_emitente_endereco_numero_path
  @invoice_emitente_endereco_numero_path
end

#invoice_emitente_endereco_uf_pathObject

Uf do emitente da NFS



109
110
111
# File 'lib/br_nfe/response/service/build_response.rb', line 109

def invoice_emitente_endereco_uf_path
  @invoice_emitente_endereco_uf_path
end

#invoice_emitente_inscricao_municipal_pathObject

Inscricao municipal do emitente da NFS



99
100
101
# File 'lib/br_nfe/response/service/build_response.rb', line 99

def invoice_emitente_inscricao_municipal_path
  @invoice_emitente_inscricao_municipal_path
end

#invoice_emitente_nome_fantasia_pathObject

Nome fantasia do emitente da NFS



101
102
103
# File 'lib/br_nfe/response/service/build_response.rb', line 101

def invoice_emitente_nome_fantasia_path
  @invoice_emitente_nome_fantasia_path
end

#invoice_emitente_razao_social_pathObject

Razao social do emitente da NFS



100
101
102
# File 'lib/br_nfe/response/service/build_response.rb', line 100

def invoice_emitente_razao_social_path
  @invoice_emitente_razao_social_path
end

#invoice_emitente_telefone_pathObject

Telefone do emitente da NFS



102
103
104
# File 'lib/br_nfe/response/service/build_response.rb', line 102

def invoice_emitente_telefone_path
  @invoice_emitente_telefone_path
end

#invoice_incentivador_cultural_pathObject

Incentivo cultural



63
64
65
# File 'lib/br_nfe/response/service/build_response.rb', line 63

def invoice_incentivador_cultural_path
  @invoice_incentivador_cultural_path
end

#invoice_iss_retained_pathObject

Se o ISS está retido



76
77
78
# File 'lib/br_nfe/response/service/build_response.rb', line 76

def invoice_iss_retained_path
  @invoice_iss_retained_path
end

#invoice_iss_tax_rate_pathObject

Percentual do imposto de ISS



80
81
82
# File 'lib/br_nfe/response/service/build_response.rb', line 80

def invoice_iss_tax_rate_path
  @invoice_iss_tax_rate_path
end

#invoice_item_lista_servico_pathObject

Código do serviço prestado



65
66
67
# File 'lib/br_nfe/response/service/build_response.rb', line 65

def invoice_item_lista_servico_path
  @invoice_item_lista_servico_path
end

#invoice_municipio_incidencia_pathObject

Código do municipio em que o serviço foi prestado



86
87
88
# File 'lib/br_nfe/response/service/build_response.rb', line 86

def invoice_municipio_incidencia_path
  @invoice_municipio_incidencia_path
end

#invoice_natureza_operacao_pathObject

natureza de operação



60
61
62
# File 'lib/br_nfe/response/service/build_response.rb', line 60

def invoice_natureza_operacao_path
  @invoice_natureza_operacao_path
end

#invoice_nfe_substituidora_pathObject

Número da NFS substituidora



95
96
97
# File 'lib/br_nfe/response/service/build_response.rb', line 95

def invoice_nfe_substituidora_path
  @invoice_nfe_substituidora_path
end

#invoice_numero_nf_pathObject

numero da nota fiscal



47
48
49
# File 'lib/br_nfe/response/service/build_response.rb', line 47

def invoice_numero_nf_path
  @invoice_numero_nf_path
end

#invoice_numero_processo_pathObject

Número do processo da NF



85
86
87
# File 'lib/br_nfe/response/service/build_response.rb', line 85

def invoice_numero_processo_path
  @invoice_numero_processo_path
end

#invoice_optante_simples_nacional_pathObject

Se é optante do simples



62
63
64
# File 'lib/br_nfe/response/service/build_response.rb', line 62

def invoice_optante_simples_nacional_path
  @invoice_optante_simples_nacional_path
end

#invoice_orgao_gerador_municipio_pathObject

Órgão gerador municipal da NFS



87
88
89
# File 'lib/br_nfe/response/service/build_response.rb', line 87

def invoice_orgao_gerador_municipio_path
  @invoice_orgao_gerador_municipio_path
end

#invoice_orgao_gerador_uf_pathObject

Órgão gerador estadual da NFS



88
89
90
# File 'lib/br_nfe/response/service/build_response.rb', line 88

def invoice_orgao_gerador_uf_path
  @invoice_orgao_gerador_uf_path
end

#invoice_outras_informacoes_pathObject

Outras informações da nf



64
65
66
# File 'lib/br_nfe/response/service/build_response.rb', line 64

def invoice_outras_informacoes_path
  @invoice_outras_informacoes_path
end

#invoice_outras_retencoes_pathObject

Valor Outras retenções



77
78
79
# File 'lib/br_nfe/response/service/build_response.rb', line 77

def invoice_outras_retencoes_path
  @invoice_outras_retencoes_path
end

#invoice_regime_especial_tributacao_pathObject

Regime especial de tributação



61
62
63
# File 'lib/br_nfe/response/service/build_response.rb', line 61

def invoice_regime_especial_tributacao_path
  @invoice_regime_especial_tributacao_path
end

#invoice_responsavel_retencao_pathObject

Responsável pela retenção



84
85
86
# File 'lib/br_nfe/response/service/build_response.rb', line 84

def invoice_responsavel_retencao_path
  @invoice_responsavel_retencao_path
end

#invoice_rps_numero_pathObject

Número do RPS da nota



51
52
53
# File 'lib/br_nfe/response/service/build_response.rb', line 51

def invoice_rps_numero_path
  @invoice_rps_numero_path
end

#invoice_rps_serie_pathObject

Número da série do RPS da nota



52
53
54
# File 'lib/br_nfe/response/service/build_response.rb', line 52

def invoice_rps_serie_path
  @invoice_rps_serie_path
end

#invoice_rps_situacao_pathObject

Situação da NF



54
55
56
# File 'lib/br_nfe/response/service/build_response.rb', line 54

def invoice_rps_situacao_path
  @invoice_rps_situacao_path
end

#invoice_rps_substituido_numero_pathObject

Número do RPS da nota substituido



55
56
57
# File 'lib/br_nfe/response/service/build_response.rb', line 55

def invoice_rps_substituido_numero_path
  @invoice_rps_substituido_numero_path
end

#invoice_rps_substituido_serie_pathObject

Número da série do RPS da nota substituido



56
57
58
# File 'lib/br_nfe/response/service/build_response.rb', line 56

def invoice_rps_substituido_serie_path
  @invoice_rps_substituido_serie_path
end

#invoice_rps_substituido_tipo_pathObject

Tipo do RPS substituido



57
58
59
# File 'lib/br_nfe/response/service/build_response.rb', line 57

def invoice_rps_substituido_tipo_path
  @invoice_rps_substituido_tipo_path
end

#invoice_rps_tipo_pathObject

Tipo do RPS



53
54
55
# File 'lib/br_nfe/response/service/build_response.rb', line 53

def invoice_rps_tipo_path
  @invoice_rps_tipo_path
end

#invoice_total_iss_pathObject

Valor total de ISS



78
79
80
# File 'lib/br_nfe/response/service/build_response.rb', line 78

def invoice_total_iss_path
  @invoice_total_iss_path
end

#invoice_total_services_pathObject

Valor total dos serviços



69
70
71
# File 'lib/br_nfe/response/service/build_response.rb', line 69

def invoice_total_services_path
  @invoice_total_services_path
end

#invoice_url_nf_pathObject

URL para visualizar a DANFE (apenas alguns emissores disponibilizam isso)



50
51
52
# File 'lib/br_nfe/response/service/build_response.rb', line 50

def invoice_url_nf_path
  @invoice_url_nf_path
end

#invoice_valor_cofins_pathObject

Valor do COFINS



72
73
74
# File 'lib/br_nfe/response/service/build_response.rb', line 72

def invoice_valor_cofins_path
  @invoice_valor_cofins_path
end

#invoice_valor_csll_pathObject

Valor da CSLL



75
76
77
# File 'lib/br_nfe/response/service/build_response.rb', line 75

def invoice_valor_csll_path
  @invoice_valor_csll_path
end

#invoice_valor_inss_pathObject

Valor do INSS



73
74
75
# File 'lib/br_nfe/response/service/build_response.rb', line 73

def invoice_valor_inss_path
  @invoice_valor_inss_path
end

#invoice_valor_ir_pathObject

Valor do IR



74
75
76
# File 'lib/br_nfe/response/service/build_response.rb', line 74

def invoice_valor_ir_path
  @invoice_valor_ir_path
end

#invoice_valor_liquido_pathObject

Valor liquido da NFS



81
82
83
# File 'lib/br_nfe/response/service/build_response.rb', line 81

def invoice_valor_liquido_path
  @invoice_valor_liquido_path
end

#invoice_valor_pis_pathObject

Valor do PIS



71
72
73
# File 'lib/br_nfe/response/service/build_response.rb', line 71

def invoice_valor_pis_path
  @invoice_valor_pis_path
end

#invoices_pathObject

o caminho para listar as notas fiscais



46
47
48
# File 'lib/br_nfe/response/service/build_response.rb', line 46

def invoices_path
  @invoices_path
end

#keys_root_pathObject

2: Um array com o caminho inicial padrão da requisição de retorno



10
11
12
# File 'lib/br_nfe/response/service/build_response.rb', line 10

def keys_root_path
  @keys_root_path
end

#lot_number_pathObject

Caminho para encontrar



28
29
30
# File 'lib/br_nfe/response/service/build_response.rb', line 28

def lot_number_path
  @lot_number_path
end

#message_code_keyObject

chave que representa o codigo do erro



43
44
45
# File 'lib/br_nfe/response/service/build_response.rb', line 43

def message_code_key
  @message_code_key
end

#message_errors_pathObject

local para encontrar as mensagens de erro



42
43
44
# File 'lib/br_nfe/response/service/build_response.rb', line 42

def message_errors_path
  @message_errors_path
end

#message_msg_keyObject

chave que representa a mensagem do erro



44
45
46
# File 'lib/br_nfe/response/service/build_response.rb', line 44

def message_msg_key
  @message_msg_key
end

#message_solution_keyObject

chave que representa a solução do erro



45
46
47
# File 'lib/br_nfe/response/service/build_response.rb', line 45

def message_solution_key
  @message_solution_key
end

#nfe_xml_pathObject

3: Caminho para encontrar o XML da NF-e



13
14
15
# File 'lib/br_nfe/response/service/build_response.rb', line 13

def nfe_xml_path
  @nfe_xml_path
end

#protocol_pathObject

o protocolo



29
30
31
# File 'lib/br_nfe/response/service/build_response.rb', line 29

def protocol_path
  @protocol_path
end

#received_date_pathObject

a data de recebimento do xml



30
31
32
# File 'lib/br_nfe/response/service/build_response.rb', line 30

def received_date_path
  @received_date_path
end

#savon_responseObject

1: A resposta da requisição soap



7
8
9
# File 'lib/br_nfe/response/service/build_response.rb', line 7

def savon_response
  @savon_response
end

#situation_key_valuesObject

Returns the value of attribute situation_key_values.



32
33
34
# File 'lib/br_nfe/response/service/build_response.rb', line 32

def situation_key_values
  @situation_key_values
end

#situation_pathObject

a situação do lote rps



31
32
33
# File 'lib/br_nfe/response/service/build_response.rb', line 31

def situation_path
  @situation_path
end

#xml_encodeObject

5: Codificação original do XML de resposta para que seja convertido

para UTF-8


23
24
25
# File 'lib/br_nfe/response/service/build_response.rb', line 23

def xml_encode
  @xml_encode
end

Instance Method Details

#body_converted_to_xmlObject

Converte o body da requisição em XML (String) Isso é necessário quando dentro do body vem a resposta com outro XML

Tipo de retorno: String



164
165
166
# File 'lib/br_nfe/response/service/build_response.rb', line 164

def body_converted_to_xml
  @body_converted_to_xml ||= canonicalize("#{find_value_for_keys(savon_response.try(:body), body_xml_path)}".encode(xml_encode).force_encoding('UTF-8'))
end

#build_cancelation_fields_nfe(nfe, invoice_hash) ⇒ Object



383
384
385
386
387
388
389
390
391
392
393
# File 'lib/br_nfe/response/service/build_response.rb', line 383

def build_cancelation_fields_nfe(nfe, invoice_hash)
  nfe.assign_attributes({
    cancelamento_codigo:              find_value_for_keys(invoice_hash, invoice_cancelamento_codigo_path             ),
    cancelamento_numero_nf:           find_value_for_keys(invoice_hash, invoice_cancelamento_numero_nf_path          ),
    cancelamento_cnpj:                find_value_for_keys(invoice_hash, invoice_cancelamento_cnpj_path               ),
    cancelamento_inscricao_municipal: find_value_for_keys(invoice_hash, invoice_cancelamento_inscricao_municipal_path),
    cancelamento_municipio:           find_value_for_keys(invoice_hash, invoice_cancelamento_municipio_path          ),
    cancelamento_data_hora:           find_value_for_keys(invoice_hash, invoice_cancelamento_data_hora_path          ),
    nfe_substituidora:                find_value_for_keys(invoice_hash, invoice_nfe_substituidora_path               ),
  })
end

#build_destinatario_nfe(nfe, invoice_hash) ⇒ Object



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/br_nfe/response/service/build_response.rb', line 437

def build_destinatario_nfe(nfe, invoice_hash)
  nfe.assign_attributes({
    destinatario: {
      cpf_cnpj: (find_value_for_keys(invoice_hash, invoice_destinatario_cpf_path) || find_value_for_keys(invoice_hash, invoice_destinatario_cnpj_path)),
      inscricao_municipal:       find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_municipal_path),
      inscricao_estadual:        find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_estadual_path),
      inscricao_suframa:         find_value_for_keys(invoice_hash, invoice_destinatario_inscricao_suframa_path),
      razao_social:              find_value_for_keys(invoice_hash, invoice_destinatario_razao_social_path),
      telefone:                  find_value_for_keys(invoice_hash, invoice_destinatario_telefone_path),
      email:                     find_value_for_keys(invoice_hash, invoice_destinatario_email_path),
      endereco: {
        logradouro:             find_value_for_keys(invoice_hash, invoice_destinatario_endereco_logradouro_path),
        numero:                 find_value_for_keys(invoice_hash, invoice_destinatario_endereco_numero_path),
        complemento:            find_value_for_keys(invoice_hash, invoice_destinatario_endereco_complemento_path),
        bairro:                 find_value_for_keys(invoice_hash, invoice_destinatario_endereco_bairro_path),
        codigo_municipio:       find_value_for_keys(invoice_hash, invoice_destinatario_endereco_codigo_municipio_path),
        uf:                     find_value_for_keys(invoice_hash, invoice_destinatario_endereco_uf_path),
        cep:                    find_value_for_keys(invoice_hash, invoice_destinatario_endereco_cep_path),
      }
    }
  })
end

#build_emitente_nfe(nfe, invoice_hash) ⇒ Object



415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
# File 'lib/br_nfe/response/service/build_response.rb', line 415

def build_emitente_nfe(nfe, invoice_hash)
  nfe.assign_attributes({
    emitente: {
      cnpj:                find_value_for_keys(invoice_hash, invoice_emitente_cnpj_path                  ),
      inscricao_municipal: find_value_for_keys(invoice_hash, invoice_emitente_inscricao_municipal_path   ),
      razao_social:        find_value_for_keys(invoice_hash, invoice_emitente_razao_social_path          ),
      nome_fantasia:       find_value_for_keys(invoice_hash, invoice_emitente_nome_fantasia_path         ),
      telefone:            find_value_for_keys(invoice_hash, invoice_emitente_telefone_path              ),
      email:               find_value_for_keys(invoice_hash, invoice_emitente_email_path                 ),
      endereco: {
        logradouro:       find_value_for_keys(invoice_hash, invoice_emitente_endereco_logradouro_path         ),
        numero:           find_value_for_keys(invoice_hash, invoice_emitente_endereco_numero_path             ),
        complemento:      find_value_for_keys(invoice_hash, invoice_emitente_endereco_complemento_path        ),
        bairro:           find_value_for_keys(invoice_hash, invoice_emitente_endereco_bairro_path             ),
        codigo_municipio: find_value_for_keys(invoice_hash, invoice_emitente_endereco_codigo_municipio_path   ),
        uf:               find_value_for_keys(invoice_hash, invoice_emitente_endereco_uf_path                 ),
        cep:              find_value_for_keys(invoice_hash, invoice_emitente_endereco_cep_path                ),
      }
    }
  })
end

#build_rps_fields_nfe(nfe, invoice_hash) ⇒ Object



370
371
372
373
374
375
376
377
378
379
380
381
# File 'lib/br_nfe/response/service/build_response.rb', line 370

def build_rps_fields_nfe(nfe, invoice_hash)
  nfe.assign_attributes({
    rps_numero:                       find_value_for_keys(invoice_hash, invoice_rps_numero_path                      ),
    rps_serie:                        find_value_for_keys(invoice_hash, invoice_rps_serie_path                       ),
    rps_tipo:                         find_value_for_keys(invoice_hash, invoice_rps_tipo_path                        ),
    rps_situacao:                     find_value_for_keys(invoice_hash, invoice_rps_situacao_path                    ),
    rps_substituido_numero:           find_value_for_keys(invoice_hash, invoice_rps_substituido_numero_path          ),
    rps_substituido_serie:            find_value_for_keys(invoice_hash, invoice_rps_substituido_serie_path           ),
    rps_substituido_tipo:             find_value_for_keys(invoice_hash, invoice_rps_substituido_tipo_path            ),
    data_emissao_rps:                 find_value_for_keys(invoice_hash, invoice_data_emissao_rps_path                ),
  })
end

#build_values_nfe(nfe, invoice_hash) ⇒ Object



395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
# File 'lib/br_nfe/response/service/build_response.rb', line 395

def build_values_nfe(nfe, invoice_hash)
  nfe.assign_attributes({
    total_services:          find_value_for_keys(invoice_hash, invoice_total_services_path                  ),
    deductions:              find_value_for_keys(invoice_hash, invoice_deductions_path                      ),
    valor_pis:               find_value_for_keys(invoice_hash, invoice_valor_pis_path                       ),
    valor_cofins:            find_value_for_keys(invoice_hash, invoice_valor_cofins_path                    ),
    valor_inss:              find_value_for_keys(invoice_hash, invoice_valor_inss_path                      ),
    valor_ir:                find_value_for_keys(invoice_hash, invoice_valor_ir_path                        ),
    valor_csll:              find_value_for_keys(invoice_hash, invoice_valor_csll_path                      ),
    iss_retained:            find_value_for_keys(invoice_hash, invoice_iss_retained_path                    ),
    outras_retencoes:        find_value_for_keys(invoice_hash, invoice_outras_retencoes_path                ),
    total_iss:               find_value_for_keys(invoice_hash, invoice_total_iss_path                       ),
    base_calculation:        find_value_for_keys(invoice_hash, invoice_base_calculation_path                ),
    iss_tax_rate:            find_value_for_keys(invoice_hash, invoice_iss_tax_rate_path                    ),
    valor_liquido:           find_value_for_keys(invoice_hash, invoice_valor_liquido_path                   ),
    desconto_condicionado:   find_value_for_keys(invoice_hash, invoice_desconto_condicionado_path           ),
    desconto_incondicionado: find_value_for_keys(invoice_hash, invoice_desconto_incondicionado_path         ),
  })
end

#find_value_for_keys(hash, keys) ⇒ Object

Método utilizado para encontrar valores em um Hash passando o caminho do valor em um array onde contém as chaves ordenadas. Recebe 2 parêmntros: 1º um o hash onde contém o valor a ser encontrado 2º um array com as chaves em sequencia formando o caminho para encontrar o valor.

A funcionalidade desse método funciona parecido com o ‘.dig` da classe Hash do Ruby 2.3.0. A diferença é que no caso de exmeplo a seguir não apresenta uma excessão par ao usuário hash = {v2: ’valor string’} hash.dig(:v1, :v2, :v3) <- Dá erro find_value_for_keys(hash, [:v1, :v2, :v3] <- Retorna nil e não da erro

Tipo de retorno: Anything



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
# File 'lib/br_nfe/response/service/build_response.rb', line 184

def find_value_for_keys(hash, keys)
  return if keys.blank?
  keys = [keys] unless keys.is_a?(Array)
  
  result = hash
  keys.each do |key|
    if result.is_a?(Hash)
      result = result[key]
    else
      result = nil
      break
    end
  end
  result
end

#get_cancelation_date_timeObject

Método utilizado para pegar o valor da data e hora de cancelmaento Só é utilizado para cancelar a NF-e

Tipo de retorno: DateTime OU Nil OU String



328
329
330
# File 'lib/br_nfe/response/service/build_response.rb', line 328

def get_cancelation_date_time
  find_value_for_keys(savon_body, path_with_root(cancelation_date_time_path)) if cancelation_date_time_path.present?
end

#get_invoicesObject

Método que retorna as notas fiscais emitidas. Como pode ser que retorne mais de uma NF, a busca pela NF pode retornar um Array ou um Hash. Se retornar um array é porque existe mais de uma NFE, então é necessario percorer com um loop e instanciar cada nota com seus valores. Se retornar um Hash é porque tem apenas uma NFe, e nesse caso irá instanciar apenas a nfe encontrada.

Tipo de retorno: Array



259
260
261
262
263
264
265
266
267
268
# File 'lib/br_nfe/response/service/build_response.rb', line 259

def get_invoices
  invoices = []
  _invoices = find_value_for_keys(savon_body, path_with_root(invoices_path))
  if _invoices.is_a?(Hash)
    invoices << instance_invoice(_invoices)
  elsif _invoices.is_a?(Array)
    _invoices.map{|inv| invoices << instance_invoice(inv) }
  end
  invoices
end

#get_lot_numberObject

Método utilizado para pegar o número do lote RPS

Tipo de retorno: String



303
304
305
# File 'lib/br_nfe/response/service/build_response.rb', line 303

def get_lot_number
  find_value_for_keys(savon_body, path_with_root(lot_number_path))
end

#get_message_for_hash(msg_hash) ⇒ Object

Método utilizado para quando encontrar uam mensagem que seja um HAsh, onde nesse caso a mensagem terá um codigo de erro, uma mensagem, e uma mensagem de solução

Tipo de retorno: hash



241
242
243
244
245
246
247
# File 'lib/br_nfe/response/service/build_response.rb', line 241

def get_message_for_hash(msg_hash)
  {
    code:     find_value_for_keys(msg_hash, message_code_key),
    message:  find_value_for_keys(msg_hash, message_msg_key),
    solution: find_value_for_keys(msg_hash, message_solution_key)
  }
end

#get_message_for_path(msg_path) ⇒ Object

Método que retorna as mensagens de retorno da requisição Quando procurar a mensagem a mesma pode retornar em 3 formatos: Hash: Onde encontrou apenas 1 mensagem com Codigo, Mensagem e Solução Array: Onde encontrou mais de uma mensagem com Codigo, Mensagem e Solução String: Onde encontrou uma unica mensagem de texto

Tipo de retorno: Array



222
223
224
225
226
227
228
229
230
231
232
233
# File 'lib/br_nfe/response/service/build_response.rb', line 222

def get_message_for_path(msg_path)
  messages = []
  _messages = find_value_for_keys(savon_body, path_with_root(msg_path) )
  if _messages.is_a?(Hash)
    messages << get_message_for_hash(_messages)
  elsif _messages.is_a?(Array)
    _messages.map{|msg| messages << get_message_for_hash(msg) if msg.present? }
  elsif _messages.present?
    messages << _messages
  end
  messages.uniq
end

#get_protocolObject

Método utilizado para pegar protocolo de solicitação de processamento do RPS. Esse protocolo é utilizado posteriormente para consultar se o RPS já foi processado

Tipo de retorno: String



277
278
279
# File 'lib/br_nfe/response/service/build_response.rb', line 277

def get_protocol
  find_value_for_keys(savon_body, path_with_root(protocol_path))
end

#get_received_dateObject

Método utilizado para pegar a data de recebimento do lote

Tipo de retorno: String



295
296
297
# File 'lib/br_nfe/response/service/build_response.rb', line 295

def get_received_date
  find_value_for_keys(savon_body, path_with_root(received_date_path))
end

#get_situationObject

Método utilizado para pegar a situação do RPS

Tipo de retorno: Symbol



285
286
287
288
289
# File 'lib/br_nfe/response/service/build_response.rb', line 285

def get_situation
  situation_value = find_value_for_keys(savon_body, path_with_root(situation_path))
  situation_value = situation_key_values[situation_value.to_s.strip] if situation_value.present?
  situation_value
end

#get_xml_nfObject

Método utilizado para pegar o XML da NF É necessário canonicalizar o document para que seja colocado os namespaces nas tags corretas. Caso contrário o XML não irá abrir.

Tipo de retorno: String



313
314
315
316
317
318
319
320
321
# File 'lib/br_nfe/response/service/build_response.rb', line 313

def get_xml_nf
  if body_xml_path.present?
    canonicalize(Nokogiri::XML.parse( body_converted_to_xml , nil, 'UTF-8').xpath(nfe_xml_path).to_xml)
  else
    canonicalize(Nokogiri::XML.parse(canonicalize(savon_response.doc.to_s), nil, 'UTF-8').xpath(nfe_xml_path).to_xml)
  end
rescue
  savon_response.xml
end

#instance_invoice(invoice_hash) ⇒ Object

Método responsável por instanciar a nota fiscal de acordo com o hash

passado por par

O parâmetro recebido deve ser o Hash representado pelo tipo de dados tcCompNfse(do manual NFS-e v1)



336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
# File 'lib/br_nfe/response/service/build_response.rb', line 336

def instance_invoice(invoice_hash)
  nfe = BrNfe::Response::Service::NotaFiscal.new({
    xml_nf:                           get_xml_nf.force_encoding('UTF-8'),
    numero_nf:                        find_value_for_keys(invoice_hash, invoice_numero_nf_path                       ),
    codigo_verificacao:               find_value_for_keys(invoice_hash, invoice_codigo_verificacao_path              ),
    data_emissao:                     find_value_for_keys(invoice_hash, invoice_data_emissao_path                    ),
    url_nf:                           find_value_for_keys(invoice_hash, invoice_url_nf_path                          ),
    competencia:                      find_value_for_keys(invoice_hash, invoice_competencia_path                     ),
    natureza_operacao:                find_value_for_keys(invoice_hash, invoice_natureza_operacao_path               ),
    regime_especial_tributacao:       find_value_for_keys(invoice_hash, invoice_regime_especial_tributacao_path      ),
    optante_simples_nacional:         find_value_for_keys(invoice_hash, invoice_optante_simples_nacional_path        ),
    incentivador_cultural:            find_value_for_keys(invoice_hash, invoice_incentivador_cultural_path           ),
    outras_informacoes:               find_value_for_keys(invoice_hash, invoice_outras_informacoes_path              ),
    item_lista_servico:               find_value_for_keys(invoice_hash, invoice_item_lista_servico_path              ),
    cnae_code:                        find_value_for_keys(invoice_hash, invoice_cnae_code_path                       ),
    description:                      find_value_for_keys(invoice_hash, invoice_description_path                     ),
    codigo_municipio:                 find_value_for_keys(invoice_hash, invoice_codigo_municipio_path                ),
    responsavel_retencao:             find_value_for_keys(invoice_hash, invoice_responsavel_retencao_path            ),
    numero_processo:                  find_value_for_keys(invoice_hash, invoice_numero_processo_path                 ),
    municipio_incidencia:             find_value_for_keys(invoice_hash, invoice_municipio_incidencia_path            ),
    orgao_gerador_municipio:          find_value_for_keys(invoice_hash, invoice_orgao_gerador_municipio_path         ),
    orgao_gerador_uf:                 find_value_for_keys(invoice_hash, invoice_orgao_gerador_uf_path                ),
    codigo_obra:                      find_value_for_keys(invoice_hash, invoice_codigo_obra_path                     ),
    codigo_art:                       find_value_for_keys(invoice_hash, invoice_codigo_art_path                      ),
  })

  build_rps_fields_nfe(nfe, invoice_hash)
  build_cancelation_fields_nfe(nfe, invoice_hash)
  build_values_nfe(nfe, invoice_hash)
  build_emitente_nfe(nfe, invoice_hash)
  build_destinatario_nfe(nfe, invoice_hash)
  nfe
end

#path_with_root(path) ⇒ Object

Quando para encontrar o valor de uma determinada chave é necessaŕio percorer o hash de retorno dês do inicio do mesmo. Como a mensagem tem uma chave ‘root’ padrão e pode ser diferente para cada orgaao emissor, é setado uma valor na variavel keys_root_path para que não seja necessário ficar setando a mesma chave em todos os métodos utilizados para encontrar determinado valor

Tipo de retorno: Array



209
210
211
212
# File 'lib/br_nfe/response/service/build_response.rb', line 209

def path_with_root(path)
  return if path.blank?
  keys_root_path + [path].flatten
end

#responseObject

FIM DA DEFINIÇÃO DOS CAMINHOS ############################



130
131
132
133
134
135
136
137
138
139
140
141
# File 'lib/br_nfe/response/service/build_response.rb', line 130

def response
  @response ||= BrNfe::Response::Service::Default.new({
    error_messages:   get_message_for_path(message_errors_path),
    notas_fiscais:    get_invoices,
    protocolo:        get_protocol,
    data_recebimento: get_received_date,
    numero_lote:      get_lot_number,
    situation:        get_situation,
    original_xml:     savon_response.xml.force_encoding('UTF-8'),
    cancelation_date_time: get_cancelation_date_time
  })
end

#savon_bodyObject

Retorna o valor encontrado no body da resposta Savon em formato de hash

Tipo de retorno: Hash



148
149
150
151
152
153
154
155
156
157
# File 'lib/br_nfe/response/service/build_response.rb', line 148

def savon_body
  return @savon_body if @savon_body.present?
  if body_xml_path.present?
    @savon_body = Nori.new.parse(
      body_converted_to_xml
    ).deep_transform_keys!{|k| k.to_s.underscore.to_sym}
  else
    @savon_body = savon_response.try(:body) || {}
  end
end