brcobranca 10.1.0 → 11.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1 -191
  3. data/README.md +20 -19
  4. data/Rakefile +0 -5
  5. data/lib/brcobranca/boleto/ailos.rb +3 -2
  6. data/lib/brcobranca/boleto/banco_brasil.rb +4 -4
  7. data/lib/brcobranca/boleto/base.rb +1 -1
  8. data/lib/brcobranca/boleto/citibank.rb +1 -1
  9. data/lib/brcobranca/boleto/sicredi.rb +1 -1
  10. data/lib/brcobranca/boleto/template/rghost.rb +16 -11
  11. data/lib/brcobranca/boleto/template/rghost2.rb +243 -235
  12. data/lib/brcobranca/boleto/template/rghost_bolepix.rb +2 -2
  13. data/lib/brcobranca/boleto/template/rghost_carne.rb +8 -8
  14. data/lib/brcobranca/formatacao.rb +12 -12
  15. data/lib/brcobranca/remessa/base.rb +1 -2
  16. data/lib/brcobranca/remessa/cnab240/ailos.rb +4 -2
  17. data/lib/brcobranca/remessa/cnab240/base.rb +1 -1
  18. data/lib/brcobranca/remessa/cnab240/santander.rb +224 -0
  19. data/lib/brcobranca/remessa/cnab240/sicoob.rb +1 -1
  20. data/lib/brcobranca/remessa/cnab240/sicoob_banco_brasil.rb +1 -1
  21. data/lib/brcobranca/remessa/cnab240/sicredi.rb +1 -1
  22. data/lib/brcobranca/remessa/cnab400/banco_brasil.rb +1 -1
  23. data/lib/brcobranca/remessa/cnab400/banrisul.rb +1 -1
  24. data/lib/brcobranca/remessa/cnab400/santander.rb +1 -1
  25. data/lib/brcobranca/remessa/pagamento.rb +3 -5
  26. data/lib/brcobranca/retorno/cnab240/ailos.rb +2 -2
  27. data/lib/brcobranca/retorno/cnab240/base.rb +1 -1
  28. data/lib/brcobranca/retorno/cnab240/santander.rb +2 -2
  29. data/lib/brcobranca/retorno/cnab240/sicoob.rb +2 -2
  30. data/lib/brcobranca/retorno/cnab240/sicredi.rb +2 -2
  31. data/lib/brcobranca/retorno/cnab400/banco_brasil.rb +1 -1
  32. data/lib/brcobranca/retorno/cnab400/banco_brasilia.rb +1 -1
  33. data/lib/brcobranca/retorno/cnab400/banco_nordeste.rb +1 -1
  34. data/lib/brcobranca/retorno/cnab400/banrisul.rb +1 -1
  35. data/lib/brcobranca/retorno/cnab400/base.rb +2 -2
  36. data/lib/brcobranca/retorno/cnab400/bradesco.rb +1 -1
  37. data/lib/brcobranca/retorno/cnab400/credisis.rb +1 -1
  38. data/lib/brcobranca/retorno/cnab400/itau.rb +1 -1
  39. data/lib/brcobranca/retorno/cnab400/santander.rb +1 -1
  40. data/lib/brcobranca/retorno/cnab400/unicred.rb +1 -1
  41. data/lib/brcobranca/retorno/retorno_cnab240.rb +2 -2
  42. data/lib/brcobranca/retorno/retorno_cnab400.rb +1 -1
  43. data/lib/brcobranca/version.rb +1 -1
  44. data/lib/brcobranca.rb +2 -0
  45. metadata +11 -11
  46. data/HISTORY.md +0 -71
@@ -1,255 +1,263 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  begin
4
- require 'rghost'
5
- rescue LoadError
6
- require 'rubygems' unless ENV['NO_RUBYGEMS']
7
- gem 'rghost'
8
- require 'rghost'
9
- end
10
-
11
- begin
12
- require 'rghost_barcode'
13
- rescue LoadError
14
- require 'rubygems' unless ENV['NO_RUBYGEMS']
15
- gem 'rghost_barcode'
16
- require 'rghost_barcode'
17
- end
18
-
19
- module Brcobranca
20
- module Boleto
21
- module Template
22
- # Templates para usar com Rghost
23
- module Rghost2
24
- extend self
25
- include RGhost unless include?(RGhost)
26
- RGhost::Config::GS[:external_encoding] = Brcobranca.configuration.external_encoding
27
- RGhost::Config::GS[:default_params] << '-dNOSAFER'
28
- RGhost::Config::GS[:unit]=Units::Cm
29
-
30
-
31
- # Gera o boleto em usando o formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
32
- #
33
- # @return [Stream]
34
- # @see http://wiki.github.com/shairontoledo/rghost/supported-devices-drivers-and-formats Veja mais formatos na documentação do rghost.
35
- # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
36
- def to(formato, options = {})
37
- modelo_generico(self, options.merge!(formato: formato))
38
- end
39
-
40
- # Gera o boleto em usando o formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
41
- #
42
- # @return [Stream]
43
- # @see http://wiki.github.com/shairontoledo/rghost/supported-devices-drivers-and-formats Veja mais formatos na documentação do rghost.
44
- # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
45
- def lote(boletos, options = {})
46
- modelo_generico_multipage(boletos, options)
47
- end
48
-
49
- # Cria o métodos dinâmicos (to_pdf, to_gif e etc) com todos os fomátos válidos.
50
- #
51
- # @return [Stream]
52
- # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
53
- # @example
54
- # @boleto.to_pdf #=> boleto gerado no formato pdf
55
- def method_missing(m, *args)
56
- method = m.to_s
57
- if method.start_with?('to_')
58
- modelo_generico(self, (args.first || {}).merge!(formato: method[3..-1]))
59
- else
60
- super
61
- end
4
+ require 'rghost'
5
+ rescue LoadError
6
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
7
+ gem 'rghost'
8
+ require 'rghost'
9
+ end
10
+
11
+ begin
12
+ require 'rghost_barcode'
13
+ rescue LoadError
14
+ require 'rubygems' unless ENV['NO_RUBYGEMS']
15
+ gem 'rghost_barcode'
16
+ require 'rghost_barcode'
17
+ end
18
+
19
+ module Brcobranca
20
+ module Boleto
21
+ module Template
22
+ # Templates para usar com Rghost
23
+ module Rghost2
24
+ extend self
25
+ include RGhost unless include?(RGhost)
26
+ RGhost::Config::GS[:external_encoding] = Brcobranca.configuration.external_encoding
27
+ RGhost::Config::GS[:default_params] << '-dNOSAFER'
28
+ RGhost::Config::GS[:unit] = Units::Cm
29
+
30
+ # Gera o boleto em usando o formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
31
+ #
32
+ # @return [Stream]
33
+ # @see http://wiki.github.com/shairontoledo/rghost/supported-devices-drivers-and-formats Veja mais formatos na documentação do rghost.
34
+ # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
35
+ def to(formato, options = {})
36
+ modelo_generico(self, options.merge!(formato: formato))
37
+ end
38
+
39
+ # Gera o boleto em usando o formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
40
+ #
41
+ # @return [Stream]
42
+ # @see http://wiki.github.com/shairontoledo/rghost/supported-devices-drivers-and-formats Veja mais formatos na documentação do rghost.
43
+ # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
44
+ def lote(boletos, options = {})
45
+ modelo_generico_multipage(boletos, options)
46
+ end
47
+
48
+ # Cria o métodos dinâmicos (to_pdf, to_gif e etc) com todos os fomátos válidos.
49
+ #
50
+ # @return [Stream]
51
+ # @see Rghost#modelo_generico Recebe os mesmos parâmetros do Rghost#modelo_generico.
52
+ # @example
53
+ # @boleto.to_pdf #=> boleto gerado no formato pdf
54
+ def method_missing(m, *args)
55
+ method = m.to_s
56
+ if method.start_with?('to_')
57
+ modelo_generico(self, (args.first || {}).merge!(formato: method[3..]))
58
+ else
59
+ super
62
60
  end
63
-
64
- private
65
-
66
- # Retorna um stream pronto para gravação em arquivo.
67
- #
68
- # @return [Stream]
69
- # @param [Boleto] Instância de uma classe de boleto.
70
- # @param [Hash] options Opção para a criação do boleto.
71
- # @option options [Symbol] :resolucao Resolução em pixels.
72
- # @option options [Symbol] :formato Formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
73
- def modelo_generico(boleto, options = {})
74
- doc = Document.new paper: [21,29.7] # A4
75
- template_path = File.join(File.dirname(__FILE__), '..', '..', 'arquivos', 'templates', 'modelo_generico2.eps')
76
- raise 'Não foi possível encontrar o template. Verifique o caminho' unless File.exist?(template_path)
77
- modelo_recibo_beneficiario(doc, boleto)
61
+ end
62
+
63
+ private
64
+
65
+ # Retorna um stream pronto para gravação em arquivo.
66
+ #
67
+ # @return [Stream]
68
+ # @param [Boleto] Instância de uma classe de boleto.
69
+ # @param [Hash] options Opção para a criação do boleto.
70
+ # @option options [Symbol] :resolucao Resolução em pixels.
71
+ # @option options [Symbol] :formato Formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
72
+ def modelo_generico(boleto, options = {})
73
+ doc = Document.new paper: [21, 29.7] # A4
74
+ template_path = File.join(File.dirname(__FILE__), '..', '..', 'arquivos', 'templates', 'modelo_generico2.eps')
75
+ raise 'Não foi possível encontrar o template. Verifique o caminho' unless File.exist?(template_path)
76
+
77
+ modelo_recibo_beneficiario(doc, boleto)
78
+ modelo_generico_template(doc, boleto, template_path)
79
+ modelo_generico_cabecalho(doc, boleto)
80
+ modelo_generico_rodape(doc, boleto)
81
+ # Gerando stream
82
+ formato = options.delete(:formato) || Brcobranca.configuration.formato
83
+ resolucao = options.delete(:resolucao) || Brcobranca.configuration.resolucao
84
+ doc.render_stream(formato.to_sym, resolution: resolucao)
85
+ end
86
+
87
+ # Retorna um stream para multiplos boletos pronto para gravação em arquivo.
88
+ #
89
+ # @return [Stream]
90
+ # @param [Array] Instâncias de classes de boleto.
91
+ # @param [Hash] options Opção para a criação do boleto.
92
+ # @option options [Symbol] :resolucao Resolução em pixels.
93
+ # @option options [Symbol] :formato Formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
94
+ def modelo_generico_multipage(boletos, options = {})
95
+ doc = Document.new paper: [21, 29.7] # A4
96
+ template_path = File.join(File.dirname(__FILE__), '..', '..', 'arquivos', 'templates', 'modelo_generico2.eps')
97
+ raise 'Não foi possível encontrar o template. Verifique o caminho' unless File.exist?(template_path)
98
+
99
+ boletos.each_with_index do |boleto, index|
78
100
  modelo_generico_template(doc, boleto, template_path)
101
+ modelo_recibo_beneficiario(doc, boleto)
79
102
  modelo_generico_cabecalho(doc, boleto)
80
103
  modelo_generico_rodape(doc, boleto)
81
- # Gerando stream
82
- formato = (options.delete(:formato) || Brcobranca.configuration.formato)
83
- resolucao = (options.delete(:resolucao) || Brcobranca.configuration.resolucao)
84
- doc.render_stream(formato.to_sym, resolution: resolucao)
85
- end
86
-
87
- # Retorna um stream para multiplos boletos pronto para gravação em arquivo.
88
- #
89
- # @return [Stream]
90
- # @param [Array] Instâncias de classes de boleto.
91
- # @param [Hash] options Opção para a criação do boleto.
92
- # @option options [Symbol] :resolucao Resolução em pixels.
93
- # @option options [Symbol] :formato Formato desejado [:pdf, :jpg, :tif, :png, :ps, :laserjet, ... etc]
94
- def modelo_generico_multipage(boletos, options = {})
95
- doc = Document.new paper: [21,29.7] # A4
96
- template_path = File.join(File.dirname(__FILE__), '..', '..', 'arquivos', 'templates', 'modelo_generico2.eps')
97
- raise 'Não foi possível encontrar o template. Verifique o caminho' unless File.exist?(template_path)
98
- boletos.each_with_index do |boleto, index|
99
- modelo_generico_template(doc, boleto, template_path)
100
- modelo_recibo_beneficiario(doc, boleto)
101
- modelo_generico_cabecalho(doc, boleto)
102
- modelo_generico_rodape(doc, boleto)
103
- # Cria nova página se não for o último boleto
104
- doc.next_page unless index == boletos.length - 1
105
- end
106
- # Gerando stream
107
- formato = (options.delete(:formato) || Brcobranca.configuration.formato)
108
- resolucao = (options.delete(:resolucao) || Brcobranca.configuration.resolucao)
109
- doc.render_stream(formato.to_sym, resolution: resolucao)
104
+ # Cria nova página se não for o último boleto
105
+ doc.next_page unless index == boletos.length - 1
110
106
  end
111
-
112
- # Define o template a ser usado no boleto
113
- def modelo_generico_template(doc, _boleto, template_path)
114
- doc.define_template(:template, template_path, x: '0.732 cm', y: '3.48 cm')
115
- doc.use_template :template
116
-
117
- doc.define_tags do
118
- tag :menor, name: "LiberationMono", size: 8
119
- tag :menor2, name: "LiberationMono", size: 6
120
- tag :menor_bold, name: "Helvetica-Bold", size: 8
121
- tag :medio, name: "Helvetica-Bold", size: 12
122
- tag :maior, name: "Helvetica-Bold", size: 13.5
123
- end
107
+ # Gerando stream
108
+ formato = options.delete(:formato) || Brcobranca.configuration.formato
109
+ resolucao = options.delete(:resolucao) || Brcobranca.configuration.resolucao
110
+ doc.render_stream(formato.to_sym, resolution: resolucao)
111
+ end
112
+
113
+ # Define o template a ser usado no boleto
114
+ def modelo_generico_template(doc, _boleto, template_path)
115
+ doc.define_template(:template, template_path, x: '0.732 cm', y: '3.48 cm')
116
+ doc.use_template :template
117
+
118
+ doc.define_tags do
119
+ tag :menor, name: 'LiberationMono', size: 8
120
+ tag :menor2, name: 'LiberationMono', size: 6
121
+ tag :menor_bold, name: 'Helvetica-Bold', size: 8
122
+ tag :medio, name: 'Helvetica-Bold', size: 12
123
+ tag :maior, name: 'Helvetica-Bold', size: 13.5
124
124
  end
125
-
126
- # Monta Recibo do Beneficiário
127
- def modelo_recibo_beneficiario(doc, boleto)
128
- doc.moveto x: 4.28, y: 26.87
129
- doc.show truncar(boleto.cedente, 90), tag: :menor
130
- doc.moveto x: 4.28, y: 26.33
131
- doc.show truncar(boleto.sacado, 90), tag: :menor
132
- doc.moveto x: 4.28, y: 25.76
133
- doc.show boleto.documento_numero, tag: :menor
134
- doc.moveto x: 4.28, y: 25.20
135
- doc.show boleto.nosso_numero_boleto, tag: :menor
136
- doc.moveto x: 4.28, y: 24.63
137
- doc.show boleto.data_vencimento.to_s_br, tag: :menor
138
- doc.moveto x: 4.28, y: 24.070
139
- doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :menor
140
- doc.moveto x: 4.28, y: 23.49
141
- doc.show boleto.agencia_conta_boleto, tag: :menor
142
- doc.moveto x: 4.28, y: 22.95
143
- doc.show boleto.valor_documento.to_currency, tag: :menor
125
+ end
126
+
127
+ # Monta Recibo do Beneficiário
128
+ def modelo_recibo_beneficiario(doc, boleto)
129
+ doc.moveto x: 4.28, y: 26.87
130
+ doc.show truncar(boleto.cedente, 90), tag: :menor
131
+ doc.moveto x: 4.28, y: 26.33
132
+ doc.show truncar(boleto.sacado, 90), tag: :menor
133
+ doc.moveto x: 4.28, y: 25.76
134
+ doc.show boleto.documento_numero, tag: :menor
135
+ doc.moveto x: 4.28, y: 25.20
136
+ doc.show boleto.nosso_numero_boleto, tag: :menor
137
+ doc.moveto x: 4.28, y: 24.63
138
+ doc.show boleto.data_vencimento.to_s_br, tag: :menor
139
+ doc.moveto x: 4.28, y: 24.070
140
+ doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :menor
141
+ doc.moveto x: 4.28, y: 23.49
142
+ doc.show boleto.agencia_conta_boleto, tag: :menor
143
+ doc.moveto x: 4.28, y: 22.95
144
+ doc.show boleto.valor_documento.to_currency, tag: :menor
145
+ end
146
+
147
+ # Monta Recibo do Pagador boleto
148
+ def modelo_generico_cabecalho(doc, boleto)
149
+ monta_logotipo(doc, boleto, 0.782, 19.717, 0.85)
150
+ doc.moveto x: 4.813, y: 19.801
151
+ doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :medio
152
+ doc.moveto x: 0.823, y: 20.942
153
+ doc.show boleto.codigo_barras.linha_digitavel, tag: :menor_bold
154
+ doc.moveto x: 1.121, y: 18.924
155
+ doc.show truncar(boleto.cedente, 47), tag: :menor
156
+ doc.moveto x: 9.9, y: 18.924
157
+ doc.show boleto.agencia_conta_boleto.tr(' ', ''), tag: :menor
158
+ doc.moveto x: 16.423, y: 18.924
159
+ doc.show boleto.nosso_numero_boleto, tag: :menor
160
+ doc.moveto x: 1.121, y: 17.984
161
+ doc.show boleto.documento_numero, tag: :menor
162
+ doc.moveto x: 14.139, y: 18.924
163
+ doc.show boleto.quantidade, tag: :menor
164
+ doc.moveto x: 7.0, y: 17.984
165
+ doc.show boleto.documento_cedente.formata_documento.to_s, tag: :menor
166
+ doc.moveto x: 10.602, y: 17.984
167
+ doc.show boleto.data_vencimento.to_s_br, tag: :menor
168
+ doc.text_area "<menor>#{boleto.valor_documento.to_currency}</menor>", width: 5.78, text_align: :right,
169
+ x: 14.12, y: 17.984, tag: :menor
170
+ doc.moveto x: 1.109, y: 17.089
171
+ doc.show truncar(boleto.sacado, 109), tag: :menor
172
+ end
173
+
174
+ # Monta o corpo e rodapé do layout do boleto
175
+ def modelo_generico_rodape(doc, boleto)
176
+ monta_logotipo(doc, boleto, 0.782, 13.9, 0.85)
177
+ doc.text_area "<menor_bold>#{boleto.data_vencimento&.to_s_br}</menor_bold>",
178
+ width: 5.786, text_align: :center, x: 14.47271, y: 13.11587
179
+ doc.text_area "<menor>#{boleto.agencia_conta_boleto}</menor>", width: 5.786, text_align: :center, x: 14.47271,
180
+ y: 12.26921
181
+ doc.text_area "<menor>#{boleto.nosso_numero_boleto}</menor>", width: 5.786, text_align: :center, x: 14.47271,
182
+ y: 11.42254
183
+ doc.text_area "<menor_bold>#{boleto.valor_documento.to_currency}</menor_bold>", width: 5.5, text_align: :right,
184
+ x: 14.47271, y: 10.56926
185
+ doc.moveto x: 4.813, y: 13.977
186
+ doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :medio
187
+ doc.moveto x: 6.815, y: 13.990
188
+ doc.show boleto.codigo_barras.linha_digitavel, tag: :maior
189
+ doc.moveto x: 1.121, y: 13.2
190
+ doc.show boleto.local_pagamento, tag: :menor
191
+ doc.moveto x: 1.121, y: 12.295
192
+ doc.show truncar(boleto.cedente, 54), tag: :menor
193
+ doc.moveto x: 11.307, y: 12.295
194
+ doc.show boleto.documento_cedente.formata_documento.to_s, tag: :menor
195
+ doc.moveto x: 1.112, y: 11.42
196
+ doc.show boleto.data_documento&.to_s_br, tag: :menor
197
+ doc.moveto x: 4.268, y: 11.42
198
+ doc.show boleto.documento_numero, tag: :menor
199
+ doc.moveto x: 7.471, y: 11.42
200
+ doc.show boleto.especie_documento, tag: :menor
201
+ doc.moveto x: 9.588, y: 11.42
202
+ doc.show boleto.aceite, tag: :menor
203
+ doc.moveto x: 11.660, y: 11.42
204
+ doc.show boleto.data_processamento&.to_s_br, tag: :menor
205
+ doc.moveto x: 4.62056, y: 10.56058
206
+ if boleto.variacao
207
+ doc.show "#{boleto.carteira}-#{boleto.variacao}"
208
+ else
209
+ doc.show boleto.carteira
144
210
  end
145
-
146
- # Monta Recibo do Pagador boleto
147
- def modelo_generico_cabecalho(doc, boleto)
148
- monta_logotipo(doc, boleto, 0.782, 19.717, 0.85)
149
- doc.moveto x: 4.813, y: 19.801
150
- doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :medio
151
- doc.moveto x: 0.823, y: 20.942
152
- doc.show boleto.codigo_barras.linha_digitavel, tag: :menor_bold
153
- doc.moveto x: 1.121, y: 18.924
154
- doc.show truncar(boleto.cedente, 47), tag: :menor
155
- doc.moveto x: 9.9, y: 18.924
156
- doc.show boleto.agencia_conta_boleto.tr(' ', ''), tag: :menor
157
- doc.moveto x: 16.423, y: 18.924
158
- doc.show boleto.nosso_numero_boleto, tag: :menor
159
- doc.moveto x: 1.121, y: 17.984
160
- doc.show boleto.documento_numero, tag: :menor
161
- doc.moveto x: 14.139, y: 18.924
162
- doc.show boleto.quantidade, tag: :menor
163
- doc.moveto x: 7.0, y: 17.984
164
- doc.show boleto.documento_cedente.formata_documento.to_s, tag: :menor
165
- doc.moveto x: 10.602, y: 17.984
166
- doc.show boleto.data_vencimento.to_s_br, tag: :menor
167
- doc.text_area "<menor>#{boleto.valor_documento.to_currency}</menor>", width: 5.78, text_align: :right, x: 14.12, y: 17.984, tag: :menor
168
- doc.moveto x: 1.109, y: 17.089
169
- doc.show truncar(boleto.sacado, 109), tag: :menor
211
+ doc.moveto x: 7.26640, y: 10.56058
212
+ doc.show boleto.especie
213
+ monta_instrucoes(doc, boleto, 0.8, 9.8)
214
+ pagador = "<menor>#{truncar(boleto.sacado, 75)} - CPF/CNPJ: #{boleto.sacado_documento.formata_documento}</menor>"
215
+ pagador += "\n<menor>#{boleto.sacado_endereco}</menor>" if boleto.sacado_endereco
216
+ doc.text_area pagador, width: 18, text_align: :left, x: 2.04611, y: 5.8, row_height: '0.4 cm'
217
+ if boleto.avalista && boleto.avalista_documento
218
+ avalista = "#{truncar(boleto.avalista,
219
+ 46)} - CPF/CNPJ: #{boleto.avalista_documento.formata_documento}"
170
220
  end
171
-
172
- # Monta o corpo e rodapé do layout do boleto
173
- def modelo_generico_rodape(doc, boleto)
174
- monta_logotipo(doc, boleto, 0.782, 13.9, 0.85)
175
- doc.text_area "<menor_bold>#{boleto.data_vencimento.to_s_br if boleto.data_vencimento}</menor_bold>", width: 5.786, text_align: :center, x: 14.47271, y: 13.11587
176
- doc.text_area "<menor>#{boleto.agencia_conta_boleto}</menor>", width: 5.786, text_align: :center, x: 14.47271, y: 12.26921
177
- doc.text_area "<menor>#{boleto.nosso_numero_boleto}</menor>", width: 5.786, text_align: :center, x: 14.47271, y: 11.42254
178
- doc.text_area "<menor_bold>#{boleto.valor_documento.to_currency}</menor_bold>", width: 5.5, text_align: :right, x: 14.47271, y: 10.56926
179
- doc.moveto x: 4.813, y: 13.977
180
- doc.show "#{boleto.banco}-#{boleto.banco_dv}", tag: :medio
181
- doc.moveto x: 6.815, y: 13.990
182
- doc.show boleto.codigo_barras.linha_digitavel, tag: :maior
183
- doc.moveto x: 1.121, y: 13.2
184
- doc.show boleto.local_pagamento, tag: :menor
185
- doc.moveto x: 1.121, y: 12.295
186
- doc.show truncar(boleto.cedente,54), tag: :menor
187
- doc.moveto x: 11.307, y: 12.295
188
- doc.show boleto.documento_cedente.formata_documento.to_s, tag: :menor
189
- doc.moveto x: 1.112, y: 11.42
190
- doc.show (boleto.data_documento.to_s_br if boleto.data_documento), tag: :menor
191
- doc.moveto x: 4.268, y: 11.42
192
- doc.show boleto.documento_numero, tag: :menor
193
- doc.moveto x: 7.471, y: 11.42
194
- doc.show boleto.especie_documento, tag: :menor
195
- doc.moveto x: 9.588, y: 11.42
196
- doc.show boleto.aceite, tag: :menor
197
- doc.moveto x: 11.660, y: 11.42
198
- doc.show (boleto.data_processamento.to_s_br if boleto.data_processamento), tag: :menor
199
- doc.moveto x: 4.62056, y: 10.56058
200
- if boleto.variacao
201
- doc.show "#{boleto.carteira}-#{boleto.variacao}"
202
- else
203
- doc.show boleto.carteira
204
- end
205
- doc.moveto x: 7.26640, y: 10.56058
206
- doc.show boleto.especie
207
- monta_instrucoes(doc, boleto, 0.8, 9.8)
208
- pagador = "<menor>#{truncar(boleto.sacado,75)} - CPF/CNPJ: #{boleto.sacado_documento.formata_documento}</menor>"
209
- pagador += "\n<menor>#{boleto.sacado_endereco.to_s}</menor>" if boleto.sacado_endereco
210
- doc.text_area pagador, width: 18, text_align: :left, x: 2.04611, y: 5.8, row_height: '0.4 cm'
211
- avalista = "#{truncar(boleto.avalista,46)} - CPF/CNPJ: #{boleto.avalista_documento.formata_documento.to_s}" if boleto.avalista && boleto.avalista_documento
212
- if avalista
213
- doc.text_area "<menor2>#{avalista}</menor2>", width: 12.312, text_align: :left, x: 2.04611, y: 4.3, row_height: '0.4 cm'
214
- end
215
- # Gerando codigo de barra com rghost_barcode
216
- if boleto.codigo_barras
217
- doc.barcode_interleaved2of5(boleto.codigo_barras, width: '10.3 cm', height: '1.3 cm', x: 1.06, y: 2.12)
218
- end
219
- # FIM Segunda parte do BOLETO
221
+ if avalista
222
+ doc.text_area "<menor2>#{avalista}</menor2>", width: 12.312, text_align: :left, x: 2.04611, y: 4.3,
223
+ row_height: '0.4 cm'
220
224
  end
225
+ # Gerando codigo de barra com rghost_barcode
226
+ return unless boleto.codigo_barras
221
227
 
222
- def truncar(string, limite)
223
- if string.length > limite
224
- string = string[0...limite].upcase + "..."
225
- end
226
- string
227
- end
228
+ doc.barcode_interleaved2of5(boleto.codigo_barras, width: '10.3 cm', height: '1.3 cm', x: 1.06, y: 2.12)
228
229
 
229
- def monta_instrucoes(doc, boleto, x, y)
230
- lista_instrucoes = Array[
231
- boleto.instrucoes,
232
- boleto.instrucao1,
233
- boleto.instrucao2,
234
- boleto.instrucao3,
235
- boleto.instrucao4,
236
- boleto.instrucao5,
237
- boleto.instrucao6,
238
- ].reject(&:blank?)
239
- lista_instrucoes = lista_instrucoes.map { |i| "<menor>#{i}</menor>" }
240
- texto_instrucoes = lista_instrucoes.join("\n")
241
- doc.text_area texto_instrucoes, width: 13.547, text_align: :left, x: x, y: y, row_height: '0.4 cm'
242
- end
230
+ # FIM Segunda parte do BOLETO
231
+ end
232
+
233
+ def truncar(string, limite)
234
+ string = "#{string[0...limite].upcase}..." if string.length > limite
235
+ string
236
+ end
237
+
238
+ def monta_instrucoes(doc, boleto, x, y)
239
+ lista_instrucoes = [
240
+ boleto.instrucoes,
241
+ boleto.instrucao1,
242
+ boleto.instrucao2,
243
+ boleto.instrucao3,
244
+ boleto.instrucao4,
245
+ boleto.instrucao5,
246
+ boleto.instrucao6
247
+ ].reject(&:blank?)
248
+ lista_instrucoes = lista_instrucoes.map { |i| "<menor>#{i}</menor>" }
249
+ texto_instrucoes = lista_instrucoes.join("\n")
250
+ doc.text_area texto_instrucoes, width: 13.547, text_align: :left, x: x, y: y, row_height: '0.4 cm'
251
+ end
243
252
 
244
- def monta_logotipo(doc, boleto, x, y, scale)
245
- doc.graphic do |g|
246
- g.scale(scale, scale)
247
- fator = 1/scale
248
- g.image boleto.logotipo, x: (x*fator), y: (y*fator)
249
- end
253
+ def monta_logotipo(doc, boleto, x, y, scale)
254
+ doc.graphic do |g|
255
+ g.scale(scale, scale)
256
+ fator = 1 / scale
257
+ g.image boleto.logotipo, x: (x * fator), y: (y * fator)
250
258
  end
251
259
  end
252
260
  end
253
261
  end
254
262
  end
255
-
263
+ end
@@ -88,8 +88,8 @@ module Brcobranca
88
88
  end
89
89
 
90
90
  # Gerando stream
91
- formato = (options.delete(:formato) || Brcobranca.configuration.formato)
92
- resolucao = (options.delete(:resolucao) || Brcobranca.configuration.resolucao)
91
+ formato = options.delete(:formato) || Brcobranca.configuration.formato
92
+ resolucao = options.delete(:resolucao) || Brcobranca.configuration.resolucao
93
93
  doc.render_stream(formato.to_sym, resolution: resolucao)
94
94
  end
95
95
 
@@ -82,8 +82,8 @@ module Brcobranca
82
82
  modelo_carne_build_data_right(doc, boleto, colunas, linhas)
83
83
 
84
84
  # Gerando stream
85
- formato = (options.delete(:formato) || Brcobranca.configuration.formato)
86
- resolucao = (options.delete(:resolucao) || Brcobranca.configuration.resolucao)
85
+ formato = options.delete(:formato) || Brcobranca.configuration.formato
86
+ resolucao = options.delete(:resolucao) || Brcobranca.configuration.resolucao
87
87
  doc.render_stream(formato.to_sym, resolution: resolucao)
88
88
  end
89
89
 
@@ -126,8 +126,8 @@ module Brcobranca
126
126
  end
127
127
 
128
128
  # Gerando stream
129
- formato = (options.delete(:formato) || Brcobranca.configuration.formato)
130
- resolucao = (options.delete(:resolucao) || Brcobranca.configuration.resolucao)
129
+ formato = options.delete(:formato) || Brcobranca.configuration.formato
130
+ resolucao = options.delete(:resolucao) || Brcobranca.configuration.resolucao
131
131
 
132
132
  doc.render_stream(formato.to_sym, resolution: resolucao)
133
133
  end
@@ -308,10 +308,10 @@ module Brcobranca
308
308
 
309
309
  # codigo de barras
310
310
  # Gerando codigo de barra com rghost_barcode
311
- if boleto.codigo_barras
312
- doc.barcode_interleaved2of5(boleto.codigo_barras, width: '10.3 cm', height: '1.2 cm', x: colunas[2],
313
- y: linhas[14])
314
- end
311
+ return unless boleto.codigo_barras
312
+
313
+ doc.barcode_interleaved2of5(boleto.codigo_barras, width: '10.3 cm', height: '1.2 cm', x: colunas[2],
314
+ y: linhas[14])
315
315
  end
316
316
  end
317
317
  end
@@ -81,20 +81,20 @@ module Brcobranca
81
81
  # @example
82
82
  # "00192376900000135000000001238798777770016818".linha_digitavel #=> "00190.00009 01238.798779 77700.168188 2 37690000013500"
83
83
  def linha_digitavel
84
- if self =~ /^(\d{4})(\d{1})(\d{14})(\d{5})(\d{10})(\d{10})$/
85
- linha = Regexp.last_match[1]
86
- linha << Regexp.last_match[4]
87
- linha << linha.modulo10.to_s
88
- linha << Regexp.last_match[5]
89
- linha << Regexp.last_match[5].modulo10.to_s
90
- linha << Regexp.last_match[6]
91
- linha << Regexp.last_match[6].modulo10.to_s
92
- linha << Regexp.last_match[2]
93
- linha << Regexp.last_match[3]
94
- linha.gsub(/^(.{5})(.{5})(.{5})(.{6})(.{5})(.{6})(.{1})(.{14})$/, '\1.\2 \3.\4 \5.\6 \7 \8')
95
- else
84
+ unless self =~ /^(\d{4})(\d{1})(\d{14})(\d{5})(\d{10})(\d{10})$/
96
85
  raise ArgumentError, "#{self} Precisa conter 44 caracteres numéricos."
97
86
  end
87
+
88
+ linha = Regexp.last_match[1]
89
+ linha << Regexp.last_match[4]
90
+ linha << linha.modulo10.to_s
91
+ linha << Regexp.last_match[5]
92
+ linha << Regexp.last_match[5].modulo10.to_s
93
+ linha << Regexp.last_match[6]
94
+ linha << Regexp.last_match[6].modulo10.to_s
95
+ linha << Regexp.last_match[2]
96
+ linha << Regexp.last_match[3]
97
+ linha.gsub(/^(.{5})(.{5})(.{5})(.{6})(.{5})(.{6})(.{1})(.{14})$/, '\1.\2 \3.\4 \5.\6 \7 \8')
98
98
  end
99
99
  end
100
100
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'active_support/core_ext/object/blank'
4
3
  module Brcobranca
5
4
  module Remessa
6
5
  class Base
@@ -50,7 +49,7 @@ module Brcobranca
50
49
  def initialize(campos = {})
51
50
  campos = { aceite: 'N' }.merge!(campos)
52
51
  campos.each do |campo, valor|
53
- send "#{campo}=", valor
52
+ send :"#{campo}=", valor
54
53
  end
55
54
 
56
55
  yield self if block_given?
@@ -127,12 +127,14 @@ module Brcobranca
127
127
  total_cobranca_caucionada = ''.rjust(23, '0')
128
128
  total_cobranca_descontada = ''.rjust(23, '0')
129
129
 
130
- "#{total_cobranca_simples}#{total_cobranca_vinculada}#{total_cobranca_caucionada}"\
130
+ "#{total_cobranca_simples}#{total_cobranca_vinculada}#{total_cobranca_caucionada}" \
131
131
  "#{total_cobranca_descontada}".ljust(217, ' ')
132
132
  end
133
133
 
134
134
  def total_segmentos(pagamentos)
135
- pagamentos.inject(0) { |total, pagamento| total += pagamento.codigo_multa == '0' ? 2 : 3 }
135
+ pagamentos.inject(0) do |total, pagamento|
136
+ total + (pagamento.codigo_multa == '0' ? 2 : 3)
137
+ end
136
138
  end
137
139
 
138
140
  def monta_segmento_r(pagamento, nro_lote, contador)
@@ -330,7 +330,7 @@ module Brcobranca
330
330
 
331
331
  seg_r = monta_segmento_r(pagamento, nro_lote, contador)
332
332
 
333
- if seg_r.present?
333
+ unless seg_r.blank?
334
334
  lote << seg_r
335
335
  contador += 1
336
336
  end