Created
August 11, 2020 14:12
-
-
Save vitormattos/f93ad5eecadde43c6b55a984946b2264 to your computer and use it in GitHub Desktop.
Cálculo INSS, IR e remuneração bruta
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
/** | |
* @param {number} Valor bruto para calcular inss | |
* @customfunction | |
*/ | |
function INSS(bruto, producao_interna, teto = 5645.80) { | |
if(producao_interna == '' || producao_interna == 0 || producao_interna == '0') { | |
aliquota = 0.2; | |
} else { | |
aliquota = 0.11; | |
} | |
inss = teto * aliquota; | |
if(bruto < teto) { | |
inss = bruto * aliquota; | |
} | |
return inss; | |
} | |
/** | |
* @customfunction | |
*/ | |
function BASE_IRPF(bruto, inss, dependentes) { | |
base = bruto - inss - dependentes * 189.59; | |
if(base < 0) { | |
base = 0; | |
} | |
return base; | |
} | |
/** | |
* @customfunction | |
*/ | |
function IRPF(baseIrpf) { | |
if(baseIrpf <= 1903.98) { | |
irpf = 0; | |
} else if(baseIrpf <= 2826.65) { | |
irpf = baseIrpf * 0.075 - 142.80; | |
} else if(baseIrpf <= 3751.05) { | |
irpf = baseIrpf * 0.15 - 354.80; | |
} else if(baseIrpf <= 4664.68) { | |
irpf = baseIrpf * 0.225 - 636.13; | |
} else { | |
irpf = baseIrpf * 0.275 - 869.36; | |
} | |
if(irpf < 0 ) { | |
irpf = 0; | |
} | |
return irpf; | |
} | |
/** | |
* @customfunction | |
*/ | |
function BRUTO(liquido, dependentes, producao_interna, teto_inss = 5645.80) { | |
if(isNaN(dependentes)) dependentes = 0; | |
if(isNaN(producao_interna)) producao_interna = 0; | |
liquido = Math.round(liquido*100)/100; | |
max = liquido * 1.4; | |
min = liquido; | |
i = 0; | |
while(min < max) { | |
i++; | |
if(i > 30) { | |
return "FALHA"; | |
} | |
meio = (max + min) / 2; | |
inss = INSS(meio, producao_interna, teto_inss); | |
base_irpf = BASE_IRPF(meio, inss, dependentes); | |
irpf = IRPF(base_irpf); | |
estimativa = Math.round((meio - inss - irpf) * 100) / 100; | |
if (estimativa == liquido) { | |
return meio; | |
} | |
if (estimativa > liquido) { | |
max = meio; | |
} else { | |
min = meio; | |
} | |
} | |
} | |
// BRUTO(1903.98,0,1);//1.903,98 | |
// INSS(5645.80,0,5645.80) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment