Created
July 2, 2021 20:49
-
-
Save IgorDePaula/8be90e83ef5b4f0dd3e46a8198a3adfd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\BankFileReaders\Itau\Retorno\Boleto; | |
class Boleto | |
{ | |
private $file; | |
public function __construct($file) | |
{ | |
$this->file = $file; | |
} | |
public function read() | |
{ | |
$lines = file($this->file); | |
$result = []; | |
$header = reset($lines); | |
$trailer = end($lines); | |
$result['header'] = (new Header($header))->process(); | |
$numLines = count($lines); | |
for($i=1;$i<($numLines-1); $i++){ | |
$result['body'][] = (new Detail($lines[$i]))->process(); | |
} | |
$result['trailer'] = (new Trailer($trailer))->process(); | |
return $result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\BankFileReaders\Itau\Retorno\Boleto; | |
class Detail extends Separator | |
{ | |
protected $data = [ | |
'tipo_registro' => ['start'=>0, 'end'=>1 ], | |
'codigo_inscricao' => ['start'=>1, 'end'=>2 ], | |
'numero_inscricao' => ['start'=>3, 'end'=>14 ], | |
'agencia' => ['start'=>17, 'end'=>4 ], | |
'zeros1' => ['start'=>21, 'end'=>2 ], | |
'conta' => ['start'=>23, 'end'=>5 ], | |
'dac' => ['start'=>28, 'end'=>1 ], | |
'brancos1' => ['start'=>29, 'end'=>8 ], | |
'uso_empresa' => ['start'=>37, 'end'=>25 ], | |
'nosso_numero1' => ['start'=>62, 'end'=>8 ], | |
'brancos2' => ['start'=>70, 'end'=>12 ], | |
'carteira' => ['start'=>82, 'end'=>3 ], | |
'nosso_numero2' => ['start'=>85, 'end'=>8 ], | |
'dac_nosso_numero' => ['start'=>93, 'end'=>1 ], | |
'brancos3' => ['start'=>94, 'end'=>13 ], | |
'carteira2' => ['start'=>107, 'end'=>1 ], | |
'codigo_ocorrencia' => ['start'=>108, 'end'=>2 ], | |
'data_ocorrencia' => ['start'=>110, 'end'=>6 ], | |
'numero_documento' => ['start'=>116, 'end'=>10 ], | |
'nosso_numero3' => ['start'=>126, 'end'=>8 ], | |
'brancos4' => ['start'=>134, 'end'=>12 ], | |
'vencimento' => ['start'=>146, 'end'=>6 ], | |
'valor_titulo' => ['start'=>152, 'end'=>11 ], | |
'codigo_banco' => ['start'=>165, 'end'=>3 ], | |
'agencia_cobradora' => ['start'=>168, 'end'=>4 ], | |
'dac_agencia_cobradora' => ['start'=>172, 'end'=>1 ], | |
'especie' => ['start'=>173, 'end'=>2 ], | |
'tarifa_cobranca' => ['start'=>175, 'end'=>11 ], | |
'brancos5' => ['start'=>188, 'end'=>26 ], | |
'valor_iof' => ['start'=>214, 'end'=>11 ], | |
'valor_abatimento' => ['start'=>227, 'end'=>11 ], | |
'descontos' => ['start'=>240, 'end'=>11 ], | |
'valor_principal' => ['start'=>253, 'end'=>11 ], | |
'juros' => ['start'=>266, 'end'=>11 ], | |
'outros_creditos' => ['start'=>279, 'end'=>11 ], | |
'boleto_dda' => ['start'=>292, 'end'=>1 ], | |
'brancos6' => ['start'=>293, 'end'=>2 ], | |
'data_credito' => ['start'=>295, 'end'=>6 ], | |
'instrucao_cancelada' => ['start'=>301, 'end'=>4 ], | |
'brancos7' => ['start'=>305, 'end'=>6 ], | |
'zeros2' => ['start'=>311, 'end'=>13 ], | |
'nome_pagador' => ['start'=>324, 'end'=>30 ], | |
'brancos8' => ['start'=>354, 'end'=>23 ], | |
'erros' => ['start'=>377, 'end'=>8 ], | |
'brancos9' => ['start'=>385, 'end'=>7 ], | |
'codigo_liquidacao' => ['start'=>392, 'end'=>2 ], | |
'numero_sequencial' => ['start'=>394, 'end'=>6 ], | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\BankFileReaders\Itau\Retorno\Boleto; | |
class Header extends Separator | |
{ | |
protected $data = [ | |
'tipo_registro' => ['start'=>0, 'end'=>1 ], | |
'codigo_retorno' => ['start'=>1, 'end'=>1 ], | |
'literal_retorno' => ['start'=>2, 'end'=>7 ], | |
'codigo_servico' => ['start'=>9, 'end'=>2 ], | |
'literal_servico' => ['start'=>11, 'end'=>15 ], | |
'agencia' => ['start'=>26, 'end'=>4 ], | |
'zeros' => ['start'=>30, 'end'=>2 ], | |
'conta' => ['start'=>32, 'end'=>5 ], | |
'dac' => ['start'=>37, 'end'=>1 ], | |
'brancos1' => ['start'=>38, 'end'=>8 ], | |
'nome_empresa' => ['start'=>46, 'end'=>30 ], | |
'codigo_banco' => ['start'=>76, 'end'=>3 ], | |
'nome_banco' => ['start'=>79, 'end'=>15 ], | |
'data_geracao' => ['start'=>94, 'end'=>6 ], | |
'densidade' => ['start'=>100, 'end'=>5 ], | |
'unidade_densidade' => ['start'=>105, 'end'=>3 ], | |
'num_sequencial_arquivo' => ['start'=>108, 'end'=>5 ], | |
'data_credito' => ['start'=>113, 'end'=>6 ], | |
'brancos2' => ['start'=>119, 'end'=>275 ], | |
'num_sequencial' => ['start'=>394, 'end'=>6 ] | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\BankFileReaders\Itau\Retorno\Boleto; | |
class Separator | |
{ | |
protected $line, $data = []; | |
public function __construct($line) | |
{ | |
$this->line = $line; | |
} | |
public function process() | |
{ | |
$result = []; | |
foreach($this->data as $index => $data){ | |
$result[$index] = trim(substr($this->line, $data['start'], $data['end'])); | |
} | |
return $result; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Services\BankFileReaders\Itau\Retorno\Boleto; | |
class Trailer extends Separator | |
{ | |
protected $data = [ | |
'tipo_registro' => ['start'=>0, 'end'=>1 ], | |
'codigo_retorno' => ['start'=>1, 'end'=>1 ], | |
'codigo_servico' => ['start'=>2, 'end'=>2 ], | |
'codigo_banco' => ['start'=>4, 'end'=>3 ], | |
'brancos1' => ['start'=>7, 'end'=>17 ], | |
'quantidade_titulos_cobranca_simples' => ['start'=>17, 'end'=>8 ], | |
'valor_total_cobranca_simples' => ['start'=>25, 'end'=>12 ], | |
'aviso_bancario1' => ['start'=>39, 'end'=>8 ], | |
'brancos2' => ['start'=>47, 'end'=>10 ], | |
'quantidade_titulos_cobranca_vinculada' => ['start'=>57, 'end'=>8 ], | |
'valor_total_cobranca_vinculada' => ['start'=>65, 'end'=>12 ], | |
'aviso_bancario2' => ['start'=>79, 'end'=>8 ], | |
'brancos3' => ['start'=>87, 'end'=>177 ], | |
'quantidade_titulos_cobranca_direta' => ['start'=>177, 'end'=>8 ], | |
'valor_total_cobranca_direta' => ['start'=>185, 'end'=>12 ], | |
'aviso_bancario3' => ['start'=>199, 'end'=>8 ], | |
'controle_arquivo' => ['start'=>207, 'end'=>5 ], | |
'quantidade_detalhes' => ['start'=>212, 'end'=>8 ], | |
'valor_total_informado' => ['start'=>220, 'end'=>8 ], | |
'brancos4' => ['start'=>234, 'end'=>160 ], | |
'num_sequencial' => ['start'=>394, 'end'=>6 ] | |
]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment