Class: Cnab240::PagamentoItau

Inherits:
Helper
  • Object
show all
Defined in:
lib/cnab240/helper/pagamento_itau.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 = {}) ⇒ PagamentoItau

Returns a new instance of PagamentoItau.



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

def initialize(campos = {})
  campos[:controle_banco] ||= '341'
  campos[:arquivo_codigo] ||= '1'
  campos[:banco_nome] ||= 'BANCO ITAU'
  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')

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

  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



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

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

  campos[:controle_banco] ||= '341'
  campos[:controle_lote] ||= @arquivo.lotes.length.to_s
  campos[:servico_numero_registro] ||= (lote.segmentos.length + 1).to_s
  campos[:servico_tipo_movimento] ||= '000'
  campos[:credito_moeda_tipo] ||= 'REA'
  campos[:totais_qtde_registros] ||= (lote.segmentos.length + 2).to_s

  segmento_a = Cnab240::V80::SegmentoA.new
  fill campos, segmento_a
  fill campos, segmento_a.favorecido_agencia_conta

  lote << segmento_a
end

#add_lote(campos = {}) ⇒ Object



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

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

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

  fill campos, lote.header
end