All Downloads are FREE. Search and download functionalities are using the official Maven repository.

tech.deepdreams.worker.services.deduction.IRPPServicev2016Impl Maven / Gradle / Ivy

There is a newer version: 0.1.2-RELEASE
Show newest version
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 IRPPServicev2016Impl implements DeductionService{
	
	private static final Double MIN_GROSS_TAXABLE_SALARY = 62_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 * 0.7 - 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 2016 ;
	}
	
	
	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)"
		} ;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy