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

tech.deepdreams.worker.lambda.cmr.LambdaServicev2024Impl Maven / Gradle / Ivy

There is a newer version: 0.0.16-RELEASE
Show newest version
package tech.deepdreams.worker.lambda.cmr;
import java.util.Map;
import java.util.stream.Collectors;
import tech.deepdreams.worker.api.context.DeductionBasisContext;
import tech.deepdreams.worker.api.context.DeductionContext;
import tech.deepdreams.worker.api.enums.CountryCode;
import tech.deepdreams.worker.api.util.SubscriberCodes;
import tech.deepdreams.worker.constants.ElementCode;
import tech.deepdreams.worker.constants.LocalConstantCode;
import tech.deepdreams.worker.input.AdvantageInCash;
import tech.deepdreams.worker.input.AdvantageInKind;
import tech.deepdreams.worker.input.PayrollRequest;
import tech.deepdreams.worker.lambda.LambdaService;
import tech.deepdreams.worker.output.Deduction;
import tech.deepdreams.worker.output.PayrollResponse;

public class LambdaServicev2024Impl implements LambdaService{

	@Override
	public String country() {
		return CountryCode.CMR.name() ;
	}

	@Override
	public int version() {
		return 2024 ;
	}

	public PayrollResponse calculate(PayrollRequest request) {
		
		Map params = request.getAdvantagesInCash().stream()
				.collect(Collectors.toMap(AdvantageInCash::getCode, AdvantageInCash::getValue)) ;
		
		Map advantagesInKind = request.getAdvantagesInKind().stream()
				.collect(Collectors.toMap(AdvantageInKind::getCode, AdvantageInKind::getValue)) ;
		
		params.put(LocalConstantCode.CODE_RISK_RATE, 1.75) ;
		params.put(LocalConstantCode.CODE_PRES_FAM_RATE, 7.0) ;
		
		params.put(SubscriberCodes.CODE_SUBSCRIBER_BRANCH, request.getBranchId()) ;
		params.put(SubscriberCodes.CODE_SUBSCRIBER_STATE, request.getStateId()) ;
		params.put(SubscriberCodes.CODE_SUBSCRIBER_LOCALITY, request.getLocalityId()) ;
		
		params.put(ElementCode.CODE_BASE_SALARY, params.getOrDefault(ElementCode.CODE_BASE_SALARY, 0.0)) ;
		
		DeductionBasisContext grossSalaryContext = new DeductionBasisContext(CountryCode.CMR.name(), LocalConstantCode.CODE_GROSS_SALARY, 2004) ;
		Double grossSalary = grossSalaryContext.calculate(params, advantagesInKind) ;
		params.put(LocalConstantCode.CODE_GROSS_SALARY, grossSalary) ;
		
		DeductionBasisContext taxableSalaryContext = new DeductionBasisContext(CountryCode.CMR.name(), LocalConstantCode.CODE_GROSS_TAXABLE_SALARY, 2024) ;
		Double taxableSalary = taxableSalaryContext.calculate(params, advantagesInKind) ;
		params.put(LocalConstantCode.CODE_GROSS_TAXABLE_SALARY, taxableSalary) ;
		
		DeductionBasisContext contribSalaryContext = new DeductionBasisContext(CountryCode.CMR.name(), LocalConstantCode.CODE_CONTRIB_SALARY, 2024) ;
		Double contribSalary = contribSalaryContext.calculate(params, advantagesInKind) ;
		params.put(LocalConstantCode.CODE_CONTRIB_SALARY, contribSalary) ;
		
		Double baseSalary =  (Double) params.getOrDefault(ElementCode.CODE_BASE_SALARY, 0.0) ;
		
		DeductionContext irppContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_IRPP, 2024) ;
		Double irpp = irppContext.calculateEmployee(params) ;
		params.put(ElementCode.CODE_IRPP, irpp) ;
		
		DeductionContext cacContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_CAC, 2004) ;
		Double cac = cacContext.calculateEmployee(params) ;
		params.put(ElementCode.CODE_CAC, cac) ;
		
		DeductionContext ravContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_RAV, 1989) ;
		Double rav = ravContext.calculateEmployee(params) ;

		DeductionContext tdlContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_TDL, 1980) ;
		Double tdl = tdlContext.calculateEmployee(params) ;
		
		DeductionContext cfcSalContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_CFC, 1977) ;
		Double cfcSal = cfcSalContext.calculateEmployee(params) ;
		
		DeductionContext cfcPatContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_CFC, 1977) ;
		Double cfcPat = cfcPatContext.calculateEmployer(params) ;
		
		DeductionContext pvidSalContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_PVID, 2016) ;
		Double pvidSal = pvidSalContext.calculateEmployee(params) ;
		
		DeductionContext pvidPatContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_PVID, 2016) ;
		Double pvidPat = pvidPatContext.calculateEmployer(params) ;
		
		DeductionContext accTravContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_ACC_TRAV, 1977) ;
		Double accTrav = accTravContext.calculateEmployer(params) ;
		
		DeductionContext allFamContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_ALL_FAM, 2016) ;
		Double allFam = allFamContext.calculateEmployer(params) ;
		
		DeductionContext fneContext = new DeductionContext(CountryCode.CMR.name(), ElementCode.CODE_FNE, 1990) ;
		Double fne = fneContext.calculateEmployer(params) ;
		
		Double employeeDeductions =  irpp + cac + rav + tdl + cfcSal + pvidSal ;
		Double employerDeductions = cfcPat + pvidPat + accTrav + allFam ;
		
		Double netSalary = grossSalary - employeeDeductions ;
		
		PayrollResponse response = new PayrollResponse() ;
		response.setGrossSalary(grossSalary) ;
		response.setEmployeeDeductions(employeeDeductions) ;
		response.setEmployerDeductions(employerDeductions) ;
		response.setNetSalary(netSalary) ;
		
		response.addDeduction(new Deduction(ElementCode.CODE_IRPP, "IRPP", taxableSalary, irpp, 0.0)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_CAC, "CAC", irpp, cac, 0.0)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_RAV, "RAV", taxableSalary, rav, 0.0)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_TDL, "TDL", baseSalary, tdl, 0.0)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_CFC, "CFC", taxableSalary, cfcSal, cfcPat)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_PVID, "PVID", contribSalary, pvidSal, pvidPat)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_ACC_TRAV, "Accident de travail", contribSalary, 0.0, accTrav)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_ALL_FAM, "Allocations familiales", contribSalary, 0.0, allFam)) ;
		response.addDeduction(new Deduction(ElementCode.CODE_FNE, "FNE", taxableSalary, 0.0, fne)) ;
		
		return response ;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy