br_nfe 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +15 -0
- data/Gemfile.lock +169 -0
- data/LICENSE +20 -0
- data/README.markdown +6 -0
- data/Rakefile +13 -0
- data/br_nfe.gemspec +28 -0
- data/lib/br_nfe/active_model_base.rb +62 -0
- data/lib/br_nfe/base.rb +168 -0
- data/lib/br_nfe/condicao_pagamento.rb +26 -0
- data/lib/br_nfe/destinatario.rb +26 -0
- data/lib/br_nfe/emitente.rb +40 -0
- data/lib/br_nfe/endereco.rb +44 -0
- data/lib/br_nfe/helper/cpf_cnpj.rb +60 -0
- data/lib/br_nfe/helper/have_address.rb +29 -0
- data/lib/br_nfe/helper/have_condicao_pagamento.rb +24 -0
- data/lib/br_nfe/helper/have_destinatario.rb +18 -0
- data/lib/br_nfe/helper/have_emitente.rb +20 -0
- data/lib/br_nfe/helper/have_intermediario.rb +24 -0
- data/lib/br_nfe/helper/have_rps.rb +27 -0
- data/lib/br_nfe/helper/string_methods.rb +21 -0
- data/lib/br_nfe/seed.rb +195 -0
- data/lib/br_nfe/servico/base.rb +35 -0
- data/lib/br_nfe/servico/betha/base.rb +74 -0
- data/lib/br_nfe/servico/betha/v1/build_response.rb +219 -0
- data/lib/br_nfe/servico/betha/v1/cancelamento_nfs.rb +52 -0
- data/lib/br_nfe/servico/betha/v1/consulta_lote_rps.rb +31 -0
- data/lib/br_nfe/servico/betha/v1/consulta_nfs_por_rps.rb +34 -0
- data/lib/br_nfe/servico/betha/v1/consulta_nfse.rb +50 -0
- data/lib/br_nfe/servico/betha/v1/consulta_situacao_lote_rps.rb +18 -0
- data/lib/br_nfe/servico/betha/v1/gateway.rb +115 -0
- data/lib/br_nfe/servico/betha/v1/recepcao_lote_rps.rb +89 -0
- data/lib/br_nfe/servico/betha/v2/cancelamento_nfs.rb +25 -0
- data/lib/br_nfe/servico/betha/v2/consulta_lote_rps.rb +27 -0
- data/lib/br_nfe/servico/betha/v2/consulta_nfse_por_rps.rb +27 -0
- data/lib/br_nfe/servico/betha/v2/envio_lote_rps_sincrono.rb +26 -0
- data/lib/br_nfe/servico/betha/v2/gateway.rb +198 -0
- data/lib/br_nfe/servico/betha/v2/gera_nfse.rb +25 -0
- data/lib/br_nfe/servico/betha/v2/recepcao_lote_rps.rb +47 -0
- data/lib/br_nfe/servico/betha/v2/response.rb +23 -0
- data/lib/br_nfe/servico/betha/v2/substituicao_nfse.rb +39 -0
- data/lib/br_nfe/servico/intermediario.rb +17 -0
- data/lib/br_nfe/servico/response/default.rb +34 -0
- data/lib/br_nfe/servico/response/nota_fiscal.rb +73 -0
- data/lib/br_nfe/servico/rps.rb +103 -0
- data/lib/br_nfe/version.rb +8 -0
- data/lib/br_nfe.rb +146 -0
- data/test/br_nfe/base_test.rb +274 -0
- data/test/br_nfe/condicao_pagamento_test.rb +23 -0
- data/test/br_nfe/destinatario_test.rb +26 -0
- data/test/br_nfe/emitente_test.rb +26 -0
- data/test/br_nfe/endereco_test.rb +50 -0
- data/test/br_nfe/helper/have_address_test.rb +62 -0
- data/test/br_nfe/helper/have_condicao_pagamento_test.rb +71 -0
- data/test/br_nfe/helper/have_destinatario_test.rb +64 -0
- data/test/br_nfe/helper/have_emitente_test.rb +63 -0
- data/test/br_nfe/helper/have_intermediario_test.rb +77 -0
- data/test/br_nfe/helper/have_rps_test.rb +59 -0
- data/test/br_nfe/servico/base_test.rb +23 -0
- data/test/br_nfe/servico/betha/base_test.rb +106 -0
- data/test/br_nfe/servico/betha/v1/build_response_test.rb +558 -0
- data/test/br_nfe/servico/betha/v1/cancelamento_nfs_test.rb +62 -0
- data/test/br_nfe/servico/betha/v1/consulta_lote_rps_test.rb +42 -0
- data/test/br_nfe/servico/betha/v1/consulta_nfs_por_rps_test.rb +68 -0
- data/test/br_nfe/servico/betha/v1/consulta_nfse_test.rb +57 -0
- data/test/br_nfe/servico/betha/v1/consulta_situacao_lote_rps_test.rb +27 -0
- data/test/br_nfe/servico/betha/v1/gateway_test.rb +174 -0
- data/test/br_nfe/servico/betha/v1/recepcao_lote_rps_test.rb +235 -0
- data/test/br_nfe/servico/response/default_test.rb +54 -0
- data/test/br_nfe/servico/response/nota_fiscal_test.rb +41 -0
- data/test/br_nfe/servico/rps_test.rb +214 -0
- data/test/certificado.rb +12 -0
- data/test/factories/base.rb +5 -0
- data/test/factories/condicao_pagamento.rb +10 -0
- data/test/factories/destinatario.rb +11 -0
- data/test/factories/emitente.rb +15 -0
- data/test/factories/endereco.rb +12 -0
- data/test/factories/servico/base.rb +5 -0
- data/test/factories/servico/betha/base.rb +5 -0
- data/test/factories/servico/betha/v1/build_response.rb +6 -0
- data/test/factories/servico/betha/v1/cancelamento_nfs.rb +7 -0
- data/test/factories/servico/betha/v1/consulta_lote_rps.rb +6 -0
- data/test/factories/servico/betha/v1/consulta_nfs_por_rps.rb +6 -0
- data/test/factories/servico/betha/v1/consulta_nfse.rb +8 -0
- data/test/factories/servico/betha/v1/consulta_situacao_lote_rps.rb +6 -0
- data/test/factories/servico/betha/v1/gateway.rb +5 -0
- data/test/factories/servico/betha/v1/recepcao_lote_rps.rb +6 -0
- data/test/factories/servico/intermediario.rb +7 -0
- data/test/factories/servico/response/default.rb +10 -0
- data/test/factories/servico/response/nota_fiscal.rb +47 -0
- data/test/factories/servico/rps.rb +44 -0
- data/test/test_helper.rb +39 -0
- metadata +263 -0
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveAddress
|
|
4
|
+
|
|
5
|
+
def validar_endereco?
|
|
6
|
+
true
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def validar_endereco
|
|
10
|
+
if endereco.invalid?
|
|
11
|
+
endereco.errors.full_messages.each { |msg| errors.add(:base, "Endereço: #{msg}") }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def endereco
|
|
16
|
+
yield(endereco) if block_given?
|
|
17
|
+
@endereco.is_a?(BrNfe.endereco_class) ? @endereco : @endereco = BrNfe.endereco_class.new()
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def endereco=(value)
|
|
21
|
+
if value.is_a?(BrNfe.endereco_class)
|
|
22
|
+
@endereco = value
|
|
23
|
+
elsif value.is_a?(Hash)
|
|
24
|
+
endereco.assign_attributes(value)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveCondicaoPagamento
|
|
4
|
+
def condicao_pagamento
|
|
5
|
+
yield(condicao_pagamento || new_condicao_pagamento) if block_given?
|
|
6
|
+
@condicao_pagamento.is_a?(BrNfe.condicao_pagamento_class) ? @condicao_pagamento : nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def condicao_pagamento=(value)
|
|
10
|
+
if value.is_a?(BrNfe.condicao_pagamento_class) || value.nil?
|
|
11
|
+
@condicao_pagamento = value
|
|
12
|
+
elsif value.is_a?(Hash)
|
|
13
|
+
condicao_pagamento ? condicao_pagamento.assign_attributes(value) : new_condicao_pagamento(value)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def new_condicao_pagamento(params={})
|
|
20
|
+
@condicao_pagamento = BrNfe.condicao_pagamento_class.new(params)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveDestinatario
|
|
4
|
+
def destinatario
|
|
5
|
+
yield(destinatario) if block_given?
|
|
6
|
+
@destinatario.is_a?(BrNfe.destinatario_class) ? @destinatario : @destinatario = BrNfe.destinatario_class.new()
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def destinatario=(value)
|
|
10
|
+
if value.is_a?(BrNfe.destinatario_class) || value.nil?
|
|
11
|
+
@destinatario = value
|
|
12
|
+
elsif value.is_a?(Hash)
|
|
13
|
+
destinatario.assign_attributes(value)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveEmitente
|
|
4
|
+
|
|
5
|
+
def emitente
|
|
6
|
+
yield emitente if block_given?
|
|
7
|
+
@emitente.is_a?(BrNfe.emitente_class) ? @emitente : @emitente = BrNfe.emitente_class.new()
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def emitente=(value)
|
|
12
|
+
if value.is_a?(BrNfe.emitente_class) || value.nil?
|
|
13
|
+
@emitente = value
|
|
14
|
+
elsif value.is_a?(Hash)
|
|
15
|
+
emitente.assign_attributes(value)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveIntermediario
|
|
4
|
+
def intermediario
|
|
5
|
+
yield(intermediario || new_intermediario) if block_given?
|
|
6
|
+
@intermediario.is_a?(BrNfe.intermediario_class) ? @intermediario : nil
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def intermediario=(value)
|
|
10
|
+
if value.is_a?(BrNfe.intermediario_class) || value.nil?
|
|
11
|
+
@intermediario = value
|
|
12
|
+
elsif value.is_a?(Hash)
|
|
13
|
+
intermediario ? intermediario.assign_attributes(value) : new_intermediario(value)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def new_intermediario(params={})
|
|
20
|
+
@intermediario = BrNfe.intermediario_class.new(params)
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Helper
|
|
3
|
+
module HaveRps
|
|
4
|
+
def rps
|
|
5
|
+
yield rps if block_given?
|
|
6
|
+
@rps.is_a?(BrNfe.rps_class) ? @rps : @rps = BrNfe.rps_class.new
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def rps=(value)
|
|
10
|
+
if value.is_a?(BrNfe.rps_class) || value.nil?
|
|
11
|
+
@rps = value
|
|
12
|
+
elsif value.is_a?(Hash)
|
|
13
|
+
rps.assign_attributes(value)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
protected
|
|
18
|
+
|
|
19
|
+
def validar_rps
|
|
20
|
+
if rps.invalid?
|
|
21
|
+
rps.errors.full_messages.map{|msg| errors.add(:rps, msg) }
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
module BrNfe
|
|
3
|
+
module StringMethods
|
|
4
|
+
|
|
5
|
+
def to_valid_format_nf
|
|
6
|
+
remove_accents.upcase
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def remove_accents
|
|
10
|
+
ActiveSupport::Inflector.transliterate(self)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def max_size(size=255)
|
|
14
|
+
self.truncate(size, omission: '')
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
[String].each do |klass|
|
|
20
|
+
klass.class_eval { include BrNfe::StringMethods }
|
|
21
|
+
end
|
data/lib/br_nfe/seed.rb
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
class Seed < BrNfe::ActiveModelBase
|
|
3
|
+
attr_accessor :env
|
|
4
|
+
attr_accessor :numero_lote
|
|
5
|
+
attr_accessor :numero_rps
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def default_values
|
|
9
|
+
{env: :test}
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def emitente
|
|
13
|
+
BrNfe::Emitente.new({
|
|
14
|
+
cnpj: '18.113.831/0001-35',
|
|
15
|
+
inscricao_municipal: '42615-6',
|
|
16
|
+
razao_social: 'TWOWEB AGENCIA DIGITAL LTDA - ME',
|
|
17
|
+
nome_fantasia: 'TWOWEB AGENCIA DIGITAL',
|
|
18
|
+
telefone: '33161107',
|
|
19
|
+
email: 'mail@mail.com',
|
|
20
|
+
regime_especial_tributacao: '1',
|
|
21
|
+
optante_simples_nacional: '2',
|
|
22
|
+
incentivo_fiscal: '2',
|
|
23
|
+
natureza_operacao: '1',
|
|
24
|
+
endereco: {
|
|
25
|
+
logradouro: 'R AFONSO PENA',
|
|
26
|
+
numero: '420',
|
|
27
|
+
complemento: 'D',
|
|
28
|
+
bairro: 'SAO CRISTOVAO',
|
|
29
|
+
nome_municipio: 'Chapeco',
|
|
30
|
+
codigo_municipio: '4204202',
|
|
31
|
+
uf: 'SC',
|
|
32
|
+
cep: '89804023',
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def destinatario
|
|
38
|
+
BrNfe::Destinatario.new({
|
|
39
|
+
cpf_cnpj: '18.077.391/0001-08',
|
|
40
|
+
razao_social: 'I9K SOLUCOES TECNOLOGICAS LTDA',
|
|
41
|
+
nome_fantasia: 'I9K SOLUCOES',
|
|
42
|
+
telefone: '336644557',
|
|
43
|
+
email: 'mail@mail.com',
|
|
44
|
+
endereco: {
|
|
45
|
+
logradouro: 'R JERUSALEM',
|
|
46
|
+
numero: '61',
|
|
47
|
+
complemento: 'E, SALAS 06 E 07',
|
|
48
|
+
bairro: 'PASSO DOS FORTES',
|
|
49
|
+
nome_municipio: 'Chapeco',
|
|
50
|
+
codigo_municipio: '4204202',
|
|
51
|
+
uf: 'SC',
|
|
52
|
+
cep: '89805675',
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def recepcao_lote_rps_v1
|
|
59
|
+
BrNfe::Servico::Betha::V1::RecepcaoLoteRps.new do |recepcao|
|
|
60
|
+
recepcao.emitente = emitente
|
|
61
|
+
recepcao.lote_rps = rps
|
|
62
|
+
recepcao.numero_lote_rps = numero_lote
|
|
63
|
+
recepcao.env = :test
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def consulta_lote_rps_v1(protocolo)
|
|
69
|
+
BrNfe::Servico::Betha::V1::ConsultaLoteRps.new do |obj|
|
|
70
|
+
obj.env = env
|
|
71
|
+
obj.emitente = emitente
|
|
72
|
+
obj.protocolo = protocolo
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def consulta_nfs_por_rps_v1
|
|
78
|
+
BrNfe::Servico::Betha::V1::ConsultaNfsPorRps.new do |obj|
|
|
79
|
+
obj.env = env
|
|
80
|
+
obj.emitente = emitente
|
|
81
|
+
obj.rps = rps
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def consulta_nfse_v1(params={})
|
|
86
|
+
BrNfe::Servico::Betha::V1::ConsultaNfse.new do |obj|
|
|
87
|
+
obj.env = env
|
|
88
|
+
obj.emitente = emitente
|
|
89
|
+
obj.numero_nfse = params[:numero_nfse]
|
|
90
|
+
obj.data_inicial = params[:data_inicial] || Date.today.beginning_of_month
|
|
91
|
+
obj.data_final = params[:data_final] || Date.today.end_of_month
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
def cancelamento_nfs_v1(params = {})
|
|
96
|
+
BrNfe::Servico::Betha::V1::CancelamentoNfs.new do |c|
|
|
97
|
+
c.env = :test
|
|
98
|
+
c.emitente = emitente
|
|
99
|
+
c.numero_nfse = params[:numero_nfse]
|
|
100
|
+
codigo_cancelamento = params[:codigo_cancelamento] || '1'
|
|
101
|
+
end
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def recepcao_lote_rps_v2
|
|
105
|
+
BrNfe::Servico::Betha::V2::RecepcaoLoteRps.new do |recepcao|
|
|
106
|
+
recepcao.emitente = emitente
|
|
107
|
+
recepcao.lote_rps = rps
|
|
108
|
+
recepcao.numero_lote_rps = numero_lote
|
|
109
|
+
recepcao.env = :test
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def consulta_lote_rps_v2(protocolo)
|
|
114
|
+
BrNfe::Servico::Betha::V2::ConsultaLoteRps.new do |obj|
|
|
115
|
+
obj.env = env
|
|
116
|
+
obj.emitente = emitente
|
|
117
|
+
obj.protocolo = protocolo
|
|
118
|
+
end
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
def consulta_nfs_por_rps_v2
|
|
122
|
+
BrNfe::Servico::Betha::V2::ConsultaNfsePorRps.new do |obj|
|
|
123
|
+
obj.env = env
|
|
124
|
+
obj.emitente = emitente
|
|
125
|
+
obj.rps = rps
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def envio_lote_rps_sincrono_v2(params={})
|
|
130
|
+
BrNfe::Servico::Betha::V2::EnvioLoteRpsSincrono.new do |recepcao|
|
|
131
|
+
recepcao.emitente = emitente
|
|
132
|
+
recepcao.lote_rps = rps
|
|
133
|
+
recepcao.numero_lote_rps = numero_lote
|
|
134
|
+
recepcao.env = :test
|
|
135
|
+
end
|
|
136
|
+
end
|
|
137
|
+
|
|
138
|
+
def gera_nfse_v2(params={})
|
|
139
|
+
BrNfe::Servico::Betha::V2::GeraNfse.new do |recepcao|
|
|
140
|
+
recepcao.emitente = emitente
|
|
141
|
+
recepcao.rps = rps
|
|
142
|
+
recepcao.env = :test
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
def substituicao_v2(params={})
|
|
147
|
+
BrNfe::Servico::Betha::V2::SubstituicaoNfse.new do |recepcao|
|
|
148
|
+
recepcao.emitente = emitente
|
|
149
|
+
recepcao.rps = rps
|
|
150
|
+
recepcao.numero_nfse = params[:numero_nfse]
|
|
151
|
+
recepcao.codigo_cancelamento = params[:codigo_cancelamento]
|
|
152
|
+
recepcao.env = :test
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def rps
|
|
159
|
+
BrNfe::Servico::Rps.new do |rps|
|
|
160
|
+
rps.destinatario = destinatario
|
|
161
|
+
rps.numero = numero_rps
|
|
162
|
+
rps.serie = 'SN'
|
|
163
|
+
rps.tipo = '1'
|
|
164
|
+
rps.data_emissao = DateTime.now
|
|
165
|
+
rps.status = '1'
|
|
166
|
+
rps.competencia = Date.today
|
|
167
|
+
|
|
168
|
+
rps.valor_servicos = '49.00'
|
|
169
|
+
rps.valor_deducoes = '0.0'
|
|
170
|
+
rps.valor_pis = '0.0'
|
|
171
|
+
rps.valor_cofins = '0.0'
|
|
172
|
+
rps.valor_inss = '0.0'
|
|
173
|
+
rps.valor_ir = '0.0'
|
|
174
|
+
rps.valor_csll = '0.0'
|
|
175
|
+
rps.outras_retencoes = '0.0'
|
|
176
|
+
# rps.valor_iss = '0.98'
|
|
177
|
+
# rps.aliquota = '0.02'
|
|
178
|
+
rps.base_calculo = '49.00'
|
|
179
|
+
rps.desconto_incondicionado = '0.0'
|
|
180
|
+
rps.desconto_condicionado = '0.0'
|
|
181
|
+
|
|
182
|
+
rps.iss_retido = '2'
|
|
183
|
+
rps.responsavel_retencao = ''
|
|
184
|
+
rps.item_lista_servico = '0107'
|
|
185
|
+
rps.codigo_tributacao_municipio = '2525'
|
|
186
|
+
rps.discriminacao = "1 MENSALIDADE PLANO LIGHT. 49,00 \n\n\n\n\nValor Aprox dos Tributos: R$ 6,59 Federal, R$ 0,00 Estadual e R$ 1,62 Municipal \n Fonte: IBPT/FECOMERCIO SC 5oi7eW"
|
|
187
|
+
rps.exigibilidade_iss = '1'
|
|
188
|
+
rps.codigo_municipio = '4204202'
|
|
189
|
+
rps.numero_processo = ''
|
|
190
|
+
rps.codigo_cnae = '6202300'
|
|
191
|
+
end
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
end
|
|
195
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Servico
|
|
3
|
+
class Base < BrNfe::Base
|
|
4
|
+
|
|
5
|
+
def initialize(attributes = {})
|
|
6
|
+
self.lote_rps = [] # Para poder utilizar o << para adicionar rps
|
|
7
|
+
super
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
attr_accessor :lote_rps
|
|
11
|
+
attr_accessor :numero_lote_rps
|
|
12
|
+
attr_accessor :operacao
|
|
13
|
+
|
|
14
|
+
def lote_rps
|
|
15
|
+
@lote_rps = [@lote_rps].flatten # Para retornar sempre um vetor
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def validar_lote_rps
|
|
21
|
+
if lote_rps.empty?
|
|
22
|
+
errors.add(:base, "Deve conter ao menos 1 RPS")
|
|
23
|
+
else
|
|
24
|
+
lote_rps.each_with_index do |rps, i|
|
|
25
|
+
rps.validar_recepcao_rps = true
|
|
26
|
+
if rps.invalid?
|
|
27
|
+
rps.errors.full_messages.map{|msg| errors.add(:base, "RPS #{i+1}: #{msg}") }
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Servico
|
|
3
|
+
module Betha
|
|
4
|
+
class Base < BrNfe::Servico::Base
|
|
5
|
+
|
|
6
|
+
def version
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
private
|
|
10
|
+
|
|
11
|
+
def tag_identificacao_rps(xml, rps)
|
|
12
|
+
xml.IdentificacaoRps {
|
|
13
|
+
dados_identificacao_rps(xml, rps)
|
|
14
|
+
}
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def tag_rps_substituido(xml, rps)
|
|
18
|
+
return unless rps.contem_substituicao?
|
|
19
|
+
xml.RpsSubstituido{
|
|
20
|
+
dados_identificacao_rps(xml, rps, true)
|
|
21
|
+
}
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def dados_identificacao_rps(xml, rps, substituicao = false)
|
|
25
|
+
xml.Numero BrNfe::Helper.only_number((substituicao ? rps.numero_substituicao : rps.numero)).max_size(15)
|
|
26
|
+
xml.Serie "#{(substituicao ? rps.serie_substituicao : rps.serie)}".max_size(5)
|
|
27
|
+
xml.Tipo "#{(substituicao ? rps.tipo_substituicao : rps.tipo)}".max_size(1)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def tag_dados_tomador(xml, destinatario)
|
|
31
|
+
xml.Tomador{
|
|
32
|
+
xml.IdentificacaoTomador {
|
|
33
|
+
xml.CpfCnpj {
|
|
34
|
+
tag_cpf_cnpj(xml, destinatario.cpf_cnpj)
|
|
35
|
+
}
|
|
36
|
+
xml.InscricaoMunicipal "#{destinatario.inscricao_municipal}".max_size(15) if destinatario.inscricao_municipal.present?
|
|
37
|
+
xml.InscricaoEstadual "#{destinatario.inscricao_estadual}".max_size(15) if destinatario.inscricao_estadual.present? && version == :v1
|
|
38
|
+
}
|
|
39
|
+
xml.RazaoSocial "#{destinatario.razao_social}".max_size(115)
|
|
40
|
+
|
|
41
|
+
tag_endereco(xml, destinatario.endereco)
|
|
42
|
+
|
|
43
|
+
xml.Contato {
|
|
44
|
+
xml.Telefone BrNfe::Helper.only_number(destinatario.telefone).max_size(11) unless destinatario.telefone.blank?
|
|
45
|
+
xml.Email "#{destinatario.email}".max_size(80) unless destinatario.email.blank?
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def tag_endereco(xml, endereco)
|
|
51
|
+
xml.Endereco {
|
|
52
|
+
xml.Endereco "#{endereco.logradouro}".max_size(125)
|
|
53
|
+
xml.Numero "#{endereco.numero}".max_size(10)
|
|
54
|
+
xml.Complemento "#{endereco.complemento}".max_size(60)
|
|
55
|
+
xml.Bairro "#{endereco.bairro}".max_size(60)
|
|
56
|
+
xml.CodigoMunicipio "#{endereco.codigo_municipio}".max_size(7)
|
|
57
|
+
xml.Uf "#{endereco.uf}".max_size(2)
|
|
58
|
+
xml.Cep BrNfe::Helper.only_number(endereco.cep).max_size(8)
|
|
59
|
+
# xml.CodigoPais endereco.codigo_pais if version == :v2
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def tag_dados_construcao_civil(xml, rps)
|
|
64
|
+
return if rps.codigo_obra.blank? || rps.codigo_art.blank?
|
|
65
|
+
xml.ConstrucaoCivil{
|
|
66
|
+
xml.CodigoObra "#{rps.codigo_obra}".max_size(15)
|
|
67
|
+
xml.Art "#{rps.codigo_art}".max_size(15)
|
|
68
|
+
}
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
module BrNfe
|
|
2
|
+
module Servico
|
|
3
|
+
module Betha
|
|
4
|
+
module V1
|
|
5
|
+
class BuildResponse < BrNfe::ActiveModelBase
|
|
6
|
+
|
|
7
|
+
attr_accessor :hash
|
|
8
|
+
attr_accessor :nfe_method
|
|
9
|
+
|
|
10
|
+
def messages
|
|
11
|
+
hash["#{nfe_method.to_s}_resposta".to_sym]
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def success?
|
|
15
|
+
messages[:lista_mensagem_retorno].blank?
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def response
|
|
19
|
+
@response ||= BrNfe::Servico::Response::Default.new do |resp|
|
|
20
|
+
resp.success = success?
|
|
21
|
+
resp.error_messages = error_messages
|
|
22
|
+
resp.notas_fiscais = get_notas_fiscais
|
|
23
|
+
resp.protocolo = messages[:protocolo]
|
|
24
|
+
resp.data_recebimento = messages[:data_recebimento]
|
|
25
|
+
resp.numero_lote = messages[:numero_lote]
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def error_messages
|
|
30
|
+
@error_messages ||= []
|
|
31
|
+
return @error_messages if success? || !@error_messages.blank?
|
|
32
|
+
msgs = messages[:lista_mensagem_retorno][:mensagem_retorno]
|
|
33
|
+
if msgs.is_a?(Hash)
|
|
34
|
+
@error_messages << get_message(msgs)
|
|
35
|
+
else #Array
|
|
36
|
+
msgs.each do |msg|
|
|
37
|
+
@error_messages << get_message(msg)
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
@error_messages
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
private
|
|
44
|
+
|
|
45
|
+
def get_message(hash)
|
|
46
|
+
{
|
|
47
|
+
codigo: hash[:codigo],
|
|
48
|
+
mensagem: hash[:mensagem],
|
|
49
|
+
correcao: hash[:correcao]
|
|
50
|
+
}
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def get_notas_fiscais
|
|
54
|
+
@notas_fiscais = []
|
|
55
|
+
return @notas_fiscais if messages[:lista_nfse].blank? || messages[:lista_nfse][:compl_nfse].blank?
|
|
56
|
+
compl_nfse = messages[:lista_nfse][:compl_nfse]
|
|
57
|
+
|
|
58
|
+
if compl_nfse.is_a?(Hash)
|
|
59
|
+
@notas_fiscais << new_nota_fiscal(compl_nfse)
|
|
60
|
+
elsif compl_nfse.is_a?(Array)
|
|
61
|
+
compl_nfse.map{|p| @notas_fiscais << new_nota_fiscal(p) }
|
|
62
|
+
end
|
|
63
|
+
@notas_fiscais
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def new_nota_fiscal(params)
|
|
67
|
+
info_nfse = params[:nfse][:inf_nfse]
|
|
68
|
+
info_cancelamento = params[:nfse_cancelamento]
|
|
69
|
+
info_substituicao = params[:nfse_substituicao]
|
|
70
|
+
|
|
71
|
+
BrNfe::Servico::Response::NotaFiscal.new do |nfse|
|
|
72
|
+
nfse.numero_nf = info_nfse[:numero]
|
|
73
|
+
nfse.codigo_verificacao = info_nfse[:codigo_verificacao]
|
|
74
|
+
nfse.data_emissao = info_nfse[:data_emissao]
|
|
75
|
+
nfse.data_emissao_rps = info_nfse[:data_emissao_rps]
|
|
76
|
+
nfse.competencia = info_nfse[:competencia]
|
|
77
|
+
nfse.outras_informacoes = info_nfse[:outras_informacoes]
|
|
78
|
+
nfse.url_nf = info_nfse[:outras_informacoes]
|
|
79
|
+
|
|
80
|
+
get_informacoes_rps nfse, info_nfse[:identificacao_rps]
|
|
81
|
+
get_dados_servico nfse, info_nfse[:servico]
|
|
82
|
+
get_emitente_servico nfse, info_nfse[:prestador_servico]
|
|
83
|
+
get_destinatario_servico nfse, info_nfse[:tomador_servico]
|
|
84
|
+
get_orgao_gerador nfse, info_nfse[:orgao_gerador]
|
|
85
|
+
get_construcao_civil nfse, info_nfse[:construcao_civil]
|
|
86
|
+
|
|
87
|
+
get_intermediario nfse, info_nfse[:intermediario_servico] if info_nfse[:intermediario_servico]
|
|
88
|
+
|
|
89
|
+
get_info_cancelamento( nfse, info_cancelamento) if info_cancelamento
|
|
90
|
+
|
|
91
|
+
get_info_substituicao( nfse, info_substituicao) if info_substituicao
|
|
92
|
+
|
|
93
|
+
nfse.emitente.optante_simples_nacional = info_nfse[:optante_simples_nacional]
|
|
94
|
+
nfse.emitente.natureza_operacao = info_nfse[:natureza_operacao]
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def get_intermediario(nfse, params)
|
|
99
|
+
nfse.intermediario do |int|
|
|
100
|
+
int.razao_social = params[:razao_social]
|
|
101
|
+
int.cpf_cnpj = params[:cpf_cnpj][:cnpj] || params[:cpf_cnpj][:cpf] if params[:cpf_cnpj]
|
|
102
|
+
int.inscricao_municipal = params[:inscricao_municipal]
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
def get_info_substituicao(nfse, params)
|
|
107
|
+
params ||= {}
|
|
108
|
+
params = params[:substituicao_nfse] || {}
|
|
109
|
+
|
|
110
|
+
nfse.nfe_substituidora = params[:nfse_substituidora]
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
def get_info_cancelamento(nfse, params)
|
|
114
|
+
params ||= {}
|
|
115
|
+
params = params[:confirmacao] || {}
|
|
116
|
+
|
|
117
|
+
info_pedido_cancelamento = params[:pedido][:inf_pedido_cancelamento] if params[:pedido]
|
|
118
|
+
info_pedido_cancelamento ||= {}
|
|
119
|
+
|
|
120
|
+
confirmacao_cancelamento = params[:inf_confirmacao_cancelamento] || {}
|
|
121
|
+
|
|
122
|
+
nfse.cancelamento_codigo = info_pedido_cancelamento[:codigo_cancelamento]
|
|
123
|
+
nfse.cancelamento_numero_nf = info_pedido_cancelamento[:identificacao_nfse][:numero] if info_pedido_cancelamento[:identificacao_nfse]
|
|
124
|
+
nfse.cancelamento_cnpj = info_pedido_cancelamento[:identificacao_nfse][:cnpj] if info_pedido_cancelamento[:identificacao_nfse]
|
|
125
|
+
nfse.cancelamento_inscricao_municipal = info_pedido_cancelamento[:identificacao_nfse][:inscricao_municipal] if info_pedido_cancelamento[:identificacao_nfse]
|
|
126
|
+
nfse.cancelamento_municipio = info_pedido_cancelamento[:identificacao_nfse][:codigo_municipio] if info_pedido_cancelamento[:identificacao_nfse]
|
|
127
|
+
nfse.cancelamento_sucesso = confirmacao_cancelamento[:sucesso]
|
|
128
|
+
nfse.cancelamento_data_hora = confirmacao_cancelamento[:data_hora]
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
def get_construcao_civil(nfse, params)
|
|
132
|
+
params ||= {}
|
|
133
|
+
nfse.codigo_obra = params[:codigo_obra]
|
|
134
|
+
nfse.codigo_art = params[:art]
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
def get_orgao_gerador(nfse, params)
|
|
138
|
+
params ||= {}
|
|
139
|
+
nfse.orgao_gerador_municipio = params[:codigo_municipio]
|
|
140
|
+
nfse.orgao_gerador_uf = params[:uf]
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def get_emitente_servico(nfse, dados_emitente)
|
|
144
|
+
dados_emitente ||= {}
|
|
145
|
+
nfse.emitente do |em|
|
|
146
|
+
em.cnpj = dados_emitente[:identificacao_prestador][:cnpj] if dados_emitente[:identificacao_prestador]
|
|
147
|
+
em.inscricao_municipal = dados_emitente[:identificacao_prestador][:inscricao_municipal] if dados_emitente[:identificacao_prestador]
|
|
148
|
+
em.razao_social = dados_emitente[:razao_social]
|
|
149
|
+
em.nome_fantasia = dados_emitente[:nome_fantasia]
|
|
150
|
+
em.telefone = dados_emitente[:contato][:telefone] if dados_emitente[:contato]
|
|
151
|
+
em.email = dados_emitente[:contato][:email] if dados_emitente[:contato]
|
|
152
|
+
em.endereco = get_endereco(dados_emitente[:endereco])
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def get_destinatario_servico(nfse, dados_destinatario)
|
|
157
|
+
dados_destinatario ||= {}
|
|
158
|
+
identificacao_tomador = dados_destinatario[:identificacao_tomador] || {}
|
|
159
|
+
nfse.destinatario do |em|
|
|
160
|
+
em.cpf_cnpj = identificacao_tomador[:cpf_cnpj][:cnpj] || identificacao_tomador[:cpf_cnpj][:cpf] if identificacao_tomador[:cpf_cnpj]
|
|
161
|
+
em.inscricao_municipal = identificacao_tomador[:inscricao_municipal]
|
|
162
|
+
em.inscricao_estadual = identificacao_tomador[:inscricao_estadual]
|
|
163
|
+
em.razao_social = dados_destinatario[:razao_social]
|
|
164
|
+
em.nome_fantasia = dados_destinatario[:nome_fantasia]
|
|
165
|
+
em.telefone = dados_destinatario[:contato][:telefone] if dados_destinatario[:contato]
|
|
166
|
+
em.email = dados_destinatario[:contato][:email] if dados_destinatario[:contato]
|
|
167
|
+
em.endereco = get_endereco(dados_destinatario[:endereco])
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def get_endereco(params)
|
|
172
|
+
params ||= {}
|
|
173
|
+
BrNfe::Endereco.new do |e|
|
|
174
|
+
e.logradouro = params[:endereco]
|
|
175
|
+
e.numero = params[:numero]
|
|
176
|
+
e.complemento = params[:complemento]
|
|
177
|
+
e.bairro = params[:bairro]
|
|
178
|
+
e.nome_municipio = params[:nome_municipio]
|
|
179
|
+
e.codigo_municipio = params[:codigo_municipio]
|
|
180
|
+
e.uf = params[:uf]
|
|
181
|
+
e.cep = params[:cep]
|
|
182
|
+
e.codigo_pais = params[:codigo_pais] if params[:codigo_pais]
|
|
183
|
+
e.nome_pais = params[:nome_pais] if params[:nome_pais]
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def get_dados_servico(nfse, dados_servico)
|
|
189
|
+
nfse.item_lista_servico = dados_servico[:item_lista_servico]
|
|
190
|
+
nfse.codigo_cnae = dados_servico[:codigo_cnae]
|
|
191
|
+
nfse.discriminacao = dados_servico[:discriminacao]
|
|
192
|
+
nfse.codigo_municipio = dados_servico[:codigo_municipio]
|
|
193
|
+
|
|
194
|
+
nfse.valor_servicos = dados_servico[:valores][:valor_servicos]
|
|
195
|
+
nfse.valor_deducoes = dados_servico[:valores][:valor_deducoes]
|
|
196
|
+
nfse.valor_pis = dados_servico[:valores][:valor_pis]
|
|
197
|
+
nfse.valor_cofins = dados_servico[:valores][:valor_cofins]
|
|
198
|
+
nfse.valor_inss = dados_servico[:valores][:valor_inss]
|
|
199
|
+
nfse.valor_ir = dados_servico[:valores][:valor_ir]
|
|
200
|
+
nfse.valor_csll = dados_servico[:valores][:valor_csll]
|
|
201
|
+
nfse.iss_retido = dados_servico[:valores][:iss_retido]
|
|
202
|
+
nfse.valor_iss = dados_servico[:valores][:valor_iss]
|
|
203
|
+
nfse.base_calculo = dados_servico[:valores][:base_calculo]
|
|
204
|
+
nfse.aliquota = dados_servico[:valores][:aliquota]
|
|
205
|
+
nfse.desconto_condicionado = dados_servico[:valores][:desconto_condicionado]
|
|
206
|
+
nfse.desconto_incondicionado = dados_servico[:valores][:desconto_incondicionado]
|
|
207
|
+
end
|
|
208
|
+
|
|
209
|
+
def get_informacoes_rps(nfse, info_rps)
|
|
210
|
+
nfse.rps_numero = info_rps[:numero]
|
|
211
|
+
nfse.rps_serie = info_rps[:serie]
|
|
212
|
+
nfse.rps_tipo = info_rps[:tipo]
|
|
213
|
+
nfse.rps_situacao = info_rps[:situacao]
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
end
|