Module: BrBoleto::Remessa::Cnab240::Helper::SegmentoP

Included in:
Base
Defined in:
lib/br_boleto/remessa/cnab240/helper/segmento_p.rb

Instance Method Summary collapse

Instance Method Details

#monta_segmento_p(pagamento, nr_lote, sequencial) ⇒ String

Monta o registro segmento P do arquivo



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 18

def monta_segmento_p(pagamento, nr_lote, sequencial)
  # campos com * na frente nao foram implementados
  #                                                      # DESCRICAO                             TAMANHO
  segmento_p =  ''
  segmento_p <<  segmento_p_posicao_001_a_003             # codigo banco                          3
  segmento_p << segmento_p_posicao_004_a_007(nr_lote)    # lote de servico                       4
  segmento_p << segmento_p_posicao_008_a_008             # tipo de registro                      1
  segmento_p << segmento_p_posicao_009_a_013(sequencial) # num. sequencial do registro no lote   5
  segmento_p << segmento_p_posicao_014_a_014             # cod. segmento                         1
  segmento_p << segmento_p_posicao_015_a_015             # uso exclusivo                         1
  segmento_p << segmento_p_posicao_016_a_017(pagamento)  # cod. movimento remessa                2
  segmento_p << segmento_p_posicao_018_a_022             # agencia                               5
  segmento_p << segmento_p_posicao_023_a_023             # dv agencia                            1
  segmento_p << segmento_p_posicao_024_a_057(pagamento)  # informacoes da conta                  34
  segmento_p << segmento_p_posicao_058_a_058             # codigo da carteira                    1
  segmento_p << segmento_p_posicao_059_a_059(pagamento)  # forma de cadastro do titulo           1
  segmento_p << segmento_p_posicao_060_a_060             # tipo de documento                     1
  segmento_p << segmento_p_posicao_061_a_061(pagamento)  # identificaco emissao                  1
  segmento_p << segmento_p_posicao_062_a_062(pagamento)  # indentificacao entrega                1
  segmento_p << segmento_p_posicao_063_a_077(pagamento)  # numro do documento                    15
  segmento_p << segmento_p_posicao_078_a_085(pagamento)  # data de venc.                         8
  segmento_p << segmento_p_posicao_086_a_100(pagamento)  # valor documento                       15
  segmento_p << segmento_p_posicao_101_a_105             # agencia cobradora                     5
  segmento_p << segmento_p_posicao_106_a_106             # dv agencia cobradora                  1
  segmento_p << segmento_p_posicao_107_a_108(pagamento)  # especie do titulo                     2
  segmento_p << segmento_p_posicao_109_a_109(pagamento)  # aceite                                1
  segmento_p << segmento_p_posicao_110_a_117(pagamento)  # data de emissao titulo                8
  segmento_p << segmento_p_posicao_118_a_118(pagamento)  # cod. do juros                         1   *
  segmento_p << segmento_p_posicao_119_a_126(pagamento)  # data juros                            8   *
  segmento_p << segmento_p_posicao_127_a_141(pagamento)  # valor juros                           15  *
  segmento_p << segmento_p_posicao_142_a_142(pagamento)  # cod. do desconto                      1
  segmento_p << segmento_p_posicao_143_a_150(pagamento)  # data desconto                         8
  segmento_p << segmento_p_posicao_151_a_165(pagamento)  # valor desconto                        15
  segmento_p << segmento_p_posicao_166_a_180(pagamento)  # valor IOF                             15
  segmento_p << segmento_p_posicao_181_a_195(pagamento)  # valor abatimento                      15
  segmento_p << segmento_p_posicao_196_a_220(pagamento)  # identificacao titulo empresa          25  *
  segmento_p << segmento_p_posicao_221_a_221(pagamento)  # cod. para protesto                    1   *
  segmento_p << segmento_p_posicao_222_a_223(pagamento)  # dias para protesto                    2   *
  segmento_p << segmento_p_posicao_224_a_224             # cod. para baixa                       1   *
  segmento_p << segmento_p_posicao_225_a_227             # dias para baixa                       2   *
  segmento_p << segmento_p_posicao_228_a_229(pagamento)  # cod. da moeda                         2
  segmento_p << segmento_p_posicao_230_a_239             # uso exclusivo                         10
  segmento_p << segmento_p_posicao_240_a_240             # uso exclusivo                         1
  segmento_p.upcase
end

#segmento_p_posicao_001_a_003Object



64
65
66
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 64

def segmento_p_posicao_001_a_003 
  conta.codigo_banco
end

#segmento_p_posicao_004_a_007(numero_do_lote) ⇒ Object

Lote de Serviço: Número seqüencial para identificar univocamente um lote de serviço. Criado e controlado pelo responsável pela geração magnética dos dados contidos no arquivo. Preencher com ‘0001’ para o primeiro lote do arquivo. Para os demais: número do lote anterior acrescido de 1. O número não poderá ser repetido dentro do arquivo. 4 posições



74
75
76
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 74

def segmento_p_posicao_004_a_007(numero_do_lote)
  numero_do_lote.to_s.rjust(4, '0')
end

#segmento_p_posicao_008_a_008Object

Tipo do registro -> Padrão 3 1 posição



81
82
83
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 81

def segmento_p_posicao_008_a_008
  '3'
end

#segmento_p_posicao_009_a_013(sequencial) ⇒ Object

Nº Sequencial do Registro no Lote: Número adotado e controlado pelo responsável pela geração magnética dos dados contidos no arquivo, para identificar a seqüência de registros encaminhados no lote. Deve ser inicializado sempre em ‘1’, em cada novo lote. 5 posições



91
92
93
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 91

def segmento_p_posicao_009_a_013(sequencial)
  sequencial.to_s.rjust(5, '0')
end

#segmento_p_posicao_014_a_014Object

Cód. Segmento do Registro - Default: “P” 1 posição



98
99
100
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 98

def segmento_p_posicao_014_a_014
  "P"
end

#segmento_p_posicao_015_a_015Object

Uso Exclusivo FEBRABAN/CNAB 1 posição



105
106
107
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 105

def segmento_p_posicao_015_a_015
  ' '
end

#segmento_p_posicao_016_a_017(pagamento) ⇒ Object

cod. movimento remessa -> Padrão 01 = Entrada de Titulos 2 posições



112
113
114
115
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 112

def segmento_p_posicao_016_a_017(pagamento)
  code = "#{pagamento.identificacao_ocorrencia}".rjust(2, '0')
  "#{conta.get_codigo_movimento_remessa(code, 240)}".adjust_size_to(2, '0')
end

#segmento_p_posicao_018_a_022Object

Agência Mantenedora da Conta 5 posições



120
121
122
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 120

def segmento_p_posicao_018_a_022
  "#{conta.agencia}".adjust_size_to(5, '0', :right)
end

#segmento_p_posicao_023_a_023Object

Dígito Verificador da Agência 1 posição



127
128
129
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 127

def segmento_p_posicao_023_a_023
  "#{conta.agencia_dv}".adjust_size_to(1, '0')
end

#segmento_p_posicao_024_a_057(pagamento) ⇒ Object

O padrão da FEBRABAN é:

Posi

Mas cada banco tem seu padrão 34 posições



139
140
141
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 139

def segmento_p_posicao_024_a_057(pagamento)
  complemento_p(pagamento)
end

#segmento_p_posicao_058_a_058Object

Código da carteira ou tipo de cobrança 1 posição



146
147
148
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 146

def segmento_p_posicao_058_a_058
  "#{conta.get_tipo_cobranca(conta.codigo_carteira, 240)}".adjust_size_to(1, '1')
end

#segmento_p_posicao_059_a_059(pagamento) ⇒ Object

Forma de Cadastr. do Título no Banco 1 posição



153
154
155
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 153

def segmento_p_posicao_059_a_059(pagamento)
  "#{pagamento.forma_cadastramento}".adjust_size_to(1,'1')
end

#segmento_p_posicao_060_a_060Object

Tipo de Documento 1 posição



160
161
162
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 160

def segmento_p_posicao_060_a_060
  '2'
end

#segmento_p_posicao_061_a_061(pagamento) ⇒ Object

Identificação da Emissão do Bloqueto 1 posição



167
168
169
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 167

def segmento_p_posicao_061_a_061(pagamento)
  "#{conta.get_identificacao_emissao(pagamento.emissao_boleto, 240)}".adjust_size_to(1, '2')
end

#segmento_p_posicao_062_a_062(pagamento) ⇒ Object

Identificação da Distribuição 1 posição



174
175
176
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 174

def segmento_p_posicao_062_a_062(pagamento)
  "#{conta.get_distribuicao_boleto(pagamento.distribuicao_boleto)}".adjust_size_to(1, '2')
end

#segmento_p_posicao_063_a_077(pagamento) ⇒ Object

Número do Documento de Cobrança Cada banco tem seu padrão 15 Posições



182
183
184
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 182

def segmento_p_posicao_063_a_077(pagamento)
  segmento_p_numero_do_documento(pagamento)
end

#segmento_p_posicao_078_a_085(pagamento) ⇒ Object

Data de Vencimento do Título 8 posições



189
190
191
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 189

def segmento_p_posicao_078_a_085(pagamento)
  pagamento.data_vencimento_formatado('%d%m%Y')
end

#segmento_p_posicao_086_a_100(pagamento) ⇒ Object

Valor Nominal do Título 15 posições (13 posições para valor inteiro e 2 posições para valor quebrado)



196
197
198
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 196

def segmento_p_posicao_086_a_100(pagamento)
  pagamento.valor_documento_formatado(15)
end

#segmento_p_posicao_101_a_105Object

Agencia cobradora 5 posições



203
204
205
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 203

def segmento_p_posicao_101_a_105
  ''.rjust(5, '0')
end

#segmento_p_posicao_106_a_106Object

Dígito Verificador da Agência cobradora 1 posição



210
211
212
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 210

def segmento_p_posicao_106_a_106
  ' '
end

#segmento_p_posicao_107_a_108(pagamento) ⇒ Object

Espécie do Título 2 posições



217
218
219
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 217

def segmento_p_posicao_107_a_108(pagamento)
  "#{conta.get_especie_titulo(pagamento.especie_titulo, 240)}".adjust_size_to(2, '0', :right)
end

#segmento_p_posicao_109_a_109(pagamento) ⇒ Object

Identific. de Título Aceito/Não Aceito (A ou N) 1 posição



224
225
226
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 224

def segmento_p_posicao_109_a_109(pagamento)
  pagamento.aceite ? 'A' : 'N'
end

#segmento_p_posicao_110_a_117(pagamento) ⇒ Object

Data da Emissão do Título 8 posições



231
232
233
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 231

def segmento_p_posicao_110_a_117(pagamento)
  pagamento.data_emissao_formatado('%d%m%Y')
end

#segmento_p_posicao_118_a_118(pagamento) ⇒ Object

Código do Juros de Mora 1 posição Padrão FEBRABAN = (1 = Valor fixo e 2 = Percentual, 3 = isento)



239
240
241
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 239

def segmento_p_posicao_118_a_118(pagamento) 
  "#{conta.get_codigo_juros(pagamento.codigo_juros)}".adjust_size_to(1, '3')
end

#segmento_p_posicao_119_a_126(pagamento) ⇒ Object

Data do Juros de Mora 8 posições



246
247
248
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 246

def segmento_p_posicao_119_a_126(pagamento)
  "#{pagamento.data_juros_formatado('%d%m%Y')}".adjust_size_to(8, '0')
end

#segmento_p_posicao_127_a_141(pagamento) ⇒ Object

Juros de Mora por Dia/Taxa 15 posições



253
254
255
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 253

def segmento_p_posicao_127_a_141(pagamento)
  pagamento.valor_juros_formatado(15)
end

#segmento_p_posicao_142_a_142(pagamento) ⇒ Object

Código do Desconto 1 1 posição



260
261
262
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 260

def segmento_p_posicao_142_a_142(pagamento)
  "#{conta.get_codigo_desconto(pagamento.cod_desconto)}".adjust_size_to(1, '0')
end

#segmento_p_posicao_143_a_150(pagamento) ⇒ Object

Data do Desconto 1 8 posições



267
268
269
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 267

def segmento_p_posicao_143_a_150(pagamento)
  pagamento.data_desconto_formatado('%d%m%Y')
end

#segmento_p_posicao_151_a_165(pagamento) ⇒ Object

Valor/Percentual a ser Concedido 15 posições



274
275
276
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 274

def segmento_p_posicao_151_a_165(pagamento)
  pagamento.valor_desconto_formatado(15)
end

#segmento_p_posicao_166_a_180(pagamento) ⇒ Object

Valor do IOF a ser Recolhido 15 posições



281
282
283
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 281

def segmento_p_posicao_166_a_180(pagamento)
  pagamento.valor_iof_formatado(15)
end

#segmento_p_posicao_181_a_195(pagamento) ⇒ Object

Valor do Abatimento 15 posições



288
289
290
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 288

def segmento_p_posicao_181_a_195(pagamento)
  pagamento.valor_abatimento_formatado(15)
end

#segmento_p_posicao_196_a_220(pagamento) ⇒ Object

Identificação do Título na Empresa 25 posições



295
296
297
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 295

def segmento_p_posicao_196_a_220(pagamento)
  ''.rjust(25, ' ') 
end

#segmento_p_posicao_221_a_221(pagamento) ⇒ Object

Código para Protesto 1 posição



302
303
304
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 302

def segmento_p_posicao_221_a_221(pagamento)
  "#{conta.get_codigo_protesto(pagamento.codigo_protesto, 240)}".adjust_size_to(1, '1')
end

#segmento_p_posicao_222_a_223(pagamento) ⇒ Object

Número de Dias para Protesto Para os códigos ‘3’ = Não Protestar e ‘8’ = Negativação sem Protesto, setar dias de protesto ‘00’, caso contrário setar o valor de dias_protesto 2 posições



311
312
313
314
315
316
317
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 311

def segmento_p_posicao_222_a_223(pagamento)
  if  pagamento.codigo_protesto.to_i.in?([3, 8])
    '00' 
  else
    "#{pagamento.dias_protesto}".adjust_size_to(2, '0')
  end
end

#segmento_p_posicao_224_a_224Object

Código para Baixa/Devolução 1 posição



322
323
324
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 322

def segmento_p_posicao_224_a_224
  '0'  
end

#segmento_p_posicao_225_a_227Object

Número de Dias para Baixa/Devolução 3 posoções



329
330
331
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 329

def segmento_p_posicao_225_a_227
  '000'
end

#segmento_p_posicao_228_a_229(pagamento) ⇒ Object

Código da Moeda (09 para real) 2 posições



336
337
338
339
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 336

def segmento_p_posicao_228_a_229(pagamento)
  moeda = "#{pagamento.codigo_moeda}".rjust(2, '0')
  "#{conta.get_codigo_moeda(moeda, 240)}".adjust_size_to(2, '0')
end

#segmento_p_posicao_230_a_239Object

Nº do Contrato da Operação de Crédito (Uso do banco) 10 posições



344
345
346
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 344

def segmento_p_posicao_230_a_239
  ''.rjust(10, '0')
end

#segmento_p_posicao_240_a_240Object

Uso livre banco/empresa ou autorização de pagamento parcial 1 posição



351
352
353
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 351

def segmento_p_posicao_240_a_240
  ' '
end