Class: Cnab240::PagamentoItau

Inherits:
Object
  • Object
show all
Includes:
Filler
Defined in:
lib/cnab240/helper/pagamento_itau.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Filler

#fill, #fill!

Constructor Details

#initialize(campos = {}) ⇒ PagamentoItau

Returns a new instance of PagamentoItau.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cnab240/helper/pagamento_itau.rb', line 8

def initialize(campos = {})

	campos[:controle_banco] ||= '341'
	campos[:arquivo_codigo] ||= '1'
	campos[:banco_nome] ||= 'BANCO ITAU'
	campos[:arquivo_data_geracao] ||= Time.now.strftime("%d%m%Y") 
	campos[:arquivo_hora_geracao] ||= Time.now.strftime("%H%M") 

	@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 Attribute Details

#arquivoObject

Returns the value of attribute arquivo.



6
7
8
# File 'lib/cnab240/helper/pagamento_itau.rb', line 6

def arquivo
  @arquivo
end

Instance Method Details

#<<(campos) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/cnab240/helper/pagamento_itau.rb', line 37

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



28
29
30
31
32
33
34
35
# File 'lib/cnab240/helper/pagamento_itau.rb', line 28

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

#save_to_file(filename) ⇒ Object



58
59
60
# File 'lib/cnab240/helper/pagamento_itau.rb', line 58

def save_to_file(filename)
	arquivo.save_to_file(filename)
end

#stringObject



54
55
56
# File 'lib/cnab240/helper/pagamento_itau.rb', line 54

def string
	arquivo.string
end