forked from umbrellaTech/ya-arquivo-remessa
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] #000 - Correção na geração do arquivo Remessa Banco Bradesco
- Loading branch information
vinicius
committed
Aug 30, 2018
1 parent
3546c90
commit e9361ed
Showing
4 changed files
with
149 additions
and
49 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Umbrella\Ya\RemessaBoleto\Modulo; | ||
|
||
/** | ||
* Class Modulo11 | ||
* @package Umbrella\Ya\RemessaBoleto\Modulo | ||
*/ | ||
class Modulo11 implements ModuloInterface | ||
{ | ||
/** | ||
* @param string $numero | ||
* @return int|mixed|string | ||
*/ | ||
public function calcularDigitoVerificador(string $numero) | ||
{ | ||
$modulo11 = $this->modulo11($numero, 7, 1); | ||
$digito = 11 - $modulo11; | ||
|
||
if ($digito == 10) { | ||
$digitoVerificador = "P"; | ||
} elseif ($digito == 11) { | ||
$digitoVerificador = 0; | ||
} else { | ||
$digitoVerificador = $digito; | ||
} | ||
|
||
return $digitoVerificador; | ||
} | ||
|
||
/** | ||
* @param $num | ||
* @param int $base | ||
* @param int $resto | ||
* @return int | ||
*/ | ||
private function modulo11($num, $base = 9, $resto = 0) | ||
{ | ||
$soma = 0; | ||
$fator = 2; | ||
|
||
/* Separacao dos numeros */ | ||
for ($i = strlen($num); $i > 0; $i--) { | ||
// pega cada numero isoladamente | ||
$numeros[$i] = substr($num, $i - 1, 1); | ||
// Efetua multiplicacao do numero pelo falor | ||
$parcial[$i] = $numeros[$i] * $fator; | ||
// Soma dos digitos | ||
$soma += $parcial[$i]; | ||
if ($fator == $base) { | ||
// restaura fator de multiplicacao para 2 | ||
$fator = 1; | ||
} | ||
$fator++; | ||
} | ||
|
||
/* Calculo do modulo 11 */ | ||
if ($resto == 0) { | ||
$soma *= 10; | ||
$digito = $soma % 11; | ||
|
||
if ($digito == 10) { | ||
$digito = 0; | ||
} | ||
|
||
return $digito; | ||
} elseif ($resto == 1) { | ||
$resto = $soma % 11; | ||
|
||
return $resto; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
namespace Umbrella\Ya\RemessaBoleto\Modulo; | ||
|
||
/** | ||
* Interface ModuloInterface | ||
* @package Umbrella\Ya\RemessaBoleto\Modulo | ||
*/ | ||
interface ModuloInterface | ||
{ | ||
/** | ||
* @param string $numero | ||
* @return mixed | ||
*/ | ||
public function calcularDigitoVerificador(string $numero); | ||
} |