formatos-febraban 0.2.23 → 0.2.24

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e76cea7520b90135426461843be0950414e89653
4
- data.tar.gz: 73d17c9d4d27464d5e6794270a525f4399b33e89
3
+ metadata.gz: 99df663aea7aa001ffb625d3cb95cdef80c2363d
4
+ data.tar.gz: 22276c19bbf7b7265f274a7e216fd21cdf52d8e4
5
5
  SHA512:
6
- metadata.gz: 193487da4f27089eebfe5f9cad115bdaabe932a4e47f79f91b5515648559fa10c901d3702e8bf9ee9a798fcfdca1493d3bfc43ed6fb27c08dd32e0df2e10d953
7
- data.tar.gz: 79085afd4aa2574bf096052a75acfd15fc89784ca4552b3e0fd3c38fe9652784519410073dce8bef6d356b71693b3a44f24bd697a160a524aa0cbf50e80cf8a8
6
+ metadata.gz: 5fa848dea73082edc917cf028ad71cc9e3f147ce53a7a0049a431896248026606df6b5d12cde958433a83549a1f20ee532259ac550072d3fea82032b0b4c3774
7
+ data.tar.gz: a385a308a781f7c11eacab868fc27f66ad01eda3eb0c0604c059eddad9e49934d3967aa54dd30edff03824e3de5a589650d33dcca03204d59d171ef69a73f0b6
@@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_development_dependency "bundler"
23
23
  spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "byebug"
24
25
  end
@@ -0,0 +1,205 @@
1
+ class Cielo
2
+ require 'date'
3
+
4
+ VERSAO = "01"
5
+
6
+ # Carrega todas as dependências de Layout
7
+ Dir[File.join(File.dirname(__FILE__), '../..', 'base', '**/*.rb')].sort.each do |file|
8
+ require file
9
+ end
10
+
11
+ # Partes do Layout
12
+ require_relative 'cielo_header' # Header
13
+ require_relative 'cielo_detalhe' # Clientes
14
+ require_relative 'cielo_trailler' # Trailler
15
+
16
+ #-------------------------------------------------------------------
17
+ #-------------------------------------------------------------------
18
+ # Construtor
19
+ def initialize file = ""
20
+ @sections = []
21
+
22
+ if file.length > 0
23
+ self.process_file file
24
+ end
25
+ end
26
+
27
+ #-------------------------------------------------------------------
28
+ #-------------------------------------------------------------------
29
+ # Geral
30
+ protected
31
+ def add_section section
32
+ if section.is_valid?
33
+ self.sections << section
34
+ else
35
+ raise "Seção #{section.get_id} está inválida:
36
+ #{section.errors.inspect}
37
+ #{section.to_s}"
38
+ end
39
+ end
40
+
41
+ def add_section_from_business section
42
+ self.add_section section
43
+ self
44
+ end
45
+
46
+ #-------------------------------------------------------------------
47
+ #-------------------------------------------------------------------
48
+ # Criação das Partes
49
+ public
50
+
51
+ # Seção Header
52
+ def create_header(params = {})
53
+
54
+ if self.get_header.nil?
55
+ section = self.get_new_section("header")
56
+
57
+
58
+ section.set_data_deposito params[:data_deposito]
59
+ section.set_numero_lote params[:numero_lote]
60
+ section.set_numero_cielo params[:numero_cielo]
61
+ section.set_moeda params[:moeda]
62
+ section.set_reservado_1
63
+ section.set_reservado_2
64
+ section.set_reservado_3
65
+ section.set_indicador_processo
66
+ section.set_indicador_venda
67
+ section.set_indicador_especial
68
+
69
+ self.add_section_from_business section
70
+
71
+ else
72
+ raise "Header já declarado!"
73
+ end
74
+ end
75
+
76
+ # Seção Client
77
+ def add_clients(params = {})
78
+
79
+ self.valida_existe_header
80
+
81
+ section = self.get_new_section("client")
82
+
83
+ section.set_sequencial params[:sequencial]
84
+ section.set_numero_cartao params[:numero_cartao]
85
+ section.set_data_venda params[:data_venda]
86
+ section.set_valor_venda params[:valor]
87
+ section.set_numero_lote params[:numero_lote]
88
+ section.set_numero_cielo params[:numero_cielo]
89
+ section.set_validade_cartao params[:validade_cartao]
90
+ section.set_codigo_autorizacao
91
+ section.set_opcao_venda
92
+ section.numero_parcelas
93
+ section.set_reservado_1
94
+ section.set_reservado_2
95
+ section.set_reservado_3
96
+ section.set_valor_parcela
97
+ section.set_reservado_4
98
+ section.set_reservado_5
99
+ section.set_status_venda
100
+ section.set_data_liquidacao
101
+ section.set_reservado_6
102
+ section.set_reservado_7
103
+ section.set_reservado_8
104
+ section.set_codigo_erro
105
+ section.set_reservado_9
106
+ section.set_cartao_novo params[:cartao_novo]
107
+ section.set_vencimento_novo params[:vencimento_novo]
108
+ section.set_reservado_10
109
+
110
+ self.add_section_from_business section
111
+ end
112
+
113
+ # Seção Trailler
114
+ def create_trailler
115
+ self.valida_existe_header
116
+
117
+ if self.get_trailler.nil?
118
+ if self.get_section("01").length > 0
119
+ section = self.get_new_section("trailler")
120
+ section.set_total_registros self.sections.length + 1
121
+ section.set_valor_total self.calculate_valor_total
122
+ section.set_valor_aceito
123
+ section.set_valor_liquido
124
+ section.set_data_prevista
125
+ section.set_reservado
126
+
127
+ self.sections << section
128
+ else
129
+ raise "Nenhum valor declarado!"
130
+ end
131
+ else
132
+ raise "Trailler já declarado!"
133
+ end
134
+ end
135
+
136
+ #-------------------------------------------------------------------
137
+ #-------------------------------------------------------------------
138
+ # Validações
139
+ protected
140
+ def valida_existe_header
141
+ raise "Header ainda não declarado" if self.get_header.nil?
142
+ end
143
+
144
+ def valida_existe_trailler
145
+ raise "Trailler ainda não declarado" if self.get_trailler.nil?
146
+ end
147
+
148
+ #--------------------------------------------------------------------------------------
149
+ #--------------------------------------------------------------------------------------
150
+ # Carregamento de Arquivo
151
+ protected
152
+ def get_new_section section_type
153
+ case section_type
154
+ when "header"
155
+ CieloHeader.new(self)
156
+ when "client"
157
+ CieloDetalhe.new(self)
158
+ when "trailler"
159
+ CieloTrailler.new(self)
160
+ end
161
+ end
162
+
163
+ #-------------------------------------------------------------------
164
+ #-------------------------------------------------------------------
165
+ # Getters
166
+ public
167
+ def sections
168
+ @sections.to_a
169
+ end
170
+
171
+ def has_section section
172
+ self.get_section(section).length > 0
173
+ end
174
+
175
+ def get_section section
176
+ self.sections.select {|c| c.is_section?(section) == true }
177
+ end
178
+
179
+ def is_sections_valid?
180
+ self.sections.select {|b| b.is_valid? == false }.length == 0
181
+ end
182
+
183
+ def to_s
184
+ self.sections.map {|a| a.to_s}.join("\n")
185
+ end
186
+
187
+ def get_header
188
+ self.get_section("00").first()
189
+ end
190
+
191
+ def get_trailler
192
+ self.get_section("99").first()
193
+ end
194
+
195
+ #--------------------------------------------------------------------------------------
196
+ #--------------------------------------------------------------------------------------
197
+ # Utilitários
198
+
199
+ protected
200
+ def calculate_valor_total
201
+ self.get_section("01").inject(0) do |sum, section|
202
+ sum += section.get_valor
203
+ end
204
+ end
205
+ end
@@ -0,0 +1,197 @@
1
+ class CieloDetalhe < FormatSection
2
+ require 'date'
3
+
4
+ def initialize master
5
+ super(master, true, true, false)
6
+
7
+ @section = Section.new({
8
+ 0 => Position.new(1, 2, false, "01", true), # Tipo do Registro
9
+ 1 => Position.new(2, 7, true), # Numero Sequencial
10
+ 2 => Position.new(3, 19, true), # Numero do Cartao
11
+ 3 => Position.new(4, 6, true, "000000"), # Código de Autorização
12
+ 4 => Position.new(5, 8, false), # Data da Venda
13
+ 5 => Position.new(6, 1, true), # Opção da Venda
14
+ 6 => Position.new(7, 15, true), # Valor da venda
15
+ 7 => Position.new(8, 3, true), # Quantidade de Parcelas
16
+ 8 => Position.new(9, 15, true), # Preencher com zeros
17
+ 9 => Position.new(10, 15, true), # Preencher com zeros
18
+ 10 => Position.new(11, 15, true), # Preencher com zeros
19
+ 11 => Position.new(12, 15, true), # Valor da Parcela
20
+ 12 => Position.new(13, 7, true), # Numero do resumo da operação
21
+ 13 => Position.new(14, 3, true), # Preencher com zeros
22
+ 14 => Position.new(15, 10, true), # Numero do estabelecimento
23
+ 15 => Position.new(16, 30, false), # Reservado
24
+ 16 => Position.new(17, 2, true), # Status da venda
25
+ 17 => Position.new(18, 8, true), # Data prevista da liquidação
26
+ 18 => Position.new(19, 4, false), # Validade do cartao
27
+ 19 => Position.new(20, 7, true), # Preencher com zeros
28
+ 20 => Position.new(21, 15, true), # Preencher com zeros
29
+ 21 => Position.new(22, 3, false), # Reservado(Brancos)
30
+ 22 => Position.new(23, 4, false), # Código do erro(Brancos na remessa)
31
+ 23 => Position.new(24, 11, false), # Referencia (Brancos)
32
+ 24 => Position.new(25, 19, false), # Cartao Novo(Brancos)
33
+ 25 => Position.new(26, 4, false), # Vencimento Novo (Brancos)
34
+ 26 => Position.new(27, 2, false), # Reservado(Brancos)
35
+
36
+ })
37
+ end
38
+
39
+ def get_sequencial
40
+ self.get_section_value(1)
41
+ end
42
+
43
+ def get_numero_cartao
44
+ self.get_section_value(2)
45
+ end
46
+
47
+ def get_data_venda
48
+ self.get_section_value(4)
49
+ end
50
+
51
+ def get_numero_lote
52
+ self.get_section_value(12)
53
+ end
54
+
55
+ def get_valor
56
+ self.get_section_value(6).to_i
57
+ end
58
+
59
+ def get_numero_cielo
60
+ self.get_section_value(14)
61
+ end
62
+
63
+ def get_validade_cartao
64
+ self.get_section_value(18)
65
+ end
66
+
67
+ def set_sequencial valor
68
+ self.set_section_value(1, valor)
69
+ end
70
+
71
+ def set_numero_cartao valor
72
+ self.set_section_value(2, valor)
73
+ end
74
+
75
+ def set_codigo_autorizacao
76
+ self.set_section_value(3, "000000")
77
+ end
78
+
79
+ def set_data_venda valor
80
+ begin
81
+ valor = Date.strptime(valor, "%d%m%Y") if valor.is_a?(String)
82
+ real_data = valor.strftime("%d%m%Y")
83
+
84
+ if real_data.length == 8
85
+ self.set_section_value(4, real_data)
86
+ else
87
+ raise "tamanho de data incorreto"
88
+ end
89
+
90
+ rescue
91
+ raise "#{get_id}: Data de Geração Inválida
92
+ Valor: #{valor}"
93
+ end
94
+ end
95
+
96
+ def set_opcao_venda
97
+ self.set_section_value(5, "0")
98
+ end
99
+
100
+ def set_valor_venda valor
101
+ self.set_section_value(6, valor)
102
+ end
103
+
104
+ def numero_parcelas
105
+ self.set_section_value(7, "0")
106
+ end
107
+
108
+ def set_reservado_1
109
+ self.set_section_value(8, "0")
110
+ end
111
+
112
+ def set_reservado_2
113
+ self.set_section_value(9, "0")
114
+ end
115
+
116
+ def set_reservado_3
117
+ self.set_section_value(10, "0")
118
+ end
119
+
120
+ def set_valor_parcela
121
+ self.set_section_value(11, "0")
122
+ end
123
+
124
+ def set_numero_lote valor
125
+ self.set_section_value(12, valor)
126
+ end
127
+
128
+ def set_reservado_4
129
+ self.set_section_value(13, "0")
130
+ end
131
+
132
+ def set_numero_cielo valor
133
+ self.set_section_value(14, valor)
134
+ end
135
+
136
+ def set_reservado_5
137
+ self.set_section_value(15, "")
138
+ end
139
+
140
+ def set_status_venda
141
+ self.set_section_value(16, "0")
142
+ end
143
+
144
+ def set_data_liquidacao
145
+ self.set_section_value(17, "0")
146
+ end
147
+
148
+ def set_validade_cartao valor
149
+ self.set_section_value(18, valor)
150
+ end
151
+
152
+ def set_reservado_6
153
+ self.set_section_value(19, "0")
154
+ end
155
+
156
+ def set_reservado_7
157
+ self.set_section_value(20, "0")
158
+ end
159
+
160
+ def set_reservado_8
161
+ self.set_section_value(21, "")
162
+ end
163
+
164
+ def set_codigo_erro
165
+ self.set_section_value(22, "")
166
+ end
167
+
168
+ def set_reservado_9
169
+ self.set_section_value(23, "")
170
+ end
171
+
172
+ def set_cartao_novo valor
173
+ self.set_section_value(24, valor)
174
+ end
175
+
176
+ def set_vencimento_novo valor
177
+ self.set_section_value(25, valor)
178
+ end
179
+
180
+ def set_reservado_10
181
+ self.set_section_value(26, "")
182
+ end
183
+
184
+ #-------------------------------------------------------------------
185
+ #-------------------------------------------------------------------
186
+ # Validações
187
+ def is_valid?
188
+ (self.get_sequencial.length > 0 and
189
+ self.get_data_venda.length > 0 and
190
+ self.get_numero_lote.length > 0 and
191
+ self.get_numero_cielo.length > 0 and
192
+ self.get_numero_cartao.length > 0 and
193
+ self.get_validade_cartao.length > 0 and
194
+ self.get_valor > 0)
195
+ end
196
+
197
+ end
@@ -0,0 +1,104 @@
1
+ class CieloHeader < FormatSection
2
+ require 'date'
3
+
4
+ def initialize master
5
+ super(master, true, true, false)
6
+
7
+ @section = Section.new({
8
+ 0 => Position.new(1, 2, false, "00", true), # Código do Registro
9
+ 1 => Position.new(2, 8, true), # Data do Deposito
10
+ 2 => Position.new(3, 7, true), # Numero do Resumo de operações
11
+ 3 => Position.new(4, 10, false), # Reservado para o estabelecimento
12
+ 4 => Position.new(5, 3, false), # Constantes zeros
13
+ 5 => Position.new(6, 10, true), # Numero do estabelecimento na Cielo
14
+ 6 => Position.new(7, 3, false), # Código da moeda
15
+ 7 => Position.new(8, 1, false,"P"), # Indicador do processo
16
+ 8 => Position.new(9, 1, false, "V"), # Indicador da venda
17
+ 9 => Position.new(10, 1, false), # Indicador de estabelecimento especial (Brancos)
18
+ 10 => Position.new(11, 204, false), # Constante (Brancos)
19
+ })
20
+ end
21
+
22
+ def get_data_deposito
23
+ self.get_section_value(1)
24
+ end
25
+
26
+ def get_numero_lote
27
+ self.get_section_value(2)
28
+ end
29
+
30
+ def get_numero_cielo
31
+ self.get_section_value(5)
32
+ end
33
+
34
+ def get_moeda
35
+ self.get_section_value(6)
36
+ end
37
+
38
+ def set_data_deposito valor
39
+ begin
40
+ valor = Date.strptime(valor, "%d%m%Y") if valor.is_a?(String)
41
+ real_data = valor.strftime("%d%m%Y")
42
+
43
+ if real_data.length == 8
44
+ self.set_section_value(1, real_data)
45
+ else
46
+ raise "tamanho de data incorreto"
47
+ end
48
+
49
+ rescue
50
+ raise "#{get_id}: Data de Geração Inválida
51
+ Valor: #{valor}"
52
+ end
53
+ end
54
+
55
+ def set_numero_lote valor
56
+ self.set_section_value(2, valor)
57
+ end
58
+
59
+ def set_reservado_1
60
+ self.set_section_value(3, "")
61
+ end
62
+
63
+ def set_reservado_2
64
+ self.set_section_value(4, "000")
65
+ end
66
+
67
+ def set_numero_cielo valor
68
+ self.set_section_value(5, valor)
69
+ end
70
+
71
+ def set_moeda valor
72
+ if ["986","840"].include? valor
73
+ self.set_section_value(6, valor)
74
+ else
75
+ raise "Código de moeda não aceito"
76
+ end
77
+ end
78
+
79
+ def set_indicador_processo
80
+ self.set_section_value(7, "P")
81
+ end
82
+
83
+ def set_indicador_venda
84
+ self.set_section_value(8, "V")
85
+ end
86
+
87
+ def set_indicador_especial
88
+ self.set_section_value(9, "")
89
+ end
90
+
91
+ def set_reservado_3
92
+ self.set_section_value(10, "")
93
+ end
94
+
95
+ #-------------------------------------------------------------------
96
+ #-------------------------------------------------------------------
97
+ # Validações
98
+ def is_valid?
99
+ (self.get_data_deposito.length > 0 and
100
+ self.get_numero_cielo.length > 0 and
101
+ self.get_numero_lote.length > 0 and
102
+ self.get_moeda.length > 0)
103
+ end
104
+ end
@@ -0,0 +1,56 @@
1
+ class CieloTrailler < FormatSection
2
+ require 'date'
3
+
4
+ def initialize master
5
+ super(master, true, true, false)
6
+
7
+ @section = Section.new({
8
+ 0 => Position.new(1, 2, false, "99", true), # Código do Registro
9
+ 1 => Position.new(2, 7, true), # Qtde de Registros
10
+ 2 => Position.new(3, 15, true), # Valor total bruto
11
+ 3 => Position.new(4, 15, true), # Valor total aceito
12
+ 4 => Position.new(5, 15, true), # Valor total liquido
13
+ 5 => Position.new(6, 8, true), # Data prevista do credito (Zeros na remessa)
14
+ 6 => Position.new(7, 188, false), # Reservado (Brancos)
15
+ })
16
+ end
17
+
18
+ def set_total_registros registros
19
+ registros = registros.to_i
20
+
21
+ if registros > 0
22
+ self.set_section_value(1, registros)
23
+ else
24
+ raise "#{get_id}: A quantidade de registros deve ser positiva e maior que 0
25
+ Valor: #{registros}"
26
+ end
27
+ end
28
+
29
+ def set_valor_total valor
30
+ valor = valor.to_i
31
+
32
+ if valor > 0
33
+ self.set_section_value(2, valor)
34
+ else
35
+ raise "#{get_id}: A quantidade de registros deve ser positiva e maior que 0
36
+ Valor: #{valor}"
37
+ end
38
+ end
39
+
40
+ def set_valor_aceito
41
+ self.set_section_value(3, "0")
42
+ end
43
+
44
+ def set_valor_liquido
45
+ self.set_section_value(4, "0")
46
+ end
47
+
48
+ def set_data_prevista
49
+ self.set_section_value(5, "0")
50
+ end
51
+
52
+ def set_reservado
53
+ self.set_section_value(6, "")
54
+ end
55
+
56
+ end
@@ -6,6 +6,7 @@ require "formatos/febraban/version"
6
6
  end
7
7
 
8
8
  require "formatos/febraban150/febraban_150"
9
+ require "formatos/cielo/cielo"
9
10
 
10
11
  module Formatos
11
12
  module Febraban
@@ -1,5 +1,5 @@
1
1
  module Formatos
2
2
  module Febraban
3
- VERSION = "0.2.23"
3
+ VERSION = "0.2.24"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formatos-febraban
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.23
4
+ version: 0.2.24
5
5
  platform: ruby
6
6
  authors:
7
7
  - josé Ricardo Almeida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-04-24 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: byebug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  description: Formatos para envido de dados bancários da FEBRABAN
42
56
  email:
43
57
  - jose@trackmob.com.br
@@ -59,6 +73,10 @@ files:
59
73
  - bin/console
60
74
  - bin/setup
61
75
  - formatos-febraban.gemspec
76
+ - lib/formatos/cielo/cielo.rb
77
+ - lib/formatos/cielo/cielo_detalhe.rb
78
+ - lib/formatos/cielo/cielo_header.rb
79
+ - lib/formatos/cielo/cielo_trailler.rb
62
80
  - lib/formatos/cnab400/cnab_400.rb
63
81
  - lib/formatos/cnab400/cnab_400_0.rb
64
82
  - lib/formatos/cnab400/cnab_400_1.rb