Skip to content

Commit

Permalink
Merge pull request #631 from elisiara/develop
Browse files Browse the repository at this point in the history
arquivo de retorno: cria campo para valorOutrasDespesas; tratamento para ocorrências '28 - Tarifas' do CNAB400 do Sicredi não serem consideradas erro
  • Loading branch information
eduardokum authored Aug 17, 2021
2 parents 7c72d66 + 4d589e7 commit 4ce57fb
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 18 deletions.
18 changes: 17 additions & 1 deletion src/Cnab/Retorno/Cnab240/Banco/Bancoob.php
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,23 @@ protected function processarDetalhe(array $detalhe)

if ($this->getSegmentType($detalhe) == 'T') {
$d->setOcorrencia($this->rem(16, 17, $detalhe))
->setOcorrenciaDescricao(Arr::get($this->ocorrencias, $this->detalheAtual()->getOcorrencia(), 'Desconhecida'))
->setOcorrenciaDescricao(Arr::get($this->ocorrencias, $this->detalheAtual()->getOcorrencia(), 'Desconhecida'));

/**
* Conforme Manual o campo Nosso Número deve ter 7 dígitos + 1DV.
* Ao enviar a remessa formatamos para 10 dígitos preenchendo com zeros a esquerda
* Da mesma forma, no arquivo retorno, volta com 10 dígitos.
* Portanto, as duas primeiras, posições 38 e 39 serão sempre 00,
* seguidos de 7 dígitos + 1 dígito DV = 8 digitos da posição 40 até a 47.
*
* Para voltar a considerar 10 digitos voltar trecho de código.
* ////->setNossoNumero($this->rem(38, 47, $detalhe))
*
*/
if ( $this->rem(38, 39, $detalhe) != "00"){
throw new \Exception("Verificar arquivo retorno: O nosso número no arquivo de retorno é maior que 7 dígitos.");
}
$d->setNossoNumero($this->rem(40, 47, $detalhe))
->setNossoNumero($this->rem(38, 47, $detalhe))
->setCarteira($this->rem(58, 58, $detalhe))
->setNumeroDocumento($this->rem(59, 73, $detalhe))
Expand Down
9 changes: 6 additions & 3 deletions src/Cnab/Retorno/Cnab240/Detalhe.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php

namespace Eduardokum\LaravelBoleto\Cnab\Retorno\Cnab240;

use Carbon\Carbon;
Expand All @@ -7,6 +7,9 @@
use Eduardokum\LaravelBoleto\MagicTrait;
use Eduardokum\LaravelBoleto\Util;




class Detalhe implements DetalheContract
{
use MagicTrait;
Expand Down Expand Up @@ -530,7 +533,7 @@ public function getValorOutrasDespesas()
}

/**
* @param string $valorTarifa
* @param string $valorOutrasDespesas
*
* @return $this
*/
Expand Down Expand Up @@ -632,7 +635,7 @@ public function setError($error)

return $this;
}

/**
* @return string
*/
Expand Down
1 change: 1 addition & 0 deletions src/Cnab/Retorno/Cnab400/Banco/Banrisul.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ protected function processarDetalhe(array $detalhe)
->setDataCredito($this->rem(296, 301, $detalhe))
->setValor(Util::nFloat($this->rem(153, 165, $detalhe)/100, 2, false))
->setValorTarifa(Util::nFloat($this->rem(176, 188, $detalhe)/100, 2, false))
->setValorOutrasDespesas(Util::nFloat($this->rem(189, 201, $detalhe), 2, false) / 100 )
->setValorDesconto(Util::nFloat($this->rem(241, 253, $detalhe)/100, 2, false))
->setValorRecebido(Util::nFloat($this->rem(254, 266, $detalhe)/100, 2, false))
->setValorMora(Util::nFloat($this->rem(267, 279, $detalhe)/100, 2, false))
Expand Down
1 change: 1 addition & 0 deletions src/Cnab/Retorno/Cnab400/Banco/Bb.php
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ protected function processarDetalhe(array $detalhe)
->setDataCredito($this->rem(176, 181, $detalhe))
->setValor(Util::nFloat($this->rem(153, 165, $detalhe)/100, 2, false))
->setValorTarifa(Util::nFloat($this->rem(182, 188, $detalhe)/100, 2, false))
->setValorOutrasDespesas(Util::nFloat($this->rem(189, 201, $detalhe), 2, false) / 100 )
->setValorIOF(Util::nFloat($this->rem(215, 227, $detalhe)/100, 2, false))
->setValorAbatimento(Util::nFloat($this->rem(228, 240, $detalhe)/100, 2, false))
->setValorDesconto(Util::nFloat($this->rem(241, 253, $detalhe)/100, 2, false))
Expand Down
1 change: 1 addition & 0 deletions src/Cnab/Retorno/Cnab400/Banco/Santander.php
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ protected function processarDetalhe(array $detalhe)
->setDataCredito($this->rem(296, 301, $detalhe))
->setValor(Util::nFloat($this->rem(153, 165, $detalhe)/100, 2, false))
->setValorTarifa(Util::nFloat($this->rem(176, 188, $detalhe)/100, 2, false))
->setValorOutrasDespesas(Util::nFloat($this->rem(189, 201, $detalhe), 2, false) / 100 )
->setValorIOF(Util::nFloat($this->rem(215, 227, $detalhe)/100, 2, false))
->setValorAbatimento(Util::nFloat($this->rem(228, 240, $detalhe)/100, 2, false))
->setValorDesconto(Util::nFloat($this->rem(241, 253, $detalhe)/100, 2, false))
Expand Down
64 changes: 50 additions & 14 deletions src/Cnab/Retorno/Cnab400/Banco/Sicredi.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,23 @@ class Sicredi extends AbstractRetorno implements RetornoCnab400
'M2' => 'Não reconhecimento da dívida pelo pagador',
];

/**
* Array com as possiveis ocorrências da Tabela de Motivos das Ocorrências para Tarifas - “28 – Tarifas” Maio 2020 v1.6
*
* @var array
*/
private $ocorrenciasTarifas = [
'03' => 'Tarifa de sustação',
'04' => 'Tarifa de protesto',
'08' => 'Tarifa de custas de protesto',
'A9' => 'Tarifa de manutenção de título vencido',
'B1' => 'Tarifa de baixa da carteira',
'B3' => 'Tarifa de registro de entrada do título',
'F5' => 'Tarifa de entrada na rede Sicredi',
'S4' => 'Tarifa de Inclusão Negativação',
'S5' => 'Tarifa de Exclusão Negativação',
];

/**
* Roda antes dos metodos de processar
*/
Expand Down Expand Up @@ -231,7 +248,7 @@ protected function processarHeader(array $header)
protected function processarDetalhe(array $detalhe)
{
$d = $this->detalheAtual();

$d->setNossoNumero($this->rem(48, 62, $detalhe))
->setNumeroControle($this->rem(117, 126, $detalhe))
->setNumeroDocumento($this->rem(117, 126, $detalhe))
Expand All @@ -241,6 +258,7 @@ protected function processarDetalhe(array $detalhe)
->setDataVencimento($this->rem(147, 152, $detalhe))
->setValor(Util::nFloat($this->rem(153, 165, $detalhe), 2, false) / 100)
->setValorTarifa(Util::nFloat($this->rem(176, 188, $detalhe), 2, false) / 100)
->setValorOutrasDespesas(Util::nFloat($this->rem(189, 201, $detalhe), 2, false) / 100 )
->setValorAbatimento(Util::nFloat($this->rem(228, 240, $detalhe), 2, false) / 100)
->setValorDesconto(Util::nFloat($this->rem(241, 253, $detalhe), 2, false) / 100)
->setValorRecebido(Util::nFloat($this->rem(254, 266, $detalhe), 2, false) / 100)
Expand All @@ -266,10 +284,10 @@ protected function processarDetalhe(array $detalhe)
$d->setOcorrenciaTipo($d::OCORRENCIA_ALTERACAO);
} elseif ($d->hasOcorrencia('03', '27', '30')) {
$this->totais['erros']++;
if($d->hasOcorrencia('03')) {
if(isset($this->rejeicoes[$this->rem(319, 320, $detalhe)])){
$d->setRejeicao($this->rejeicoes[$this->rem(319, 320, $detalhe)]);
}
if($d->hasOcorrencia('03')) {
if(isset($this->rejeicoes[$this->rem(319, 320, $detalhe)])){
$d->setRejeicao($this->rejeicoes[$this->rem(319, 320, $detalhe)]);
}
}
} else {
$d->setOcorrenciaTipo($d::OCORRENCIA_OUTROS);
Expand All @@ -278,17 +296,35 @@ protected function processarDetalhe(array $detalhe)
$stringErrors = sprintf('%010s', $this->rem(319, 328, $detalhe));
$errorsRetorno = str_split($stringErrors, 2) + array_fill(0, 5, '') + array_fill(0, 5, '');
if (trim($stringErrors, '0') != '') {
$error = [];
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[0], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[1], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[2], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[3], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[4], '');

$error = array_filter($error);
//Caso seja detalhe de Tarifa ('28' => 'Tarifa') Buscar as mensagens especificas e não classificar como erro
if ($d->hasOcorrencia('28')) {
$motivo = [];
$motivo[] = Arr::get($this->ocorrenciasTarifas, $errorsRetorno[0], '');
$motivo[] = Arr::get($this->ocorrenciasTarifas, $errorsRetorno[1], '');
$motivo[] = Arr::get($this->ocorrenciasTarifas, $errorsRetorno[2], '');
$motivo[] = Arr::get($this->ocorrenciasTarifas, $errorsRetorno[3], '');
$motivo[] = Arr::get($this->ocorrenciasTarifas, $errorsRetorno[4], '');

$motivo = array_filter($motivo);

if (count($motivo) > 0){
$d->setRejeicao(implode(PHP_EOL, $motivo));
}

} else {
$error = [];
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[0], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[1], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[2], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[3], '');
$error[] = Arr::get($this->rejeicoes, $errorsRetorno[4], '');

$error = array_filter($error);

if (count($error) > 0){
$d->setError(implode(PHP_EOL, $error));
if (count($error) > 0){
$d->setError(implode(PHP_EOL, $error));
}
}
}

Expand Down
24 changes: 24 additions & 0 deletions src/Cnab/Retorno/Cnab400/Detalhe.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ class Detalhe implements DetalheContract
* @var string
*/
protected $valorTarifa;
/**
* @var string
*/
protected $valorOutrasDespesas;
/**
* @var string
*/
Expand Down Expand Up @@ -408,6 +412,26 @@ public function setValorTarifa($valorTarifa)
return $this;
}

/**
* @return string
*/
public function getValorOutrasDespesas()
{
return $this->valorOutrasDespesas;
}

/**
* @param string $valorOutrasDespesas
*
* @return Detalhe
*/
public function setValorOutrasDespesas($valorOutrasDespesas)
{
$this->valorOutrasDespesas = $valorOutrasDespesas;

return $this;
}

/**
* @return string
*/
Expand Down

0 comments on commit 4ce57fb

Please sign in to comment.