Last active
April 22, 2020 04:02
-
-
Save lpj145/9a16a79d165aa6d9fa92340bb8d8bbba to your computer and use it in GitHub Desktop.
Calculo novo inss por faixas.
This file contains hidden or 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 | |
function calcularAliqPorFaixa($numero, array $faixasDeAliquotas) { | |
$calcPorcetagem = function($numero, $alvo) { | |
return ($numero * $alvo) / 100; | |
}; | |
$calcAliq = function(float $aliquota, float $alvoUm, ?float $alvoDois = 0) use ($numero, $calcPorcetagem) { | |
if (($numero <= $alvoUm || $numero >= $alvoUm) && $alvoDois <= 0) { | |
return $calcPorcetagem($aliquota, $alvoUm); | |
} | |
if ($numero > $alvoUm && $numero < $alvoDois) { | |
return $calcPorcetagem($aliquota, ($numero - $alvoUm)); | |
} | |
if ($numero >= $alvoDois) { | |
return $calcPorcetagem($aliquota, ($alvoDois - $alvoUm)); | |
} | |
return 0; | |
}; | |
$valoresCalculados = array_map(function(array $faixas) use($calcAliq){ | |
$aliquota = key($faixas); | |
list($alvoUm, $alvoDois) = array_merge($faixas[$aliquota], [0]); | |
if ($alvoUm <= 0 && $alvoDois <= $alvoUm) { | |
return 0; | |
} | |
return $calcAliq($aliquota, $alvoUm, $alvoDois); | |
}, $faixasDeAliquotas); | |
return array_reduce($valoresCalculados, function(float $acumulado, $valorCalculado){ | |
return $acumulado + $valorCalculado; | |
}, 0); | |
} | |
$VALOR_DO_MINIMO = 1045.00; | |
$aliquotas = [ | |
['7.5' => [$VALOR_DO_MINIMO]], | |
['9' => [1045.01, 2089.60]], | |
['12' => [2089.61, 3134.40]], | |
['14' => [3134.41, 6101.06]], | |
]; | |
$aliqIRRF = [ | |
['7.5' => [1903.99, 2826.65]], | |
['15' => [2826.66, 3751.05]], | |
['22.5' => [3751.06, 4664.68]], | |
['27.5' => [4664.68, 99999999]] | |
]; | |
$salario = 7200.00; | |
echo 'Valor do calculo INSS > '.calcularAliqPorFaixa($salario, $aliquotas); | |
echo 'Valor do calculo IRRF > '.calcularAliqPorFaixa($salario, $aliqIRRF); |
Adicionado exemplo do irrf.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Código pensado nas modificações futuras que a tabela possa sofrer.