Skip to content

Commit

Permalink
DEV - CEF com Layout Diferente
Browse files Browse the repository at this point in the history
  • Loading branch information
Julio Lustosa committed Apr 16, 2015
1 parent 9d4d43c commit 601f06b
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Cnab/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Factory
{
private static $cnabFormatPath = null;
private static $layout_versao = null;

public static function getCnabFormatPath() {
if (self::$cnabFormatPath === null) {
Expand All @@ -26,6 +27,23 @@ public static function setCnabFormatPath($value) {
self::$cnabFormatPath = $value;
}

public static function getLayoutVersao($filename = null)
{
if(self::$layout_versao === null && $filename != null)
{
$identifier = new Format\Identifier;
$format = $identifier->identifyFile($filename);

self::$layout_versao = $format['layout_versao'];
}

return self::$layout_versao;
}

public static function setLayoutVersao($value) {
self::$layout_versao = $value;
}

/**
* Cria um arquivo de remessa
* @return \Cnab\Remessa\IArquivo
Expand Down
21 changes: 21 additions & 0 deletions src/Cnab/Format/Identifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public function identifyFile($filename)
$codigo_banco = \substr($lines[0], 76, 3);
$codigo_tipo = \substr($lines[0], 1, 1);
$tipo = null;
$layout_versao = null;

if($codigo_tipo == '1')
$tipo = 'remessa';
else if ($codigo_tipo == '2')
Expand All @@ -47,6 +49,24 @@ public function identifyFile($filename)
$codigo_banco = \substr($lines[0], 0, 3);
$codigo_tipo = \substr($lines[0], 142, 1);
$tipo = null;
$layout_versao = null;

// Pega a Versao do Layout da CEF
if(\Cnab\Banco::CEF == $codigo_banco)
{
$layout_versao = \substr($lines[0], 163, 3);

if($layout_versao == '040' || $layout_versao == '050')
{
$layout_versao = 'SIGCB';
}
else
{
// Layout SICOB
$layout_versao = null;
}
}

if(\strtoupper($codigo_tipo) == '1')
$tipo = 'remessa';
elseif (\strtoupper($codigo_tipo) == '2')
Expand All @@ -59,6 +79,7 @@ public function identifyFile($filename)
'banco' => $codigo_banco,
'tipo' => $tipo,
'bytes' => $bytes,
'layout_versao' => $layout_versao,
);

return $result;
Expand Down
9 changes: 8 additions & 1 deletion src/Cnab/Format/YamlLoad.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
class YamlLoad
{
public $codigo_banco = null;
public $layout_versao = null;
public $formatPath;

public function __construct($codigo_banco)
public function __construct($codigo_banco, $layout_versao = null)
{
$this->codigo_banco = $codigo_banco;
$this->formatPath = Factory::getCnabFormatPath();
Expand Down Expand Up @@ -95,6 +96,12 @@ public function loadFormat($cnab, $filename) {
$filenamePadrao = $this->formatPath.'/'.$cnab.'/generic/'.$filename.'.yml';
$filenameEspecifico = $this->formatPath.'/'.$cnab.'/'.$banco.'/'.$filename.'.yml';

if($this->layout_versao != null)
{
// Usado quando o banco possuir mais de uma versao de Layout
$filenameEspecifico = $this->formatPath.'/'.$cnab.'/'.$banco.'/'.$this->layout_versao.'/'.$filename.'.yml';
}

if(!file_exists($filenamePadrao) && !file_exists($filenameEspecifico))
throw new \Exception('Arquivo não encontrado '. $filename);

Expand Down
5 changes: 5 additions & 0 deletions src/Cnab/Retorno/Cnab240/Arquivo.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
namespace Cnab\Retorno\Cnab240;
use Cnab\Factory;

class Arquivo implements \Cnab\Retorno\IArquivo
{
Expand All @@ -16,6 +17,10 @@ class Arquivo implements \Cnab\Retorno\IArquivo
public function __construct($codigo_banco, $filename)
{
$this->filename = $filename;

$layout_versao = Factory::getLayoutVersao($this->filename);
Factory::setLayoutVersao($layout_versao);


if(!file_exists($this->filename))
throw new \Exception("Arquivo não encontrado: {$this->filename}");
Expand Down

0 comments on commit 601f06b

Please sign in to comment.