cnab240 0.0.9 → 0.0.10

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.
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ pkg
15
15
  rdoc
16
16
  spec/reports
17
17
  test/tmp
18
+ spec/tmp
18
19
  test/version_tmp
@@ -32,7 +32,7 @@ module Cnab240::Arquivo
32
32
  end
33
33
 
34
34
  def string
35
- linhas.join("\n")
35
+ linhas.join("\r\n")
36
36
  end
37
37
 
38
38
  def save_to_file(filename)
@@ -34,8 +34,12 @@ module Cnab240
34
34
  def <<(s)
35
35
  versao = arquivo.versao unless arquivo.nil?
36
36
  versao ||= @versao
37
-
38
- segmentos << seg = eval("Cnab240::#{versao}::Segmento#{s.to_s.upcase}.new")
37
+ case s
38
+ when Symbol, String
39
+ segmentos << seg = eval("Cnab240::#{versao}::Segmento#{s.to_s.upcase}.new")
40
+ else
41
+ segmentos << seg = s
42
+ end
39
43
  seg.lote = self
40
44
  seg
41
45
  end
@@ -52,7 +56,7 @@ module Cnab240
52
56
  end
53
57
 
54
58
  def string
55
- linhas.join("\n")
59
+ linhas.join("\r\n")
56
60
  end
57
61
 
58
62
  end
@@ -24,7 +24,7 @@ module Cnab240::V40::Arquivo
24
24
  lstring :empresa_conta_numero, :length => 5, :pad_byte => '0'
25
25
  string :brancos_5, :length => 1, :pad_byte => ' '
26
26
 
27
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
27
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
28
28
  string :empresa_nome, :length => 30, :pad_byte => ' '
29
29
 
30
30
  string :banco_nome, :length => 30, :pad_byte => ' '
@@ -19,7 +19,7 @@ module Cnab240::V80::Arquivo
19
19
  string :brancos_3, :length => 1, :initial_value => ' ', :pad_byte => ' '
20
20
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
21
21
  string :brancos_4, :length => 1, :initial_value => ' ', :pad_byte => ' '
22
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
22
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
23
23
  string :empresa_nome, :length => 30, :pad_byte => ' '
24
24
  string :banco_nome, :length => 30, :pad_byte => ' '
25
25
  string :brancos_5, :length => 10, :initial_value => ' ', :pad_byte => ' '
@@ -16,7 +16,7 @@ module Cnab240::V86::Arquivo
16
16
  string :empresa_agencia_dv, :length => 1, :pad_byte => ' '
17
17
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
18
18
  string :empresa_conta_dv, :length => 1, :pad_byte => ' '
19
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
19
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
20
20
  string :empresa_nome, :length => 30, :pad_byte => ' '
21
21
 
22
22
  string :banco_nome, :length => 30, :pad_byte => ' '
@@ -8,6 +8,7 @@ module Cnab240
8
8
  self.send("#{k}=", v)
9
9
  end
10
10
  end
11
+ yield self if block_given?
11
12
  end
12
13
 
13
14
 
@@ -6,8 +6,6 @@ module Cnab240
6
6
  attr_accessor :arquivo
7
7
 
8
8
  def initialize(campos = {})
9
- @arquivo = Cnab240::Arquivo::Arquivo.new('V80')
10
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
11
9
 
12
10
  campos[:controle_banco] ||= '341'
13
11
  campos[:arquivo_codigo] ||= '1'
@@ -15,6 +13,9 @@ module Cnab240
15
13
  campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y")
16
14
  campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M")
17
15
 
16
+ @arquivo = Cnab240::Arquivo::Arquivo.new('V80')
17
+ @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
18
+
18
19
  fill campos, arquivo.header, arquivo.trailer
19
20
 
20
21
  campos[:servico_operacao] ||= 'C'
@@ -27,15 +28,19 @@ module Cnab240
27
28
 
28
29
  def <<(campos)
29
30
  lote = @arquivo.lotes.last
30
- lote << :a
31
+
31
32
  campos[:controle_banco] ||= '341'
32
33
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
33
34
  campos[:servico_numero_registro] ||= lote.segmentos.length.to_s
34
35
  campos[:servico_tipo_movimento] ||= '000'
35
36
  campos[:credito_moeda_tipo] ||= 'REA'
36
37
  campos[:totais_qtde_registros] ||= (lote.segmentos.length + 2).to_s
38
+
39
+ segmento_a = Cnab240::V80::SegmentoA.new
40
+ fill campos, segmento_a
41
+ fill campos, segmento_a.favorecido_agencia_conta
37
42
 
38
- fill campos, lote.segmentos.last
43
+ lote << segmento_a
39
44
  end
40
45
 
41
46
  def string
@@ -31,7 +31,7 @@ module Cnab240::V40::Pagamentos
31
31
 
32
32
  string :brancos_5, :length => 1, :pad_byte => ' '
33
33
 
34
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
34
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
35
35
  string :empresa_nome, :length => 30, :pad_byte => ' '
36
36
 
37
37
  string :informacao_1, :length => 40, :pad_byte => ' '
@@ -22,7 +22,7 @@ module Cnab240::V80::Pagamentos
22
22
  string :brancos_2, :length => 1, :pad_byte => ' '
23
23
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
24
24
  string :brancos_3, :length => 1, :pad_byte => ' '
25
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
25
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
26
26
  string :empresa_nome, :length => 30, :pad_byte => ' '
27
27
 
28
28
  string :finalidade_lote, :length => 30, :pad_byte => ' '
@@ -17,10 +17,10 @@ module Cnab240::V86::Pagamentos
17
17
  lstring :empresa_numero, :length => 14, :pad_byte => '0'
18
18
  string :empresa_convenio, :length => 20, :pad_byte => ' '
19
19
  lstring :empresa_agencia_codigo, :length => 5, :pad_byte => '0'
20
- string :empresa_agencia_dv, :length => 1, :pad_byte => ' '
20
+ string :empresa_agencia_dv, :length => 1, :pad_byte => '0'
21
21
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
22
22
  string :empresa_conta_dv, :length => 1, :pad_byte => ' '
23
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
23
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
24
24
  string :empresa_nome, :length => 30, :pad_byte => ' '
25
25
 
26
26
  string :informacao_1, :length => 40, :pad_byte => ' '
@@ -18,10 +18,10 @@ module Cnab240::V86::PagamentosTitulos
18
18
  lstring :empresa_numero, :length => 14, :pad_byte => '0'
19
19
  string :empresa_convenio, :length => 20, :pad_byte => ' '
20
20
  lstring :empresa_agencia_codigo, :length => 5, :pad_byte => '0'
21
- string :empresa_agencia_dv, :length => 1, :pad_byte => ' '
21
+ string :empresa_agencia_dv, :length => 1, :pad_byte => '0'
22
22
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
23
- string :empresa_conta_dv, :length => 1, :pad_byte => ' '
24
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
23
+ string :empresa_conta_dv, :length => 1, :pad_byte => '0'
24
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
25
25
  string :empresa_nome, :length => 30, :pad_byte => ' '
26
26
 
27
27
  string :informacao_1, :length => 40, :pad_byte => ' '
@@ -18,10 +18,10 @@ module Cnab240::V86::PagamentosTributos
18
18
  lstring :empresa_numero, :length => 14, :pad_byte => '0'
19
19
  string :empresa_convenio, :length => 20, :pad_byte => ' '
20
20
  lstring :empresa_agencia_codigo, :length => 5, :pad_byte => '0'
21
- string :empresa_agencia_dv, :length => 1, :pad_byte => ' '
21
+ string :empresa_agencia_dv, :length => 1, :pad_byte => '0'
22
22
  lstring :empresa_conta_numero, :length => 12, :pad_byte => '0'
23
- string :empresa_conta_dv, :length => 1, :pad_byte => ' '
24
- string :empresa_agencia_conta_dv, :length => 1, :pad_byte => ' '
23
+ string :empresa_conta_dv, :length => 1, :pad_byte => '0'
24
+ string :empresa_agencia_conta_dv, :length => 1, :pad_byte => '0'
25
25
  string :empresa_nome, :length => 30, :pad_byte => ' '
26
26
 
27
27
  string :informacao_1, :length => 40, :pad_byte => ' '
@@ -0,0 +1,16 @@
1
+ module Cnab240::V80
2
+ class AgenciaItau < BinData::Record
3
+
4
+ include Cnab240::DefaultMixin
5
+ include Cnab240::SegmentoMixin
6
+
7
+ lstring :zeros_1, :length => 1, :pad_byte => '0'
8
+ lstring :favorecido_agencia, :length => 4, :pad_byte => '0'
9
+ string :brancos_1, :length => 1, :pad_byte => ' '
10
+ lstring :zeros_2, :length => 6, :pad_byte => '0'
11
+ lstring :favorecido_conta, :length => 6, :pad_byte => '0'
12
+ string :brancos_2, :length => 1, :pad_byte => ' '
13
+ lstring :favorecido_agencia_conta_dv, :length => 1, :pad_byte => '0'
14
+
15
+ end
16
+ end
@@ -0,0 +1,14 @@
1
+ module Cnab240::V80
2
+ class AgenciaOutros < BinData::Record
3
+
4
+ include Cnab240::DefaultMixin
5
+ include Cnab240::SegmentoMixin
6
+
7
+ lstring :favorecido_agencia, :length => 5, :pad_byte => '0'
8
+ string :brancos_1, :length => 1, :pad_byte => ' '
9
+ lstring :favorecido_conta, :length => 12, :pad_byte => '0'
10
+ string :brancos_2, :length => 1, :pad_byte => ' '
11
+ lstring :favorecido_agencia_conta_dv, :length => 1, :pad_byte => '0'
12
+
13
+ end
14
+ end
@@ -14,7 +14,13 @@ module Cnab240::V80
14
14
  lstring :zeros_1, :length => 3, :pad_byte => '0'
15
15
 
16
16
  lstring :favorecido_banco, :length => 3, :pad_byte => '0'
17
- lstring :favorecido_agencia_conta, :length => 20, :pad_byte => ' '
17
+
18
+ choice :favorecido_agencia_conta, :selection => :get_favorecido_agencia_conta do
19
+ string 0, :length => 20, :pad_byte => ' '
20
+ agencia_itau 1
21
+ agencia_outros 2
22
+ end
23
+
18
24
  string :favorecido_nome, :length => 30, :pad_byte => ' '
19
25
  string :credito_seu_numero, :length => 20, :pad_byte => ' '
20
26
  lstring :credito_data_pagamento, :length => 8, :pad_byte => '0'
@@ -41,5 +47,17 @@ module Cnab240::V80
41
47
  lstring :aviso, :length => 1, :pad_byte => ' '
42
48
  string :ocorrencias, :length => 10, :pad_byte => ' '
43
49
 
50
+
51
+ def get_favorecido_agencia_conta
52
+ case favorecido_banco
53
+ when '341'
54
+ return 1
55
+ when '409'
56
+ return 1
57
+ else
58
+ return 2
59
+ end
60
+ end
61
+
44
62
  end
45
63
  end
@@ -1,4 +1,4 @@
1
1
  module Cnab240
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
4
4
 
data/lib/cnab240.rb CHANGED
@@ -31,6 +31,8 @@ require "cnab240/segmentos/v86/segmento_w1"
31
31
  require "cnab240/segmentos/v86/segmento_w"
32
32
  require "cnab240/segmentos/v86/segmento_z"
33
33
 
34
+ require "cnab240/segmentos/v80/agencia_itau"
35
+ require "cnab240/segmentos/v80/agencia_outros"
34
36
  require "cnab240/segmentos/v40/segmento_a"
35
37
  require "cnab240/segmentos/v80/segmento_a"
36
38
 
@@ -27,7 +27,8 @@ describe PagamentoItau do
27
27
  })
28
28
 
29
29
  pagamento << { :favorecido_banco => '001',
30
- :favorecido_agencia_conta => '2290124',
30
+ :favorecido_agencia => '2290',
31
+ :favorecido_conta => '335959',
31
32
  :credito_seu_numero => '1234',
32
33
  :credito_data_pagamento => '31122012',
33
34
  :credito_valor_pagamento => '100',
@@ -39,7 +40,8 @@ describe PagamentoItau do
39
40
  }
40
41
 
41
42
  pagamento << { :favorecido_banco => '001',
42
- :favorecido_agencia_conta => '2290124',
43
+ :favorecido_agencia => '2290',
44
+ :favorecido_conta => '335959',
43
45
  :credito_seu_numero => '1234',
44
46
  :credito_data_pagamento => '31122012',
45
47
  :credito_valor_pagamento => '100',
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ include Cnab240
4
+
5
+ describe "HomSpec" do
6
+
7
+ it "teste para envio ao banco Itau: homologacao" do
8
+
9
+ pagamento = PagamentoItau.new({
10
+ :empresa_tipo => '2',
11
+ :empresa_numero => '05946982000122',
12
+ :empresa_nome => 'REDE DE CONVENIOS DO BRASIL',
13
+ :empresa_agencia_codigo => '0663',
14
+ :empresa_conta_numero => '015402',
15
+ # :empresa_agencia_conta_dv => '',
16
+ :arquivo_sequencia => '1',
17
+
18
+ :endereco_logradouro => 'RUA GETULIO VARGAS',
19
+ :endereco_numero => '3646',
20
+ :endereco_cidade => 'PORTO VELHO',
21
+ :endereco_cep => '76000000',
22
+ :endereco_estado => 'RO',
23
+ :servico_tipo => '98', # pagamentos - diversos
24
+ :servico_forma => '41', # doc, ted, etc
25
+ })
26
+
27
+ pagamento << {
28
+ :favorecido_banco => '001',
29
+ :favorecido_agencia => '2290',
30
+ :favorecido_conta => '335959',
31
+ :credito_seu_numero => '1',
32
+ :credito_data_pagamento => '03082012',
33
+ :credito_valor_pagamento => '500000',
34
+ :numero_inscricao => '69375208168',
35
+ :favorecido_nome => 'JOSE EDUARDO MOURAO'
36
+ }
37
+
38
+ pagamento.save_to_file("spec/tmp/itau07.rem")
39
+ end
40
+
41
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cnab240
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 9
10
- version: 0.0.9
9
+ - 10
10
+ version: 0.0.10
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eduardo Mourao
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-07-24 00:00:00 -04:00
18
+ date: 2012-08-13 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -96,6 +96,8 @@ files:
96
96
  - lib/cnab240/pagamentos/v86/tributos/header.rb
97
97
  - lib/cnab240/pagamentos/v86/tributos/trailer.rb
98
98
  - lib/cnab240/segmentos/v40/segmento_a.rb
99
+ - lib/cnab240/segmentos/v80/agencia_itau.rb
100
+ - lib/cnab240/segmentos/v80/agencia_outros.rb
99
101
  - lib/cnab240/segmentos/v80/segmento_a.rb
100
102
  - lib/cnab240/segmentos/v86/segmento_a.rb
101
103
  - lib/cnab240/segmentos/v86/segmento_b.rb
@@ -126,6 +128,7 @@ files:
126
128
  - spec/bindata/bindata_spec.rb
127
129
  - spec/cnab240_spec.rb
128
130
  - spec/helper/pagamento_itau_spec.rb
131
+ - spec/hom/hom_spec.rb
129
132
  - spec/pagamentos/v40/header_spec.rb
130
133
  - spec/pagamentos/v40/lote_spec.rb
131
134
  - spec/pagamentos/v40/trailer_spec.rb
@@ -208,6 +211,7 @@ test_files:
208
211
  - spec/bindata/bindata_spec.rb
209
212
  - spec/cnab240_spec.rb
210
213
  - spec/helper/pagamento_itau_spec.rb
214
+ - spec/hom/hom_spec.rb
211
215
  - spec/pagamentos/v40/header_spec.rb
212
216
  - spec/pagamentos/v40/lote_spec.rb
213
217
  - spec/pagamentos/v40/trailer_spec.rb