tech.deepdreams.worker.services.deductionbasis.GrossTaxableSalaryv2020Impl 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.deductionbasis;
import static tech.deepdreams.worker.constants.CIVElementCode.*;
import static tech.deepdreams.worker.constants.LocalConstantCode.*;
import java.util.Arrays;
import java.util.Map;
import tech.deepdreams.worker.api.services.DeductionBasisService;
import tech.deepdreams.worker.api.util.CommonCodes;
import tech.deepdreams.worker.constants.LocalConstantCode;
import tech.deepdreams.worker.api.context.DeductionBasisContext;
import tech.deepdreams.worker.api.enums.CountryCode;
public class GrossTaxableSalaryv2020Impl implements DeductionBasisService{
public Double calculate(Map params, Map advantagesInKind) {
DeductionBasisContext context = new DeductionBasisContext(CountryCode.CIV, LocalConstantCode.CODE_GROSS_SALARY, 2020) ;
Double grossSalary = context.calculate(params, advantagesInKind) ;
Double nonExemptedSalary = params.entrySet()
.stream()
.filter(entry -> {
int key = Integer.parseInt(entry.getKey()) ;
boolean all = key >= 200 && key <= 369 ;
return all && ! Arrays.asList(EXEMPTED_ITEMS).contains(entry.getKey()) ;
})
.mapToDouble(entry -> {
if(CODE_TRANSPORT_BONUS.equals(entry.getKey())) {
Long localityId = (Long) params.get(CommonCodes.CODE_SUBSCRIBER_LOCALITY) ;
if(ABIDJAN_ID.equals(localityId)) {
return Math.max(FEES_ABIDJAN - Double.parseDouble(entry.getValue().toString()), 0.0) ;
} else if(BOUAKE_ID.equals(localityId)) {
return Math.max(FEES_BOUAKE - Double.parseDouble(entry.getValue().toString()), 0.0) ;
} else {
return Math.max(FEES_OTHERS - Double.parseDouble(entry.getValue().toString()), 0.0) ;
}
}
return Double.parseDouble(entry.getValue().toString()) ;
})
.sum() ;
Double indemnitiesSalary = params.entrySet()
.stream()
.filter(entry -> {
return Arrays.asList(EXEMPTED_ITEMS).contains(entry.getKey()) ;
})
.mapToDouble(entry -> {
return Double.parseDouble(entry.getValue().toString()) ;
})
.sum() ;
Double nonExemptedIndemnities = Math.max(indemnitiesSalary - grossSalary/10.0, 0.0) ;
Double advantagesInKindAmount = advantagesInKind.entrySet()
.stream()
.filter(entry -> {
return Arrays.asList(ADVANTAGES_IN_KIND).contains(entry.getKey()) ;
})
.mapToDouble(entry -> {
int pieces = (Integer) advantagesInKind.getOrDefault(CODE_PIECES, 0) ;
return switch(entry.getKey()) {
case CODE_ACCOMODATION :
yield HOUSING[Math.min(6, pieces-1)] ;
case CODE_FURNITURE :
yield FURNITURE[Math.min(6, pieces-1)] ;
case CODE_WATER :
Double poolAmount = advantagesInKind.getOrDefault(LocalConstantCode.CODE_SWIM_POOL, 0) >= 1 ? SWIM_POOL : 0.0 ;
yield WATER[Math.min(6, pieces-1)] + poolAmount ;
case CODE_ELECTRICITY :
int heatedPieces = advantagesInKind.getOrDefault(LocalConstantCode.CODE_AIR_CONDITIONING_UNIT, 0) ;
yield ELECTRICITY[Math.min(6, pieces-1)] + heatedPieces * AIR_CONDITIONING ;
case CODE_HOUSE_PEOPLE :
yield HOUSE_PEOPLE ;
case CODE_GUARDIAN :
yield GUARDIAN ;
case CODE_GARDENER :
yield GARDENER ;
case CODE_COOKER :
yield COOKER ;
default:
yield 0.0 ;
} ;
})
.sum() ;
return nonExemptedSalary + advantagesInKindAmount + nonExemptedIndemnities ;
}
public CountryCode country() {
return CountryCode.CIV ;
}
public String code() {
return CODE_GROSS_TAXABLE_SALARY ;
}
public int version() {
return 2020 ;
}
private static Double FEES_ABIDJAN = 30_000.0 ;
private static Double FEES_BOUAKE = 24_000.0 ;
private static Double FEES_OTHERS = 20_000.0 ;
private static Long ABIDJAN_ID = 0L ;
private static Long BOUAKE_ID = 0L ;
private static Double HOUSE_PEOPLE = 60_000.0 ;
private static Double GUARDIAN = 50_000.0 ;
private static Double GARDENER = 50_000.0 ;
private static Double COOKER = 90_000.0 ;
private static Double SWIM_POOL = 30_000.0 ;
private static Double AIR_CONDITIONING = 20_000.0 ;
private static final Double[] HOUSING = new Double[] { 60_000.0, 80_000.0, 160_000.0, 300_000.0, 480_000.0, 600_000.0, 800_000.0 } ;
private static final Double[] FURNITURE = new Double[] { 10_000.0, 20_000.0, 40_000.0, 60_000.0, 80_000.0, 100_000.0, 150_000.0 } ;
private static final Double[] ELECTRICITY = new Double[] { 10_000.0, 20_000.0, 30_000.0, 40_000.0, 50_000.0, 60_000.0, 70_000.0 } ;
private static final Double[] WATER = new Double[] { 10_000.0, 15_000.0, 20_000.0, 30_000.0, 40_000.0, 50_000.0, 60_000.0 } ;
private static final String[] EXEMPTED_ITEMS = new String[] {CODE_REPRESENTATION_BONUS, CODE_TRAVEL_BONUS,
CODE_DIRTY_BONUS, CODE_OUTFIT_BONUS, CODE_CASH_BONUS, CODE_REPONSIBILITY_BONUS, CODE_FUNCTION_BONUS } ;
private static final String[] ADVANTAGES_IN_KIND = new String[] { CODE_ACCOMODATION, CODE_FURNITURE, CODE_WATER,
CODE_SWIMPOOL, CODE_ELECTRICITY, CODE_AIR_CONDITIONING, CODE_GUARDIAN, CODE_GARDENER, CODE_HOUSE_PEOPLE,
CODE_COOKER, CODE_VEHICLE, CODE_FOOD, CODE_PHONE, CODE_INTERNET, CODE_FUEL, CODE_HEALTH_INSURANCE,
CODE_TRAVEL_HOLIDAYS } ;
}