Example usage for java.math RoundingMode HALF_EVEN

List of usage examples for java.math RoundingMode HALF_EVEN

Introduction

In this page you can find the example usage for java.math RoundingMode HALF_EVEN.

Prototype

RoundingMode HALF_EVEN

To view the source code for java.math RoundingMode HALF_EVEN.

Click Source Link

Document

Rounding mode to round towards the "nearest neighbor" unless both neighbors are equidistant, in which case, round towards the even neighbor.

Usage

From source file:com.willwinder.universalgcodesender.MainWindow.java

private void setStepSize(double val) {
    BigDecimal bd = new BigDecimal(val).setScale(3, RoundingMode.HALF_EVEN);
    val = bd.doubleValue();
    this.stepSizeSpinner.setValue(val);
}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId/*from w w  w .  ja  v  a  2 s .  co m*/
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleOne(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal apportionedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);

    // get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);
    // Get project details
    Map<Integer, EmpClientProjectTeamStruct> employeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();

    Map<Integer, EmpClientProjectTeamStruct> validEmployeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();
    for (EmpClientProjectTeamStruct empClientProjectTeamStructThree : empClientProjectTeamStructList) {
        employeeProjectIds.put(empClientProjectTeamStructThree.getProjectMaster().getProjectId(),
                empClientProjectTeamStructThree);
    }

    validEmployeeProjectIds.putAll(employeeProjectIds);
    // logger.debug("validEmployeeProjectIds 1:size===>" +
    // validEmployeeProjectIds.size());

    // check in revenue table
    for (Integer key : employeeProjectIds.keySet()) {
        EmpClientProjectTeamStruct mapValues = employeeProjectIds.get(key);
        List<CollageProjectRevenue> listValues = collageProjectRevenueDao
                .findByYearIdMonthIdProjectIdCostCentreId(mapValues.getTabYear().getYearId(),
                        mapValues.getTabMonth().getMonthId(), mapValues.getProjectMaster().getProjectId(),
                        costCentre.getCostCentreId());
        if (listValues.isEmpty()) {
            validEmployeeProjectIds.remove(key);
        }
    }
    // logger.debug("validEmployeeProjectIds 2:size===>" +
    // validEmployeeProjectIds.size());
    if (validEmployeeProjectIds.isEmpty()) {
        ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList,
                empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList,
                employeeMonthlyAssignmentCount, countTypeId, employeePcTagsTeamStructMap);
    } else {

        Set<Integer> clientCount = new HashSet<Integer>();
        Set<Integer> projectCount = new HashSet<Integer>();

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            clientCount.add(empClientProjectTeamStruct.getCompanyMaster().getCompanyId());
        }

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            projectCount.add(empClientProjectTeamStruct.getProjectMaster().getProjectId());
        }

        BigDecimal clintCountSize = new BigDecimal(clientCount.size());
        BigDecimal projectCountSize = new BigDecimal(projectCount.size());

        BigDecimal proportionToEveryClient = BigDecimal.ONE.divide(clintCountSize, 2, RoundingMode.HALF_EVEN);
        BigDecimal proportionToProjectAligned = proportionToEveryClient.divide(projectCountSize, 2,
                RoundingMode.HALF_EVEN);

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            CompanyMaster companyMaster = empClientProjectTeamStruct.getCompanyMaster();
            ProjectMaster projectMaster = empClientProjectTeamStruct.getProjectMaster();
            EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster,
                    companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre,
                    proportionToProjectAligned, assistedTimeZero, apportionedTimeZero,
                    proportionToProjectAligned);
            if (countTypeId == 1) {
                empOpenCntClientProjectDataList.add(empcntClientProjectData);
            }
            if (countTypeId == 2) {
                empCloseCntClientProjectDataList.add(empcntClientProjectData);
            }
        }

    }

}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId/*from ww  w.  j  a va 2  s.  c om*/
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleTwo(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal apportionedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);
    // get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);

    // Get project details
    Map<Integer, EmpClientProjectTeamStruct> employeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();

    Map<Integer, EmpClientProjectTeamStruct> validEmployeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();
    for (EmpClientProjectTeamStruct empClientProjectTeamStructThree : empClientProjectTeamStructList) {
        employeeProjectIds.put(empClientProjectTeamStructThree.getProjectMaster().getProjectId(),
                empClientProjectTeamStructThree);
    }

    validEmployeeProjectIds.putAll(employeeProjectIds);
    // logger.debug("validEmployeeProjectIds 1:size===>" +
    // validEmployeeProjectIds.size());

    // check in revenue table
    for (Integer key : employeeProjectIds.keySet()) {
        EmpClientProjectTeamStruct mapValues = employeeProjectIds.get(key);
        List<CollageProjectRevenue> listValues = collageProjectRevenueDao
                .findByYearIdMonthIdProjectIdCostCentreId(mapValues.getTabYear().getYearId(),
                        mapValues.getTabMonth().getMonthId(), mapValues.getProjectMaster().getProjectId(),
                        costCentre.getCostCentreId());
        if (listValues.isEmpty()) {
            validEmployeeProjectIds.remove(key);
        }
    }
    // logger.debug("validEmployeeProjectIds 2:size===>" +
    // validEmployeeProjectIds.size());
    if (validEmployeeProjectIds.isEmpty()) {
        ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList,
                empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList,
                employeeMonthlyAssignmentCount, countTypeId, employeePcTagsTeamStructMap);
    } else {
        Set<Integer> clientCount = new HashSet<Integer>();

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            clientCount.add(empClientProjectTeamStruct.getCompanyMaster().getCompanyId());
        }

        BigDecimal clintCountSize = new BigDecimal(clientCount.size());
        BigDecimal proportionToEveryClient = BigDecimal.ONE.divide(clintCountSize, 2, RoundingMode.HALF_EVEN);

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            CompanyMaster companyMaster = empClientProjectTeamStruct.getCompanyMaster();
            ProjectMaster projectMaster = empClientProjectTeamStruct.getProjectMaster();
            EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster,
                    companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre,
                    proportionToEveryClient, assistedTimeZero, apportionedTimeZero, proportionToEveryClient);
            if (countTypeId == 1) {
                empOpenCntClientProjectDataList.add(empcntClientProjectData);
            }
            if (countTypeId == 2) {
                empCloseCntClientProjectDataList.add(empcntClientProjectData);
            }
        }
    }

}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId//from  w w w  .  j ava  2 s.  c  o  m
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleThree(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal apportionedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);
    // get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);
    // Get project details
    Map<Integer, EmpClientProjectTeamStruct> employeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();

    Map<Integer, EmpClientProjectTeamStruct> validEmployeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();
    for (EmpClientProjectTeamStruct empClientProjectTeamStructThree : empClientProjectTeamStructList) {
        employeeProjectIds.put(empClientProjectTeamStructThree.getProjectMaster().getProjectId(),
                empClientProjectTeamStructThree);
    }

    validEmployeeProjectIds.putAll(employeeProjectIds);
    // logger.debug("validEmployeeProjectIds 1:size===>" +
    // validEmployeeProjectIds.size());

    // check in revenue table
    for (Integer key : employeeProjectIds.keySet()) {
        EmpClientProjectTeamStruct mapValues = employeeProjectIds.get(key);
        List<CollageProjectRevenue> listValues = collageProjectRevenueDao
                .findByYearIdMonthIdProjectIdCostCentreId(mapValues.getTabYear().getYearId(),
                        mapValues.getTabMonth().getMonthId(), mapValues.getProjectMaster().getProjectId(),
                        costCentre.getCostCentreId());
        if (listValues.isEmpty()) {
            validEmployeeProjectIds.remove(key);
        }
    }
    // logger.debug("validEmployeeProjectIds 2:size===>" +
    // validEmployeeProjectIds.size());
    if (validEmployeeProjectIds.isEmpty()) {
        ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList,
                empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList,
                employeeMonthlyAssignmentCount, countTypeId, employeePcTagsTeamStructMap);
    } else {
        List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao
                .findByYearIdMonthId(yearId, monthId);
        BigDecimal sumOfRevenue = BigDecimal.ZERO;
        for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) {
            sumOfRevenue.add(collageProjectRevenue.getRevenueValue());
        }

        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            collageProjectRevenueList = new ArrayList<CollageProjectRevenue>();
            collageProjectRevenueList = collageProjectRevenueDao.findByYearIdMonthIdProjectId(yearId, monthId,
                    empClientProjectTeamStruct.getProjectMaster().getProjectId());
            BigDecimal proportionToSpecificProject = collageProjectRevenueList.get(0).getRevenueValue()
                    .divide(sumOfRevenue, 2, RoundingMode.HALF_EVEN);

            CompanyMaster companyMaster = empClientProjectTeamStruct.getCompanyMaster();
            ProjectMaster projectMaster = empClientProjectTeamStruct.getProjectMaster();

            EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster,
                    companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre,
                    proportionToSpecificProject, assistedTimeZero, apportionedTimeZero,
                    proportionToSpecificProject);
            if (countTypeId == 1) {
                empOpenCntClientProjectDataList.add(empcntClientProjectData);
            }
            if (countTypeId == 2) {
                empCloseCntClientProjectDataList.add(empcntClientProjectData);
            }
        }
    }

}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId//from  ww w.j  a  v  a2  s.co m
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleFour(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal apportionedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);
    // get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);
    // Get project details
    Map<Integer, EmpClientProjectTeamStruct> employeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();

    Map<Integer, EmpClientProjectTeamStruct> validEmployeeProjectIds = new HashMap<Integer, EmpClientProjectTeamStruct>();
    for (EmpClientProjectTeamStruct empClientProjectTeamStructThree : empClientProjectTeamStructList) {
        employeeProjectIds.put(empClientProjectTeamStructThree.getProjectMaster().getProjectId(),
                empClientProjectTeamStructThree);
    }

    validEmployeeProjectIds.putAll(employeeProjectIds);
    // logger.debug("validEmployeeProjectIds 1:size===>" +
    // validEmployeeProjectIds.size());

    // check in revenue table
    for (Integer key : employeeProjectIds.keySet()) {
        EmpClientProjectTeamStruct mapValues = employeeProjectIds.get(key);
        List<CollageProjectRevenue> listValues = collageProjectRevenueDao
                .findByYearIdMonthIdProjectIdCostCentreId(mapValues.getTabYear().getYearId(),
                        mapValues.getTabMonth().getMonthId(), mapValues.getProjectMaster().getProjectId(),
                        costCentre.getCostCentreId());
        if (listValues.isEmpty()) {
            validEmployeeProjectIds.remove(key);
        }
    }
    // logger.debug("validEmployeeProjectIds 2:size===>" +
    // validEmployeeProjectIds.size());
    if (validEmployeeProjectIds.isEmpty()) {
        ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList,
                empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList,
                employeeMonthlyAssignmentCount, countTypeId, employeePcTagsTeamStructMap);
    } else {
        BigDecimal toatalHours = BigDecimal.ZERO;
        BigDecimal proportionToSpecificProject = BigDecimal.ZERO;
        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            List<BigDecimal> findByProjectId = executionDataDao
                    .findByProjectId(empClientProjectTeamStruct.getProjectMaster().getProjectId());
            toatalHours.add(findByProjectId.get(0));
        }
        for (Integer key : validEmployeeProjectIds.keySet()) {
            EmpClientProjectTeamStruct empClientProjectTeamStruct = employeeProjectIds.get(key);
            List<BigDecimal> projectIdList = executionDataDao
                    .findByProjectId(empClientProjectTeamStruct.getProjectMaster().getProjectId());
            proportionToSpecificProject = projectIdList.get(0).divide(toatalHours, 2, RoundingMode.HALF_EVEN);

            CompanyMaster companyMaster = empClientProjectTeamStruct.getCompanyMaster();
            ProjectMaster projectMaster = empClientProjectTeamStruct.getProjectMaster();

            EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster,
                    companyMaster, countClassification, tabMonth, projectMaster, tabYear, costCentre,
                    proportionToSpecificProject, assistedTimeZero, apportionedTimeZero,
                    proportionToSpecificProject);
            if (countTypeId == 1) {
                empOpenCntClientProjectDataList.add(empcntClientProjectData);
            }
            if (countTypeId == 2) {
                empCloseCntClientProjectDataList.add(empcntClientProjectData);
            }
        }
    }
}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId/*from  w w w. j av a  2  s.  co m*/
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleFive(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal allignedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);
    // get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);
    for (EmpClientProjectTeamStruct empClientProjectTeamStruct : empClientProjectTeamStructList) {
        // get the EmpCntPcApportionApproach for the employee and type
        List<EmpCntPcApportionApproach> empCntPcApportionApproachList = empCntPcApportionApproachDao
                .findByYearIdMonthIdEmployeeIdTypeId(yearId, monthId,
                        empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId(), countTypeId);
        // get the EmployeePcTagsTeamStruct for the employee and type
        List<EmployeePcTagsTeamStruct> employeePcTagsTeamStructList = employeePcTagsTeamStructDao
                .findByyearIdMonthIdEmployeeIdTypeId(yearId, monthId,
                        empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId(), countTypeId);

        if (empCntPcApportionApproachList.get(0).getApportionApproach() == 1) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao
                        .findByYearIdMonthIdProfitCentreId(yearId, monthId, profitCentreId);
                BigDecimal projectCount = new BigDecimal(collageProjectRevenueList.size());
                for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) {
                    BigDecimal projectValue = BigDecimal.ONE.divide(projectCount, 2, RoundingMode.HALF_EVEN);
                    projectValue = projectValue.multiply(BigDecimal.ONE);
                    projectValue = projectValue.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(),
                            countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear,
                            costCentre, allignedTimeZero, assistedTimeZero, projectValue, projectValue);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(projectValue);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }
        } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 2) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<Object[]> objectList = executionDataDao.findByYearIdMonthIdCostCentreIdProfitCentreId(
                        yearId, monthId, costCentreId, profitCentreId);
                BigDecimal hoursSum = BigDecimal.ZERO;
                for (Object[] hours : objectList) {
                    BigDecimal hour = (BigDecimal) hours[1];
                    hoursSum.add(hour);
                }
                for (Object[] result : objectList) {
                    Integer projectId = (Integer) result[0];
                    BigDecimal hour = (BigDecimal) result[1];
                    Integer companyId = (Integer) result[2];
                    ProjectMaster projectMaster = new ProjectMaster();
                    projectMaster.setProjectId(projectId);
                    CompanyMaster companyMaster = new CompanyMaster();
                    companyMaster.setCompanyId(companyId);
                    BigDecimal resultHour = hour.divide(hoursSum, 2, RoundingMode.HALF_EVEN);
                    resultHour = resultHour.multiply(BigDecimal.ONE);
                    resultHour = resultHour.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, companyMaster, countClassification, tabMonth, projectMaster,
                            tabYear, costCentre, allignedTimeZero, assistedTimeZero, resultHour, resultHour);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(resultHour);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }
        } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 3) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao
                        .findByYearIdMonthIdProfitCentreId(yearId, monthId, profitCentreId);
                BigDecimal revenueSum = BigDecimal.ZERO;
                for (CollageProjectRevenue val : collageProjectRevenueList) {
                    revenueSum.add(val.getRevenueValue());
                }
                for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) {
                    BigDecimal revenueValue = collageProjectRevenue.getRevenueValue().divide(revenueSum, 2,
                            RoundingMode.HALF_EVEN);
                    revenueValue = revenueValue.multiply(BigDecimal.ONE);
                    revenueValue = revenueValue.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(),
                            countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear,
                            costCentre, allignedTimeZero, assistedTimeZero, revenueValue, revenueValue);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(revenueValue);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }
        }
    }
}

From source file:com.ugam.collage.plus.service.people_count.impl.PeopleAccountingServiceImpl.java

/**
 * @param yearId// w  ww.  j  av  a2  s.  c  o  m
 * @param monthId
 * @param costCentreId
 * @param empcntClientProjectDataVoList
 * @param empcntClientProjectDataList
 * @param employeeIdList
 * @param employeeMonthlyAssignmentCount
 */
private void ruleSix(Integer yearId, Integer monthId, String costCentreId,
        List<EmpcntClientProjectData> empOpenCntClientProjectDataList,
        List<EmpcntClientProjectData> empCloseCntClientProjectDataList,
        List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList,
        EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId,
        Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) {

    BigDecimal constantHours = new BigDecimal(Constants.TOTAL_WORKING_HOURS);
    BigDecimal allignedTimeZero = BigDecimal.ZERO;
    BigDecimal assistedTimeZero = BigDecimal.ZERO;
    BigDecimal apportionedTimeZero = BigDecimal.ZERO;
    EmployeeMaster employeeMaster = employeeMonthlyAssignmentCount.getEmployeeMaster();
    TabMonth tabMonth = employeeMonthlyAssignmentCount.getTabMonth();
    TabYear tabYear = employeeMonthlyAssignmentCount.getTabYear();
    CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre();
    CountClassification countClassification = new CountClassification();
    countClassification.setId(countTypeId);

    // Get the employee aligned project for opening count
    List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao
            .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList);

    // Get Total hours of existing project then do for profit centre
    // projects;
    Map<Integer, Set<Integer>> employeeIdProjectIdsMap = new HashMap<Integer, Set<Integer>>();
    Map<Integer, Integer> projectIdCompanyIdsMap = new HashMap<Integer, Integer>();

    for (EmpClientProjectTeamStruct empClientProjectTeamStruct : empClientProjectTeamStructList) {
        int employeeId = empClientProjectTeamStruct.getEmployeeMaster().getEmployeeId();
        Integer projectId = empClientProjectTeamStruct.getProjectMaster().getProjectId();
        Integer companyId = empClientProjectTeamStruct.getCompanyMaster().getCompanyId();
        if (employeeIdProjectIdsMap.containsKey(employeeId)
                && employeeIdProjectIdsMap.get(employeeId) != null) {
            employeeIdProjectIdsMap.get(employeeId).add(projectId);
        } else {
            Set<Integer> projectIds = new HashSet<Integer>();
            projectIds.add(projectId);
            employeeIdProjectIdsMap.put(employeeId, projectIds);
        }

        projectIdCompanyIdsMap.put(projectId, companyId);
    }
    for (Integer employeeId : employeeIdProjectIdsMap.keySet()) {
        Set<Integer> projectIds = new HashSet<Integer>();
        BigDecimal proportionOfCount = BigDecimal.ZERO;
        projectIds.addAll(employeeIdProjectIdsMap.get(employeeId));
        for (Integer projectId : projectIds) {
            List<BigDecimal> totalHour = executionDataDao.findByProjectId(projectId);

            BigDecimal propotionOfProject = totalHour.get(0).divide(constantHours, 2, RoundingMode.HALF_EVEN);
            proportionOfCount = proportionOfCount.add(propotionOfProject);

            ProjectMaster pMaster = new ProjectMaster();
            pMaster.setProjectId(projectId);

            CompanyMaster cMaster = new CompanyMaster();
            cMaster.setCompanyId(projectIdCompanyIdsMap.get(projectId));

            EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employeeMaster,
                    cMaster, countClassification, tabMonth, pMaster, tabYear, costCentre, allignedTimeZero,
                    propotionOfProject, apportionedTimeZero, propotionOfProject);
            if (countTypeId == 1) {
                empOpenCntClientProjectDataList.add(empcntClientProjectData);
            }
            if (countTypeId == 2) {
                empCloseCntClientProjectDataList.add(empcntClientProjectData);
            }
        }
        List<Integer> projectIdList = new ArrayList<Integer>(projectIds);
        // get the EmpCntPcApportionApproach for the employee and type
        List<EmpCntPcApportionApproach> empCntPcApportionApproachList = empCntPcApportionApproachDao
                .findByYearIdMonthIdEmployeeIdTypeId(yearId, monthId, employeeId, countTypeId);
        // get the EmployeePcTagsTeamStruct for the employee and type
        List<EmployeePcTagsTeamStruct> employeePcTagsTeamStructList = employeePcTagsTeamStructDao
                .findByyearIdMonthIdEmployeeIdTypeId(yearId, monthId, employeeId, countTypeId);
        BigDecimal remainingCount = BigDecimal.ONE.subtract(proportionOfCount);
        if (empCntPcApportionApproachList.get(0).getApportionApproach() == 1) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao
                        .findByYearIdMonthIdProfitCentreIdProjectIds(yearId, monthId, profitCentreId,
                                projectIdList);

                BigDecimal projectCount = new BigDecimal(collageProjectRevenueList.size());
                for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) {
                    BigDecimal projectValue = BigDecimal.ONE.divide(projectCount, 2, RoundingMode.HALF_EVEN);
                    projectValue = projectValue.multiply(remainingCount);
                    projectValue = projectValue.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(),
                            countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear,
                            costCentre, allignedTimeZero, assistedTimeZero, projectValue, projectValue);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(projectValue);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }
        } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 2) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<Object[]> objectList = executionDataDao
                        .findByYearIdMonthIdCostCentreIdProfitCentreIdProjectIds(yearId, monthId, costCentreId,
                                profitCentreId, projectIdList);
                BigDecimal hoursSum = BigDecimal.ZERO;
                for (Object[] hours : objectList) {
                    BigDecimal hour = (BigDecimal) hours[1];
                    hoursSum.add(hour);
                }
                for (Object[] result : objectList) {
                    Integer projectId = (Integer) result[0];
                    BigDecimal hour = (BigDecimal) result[1];
                    Integer companyId = (Integer) result[2];
                    ProjectMaster projectMaster = new ProjectMaster();
                    projectMaster.setProjectId(projectId);
                    CompanyMaster companyMaster = new CompanyMaster();
                    companyMaster.setCompanyId(companyId);
                    BigDecimal resultHour = hour.divide(hoursSum, 2, RoundingMode.HALF_EVEN);
                    resultHour = resultHour.multiply(remainingCount);
                    resultHour = resultHour.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, companyMaster, countClassification, tabMonth, projectMaster,
                            tabYear, costCentre, allignedTimeZero, assistedTimeZero, resultHour, resultHour);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(resultHour);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }
        } else if (empCntPcApportionApproachList.get(0).getApportionApproach() == 3) {
            for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) {
                String profitCentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId();
                List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao
                        .findByYearIdMonthIdProfitCentreIdProjectIds(yearId, monthId, profitCentreId,
                                projectIdList);
                BigDecimal revenueSum = BigDecimal.ZERO;
                for (CollageProjectRevenue val : collageProjectRevenueList) {
                    revenueSum.add(val.getRevenueValue());
                }
                for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) {
                    BigDecimal revenueValue = collageProjectRevenue.getRevenueValue().divide(revenueSum);
                    revenueValue = revenueValue.multiply(remainingCount);
                    revenueValue = revenueValue.multiply(employeePcTagsTeamStruct.getProportion());
                    EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(
                            employeeMaster, collageProjectRevenue.getProjectMaster().getCompanyMaster(),
                            countClassification, tabMonth, collageProjectRevenue.getProjectMaster(), tabYear,
                            costCentre, allignedTimeZero, assistedTimeZero, revenueValue, revenueValue);
                    if (countTypeId == 1) {
                        empOpenCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    if (countTypeId == 2) {
                        empCloseCntClientProjectDataList.add(empcntClientProjectData);
                    }
                    // copy proprotion
                    String mapId = yearId + "-" + monthId + "-" + employeeMaster.getEmployeeId() + "-"
                            + profitCentreId;
                    EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct;
                    employeePcTagsTeamStructCopy.setApportionedCnt(revenueValue);
                    employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy);
                }
            }

        }

    }
}