cnab240 0.1.0 → 0.2.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.
Files changed (110) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +2 -2
  3. data/cnab240.gemspec +10 -12
  4. data/lib/cnab240.rb +108 -91
  5. data/lib/cnab240/arquivo/arquivo.rb +6 -9
  6. data/lib/cnab240/arquivo/builder.rb +111 -90
  7. data/lib/cnab240/arquivo/estrutura.rb +161 -99
  8. data/lib/cnab240/arquivo/v40/header.rb +27 -29
  9. data/lib/cnab240/arquivo/v40/trailer.rb +8 -10
  10. data/lib/cnab240/arquivo/v60/header.rb +38 -0
  11. data/lib/cnab240/arquivo/v60/trailer.rb +17 -0
  12. data/lib/cnab240/arquivo/v80/header.rb +23 -26
  13. data/lib/cnab240/arquivo/v80/trailer.rb +8 -9
  14. data/lib/cnab240/arquivo/v81/header.rb +37 -0
  15. data/lib/cnab240/arquivo/v81/trailer.rb +17 -0
  16. data/lib/cnab240/arquivo/v83/header.rb +25 -26
  17. data/lib/cnab240/arquivo/v83/trailer.rb +9 -9
  18. data/lib/cnab240/arquivo/v86/header.rb +25 -26
  19. data/lib/cnab240/arquivo/v86/trailer.rb +9 -10
  20. data/lib/cnab240/arquivo/v87/header.rb +25 -26
  21. data/lib/cnab240/arquivo/v87/trailer.rb +9 -10
  22. data/lib/cnab240/ext/attribute_accessors.rb +4 -4
  23. data/lib/cnab240/ext/bindata.rb +4 -4
  24. data/lib/cnab240/ext/default_mixin.rb +2 -4
  25. data/lib/cnab240/ext/filler.rb +1 -3
  26. data/lib/cnab240/ext/lstring.rb +9 -10
  27. data/lib/cnab240/ext/segmento_mixin.rb +1 -3
  28. data/lib/cnab240/helper/boleto_bancoob.rb +60 -0
  29. data/lib/cnab240/helper/helper.rb +1 -1
  30. data/lib/cnab240/helper/pagamento_bb.rb +7 -9
  31. data/lib/cnab240/helper/pagamento_bradesco.rb +6 -8
  32. data/lib/cnab240/helper/pagamento_itau.rb +6 -8
  33. data/lib/cnab240/helper/transferencia_citibank.rb +56 -0
  34. data/lib/cnab240/helper/{pagamento_sicoob.rb → transferencia_sicoob.rb} +8 -15
  35. data/lib/cnab240/{arquivo/lote.rb → lote.rb} +29 -14
  36. data/lib/cnab240/lote/v40/boletos/header.rb +46 -0
  37. data/lib/cnab240/lote/v40/boletos/trailer.rb +29 -0
  38. data/lib/cnab240/pagamentos/v40/header.rb +30 -32
  39. data/lib/cnab240/pagamentos/v40/trailer.rb +10 -11
  40. data/lib/cnab240/pagamentos/v60/header.rb +43 -0
  41. data/lib/cnab240/pagamentos/v60/trailer.rb +17 -0
  42. data/lib/cnab240/pagamentos/v80/header.rb +35 -37
  43. data/lib/cnab240/pagamentos/v80/trailer.rb +10 -11
  44. data/lib/cnab240/pagamentos/v83/header.rb +33 -35
  45. data/lib/cnab240/pagamentos/v83/trailer.rb +11 -12
  46. data/lib/cnab240/pagamentos/v86/header.rb +34 -36
  47. data/lib/cnab240/pagamentos/v86/titulos/header.rb +28 -30
  48. data/lib/cnab240/pagamentos/v86/titulos/trailer.rb +11 -12
  49. data/lib/cnab240/pagamentos/v86/trailer.rb +11 -12
  50. data/lib/cnab240/pagamentos/v86/tributos/header.rb +35 -37
  51. data/lib/cnab240/pagamentos/v86/tributos/trailer.rb +9 -10
  52. data/lib/cnab240/pagamentos/v87/header.rb +34 -36
  53. data/lib/cnab240/pagamentos/v87/titulos/header.rb +28 -30
  54. data/lib/cnab240/pagamentos/v87/titulos/trailer.rb +11 -12
  55. data/lib/cnab240/pagamentos/v87/trailer.rb +11 -12
  56. data/lib/cnab240/pagamentos/v87/tributos/header.rb +35 -37
  57. data/lib/cnab240/pagamentos/v87/tributos/trailer.rb +9 -10
  58. data/lib/cnab240/segmentos/v40/segmento_a.rb +40 -41
  59. data/lib/cnab240/segmentos/v60/segmento_a.rb +43 -0
  60. data/lib/cnab240/segmentos/v60/segmento_b.rb +38 -0
  61. data/lib/cnab240/segmentos/v60/segmento_j.rb +32 -0
  62. data/lib/cnab240/segmentos/v80/agencia_itau.rb +8 -9
  63. data/lib/cnab240/segmentos/v80/agencia_outros.rb +6 -7
  64. data/lib/cnab240/segmentos/v80/segmento_a.rb +30 -32
  65. data/lib/cnab240/segmentos/v81/segmento_p.rb +79 -0
  66. data/lib/cnab240/segmentos/v81/segmento_q.rb +36 -0
  67. data/lib/cnab240/segmentos/v81/segmento_r.rb +49 -0
  68. data/lib/cnab240/segmentos/v81/segmento_s.rb +37 -0
  69. data/lib/cnab240/segmentos/v83/segmento_a.rb +35 -36
  70. data/lib/cnab240/segmentos/v83/segmento_b.rb +33 -34
  71. data/lib/cnab240/segmentos/v83/segmento_j.rb +22 -23
  72. data/lib/cnab240/segmentos/v83/segmento_z.rb +10 -11
  73. data/lib/cnab240/segmentos/v86/segmento_a.rb +37 -38
  74. data/lib/cnab240/segmentos/v86/segmento_b.rb +33 -34
  75. data/lib/cnab240/segmentos/v86/segmento_c.rb +19 -20
  76. data/lib/cnab240/segmentos/v86/segmento_j.rb +22 -23
  77. data/lib/cnab240/segmentos/v86/segmento_j52.rb +19 -20
  78. data/lib/cnab240/segmentos/v86/segmento_n.rb +17 -18
  79. data/lib/cnab240/segmentos/v86/segmento_n1.rb +10 -11
  80. data/lib/cnab240/segmentos/v86/segmento_n2.rb +12 -13
  81. data/lib/cnab240/segmentos/v86/segmento_n3.rb +12 -13
  82. data/lib/cnab240/segmentos/v86/segmento_n4.rb +14 -15
  83. data/lib/cnab240/segmentos/v86/segmento_n5.rb +12 -13
  84. data/lib/cnab240/segmentos/v86/segmento_n6.rb +12 -13
  85. data/lib/cnab240/segmentos/v86/segmento_n7.rb +13 -14
  86. data/lib/cnab240/segmentos/v86/segmento_n8.rb +12 -14
  87. data/lib/cnab240/segmentos/v86/segmento_o.rb +17 -18
  88. data/lib/cnab240/segmentos/v86/segmento_w.rb +12 -13
  89. data/lib/cnab240/segmentos/v86/segmento_w1.rb +9 -10
  90. data/lib/cnab240/segmentos/v86/segmento_z.rb +10 -11
  91. data/lib/cnab240/segmentos/v87/segmento_a.rb +37 -38
  92. data/lib/cnab240/segmentos/v87/segmento_b.rb +33 -34
  93. data/lib/cnab240/segmentos/v87/segmento_c.rb +19 -20
  94. data/lib/cnab240/segmentos/v87/segmento_j.rb +22 -23
  95. data/lib/cnab240/segmentos/v87/segmento_j52.rb +19 -20
  96. data/lib/cnab240/segmentos/v87/segmento_n.rb +17 -18
  97. data/lib/cnab240/segmentos/v87/segmento_n1.rb +10 -11
  98. data/lib/cnab240/segmentos/v87/segmento_n2.rb +12 -13
  99. data/lib/cnab240/segmentos/v87/segmento_n3.rb +12 -13
  100. data/lib/cnab240/segmentos/v87/segmento_n4.rb +14 -15
  101. data/lib/cnab240/segmentos/v87/segmento_n5.rb +12 -13
  102. data/lib/cnab240/segmentos/v87/segmento_n6.rb +12 -13
  103. data/lib/cnab240/segmentos/v87/segmento_n7.rb +13 -14
  104. data/lib/cnab240/segmentos/v87/segmento_n8.rb +12 -14
  105. data/lib/cnab240/segmentos/v87/segmento_o.rb +17 -18
  106. data/lib/cnab240/segmentos/v87/segmento_w.rb +12 -13
  107. data/lib/cnab240/segmentos/v87/segmento_w1.rb +9 -10
  108. data/lib/cnab240/segmentos/v87/segmento_z.rb +10 -11
  109. data/lib/cnab240/version.rb +1 -1
  110. metadata +30 -40
@@ -1,11 +1,11 @@
1
1
  module BinData
2
2
  class Record < BinData::Struct
3
3
  def linha # lulz
4
- self.auto_fill if self.respond_to?(:auto_fill) && Cnab240.auto_fill_enabled
4
+ auto_fill if self.respond_to?(:auto_fill) && Cnab240.auto_fill_enabled
5
5
  s = StringIO.new
6
- self.write(s)
7
- raise "Invalid line length #{s.string.length}" unless (s.string.length == 240) || self.respond_to?(:lote)
6
+ write(s)
7
+ fail "Invalid line length #{s.string.length}" unless (s.string.length == 240) || self.respond_to?(:lote)
8
8
  s.string
9
9
  end
10
10
  end
11
- end
11
+ end
@@ -1,15 +1,13 @@
1
1
  module Cnab240
2
2
  module DefaultMixin
3
-
4
3
  def initialize_instance
5
4
  super
6
5
  Cnab240.defaults.each do |k, v|
7
6
  if self.respond_to?("#{k}=")
8
- self.send("#{k}=", v)
7
+ send("#{k}=", v)
9
8
  end
10
9
  end
11
10
  yield self if block_given?
12
11
  end
13
-
14
12
  end
15
- end
13
+ end
@@ -1,6 +1,5 @@
1
1
  module Cnab240
2
2
  module Filler
3
-
4
3
  def fill(hash, *objects)
5
4
  objects.each do |object|
6
5
  hash.each do |k, v|
@@ -16,6 +15,5 @@ module Cnab240
16
15
  end
17
16
  end
18
17
  end
19
-
20
18
  end
21
- end
19
+ end
@@ -1,17 +1,14 @@
1
- require "bindata/base_primitive"
1
+ require 'bindata/base_primitive'
2
2
 
3
3
  module BinData
4
-
5
4
  # I didn't want to monkey patch bindata's String primitive.
6
5
  class Lstring < BinData::BasePrimitive
7
-
8
6
  optional_parameters :read_length, :length, :trim_padding
9
- default_parameters :pad_byte => "\0"
7
+ default_parameters pad_byte: "\0"
10
8
  mutually_exclusive_parameters :read_length, :length
11
9
  mutually_exclusive_parameters :length, :value
12
10
 
13
11
  class << self
14
-
15
12
  def sanitize_parameters!(params) #:nodoc:
16
13
  params.warn_replacement_parameter(:initial_length, :read_length)
17
14
 
@@ -24,18 +21,19 @@ module BinData
24
21
  end
25
22
 
26
23
  #-------------
24
+
27
25
  private
28
26
 
29
27
  def sanitized_pad_byte(byte)
30
28
  result = byte.is_a?(Integer) ? byte.chr : byte_string(byte.to_s.dup)
31
29
  if result.length > 1
32
- raise ArgumentError, ":pad_byte must not contain more than 1 byte"
30
+ fail ArgumentError, ':pad_byte must not contain more than 1 byte'
33
31
  end
34
32
  result
35
33
  end
36
34
 
37
35
  def byte_string(str)
38
- if RUBY_VERSION >= "1.9"
36
+ if RUBY_VERSION >= '1.9'
39
37
  str.force_encoding(Encoding::BINARY)
40
38
  else
41
39
  str
@@ -59,10 +57,11 @@ module BinData
59
57
  end
60
58
 
61
59
  #---------------
60
+
62
61
  private
63
62
 
64
63
  def byte_string(str)
65
- if RUBY_VERSION >= "1.9"
64
+ if RUBY_VERSION >= '1.9'
66
65
  str.force_encoding(Encoding::BINARY)
67
66
  else
68
67
  str
@@ -83,7 +82,7 @@ module BinData
83
82
  end
84
83
 
85
84
  def trim_padding(str)
86
- str.sub(/#{eval_parameter(:pad_byte)}*$/, "")
85
+ str.sub(/#{eval_parameter(:pad_byte)}*$/, '')
87
86
  end
88
87
 
89
88
  def value_to_binary_string(val)
@@ -96,7 +95,7 @@ module BinData
96
95
  end
97
96
 
98
97
  def sensible_default
99
- ""
98
+ ''
100
99
  end
101
100
  end
102
101
  end
@@ -1,7 +1,5 @@
1
1
  module Cnab240
2
2
  module SegmentoMixin
3
-
4
3
  attr_accessor :lote
5
-
6
4
  end
7
- end
5
+ end
@@ -0,0 +1,60 @@
1
+ module Cnab240
2
+ class BoletoBancoob < Helper
3
+ def initialize(campos = {})
4
+ campos[:controle_banco] ||= '756'
5
+ campos[:banco_nome] ||= 'BANCO COOPERATIVO DO BRASIL S/A.'
6
+ campos[:empresa_tipo] ||= '2'
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
9
+ campos[:arquivo_codigo] ||= '1'
10
+
11
+ @arquivo = Cnab240::Arquivo::Arquivo.new('V81')
12
+
13
+ fill campos, arquivo.header, arquivo.trailer
14
+ end
15
+
16
+ def add_lote(campos = {})
17
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :boleto, tipo: :remessa, versao: 'V81')
18
+
19
+ campos[:controle_banco] ||= '756'
20
+ campos[:controle_lote] = (@arquivo.lotes.length).to_s
21
+
22
+ fill campos, lote.header, lote.trailer
23
+ end
24
+
25
+ def <<(campos)
26
+ lote = @arquivo.lotes.last
27
+
28
+ campos[:controle_banco] ||= '756'
29
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
30
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
31
+ # 01 - Entrada de títulos
32
+ campos[:servico_codigo_movimento] ||= '01'
33
+
34
+ segmento_p = Cnab240::V81::SegmentoP.new
35
+ fill campos, segmento_p
36
+ lote << segmento_p
37
+
38
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
39
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
40
+
41
+ segmento_q = Cnab240::V81::SegmentoQ.new
42
+ fill campos, segmento_q
43
+ lote << segmento_q
44
+
45
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
46
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
47
+
48
+ segmento_r = Cnab240::V81::SegmentoR.new
49
+ fill campos, segmento_r
50
+ lote << segmento_r
51
+
52
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
53
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
54
+
55
+ segmento_s = Cnab240::V81::SegmentoS.new
56
+ fill campos, segmento_s
57
+ lote << segmento_s
58
+ end
59
+ end
60
+ end
@@ -12,4 +12,4 @@ module Cnab240
12
12
  arquivo.save_to_file(file)
13
13
  end
14
14
  end
15
- end
15
+ end
@@ -1,16 +1,15 @@
1
1
  module Cnab240
2
2
  class PagamentoBb < Helper
3
-
4
3
  def initialize(campos = {})
5
4
  campos[:controle_banco] ||= '001'
6
5
  campos[:banco_nome] ||= 'BANCO DO BRASIL S.A.'
7
6
  campos[:empresa_tipo] ||= '2'
8
- campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y")
9
- campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M")
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
10
9
  campos[:arquivo_codigo] ||= '1'
11
10
 
12
11
  @arquivo = Cnab240::Arquivo::Arquivo.new('V86')
13
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V86')
12
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V86')
14
13
 
15
14
  fill campos, arquivo.header, arquivo.trailer
16
15
 
@@ -21,7 +20,7 @@ module Cnab240
21
20
  end
22
21
 
23
22
  def add_lote(campos = {})
24
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V86')
23
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V86')
25
24
 
26
25
  campos[:servico_operacao] ||= 'C'
27
26
  campos[:controle_lote] ||= '0001'
@@ -34,7 +33,7 @@ module Cnab240
34
33
 
35
34
  campos[:controle_banco] ||= '001'
36
35
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
37
- campos[:servico_numero_registro] ||= (lote.segmentos.length+1).to_s
36
+ campos[:servico_numero_registro] ||= (lote.segmentos.length + 1).to_s
38
37
  # 000 para inclusao e 999 para exclusao
39
38
  campos[:servico_tipo_movimento] ||= '000'
40
39
  campos[:credito_moeda_tipo] ||= 'BRL'
@@ -42,10 +41,9 @@ module Cnab240
42
41
 
43
42
  segmento_a = Cnab240::V86::SegmentoA.new
44
43
  fill campos, segmento_a
45
- #fill campos, segmento_a.favorecido_agencia_conta
44
+ # fill campos, segmento_a.favorecido_agencia_conta
46
45
 
47
46
  lote << segmento_a
48
47
  end
49
-
50
48
  end
51
- end
49
+ end
@@ -1,15 +1,14 @@
1
1
  module Cnab240
2
2
  class PagamentoBradesco < Helper
3
-
4
3
  def initialize(campos = {})
5
4
  campos[:controle_banco] ||= '237'
6
5
  campos[:arquivo_codigo] ||= '1'
7
6
  campos[:banco_nome] ||= 'BANCO BRADESCO'
8
- campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y")
9
- campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M")
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
10
9
 
11
10
  @arquivo = Cnab240::Arquivo::Arquivo.new('V80')
12
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
11
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V80')
13
12
 
14
13
  fill campos, arquivo.header, arquivo.trailer
15
14
 
@@ -20,7 +19,7 @@ module Cnab240
20
19
  end
21
20
 
22
21
  def add_lote(campos = {})
23
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
22
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V80')
24
23
 
25
24
  campos[:servico_operacao] ||= 'C'
26
25
  campos[:controle_lote] ||= '0001'
@@ -33,7 +32,7 @@ module Cnab240
33
32
 
34
33
  campos[:controle_banco] ||= '237'
35
34
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
36
- campos[:servico_numero_registro] ||= (lote.segmentos.length+1).to_s
35
+ campos[:servico_numero_registro] ||= (lote.segmentos.length + 1).to_s
37
36
  campos[:servico_tipo_movimento] ||= '000'
38
37
  campos[:credito_moeda_tipo] ||= 'REA'
39
38
  campos[:totais_qtde_registros] ||= (lote.segmentos.length + 2).to_s
@@ -44,6 +43,5 @@ module Cnab240
44
43
 
45
44
  lote << segmento_a
46
45
  end
47
-
48
46
  end
49
- end
47
+ end
@@ -1,15 +1,14 @@
1
1
  module Cnab240
2
2
  class PagamentoItau < Helper
3
-
4
3
  def initialize(campos = {})
5
4
  campos[:controle_banco] ||= '341'
6
5
  campos[:arquivo_codigo] ||= '1'
7
6
  campos[:banco_nome] ||= 'BANCO ITAU'
8
- campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y")
9
- campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M")
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
10
9
 
11
10
  @arquivo = Cnab240::Arquivo::Arquivo.new('V80')
12
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
11
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V80')
13
12
 
14
13
  fill campos, arquivo.header, arquivo.trailer
15
14
 
@@ -20,7 +19,7 @@ module Cnab240
20
19
  end
21
20
 
22
21
  def add_lote(campos = {})
23
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V80')
22
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V80')
24
23
 
25
24
  campos[:servico_operacao] ||= 'C'
26
25
  campos[:controle_lote] ||= '0001'
@@ -33,7 +32,7 @@ module Cnab240
33
32
 
34
33
  campos[:controle_banco] ||= '341'
35
34
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
36
- campos[:servico_numero_registro] ||= (lote.segmentos.length+1).to_s
35
+ campos[:servico_numero_registro] ||= (lote.segmentos.length + 1).to_s
37
36
  campos[:servico_tipo_movimento] ||= '000'
38
37
  campos[:credito_moeda_tipo] ||= 'REA'
39
38
  campos[:totais_qtde_registros] ||= (lote.segmentos.length + 2).to_s
@@ -44,6 +43,5 @@ module Cnab240
44
43
 
45
44
  lote << segmento_a
46
45
  end
47
-
48
46
  end
49
- end
47
+ end
@@ -0,0 +1,56 @@
1
+ module Cnab240
2
+ class TransferenciaCitibank < Helper
3
+ def initialize(campos = {})
4
+ campos[:controle_banco] ||= '745'
5
+ campos[:banco_nome] ||= 'BANCO CITIBANK S/A'
6
+ campos[:empresa_tipo] ||= '2'
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
9
+ campos[:arquivo_codigo] ||= '1'
10
+
11
+ @arquivo = Cnab240::Arquivo::Arquivo.new('V60')
12
+
13
+ fill campos, arquivo.header, arquivo.trailer
14
+ end
15
+
16
+ def add_lote(campos = {})
17
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V60')
18
+
19
+ campos[:controle_banco] ||= '745'
20
+ campos[:servico_operacao] ||= 'C'
21
+ campos[:controle_lote] = (@arquivo.lotes.length).to_s
22
+
23
+ fill campos, lote.header, lote.trailer
24
+ end
25
+
26
+ def <<(campos)
27
+ lote = @arquivo.lotes.last
28
+
29
+ campos[:controle_banco] ||= '745'
30
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
31
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
32
+ # 000 para inclusao e 999 para exclusao
33
+ campos[:servico_tipo_movimento] ||= '000'
34
+ campos[:credito_moeda_tipo] ||= 'BRL'
35
+ # [018] TED (STR,CIP) ou [700] DOC.
36
+ campos[:favorecido_camara] = favorecido_camara(lote, campos)
37
+
38
+ segmento_a = Cnab240::V60::SegmentoA.new
39
+ fill campos, segmento_a
40
+ lote << segmento_a
41
+
42
+ campos[:controle_lote] = @arquivo.lotes.length.to_s
43
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
44
+ campos[:pagamento_data_vencimento] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
45
+
46
+ segmento_b = Cnab240::V60::SegmentoB.new
47
+ fill campos, segmento_b
48
+ lote << segmento_b
49
+ end
50
+
51
+ # [018] TED (STR,CIP) ou [700] DOC (COMPE)
52
+ def favorecido_camara(lote, campos)
53
+ lote.header[:servico_forma] == '01' ? '000' : (campos[:credito_valor_pagamento].to_i < 749) ? '700' : '018'
54
+ end
55
+ end
56
+ end
@@ -1,28 +1,22 @@
1
1
  module Cnab240
2
- class PagamentoSicoob < Helper
3
-
2
+ class TransferenciaSicoob < Helper
4
3
  def initialize(campos = {})
5
4
  campos[:controle_banco] ||= '756'
6
5
  campos[:banco_nome] ||= 'BANCO COOPERATIVO DO BRASIL S.A.'
7
6
  campos[:empresa_tipo] ||= '2'
8
- campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y")
9
- campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M")
7
+ campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
8
+ campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
10
9
  campos[:arquivo_codigo] ||= '1'
11
10
 
12
11
  @arquivo = Cnab240::Arquivo::Arquivo.new('V87')
13
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V87')
14
12
 
15
13
  fill campos, arquivo.header, arquivo.trailer
16
-
17
- campos[:servico_operacao] ||= 'C'
18
- campos[:controle_lote] ||= '0001'
19
-
20
- fill campos, lote.header, lote.trailer
21
14
  end
22
15
 
23
16
  def add_lote(campos = {})
24
- @arquivo.lotes << lote = Cnab240::Lote.new(:operacao => :pagamento, :tipo => :remessa, :versao => 'V87')
17
+ @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V87')
25
18
 
19
+ campos[:controle_banco] ||= '756'
26
20
  campos[:servico_operacao] ||= 'C'
27
21
  campos[:controle_lote] = (@arquivo.lotes.length).to_s
28
22
 
@@ -34,7 +28,7 @@ module Cnab240
34
28
 
35
29
  campos[:controle_banco] ||= '756'
36
30
  campos[:controle_lote] = @arquivo.lotes.length.to_s
37
- campos[:servico_numero_registro] = (lote.segmentos.length+1).to_s
31
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
38
32
  # 000 para inclusao e 999 para exclusao
39
33
  campos[:servico_tipo_movimento] ||= '000'
40
34
  campos[:credito_moeda_tipo] ||= 'BRL'
@@ -44,12 +38,11 @@ module Cnab240
44
38
  lote << segmento_a
45
39
 
46
40
  campos[:controle_lote] = @arquivo.lotes.length.to_s
47
- campos[:servico_numero_registro] = (lote.segmentos.length+1).to_s
41
+ campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
48
42
 
49
43
  segmento_b = Cnab240::V87::SegmentoB.new
50
44
  fill campos, segmento_b
51
45
  lote << segmento_b
52
46
  end
53
-
54
47
  end
55
- end
48
+ end