Skip to content

Commit

Permalink
Calculando dígito da agência e conta corrente - Remessa CNAB240 Santa…
Browse files Browse the repository at this point in the history
…nder
  • Loading branch information
henriqueshiraishi committed Jan 11, 2024
1 parent b66929e commit 0b17b29
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 20 deletions.
14 changes: 9 additions & 5 deletions lib/brcobranca/remessa/cnab240/santander.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,12 @@ class Santander < Brcobranca::Remessa::Cnab240::Base

Check notice

Code scanning / Rubocop

Keeps track of empty lines around class bodies. Note

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body beginning.
# Código de Transmissão
attr_accessor :codigo_transmissao
# Dígito da Agência
attr_accessor :digito_agencia

validates_presence_of :codigo_transmissao, :digito_agencia, :digito_conta, message: 'não pode estar em branco.'
validates_presence_of :codigo_transmissao, message: 'não pode estar em branco.'

validates_length_of :codigo_transmissao, maximum: 15, message: 'deve ter no máximo 15 dígitos.'
validates_length_of :agencia, maximum: 4, message: 'deve ter 4 dígitos.'
validates_length_of :digito_agencia, maximum: 1, message: 'deve ter 1 dígito.'
validates_length_of :conta_corrente, maximum: 9, message: 'deve ter 9 dígitos.'
validates_length_of :digito_conta, maximum: 1, message: 'deve ter 1 dígito.'

def initialize(campos = {})
campos = { emissao_boleto: ' ', distribuicao_boleto: ' ',
Expand All @@ -28,6 +24,14 @@ def codigo_transmissao=(valor)
@codigo_transmissao = valor.to_s.strip.rjust(15, '0') if valor
end

def digito_agencia
agencia.modulo11(mapeamento: { 10 => 'X', 11 => 'X' }).to_s
end

def digito_conta
conta_corrente.modulo11(mapeamento: { 10 => 'X', 11 => 'X' }).to_s
end

def complemento_header
''.rjust(29, ' ')
end
Expand Down
15 changes: 1 addition & 14 deletions spec/brcobranca/remessa/cnab240/santander_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,8 @@
documento_cedente: '28254225000193',
codigo_transmissao: '000100001234567',
agencia: '0001',
digito_agencia: '3',
conta_corrente: '013001234',
digito_conta: '1',
digito_conta: '3',
sequencial_remessa: '1',
pagamentos: [pagamento] }
end
Expand All @@ -52,12 +51,6 @@
expect(santander.invalid?).to be true
expect(santander.errors.full_messages).to include('Agencia deve ter 4 dígitos.')
end

it 'deve ser invalido se o digito_agencia tiver mais de 1 digito' do
santander.digito_agencia = '12'
expect(santander.invalid?).to be true
expect(santander.errors.full_messages).to include('Digito agencia deve ter 1 dígito.')
end
end

context '@conta_corrente' do

Check notice

Code scanning / Rubocop

Checks that `context` docstring starts with an allowed prefix. Note test

RSpec/ContextWording: Context description should match /^when\b/, /^with\b/, or /^without\b/.
Expand All @@ -66,12 +59,6 @@
expect(santander.invalid?).to be true
expect(santander.errors.full_messages).to include('Conta corrente deve ter 9 dígitos.')
end

it 'deve ser invalido se o digito_conta tiver mais de 1 digito' do
santander.digito_conta = '12'
expect(santander.invalid?).to be true
expect(santander.errors.full_messages).to include('Digito conta deve ter 1 dígito.')
end
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/fixtures/remessa/remessa-santander-cnab240.rem
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
03300000 2028254225000193000100001234567 SOCIEDADE BRASILEIRA DE ZOOLOGBANCO SANTANDER 114072015 000001040
03300011R01 030 2028254225000193 000100001234567 SOCIEDADE BRASILEIRA DE ZOOLOG 000000011407201500000000
0330001300001P 010001301300123410130012341 0000012345679112 9999 1407201500000000001999000000 02N140720153000000000000000000000000000000000000000000000000000000000000000000000000000009999 300300000
0330001300001P 010001901300123430130012343 0000012345679112 9999 1407201500000000001999000000 02N140720153000000000000000000000000000000000000000000000000000000000000000000000000000009999 300300000
0330001300002Q 011000012345678901PABLO DIEGO JOSE FRANCISCO DE PAULA JUANRUA RIO GRANDE DO SUL SAO PAULO MINAS CASAO JOSE DOS QU12345678SANTA RITA DE CSP0000000000000000 000000000000
0330001300003R 01000000000000000000000000000000000000000000000000000000000000000000000000
03300015 000005
Expand Down

0 comments on commit 0b17b29

Please sign in to comment.