tech.deepdreams.worker.services.deduction.IGRServicev2020Impl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worker-civ-impl Show documentation
Show all versions of worker-civ-impl Show documentation
Payroll Worker API project for Spring Boot
package tech.deepdreams.worker.services.deduction ;
import java.util.Arrays;
import java.util.Map;
import net.objecthunter.exp4j.Expression;
import net.objecthunter.exp4j.ExpressionBuilder;
import tech.deepdreams.worker.api.services.DeductionService;
import tech.deepdreams.worker.constants.CIVElementCode;
import tech.deepdreams.worker.constants.LocalConstantCode;
import tech.deepdreams.worker.api.enums.CountryCode;
public class IGRServicev2020Impl implements DeductionService{
public Double calculateEmployee(Map params) {
Double shares = (Double) params.get(LocalConstantCode.CODE_SHARES) ;
Double value = (Double) params.get(LocalConstantCode.CODE_GROSS_TAXABLE_SALARY) ;
Double amountIS = (Double) params.get(CIVElementCode.CODE_IS) ;
Double amountCN = (Double) params.get(CIVElementCode.CODE_CN) ;
Double base = 0.85*(0.80*value-(amountIS+amountCN))/shares ;
int rawIndex = Arrays.binarySearch(rangeArray, base) ;
int index = Math.max(rawIndex >= 0 ? rawIndex - 1 : -1 * (rawIndex + 1) - 1, 0) ;
String formula = formulaArray[index] ;
String[] variables = new String[] { "BASE", "SHARES" } ;
Expression expression = new ExpressionBuilder(formula).variables(variables).build() ;
expression.setVariable("BASE", base) ;
expression.setVariable("SHARES", shares) ;
Object resultat = expression.evaluate() ;
return Double.parseDouble(resultat.toString()) ;
}
public Double calculateEmployer(Map params) {
return 0.0 ;
}
public CountryCode country() {
return CountryCode.CIV ;
}
public String code() {
return CIVElementCode.CODE_IGR ;
}
public int version() {
return 2020 ;
}
private Double[] rangeArray = new Double[] {0.0, 25_000.0, 45_584.0, 81_584.0, 126_584.0, 220_334.0, 389_084.0, 842_167.0, 999_999_999.99} ;
private String[] formulaArray = new String[] {
"0",
"BASE*10/110-2273*SHARES",
"BASE*15/115-4076*SHARES",
"BASE*20/120-7031*SHARES",
"BASE*25/125-11250*SHARES",
"BASE*35/135-24306*SHARES",
"BASE*45/145-44181*SHARES",
"BASE*60/160-98633*SHARES"
} ;
}