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



17
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
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 17

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             # 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             # cod. para protesto                    1   *
  segmento_p << segmento_p_posicao_222_a_223             # 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             # 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



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

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



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

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



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

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



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

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



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

def segmento_p_posicao_014_a_014
  "P"
end

#segmento_p_posicao_015_a_015Object

Uso Exclusivo FEBRABAN/CNAB 1 posição



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

def segmento_p_posicao_015_a_015
  ' '
end

#segmento_p_posicao_016_a_017Object

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



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

def segmento_p_posicao_016_a_017
  '01'
end

#segmento_p_posicao_018_a_022Object

Agência Mantenedora da Conta 5 posições



118
119
120
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 118

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



125
126
127
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 125

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



137
138
139
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 137

def segmento_p_posicao_024_a_057(pagamento)
  complemento_p(pagamento)
end

#segmento_p_posicao_058_a_058Object

Código da carteira 1 posição



144
145
146
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 144

def segmento_p_posicao_058_a_058
  conta.carteira
end

#segmento_p_posicao_059_a_059(pagamento) ⇒ Object

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



151
152
153
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 151

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



158
159
160
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 158

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



165
166
167
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 165

def segmento_p_posicao_061_a_061(pagamento)
  pagamento.emissao_boleto
end

#segmento_p_posicao_062_a_062(pagamento) ⇒ Object

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



172
173
174
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 172

def segmento_p_posicao_062_a_062(pagamento)
  pagamento.distribuicao_boleto
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



180
181
182
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 180

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



187
188
189
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 187

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)



194
195
196
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 194

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



201
202
203
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 201

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



208
209
210
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 208

def segmento_p_posicao_106_a_106
  ' '
end

#segmento_p_posicao_107_a_108(pagamento) ⇒ Object

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



215
216
217
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 215

def segmento_p_posicao_107_a_108(pagamento)
  "#{pagamento.especie_titulo}".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



222
223
224
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 222

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



229
230
231
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 229

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)



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

def segmento_p_posicao_118_a_118(pagamento) 
  cod = "#{pagamento.codigo_juros}".adjust_size_to(1, '3')
  cod.in?(['1','2','3']) ? cod : '3'
end

#segmento_p_posicao_119_a_126(pagamento) ⇒ Object

Data do Juros de Mora 8 posições



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

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



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

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



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

def segmento_p_posicao_142_a_142(pagamento)
  "#{pagamento.cod_desconto}".adjust_size_to(1)
end

#segmento_p_posicao_143_a_150(pagamento) ⇒ Object

Data do Desconto 1 8 posições



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

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



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

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



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

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



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

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



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

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

#segmento_p_posicao_221_a_221Object

Código para Protesto 1 posição



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

def segmento_p_posicao_221_a_221 
  '1'
end

#segmento_p_posicao_222_a_223Object

Número de Dias para Protesto 2 posições



308
309
310
# File 'lib/br_boleto/remessa/cnab240/helper/segmento_p.rb', line 308

def segmento_p_posicao_222_a_223
  '00' 
end

#segmento_p_posicao_224_a_224Object

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



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

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



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

def segmento_p_posicao_225_a_227
  '000'
end

#segmento_p_posicao_228_a_229Object

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



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

def segmento_p_posicao_228_a_229
  '09'
end

#segmento_p_posicao_230_a_239Object

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



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

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



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

def segmento_p_posicao_240_a_240
  ' '
end