Class: Cnab240::PagamentoBb

Inherits:
Helper
  • Object
show all
Defined in:
lib/cnab240/helper/pagamento_bb.rb

Instance Attribute Summary

Attributes inherited from Helper

#arquivo

Instance Method Summary collapse

Methods inherited from Helper

#save_to_file, #string

Methods included from Filler

#fill, #fill!

Constructor Details

#initialize(campos = {}) ⇒ PagamentoBb

Returns a new instance of PagamentoBb.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cnab240/helper/pagamento_bb.rb', line 3

def initialize(campos = {})
  campos[:controle_banco] ||= '001'
  campos[:banco_nome] ||= 'BANCO DO BRASIL S.A.'
  campos[:empresa_tipo] ||= '2'
  campos[:arquivo_data_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')
  campos[:arquivo_hora_geracao] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%H%M%S')
  campos[:arquivo_codigo] ||= '1'

  @arquivo = Cnab240::Arquivo::Arquivo.new('V86')
  @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V86')

  fill campos, arquivo.header, arquivo.trailer

  campos[:servico_operacao] ||= 'C'
  campos[:controle_lote] ||= '0001'

  fill campos, lote.header, lote.trailer
end

Instance Method Details

#<<(campos) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cnab240/helper/pagamento_bb.rb', line 31

def <<(campos)
  lote = @arquivo.lotes.last

  campos[:controle_banco] ||= '001'
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
  campos[:servico_numero_registro] ||= (lote.segmentos.length + 1).to_s
  # 000 para inclusao e 999 para exclusao
  campos[:servico_tipo_movimento] ||= '000'
  campos[:credito_moeda_tipo] ||= 'BRL'
  campos[:totais_qtde_registros] ||= (lote.segmentos.length + 2).to_s

  segmento_a = Cnab240::V86::SegmentoA.new
  fill campos, segmento_a
  # fill campos, segmento_a.favorecido_agencia_conta

  lote << segmento_a
end

#add_lote(campos = {}) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/cnab240/helper/pagamento_bb.rb', line 22

def add_lote(campos = {})
  @arquivo.lotes << lote = Cnab240::Lote.new(operacao: :pagamento, tipo: :remessa, versao: 'V86')

  campos[:servico_operacao] ||= 'C'
  campos[:controle_lote] ||= '0001'

  fill campos, lote.header
end