Skip to content

Commit

Permalink
Merge pull request #27 from Pandora-una/master
Browse files Browse the repository at this point in the history
Importação do CNAB 400 do BB
  • Loading branch information
andersondanilo committed Sep 23, 2015
2 parents cd1068d + b34d6de commit 9e0cdd3
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Projeto para criar arquivos de remessas e processar arquivos de retorno no forma

| Banco | Versão da Remessa | Versão do Retorno |
|-----------------|--------------------|--------------------|
| Banco do Brasil | | 240 |
| Banco do Brasil | | 240 e 400 |
| Bradesco | | 240 |
| Caixa | 240 | 240 e 400 |
| Itaú | 400 | 400 |
Expand Down Expand Up @@ -54,4 +54,4 @@ Consulte na wiki: https://github.com/andersondanilo/CnabPHP/wiki/Criando-um-arqu
Você pode contribuir com testes (unitários ou manuais), ou adaptando o formato para outro banco através do projeto cnab_yaml (https://github.com/andersondanilo/cnab_yaml) (que é utilidado pelo cnab_php). [Leia a wiki](https://github.com/andersondanilo/CnabPHP/wiki)

## Licença
Este projeto esta sobre a licença MIT
Este projeto esta sobre a licença MIT
2 changes: 1 addition & 1 deletion src/Cnab/Retorno/Cnab400/Arquivo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($codigo_banco, $filename, $layoutVersao=null)
{
$this->header->loadFromString($linha);
}
else if($tipo_registro == '1')
else if(in_array((int)$tipo_registro,array(1,7)))
{
$detalhe = new Detalhe($this);
$detalhe->loadFromString($linha);
Expand Down
11 changes: 7 additions & 4 deletions src/Cnab/Retorno/Cnab400/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ public function __construct(\Cnab\Retorno\IArquivo $arquivo)
*/
public function isBaixa()
{
$tipo_baixa = array(9, 10, 32, 47, 59, 72);
$codigo_ocorrencia = (int)$this->codigo_de_ocorrencia;
return self::isBaixaStatic($codigo_ocorrencia);
return self::isBaixaStatic($codigo_ocorrencia,$this->_codigo_banco);
}

public static function isBaixaStatic($codigo)
public static function isBaixaStatic($codigo,$banco = null)
{
$tipo_baixa = array(9, 10, 32, 47, 59, 72);
if ($banco == 1) //Banco do Brasil
$tipo_baixa = array(6);
else
$tipo_baixa = array(9, 10, 32, 47, 59, 72);

$codigo_ocorrencia = (int)$codigo;
if(in_array($codigo_ocorrencia, $tipo_baixa))
return true;
Expand Down
2 changes: 2 additions & 0 deletions src/Cnab/Retorno/CodigoOcorrencia.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public function getNome($codigo_banco, $codigo_ocorrencia, $format='cnab400')
$codigo_ocorrencia = (int)$codigo_ocorrencia;
$yamlLoad = new \Cnab\Format\YamlLoad($codigo_banco);
$array = $yamlLoad->loadFormat($format, 'retorno/codigo_ocorrencia');

$codigo_banco = str_pad($codigo_banco,3,'0',STR_PAD_LEFT);

if(array_key_exists($codigo_banco, $array) && array_key_exists($codigo_ocorrencia, $array[$codigo_banco]))
{
Expand Down
23 changes: 23 additions & 0 deletions tests/Cnab/Retorno/Cnab400/ArquivoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,29 @@ public function testArquivoBradescoCnab400PodeSerLido()
$this->assertEquals(new \DateTime('2012-04-11 00:00:00'), $detalhe->getDataOcorrencia());
}

public function testArquivoBancoDoBrasilCnab400PodeSerLido()
{
$factory = new \Cnab\Factory;
$arquivo = $factory->createRetorno('tests/fixtures/cnab400/retorno-cnab400-bb.ret');

$this->assertNotNull($arquivo);
$this->assertNotNull($arquivo->header);
$this->assertNotNull($arquivo->trailer);

$this->assertEquals('33448000011113', $arquivo->getCodigoCedente());
$this->assertEquals(\Cnab\Banco::BANCO_DO_BRASIL, $arquivo->getCodigoBanco());

$detalhes = $arquivo->listDetalhes();
$detalhe = $detalhes[0];


$this->assertEquals(25.0, $detalhe->getValorRecebido());
$this->assertEquals('11122450000000290', $detalhe->getNossoNumero());
$this->assertEquals(new \DateTime('2015-09-10 00:00:00'), $detalhe->getDataCredito());
$this->assertEquals(new \DateTime('2015-09-08 00:00:00'), $detalhe->getDataOcorrencia());
$this->assertTrue($detalhe->isBaixa());
}

public function testArquivoItauCnab400PodeSerLido()
{
$factory = new \Cnab\Factory;
Expand Down
3 changes: 3 additions & 0 deletions tests/fixtures/cnab400/retorno-cnab400-bb.ret
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
02RETORNO01COBRANCA 33448000011113000000EMPRESA TESTE 001BANCO DO BRASIL0809150000017 000000017910400476 1112245 000001
70000000000000000334480000112131112245 1112245000000029010000001 01900000000000 1806080915 000000000000000250000157045001009150000900000000000000000000000000000000000000000000000000000000000000000000000000002500000000000000000000000000000000000000000000000000160020000000000000 0000000000000000000000000000000000000000000000001002000002
9201001 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000000000000000000000000000000 000003

0 comments on commit 9e0cdd3

Please sign in to comment.