Class: Cnab240::TransferenciaCitibank

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

Returns a new instance of TransferenciaCitibank.



3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/cnab240/helper/transferencia_citibank.rb', line 3

def initialize(campos = {})
  campos[:controle_banco] ||= '745'
  campos[:banco_nome] ||= 'BANCO CITIBANK 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('V60')

  fill campos, arquivo.header, arquivo.trailer
end

Instance Method Details

#<<(campos) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/cnab240/helper/transferencia_citibank.rb', line 26

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

  campos[:controle_banco] ||= '745'
  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'
  # [018] TED (STR,CIP) ou [700] DOC.
  campos[:favorecido_camara] = favorecido_camara(lote, campos)

  segmento_a = Cnab240::V60::SegmentoA.new
  fill campos, segmento_a
  lote << segmento_a

  campos[:controle_lote] = @arquivo.lotes.length.to_s
  campos[:servico_numero_registro] = (lote.segmentos.length + 1).to_s
  campos[:pagamento_data_vencimento] ||= (Time.respond_to?(:current) ? Time.current : Time.now).strftime('%d%m%Y')

  segmento_b = Cnab240::V60::SegmentoB.new
  fill campos, segmento_b
  lote << segmento_b
end

#add_lote(campos = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/cnab240/helper/transferencia_citibank.rb', line 16

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

  campos[:controle_banco] ||= '745'
  campos[:servico_operacao] ||= 'C'
  campos[:controle_lote] = (@arquivo.lotes.length).to_s

  fill campos, lote.header, lote.trailer
end

#favorecido_camara(lote, campos) ⇒ Object

018

TED (STR,CIP) ou [700] DOC (COMPE)



52
53
54
# File 'lib/cnab240/helper/transferencia_citibank.rb', line 52

def favorecido_camara(lote, campos)
  lote.header[:servico_forma] == '01' ? '000' : (campos[:credito_valor_pagamento].to_i < 749) ? '700' : '018'
end