Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adiciona Santander CNAB240 Remessa #254

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 19 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,32 @@ Criado pelo pessoal da [Akretion](http://www.akretion.com) muito TOP \o/

### Retornos e Remessas

| Banco | Retorno | Remessa |
| ----------------- | -------------- | --------------------- |
| Banco do Brasil | 400(ou CBR643) | 400 (ou CBR641) e 240 |
| Banco do Nordeste | 400 | 400 |
| Banco de Brasília | Não | 400 |
| Banestes | Sim | Não |
| Banrisul | 400 | 400 |
| Bradesco | 400 | 400 |
| Caixa | 240 | 240 |
| Citibank | Não | 400 |
| HSBC | Não | Não |
| Itaú | 400 | 400 |
| Santander | 240 | 400 |
| Sicoob | 240 | 400 e 240 |
| Sicredi | 240 | 240 |
| UNICRED | 400 | 400 e 240 |
| AILOS | 240 | 240 |
| CREDISIS | 400 | 400 |
| Banco | Retorno | Remessa |
| ----------------- | --------------- | --------------------- |
| Banco do Brasil | 400 (ou CBR643) | 400 (ou CBR641) e 240 |
| Banco do Nordeste | 400 | 400 |
| Banco de Brasília | 400 | 400 |
| Banestes | Não | Não |
| Banrisul | 400 | 400 |
| Bradesco | 400 | 400 |
| Caixa | 240 | 240 |
| Citibank | Não | 400 |
| HSBC | Não | Não |
| Itaú | 400 | 400 |
| Santander | 400 e 240 | 400 e 240 |
| Sicoob | 240 | 400 e 240 |
| Sicredi | 240 | 240 |
| UNICRED | 400 | 400 e 240 |
| AILOS | 240 | 240 |
| CREDISIS | 400 | 400 |

- Banco do Brasil (CNAB240) [Isabella](https://github.com/isabellaSantos) da [Zaez](http://www.zaez.net)
- Caixa Economica Federal (CNAB240) [Isabella](https://github.com/isabellaSantos) da [Zaez](http://www.zaez.net)
- Bradesco (CNAB400) [Isabella](https://github.com/isabellaSantos) da [Zaez](http://www.zaez.net)
- Itaú (CNAB400) [Isabella](https://github.com/isabellaSantos) da [Zaez](http://www.zaez.net)
- Citibank (CNAB400)
- Santander (CNAB400)
- Santander (CNAB240)

### Documentação

Expand Down
1 change: 1 addition & 0 deletions lib/brcobranca.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ module Cnab240
autoload :BaseCorrespondente, 'brcobranca/remessa/cnab240/base_correspondente'
autoload :Caixa, 'brcobranca/remessa/cnab240/caixa'
autoload :BancoBrasil, 'brcobranca/remessa/cnab240/banco_brasil'
autoload :Santander, 'brcobranca/remessa/cnab240/santander'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

autoload :Sicoob, 'brcobranca/remessa/cnab240/sicoob'
autoload :SicoobBancoBrasil, 'brcobranca/remessa/cnab240/sicoob_banco_brasil'
autoload :Sicredi, 'brcobranca/remessa/cnab240/sicredi'
Expand Down
226 changes: 226 additions & 0 deletions lib/brcobranca/remessa/cnab240/santander.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
# frozen_string_literal: true

module Brcobranca
module Remessa
module Cnab240
class Santander < Brcobranca::Remessa::Cnab240::Base

Check notice

Code scanning / Rubocop

Avoid classes longer than 100 lines of code. Note

Metrics/ClassLength: Class has too many lines. [185/100]

Check notice

Code scanning / Rubocop

Document classes and non-namespace modules. Note

Style/Documentation: Missing top-level documentation comment for class Brcobranca::Remessa::Cnab240::Santander.

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

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 :conta_corrente, maximum: 9, message: 'deve ter 9 dígitos.'

def initialize(campos = {})
campos = { emissao_boleto: ' ', distribuicao_boleto: ' ',
especie_titulo: '02', tipo_documento: '2' }.merge!(campos)
super(campos)
end

def codigo_transmissao=(valor)

Check warning

Code scanning / Rubocop

Check for duplicate method definitions. Warning

Lint/DuplicateMethods: Method Brcobranca::Remessa::Cnab240::Santander#codigo\_transmissao= is defined at both lib/brcobranca/remessa/cnab240/santander.rb:8 and lib/brcobranca/remessa/cnab240/santander.rb:23.
@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

def complemento_trailer
''.rjust(217, ' ')
end

def complemento_p(pagamento)
complemento_p = ''
complemento_p += conta_corrente.rjust(9, '0')
complemento_p << digito_conta.to_s
complemento_p << conta_corrente.rjust(9, '0')
complemento_p << digito_conta.to_s
complemento_p << ' '
complemento_p << identificador_titulo(pagamento.nosso_numero)
complemento_p
end

def complemento_r
''.rjust(61, ' ')
end

def versao_layout_arquivo
'040'
end

def versao_layout_lote
'030'
end

def convenio_lote
identificacao_conta = ''
identificacao_conta += ''.rjust(20, ' ')
identificacao_conta << codigo_transmissao
identificacao_conta << ''.rjust(5, ' ')
identificacao_conta
end

def nome_banco
'BANCO SANTANDER'.ljust(30, ' ')
end

def cod_banco
'033'
end

def info_conta
''
end

def codigo_convenio
identificacao_conta = ''
identificacao_conta += codigo_transmissao
identificacao_conta << ''.rjust(25, ' ')
identificacao_conta
end

def identificador_titulo(nosso_numero)
nosso_numero_dv = nosso_numero.modulo11(
multiplicador: (2..9).to_a,
mapeamento: { 10 => 0, 11 => 0 }
) { |total| 11 - (total % 11) }

"#{nosso_numero}#{nosso_numero_dv}".rjust(13, '0')
end

def formata_documento_ou_numero(pagamento, tamanho = 25, caracter = ' ')
doc = pagamento.documento_ou_numero.to_s.gsub(/[^0-9A-Za-z ]/, '')
doc.ljust(tamanho, caracter)[0...tamanho]
end

def densidade_gravacao
''.rjust(5, ' ')
end

def uso_exclusivo_banco
''.rjust(20, ' ')
end

def uso_exclusivo_empresa
''.rjust(20, ' ')
end

def hora_geracao
''.rjust(6, ' ')
end

def dv_agencia_cobradora
''.rjust(1, ' ')
end

def monta_header_arquivo

Check notice

Code scanning / Rubocop

A calculated magnitude based on number of assignments, branches, and conditions. Note

Metrics/AbcSize: Assignment Branch Condition size for monta_header_arquivo is too high. [<3, 44, 0> 44.1/17]

Check notice

Code scanning / Rubocop

Avoid methods longer than 10 lines of code. Note

Metrics/MethodLength: Method has too many lines. [22/10]
header_arquivo = '' # CAMPO TAMANHO
header_arquivo += cod_banco # codigo do banco 3
header_arquivo << '0000' # lote do servico 4
header_arquivo << '0' # tipo de registro 1
header_arquivo << ''.rjust(8, ' ') # uso exclusivo FEBRABAN 9
header_arquivo << Brcobranca::Util::Empresa.new(documento_cedente, false).tipo # tipo inscricao 1
header_arquivo << documento_cedente.to_s.rjust(15, '0') # numero de inscricao 15
header_arquivo << codigo_convenio # codigo do convenio no banco 20
header_arquivo << info_conta # informacoes da conta 20
header_arquivo << empresa_mae.format_size(30) # nome da empresa 30
header_arquivo << nome_banco.format_size(30) # nome do banco 30
header_arquivo << ''.rjust(10, ' ') # uso exclusivo FEBRABAN 10
header_arquivo << '1' # codigo remessa 1
header_arquivo << data_geracao # data geracao 8
header_arquivo << hora_geracao # hora geracao 6
header_arquivo << sequencial_remessa.to_s.rjust(6, '0') # numero seq. arquivo 6
header_arquivo << versao_layout_arquivo # num. versao arquivo 3
header_arquivo << densidade_gravacao # densidade gravacao 5
header_arquivo << uso_exclusivo_banco # uso exclusivo 20
header_arquivo << uso_exclusivo_empresa # uso exclusivo 20
header_arquivo << complemento_header # complemento do arquivo 29
header_arquivo
end

def monta_segmento_p(pagamento, nro_lote, sequencial)

Check notice

Code scanning / Rubocop

A calculated magnitude based on number of assignments, branches, and conditions. Note

Metrics/AbcSize: Assignment Branch Condition size for monta_segmento_p is too high. [<3, 81, 0> 81.06/17]

Check notice

Code scanning / Rubocop

Avoid methods longer than 10 lines of code. Note

Metrics/MethodLength: Method has too many lines. [41/10]
segmento_p = ''
# # DESCRICAO TAMANHO
segmento_p += cod_banco # codigo banco 3
segmento_p << nro_lote.to_s.rjust(4, '0') # lote de servico 4
segmento_p << '3' # tipo de registro 1
segmento_p << sequencial.to_s.rjust(5, '0') # num. sequencial do registro no lote 5
segmento_p << 'P' # cod. segmento 1
segmento_p << ' ' # uso exclusivo 1
segmento_p << pagamento.identificacao_ocorrencia # cod. movimento remessa 2
segmento_p << agencia.to_s.rjust(4, '0') # agencia 4
segmento_p << digito_agencia.to_s # dv agencia 1
segmento_p << complemento_p(pagamento) # informacoes da conta 34
segmento_p << codigo_carteira # codigo da carteira 1
segmento_p << forma_cadastramento # forma de cadastro do titulo 1
segmento_p << tipo_documento # tipo de documento 1
segmento_p << emissao_boleto # identificaco emissao 1
segmento_p << distribuicao_boleto # indentificacao entrega 1
segmento_p << formata_documento_ou_numero(pagamento, 15) # uso exclusivo 4
segmento_p << pagamento.data_vencimento.strftime('%d%m%Y') # data de venc. 8
segmento_p << pagamento.formata_valor(15) # valor documento 15
segmento_p << ''.rjust(5, '0') # agencia cobradora 5
segmento_p << dv_agencia_cobradora # dv agencia cobradora 1
segmento_p << especie_titulo # especie do titulo 2
segmento_p << aceite # aceite 1
segmento_p << pagamento.data_emissao.strftime('%d%m%Y') # data de emissao titulo 8
segmento_p << pagamento.tipo_mora # cod. do mora 1
segmento_p << data_mora(pagamento) # data mora 8
segmento_p << pagamento.formata_valor_mora(15) # valor mora 15
segmento_p << codigo_desconto(pagamento) # cod. do desconto 1
segmento_p << pagamento.formata_data_desconto('%d%m%Y') # data desconto 8
segmento_p << pagamento.formata_valor_desconto(15) # valor desconto 15
segmento_p << pagamento.formata_valor_iof(15) # valor IOF 15
segmento_p << pagamento.formata_valor_abatimento(15) # valor abatimento 15
segmento_p << formata_documento_ou_numero(pagamento) # identificacao titulo empresa 25
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [114/80]

segmento_p << pagamento.codigo_protesto # cod. para protesto 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_p << pagamento.dias_protesto.to_s.rjust(2, '0') # dias para protesto 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_p << '3' # cod. para baixa 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_p << '0' # zero fixo 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_p << '00' # dias para baixa 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_p << '00' # cod. da moeda 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_p << ''.rjust(11, ' ') # uso exclusivo 11
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [114/80]

segmento_p
end

def monta_segmento_q(pagamento, nro_lote, sequencial)

Check notice

Code scanning / Rubocop

A calculated magnitude based on number of assignments, branches, and conditions. Note

Metrics/AbcSize: Assignment Branch Condition size for monta_segmento_q is too high. [<3, 51, 0> 51.09/17]

Check notice

Code scanning / Rubocop

Avoid methods longer than 10 lines of code. Note

Metrics/MethodLength: Method has too many lines. [23/10]
segmento_q = '' # CAMPO TAMANHO
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [118/80]

segmento_q += cod_banco # codigo banco 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << nro_lote.to_s.rjust(4, '0') # lote de servico 4
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [112/80]

segmento_q << '3' # tipo de registro 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [112/80]

segmento_q << sequencial.to_s.rjust(5, '0') # num. sequencial do registro no lote 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [112/80]

segmento_q << 'Q' # cod. segmento 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [112/80]

segmento_q << ' ' # uso exclusivo 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.identificacao_ocorrencia # cod. movimento remessa 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.identificacao_sacado(false) # tipo insc. sacado 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.documento_sacado.to_s.rjust(15, '0') # documento sacado 14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_q << pagamento.nome_sacado.format_size(40) # nome cliente 40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_q << pagamento.endereco_sacado.format_size(40) # endereco cliente 40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_q << pagamento.bairro_sacado.format_size(15) # bairro 15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_q << pagamento.cep_sacado[0..4] # cep 5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.cep_sacado[5..7] # sufixo cep 3
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.cidade_sacado.format_size(15) # cidade 15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_q << pagamento.uf_sacado # uf 2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.identificacao_avalista(false) # identificacao do sacador 1
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [112/80]

segmento_q << pagamento.documento_avalista.to_s.rjust(15, '0') # documento sacador 15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [114/80]

segmento_q << pagamento.nome_avalista.format_size(40) # nome avalista 40
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Metrics/LineLength: Line is too long. [113/80]

segmento_q << ''.rjust(12, '0') # Reservado (uso Branco) 12
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_q << ''.rjust(19, ' ') # Reservado (uso Branco) 19
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
Metrics/LineLength: Line is too long. [113/80]

segmento_q
end

Check notice

Code scanning / Rubocop

Keeps track of empty lines around class bodies. Note

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layout/EmptyLinesAroundClassBody: Extra empty line detected at class body end.

end
end
end
end
Loading
Loading