tech.deepdreams.worker.services.deduction.IRPPServicev2024Impl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of worker-cmr-impl Show documentation
Show all versions of worker-cmr-impl Show documentation
Payroll Worker CMR Impl project for Java 17
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.context.DeductionContext;
import tech.deepdreams.worker.api.services.DeductionService;
import tech.deepdreams.worker.api.enums.CountryCode;
import tech.deepdreams.worker.constants.ElementCode;
import tech.deepdreams.worker.constants.LocalConstantCode;
public class IRPPServicev2024Impl implements DeductionService{
private static final Double MIN_GROSS_TAXABLE_SALARY = 62_000.0 ;
private static final Double MAX_RATE_DEDUCTION = 4_800_000.0 ;
public Double calculateEmployee(Map params) {
Double value = (Double) params.get(LocalConstantCode.CODE_GROSS_TAXABLE_SALARY) ;
if(value <= MIN_GROSS_TAXABLE_SALARY) {
return 0.0 ;
}
DeductionContext context = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_PVID, 2016) ;
Double base = value - Math.min(value * 0.3, MAX_RATE_DEDUCTION/12.0) - context.calculateEmployee(params) - 500_000.0/12 ;
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" } ;
Expression expression = new ExpressionBuilder(formula).variables(variables).build() ;
expression.setVariable("BASE", base) ;
Object resultat = expression.evaluate() ;
return Double.parseDouble(resultat.toString()) ;
}
public Double calculateEmployer(Map params) {
return 0.0 ;
}
public CountryCode country() {
return CountryCode.CMR ;
}
public String code() {
return ElementCode.CODE_IRPP ;
}
public int version() {
return 2024 ;
}
private Double[] rangeArray = new Double[] {0.0, 166_666.67, 250_000.0, 416_666.67, 999_999_999.99} ;
private String[] formulaArray = new String[] {
"0.1*BASE",
"16666.67+0.15*(BASE-166666.67)",
"29166.67+0.25*(BASE-250000.00)",
"70833.34+0.35*(BASE-416666.67)"
} ;
}