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

tech.deepdreams.worker.services.deductionbasis.GrossTaxableSalaryv2004Impl Maven / Gradle / Ivy

There is a newer version: 0.1.2-RELEASE
Show newest version
package tech.deepdreams.worker.services.deductionbasis;
import static tech.deepdreams.worker.constants.ElementCode.*;
import static tech.deepdreams.worker.constants.LocalConstantCode.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import tech.deepdreams.worker.api.services.DeductionBasisService;
import tech.deepdreams.worker.api.enums.CountryCode;

public class GrossTaxableSalaryv2004Impl implements DeductionBasisService{

	
	public Double calculate(Map params, Map advantagesInKind) {
		Double taxableSalary = params.entrySet()
					.stream()
					.filter(entry -> {
						return Arrays.asList(NON_EXEMPTED_ITEMS).contains(entry.getKey()) || Arrays.asList(EXCEPTIONAL_INCOMES).contains(entry.getKey()) ;   
					})
					.mapToDouble(entry -> {
						return Double.parseDouble(entry.getValue().toString()) ;
					})
					.sum() ;
		
		Map additionalAdvantages = params.entrySet().stream()
			  		.filter(entry -> {
			  			return Arrays.asList(ADVANTAGES_IN_KIND).contains(entry.getKey()) ;
			  		})
			  		.collect(Collectors.toMap(entry -> entry.getKey(), entry -> 1)) ;
		
		Map allAdvantagesInKind = new HashMap() ;
		allAdvantagesInKind.putAll(advantagesInKind) ;
		allAdvantagesInKind.putAll(additionalAdvantages) ;
		
		return taxableSalary + allAdvantagesInKind.entrySet()
					.stream()
					.filter(entry -> {
						return Arrays.asList(ADVANTAGES_IN_KIND).contains(entry.getKey()) ;   
					})
					.mapToDouble(entry -> {
						return switch(entry.getKey()) {
									case CODE_ACCOMODATION :
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.15*taxableSalary) ;
									case CODE_ELECTRICITY :
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.04*taxableSalary) ;
									case CODE_WATER :
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.02*taxableSalary) ;
									case CODE_VEHICLE :
										Double number = Double.parseDouble(entry.getValue().toString()) ;
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.1*number*taxableSalary) ;
									case CODE_DOMESTIC :
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.05*taxableSalary) ;
									case CODE_FOOD :
										yield Math.min(Double.parseDouble(params.getOrDefault(entry.getKey(), Double.MAX_VALUE).toString()), 0.1*taxableSalary) ;
									default:
										yield 0.0 ;
						} ;
					})
					.sum() ;
	}

	
	public CountryCode country() {
		return CountryCode.CMR ;
	}

	
	public String code() {
		return CODE_GROSS_TAXABLE_SALARY ;
	}

	
	public int version() {
		return 2004 ;
	}

	
	private static final String[] NON_EXEMPTED_ITEMS = new String[] { CODE_BASE_SALARY, CODE_OVERTIME_BONUS, 
			CODE_SENIORITY_BONUS, CODE_SALARY_SUPPLEMENT, CODE_REPONSIBILITY_BONUS, CODE_FUNCTION_BONUS, 
			CODE_TRANSPORT_BONUS, CODE_TECHNICAL_BONUS, CODE_TRANSPORT_ALLOWANCE, CODE_FUNCTION_BONUS, CODE_ATTENDANCE_BONUS, 
			CODE_PERFORMANCE_BONUS, CODE_PERFORMANCE2_BONUS, CODE_SUBJECTIVITY_BONUS, CODE_PACKAGING_BONUS, CODE_PAID_HOLIDAY_BONUS, 
			CODE_RECOVERY_BONUS, CODE_TRAINING_BONUS, CODE_HARDSHIP_BONUS,CODE_RISK_BONUS, 
			CODE_PRECARIOUSNESS_BOUNTY, CODE_PENALTY_BONUS, CODE_CLOTHING_BONUS, CODE_EXPATRIATION_BONUS, 
			CODE_PHONE, CODE_FUEL, CODE_CAREKEEPING, CODE_INTERNET } ;
	
	private static final String[] EXCEPTIONAL_INCOMES = new String[] { CODE_13TH_MONTH_BONUS, CODE_YEAR_END_BONUS,
			CODE_BALANCE_SHEET_BONUS, CODE_RETIREMENT_BONUS, CODE_END_OF_CAREER_ALLOWANCE } ;
	
	private static final String[] ADVANTAGES_IN_KIND = new String[] { CODE_ACCOMODATION, CODE_WATER,
			CODE_ELECTRICITY, CODE_VEHICLE, CODE_DOMESTIC, CODE_FOOD } ;
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy