Java tutorial
/** * Class Name: PeopleAccountingServiceImpl * * Created By: Rishi.c2 * Created On: 7:33:27 PM, Sep 23, 2014 * * Modified By: Rishi.c2 * Modified On: 7:33:27 PM, Sep 23, 2014 * * Description: * * Copyright (c) 2013 Ugam Interactive. All rights reserved. * * Use is subject to license terms. */ package com.ugam.collage.plus.service.people_count.impl; import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; import com.ugam.collage.plus.common.utils.Constants; import com.ugam.collage.plus.dao.CollageProjectRevenueDao; import com.ugam.collage.plus.dao.CustomGroupTab3FieldsDataDao; import com.ugam.collage.plus.dao.EmpClientProjectTeamStructDao; import com.ugam.collage.plus.dao.EmpCntPcApportionApproachDao; import com.ugam.collage.plus.dao.EmpcntClientProjectDataDao; import com.ugam.collage.plus.dao.EmpcntProjectActivityDataDao; import com.ugam.collage.plus.dao.EmployeeMonthlyAssignmentDao; import com.ugam.collage.plus.dao.EmployeePcTagsTeamStructDao; import com.ugam.collage.plus.dao.EmployeeSummaryCssplitDao; import com.ugam.collage.plus.dao.EmployeeSummaryTotalDao; import com.ugam.collage.plus.dao.ExecutionDataDao; import com.ugam.collage.plus.dao.ProjectMasterDao; import com.ugam.collage.plus.model.ActivityFinanceMaster; import com.ugam.collage.plus.model.CollageProjectRevenue; import com.ugam.collage.plus.model.CompanyMaster; import com.ugam.collage.plus.model.CostCentre; import com.ugam.collage.plus.model.CountClassification; import com.ugam.collage.plus.model.CustomGroupTab3FieldsData; import com.ugam.collage.plus.model.EmpClientProjectTeamStruct; import com.ugam.collage.plus.model.EmpCntPcApportionApproach; import com.ugam.collage.plus.model.EmpcntClientProjectData; import com.ugam.collage.plus.model.EmpcntProjectActivityData; import com.ugam.collage.plus.model.EmployeeMaster; import com.ugam.collage.plus.model.EmployeeMonthlyAssignment; import com.ugam.collage.plus.model.EmployeePcTagsTeamStruct; import com.ugam.collage.plus.model.EmployeeSummaryCssplit; import com.ugam.collage.plus.model.EmployeeSummaryTotal; import com.ugam.collage.plus.model.ExecutionData; import com.ugam.collage.plus.model.ProjectMaster; import com.ugam.collage.plus.model.TabMonth; import com.ugam.collage.plus.model.TabYear; import com.ugam.collage.plus.service.people_count.PeopleAccountingService; import com.ugam.collage.plus.vo.ClientProjectStatusVo; import com.ugam.collage.plus.vo.EmpcntClientProjectDataVo; import com.ugam.collage.plus.vo.IdNameValueVo; import com.ugam.collage.plus.vo.IdTextVo; import com.ugam.collage.plus.vo.PCValidationSummaryVo; @Transactional public class PeopleAccountingServiceImpl implements PeopleAccountingService { private static final String UI_DISPLAY_GROUP_FOR_SELECTED_COST_CENTER = "For Selected Cost Center"; private static final String COUNT_MATCH = "Match"; public static final String COUNT_NOT_MATCHED = "Not-Matched"; private static final Logger logger = LoggerFactory.getLogger(PeopleAccountingServiceImpl.class); @Autowired EmployeeSummaryCssplitDao employeeSummaryCssplitDao; @Autowired EmployeeSummaryTotalDao employeeSummaryTotalDao; @Autowired EmployeeMonthlyAssignmentDao employeeMonthlyAssignmentDao; @Autowired ExecutionDataDao executionDataDao; @Autowired CollageProjectRevenueDao collageProjectRevenueDao; @Autowired EmpClientProjectTeamStructDao empClientProjectTeamStructDao; @Autowired EmployeePcTagsTeamStructDao employeePcTagsTeamStructDao; @Autowired EmpcntClientProjectDataDao empcntClientProjectDataDao; @Autowired EmpCntPcApportionApproachDao empCntPcApportionApproachDao; @Autowired CustomGroupTab3FieldsDataDao customGroupTab3FieldsDataDao; @Autowired EmpcntProjectActivityDataDao empcntProjectActivityDataDao; @Autowired ProjectMasterDao projectMasterDao; /* * (non-Javadoc) * * @see com.ugam.collage.plus.service.PeopleAccountingService# * getEmpcntClientProjectData(java.lang.Integer, java.lang.Integer, * java.lang.String, java.lang.Integer) */ @Override public List<EmpcntClientProjectDataVo> getEmpcntClientProjectData(Integer yearId, Integer monthId, String costCentreId, Integer classificationId) { List<EmpcntClientProjectData> empcntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); List<EmpcntClientProjectDataVo> empcntClientProjectDataVoList = new ArrayList<EmpcntClientProjectDataVo>(); for (EmpcntClientProjectData empcntClientProjectData : empcntClientProjectDataList) { EmpcntClientProjectDataVo empcntClientProjectDataVo = new EmpcntClientProjectDataVo(); // TODO: set model data in vo empcntClientProjectDataVoList.add(empcntClientProjectDataVo); } return empcntClientProjectDataVoList; } /* * (non-Javadoc) * * @see com.ugam.collage.plus.service.PeopleAccountingService#runAlgorithm * (java.lang.Integer, java.lang.Integer, java.lang.String) */ @Override public PCValidationSummaryVo validateEmployeeSummary(Integer yearId, Integer monthId, String costCentreId) { List<EmployeeSummaryCssplit> employeeSummaryCssplitList = employeeSummaryCssplitDao .findByYearIdMonthIdConstCentreId(yearId, monthId, costCentreId); if (employeeSummaryCssplitList == null || employeeSummaryCssplitList.isEmpty()) { return null; } List<EmployeeSummaryTotal> employeeSummaryTotalList = employeeSummaryTotalDao.findByYeadIdAndMonthId(yearId, monthId); if (employeeSummaryTotalList == null || employeeSummaryTotalList.isEmpty()) { return null; } List<EmployeeMonthlyAssignment> openCountList = employeeMonthlyAssignmentDao.findByOpeningCount(yearId, monthId, costCentreId); List<EmployeeMonthlyAssignment> closingCountList = employeeMonthlyAssignmentDao.findByClosingCount(yearId, monthId, costCentreId); PCValidationSummaryVo pcValidationSummaryVo = new PCValidationSummaryVo(); Boolean summaryCountMatch = false; Boolean masterOpeningCount = false; Boolean masterCloseCount = false; EmployeeSummaryCssplit employeeSummaryCssplit = employeeSummaryCssplitList.get(0); EmployeeSummaryTotal employeeSummaryTotal = employeeSummaryTotalList.get(0); if (employeeSummaryCssplit == null || employeeSummaryTotal == null) { return null; } // TODO: check the below condition after putiing the data if (openCountList == null || openCountList.isEmpty() || closingCountList == null || closingCountList.isEmpty()) { return null; } // Get Count Match Summary List<IdNameValueVo<String>> countMatchSummaryList = new ArrayList<IdNameValueVo<String>>(); if (employeeSummaryCssplit.getOpeningCnt() == employeeSummaryTotal.getOpeningCnt() && employeeSummaryCssplit.getClosingCnt() == employeeSummaryTotal.getClosingCnt() && employeeSummaryCssplit.getAverageCnt() == employeeSummaryTotal.getAverageCnt()) { summaryCountMatch = true; IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(1, "Overall Count", COUNT_MATCH, " "); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Overall Count}===>{COUNT_MATCH}:" + // summaryCountMatch); } else { IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(1, "Overall Count", COUNT_NOT_MATCHED, " "); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Overall Count}===>{COUNT_NOT_MATCHED}:" + // summaryCountMatch); } if (openCountList.size() == employeeSummaryCssplit.getOpeningCnt()) { masterOpeningCount = true; IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(2, "Opening Count", COUNT_MATCH, UI_DISPLAY_GROUP_FOR_SELECTED_COST_CENTER); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Opening Count}===>{COUNT_MATCH}:" + // masterOpeningCount); } else { IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(2, "Opening Count", COUNT_NOT_MATCHED, UI_DISPLAY_GROUP_FOR_SELECTED_COST_CENTER); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Opening Count}===>{COUNT_NOT_MATCHED}:" + // masterOpeningCount); } if (closingCountList.size() == employeeSummaryCssplit.getClosingCnt()) { masterCloseCount = true; IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(3, "Clossing Count", COUNT_MATCH, UI_DISPLAY_GROUP_FOR_SELECTED_COST_CENTER); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Clossing Count}===>{COUNT_MATCH}:" + // masterCloseCount); } else { IdNameValueVo<String> countMatchSummary = new IdNameValueVo<String>(3, "Clossing Count", COUNT_NOT_MATCHED, UI_DISPLAY_GROUP_FOR_SELECTED_COST_CENTER); countMatchSummaryList.add(countMatchSummary); // logger.debug("{Clossing Count}===>{COUNT_NOT_MATCHED}:" + // masterCloseCount); } pcValidationSummaryVo.setCountMatchSummary(countMatchSummaryList); // Get UnAllocated Data List<IdTextVo> unPickedPeopleDataList = new ArrayList<IdTextVo>(); List<EmployeeMonthlyAssignment> allUnPickedPeopleDataList = employeeMonthlyAssignmentDao .findUnPickedPeopleData(yearId, monthId, costCentreId); logger.debug("{People who have not been picked by anyone}===>{allUnPickedPeopleDataList.size()}:" + allUnPickedPeopleDataList.size()); if (unPickedPeopleDataList != null && !unPickedPeopleDataList.isEmpty()) { for (EmployeeMonthlyAssignment allUnPickedPeopleData : allUnPickedPeopleDataList) { EmployeeMaster employee = allUnPickedPeopleData.getEmployeeMaster(); IdTextVo idTextVo = new IdTextVo(employee.getEmployeeId(), employee.getEmployeeName()); unPickedPeopleDataList.add(idTextVo); } } pcValidationSummaryVo.setUnPickedPeopleData(unPickedPeopleDataList); // Get UnAllocated People Data List<IdTextVo> unAllocatedPeopleDataList = new ArrayList<IdTextVo>(); List<EmployeeMonthlyAssignment> allUnAllocatedPeopleDataList = employeeMonthlyAssignmentDao .findUnAllocatedPeopleData(yearId, monthId, costCentreId); logger.debug( "{People who are not part of any client-project team-structure}===>{allUnAllocatedPeopleDataList.size()}:" + allUnAllocatedPeopleDataList.size()); if (allUnAllocatedPeopleDataList != null && !allUnAllocatedPeopleDataList.isEmpty()) { for (EmployeeMonthlyAssignment allUnAllocatedPeopleData : allUnAllocatedPeopleDataList) { EmployeeMaster employee = allUnAllocatedPeopleData.getEmployeeMaster(); IdTextVo idTextVo = new IdTextVo(employee.getEmployeeId(), employee.getEmployeeName()); unAllocatedPeopleDataList.add(idTextVo); } } pcValidationSummaryVo.setUnAllocatedPeopleData(unAllocatedPeopleDataList); // Get client project summary boolean isFalse = false; List<ClientProjectStatusVo> clientProjectSummaryList = new ArrayList<ClientProjectStatusVo>(); // executionDataDao for type one List<ExecutionData> executionDataListTypeOne = executionDataDao.findByTypeOne(yearId, monthId, costCentreId); if (executionDataListTypeOne != null && !executionDataListTypeOne.isEmpty()) { for (ExecutionData executionData : executionDataListTypeOne) { ClientProjectStatusVo clientProjectStatusVo = new ClientProjectStatusVo( executionData.getProjectMaster().getProjectId(), executionData.getProjectName(), executionData.getCompanyMaster().getCompanyId(), executionData.getCompanyName(), isFalse, BigDecimal.ZERO); clientProjectSummaryList.add(clientProjectStatusVo); } } List<ExecutionData> executionDataListTypeTwo = executionDataDao.findByTypeTwo(yearId, monthId, costCentreId); if (executionDataListTypeTwo != null && !executionDataListTypeTwo.isEmpty()) { BigDecimal revenue = BigDecimal.ZERO; for (ExecutionData executionData : executionDataListTypeTwo) { // collageProjectRevenueDao for type 2 List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdPrjectIdZohoId(yearId, monthId, executionData.getProjectMaster().getProjectId(), executionData.getZohoMaster().getZohoId()); // logger.debug("{Project revenue }===>{collageProjectRevenueList.size()}:" // + collageProjectRevenueList.size()); if (collageProjectRevenueList != null & !collageProjectRevenueList.isEmpty()) { revenue = collageProjectRevenueList.get(0).getRevenueValue(); } ClientProjectStatusVo clientProjectStatusVo = new ClientProjectStatusVo( executionData.getProjectMaster().getProjectId(), executionData.getProjectName(), executionData.getCompanyMaster().getCompanyId(), executionData.getCompanyName(), isFalse, revenue); clientProjectSummaryList.add(clientProjectStatusVo); } } pcValidationSummaryVo.setClientProjectSummary(clientProjectSummaryList); return pcValidationSummaryVo; } /* * (non-Javadoc) * * @see * com.ugam.collage.plus.service.PeopleAccountingService#generateEmployeeSummary * (java.lang.Integer, java.lang.Integer, java.lang.String) */ @Override public List<EmpcntClientProjectDataVo> generateEmployeeSummary(Integer yearId, Integer monthId, String costCentreId) { List<EmpcntClientProjectDataVo> empcntClientProjectDataVoList = new ArrayList<EmpcntClientProjectDataVo>(); List<EmpcntClientProjectData> empcntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); List<EmpcntClientProjectData> empOpenCntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); List<EmpcntClientProjectData> empCloseCntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); List<EmpcntClientProjectData> empAverageCntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); List<EmpcntProjectActivityData> empcntProjectActivityDataList = new ArrayList<EmpcntProjectActivityData>(); Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap = new HashMap<String, EmployeePcTagsTeamStruct>(); // Get opening count loop List<EmployeeMonthlyAssignment> openCountList = employeeMonthlyAssignmentDao.findByOpeningCount(yearId, monthId, costCentreId); // Get closing count loop List<EmployeeMonthlyAssignment> closingCountList = employeeMonthlyAssignmentDao.findByClosingCount(yearId, monthId, costCentreId); Integer openCountTypeId = Constants.COUNT_CLASSIFICATION_TYPE_OPENING; Integer closeCountTypeId = 2; // logger.debug("{Opening Count }===>openCountList.size()}:" + // openCountList.size()); // logger.debug("{Close Count }===>closingCountList.size()}:" + // closingCountList.size()); // Check For Opening Count Rule for (EmployeeMonthlyAssignment openCount : openCountList) { List<Integer> employeeIdList = new ArrayList<Integer>(); employeeIdList.add(openCount.getEmployeeMaster().getEmployeeId()); Integer ruleId = openCount.getEmployeeCntRulesByOpeningRuleId().getId(); // logger.debug("Rule Id:===========================>" +ruleId); switch (ruleId) { case 1: // logger.debug("{Opening Count EmployeeMonthlyAssignment}===>getEmployeeMaster}:" // + openCount.getEmployeeMaster()); defaultRule(yearId, monthId, costCentreId, empcntClientProjectDataVoList, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 2: ruleOne(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 3: ruleTwo(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 4: ruleThree(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 5: ruleFour(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 6: ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; case 7: ruleSix(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, openCount, openCountTypeId, employeePcTagsTeamStructMap); break; } } // logger.debug("{Clossing Count }===>openCountList.size()}:" + // closingCountList.size()); // Check For Clossing Count Rule for (EmployeeMonthlyAssignment closingCount : closingCountList) { List<Integer> employeeIdList = new ArrayList<Integer>(); employeeIdList.add(closingCount.getEmployeeMaster().getEmployeeId()); Integer ruleId = closingCount.getEmployeeCntRulesByOpeningRuleId().getId(); switch (ruleId) { case 1: defaultRule(yearId, monthId, costCentreId, empcntClientProjectDataVoList, empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, empAverageCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 2: ruleOne(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 3: ruleTwo(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 4: ruleThree(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 5: ruleFour(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 6: ruleFive(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; case 7: ruleSix(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empAverageCntClientProjectDataList, empCloseCntClientProjectDataList, employeeIdList, closingCount, closeCountTypeId, employeePcTagsTeamStructMap); break; } } // Need to implement for Cost centre CI if (costCentreId.equalsIgnoreCase("CI")) { for (EmpcntClientProjectData empcntClientProjectData : empcntClientProjectDataList) { // Get Data Id for given Employee Id List<CustomGroupTab3FieldsData> customGroupTab3FieldsDataList = customGroupTab3FieldsDataDao .findByYearIdMonthIdDataId(yearId, monthId, empcntClientProjectData.getEmployeeMaster().getEmployeeId()); if (customGroupTab3FieldsDataList.isEmpty()) { ActivityFinanceMaster activityFinanceMaster = new ActivityFinanceMaster(); activityFinanceMaster.setActFinId(4); EmpcntProjectActivityData empcntProjectActivityData = new EmpcntProjectActivityData( empcntClientProjectData.getEmployeeMaster(), activityFinanceMaster, empcntClientProjectData.getCountClassification(), empcntClientProjectData.getTabMonth(), empcntClientProjectData.getProjectMaster(), empcntClientProjectData.getTabYear(), empcntClientProjectData.getCostCentre(), empcntClientProjectData.getAssignedCnt(), empcntClientProjectData.getAssistedCnt(), empcntClientProjectData.getApportionedCnt(), empcntClientProjectData.getTotalCnt()); empcntProjectActivityDataList.add(empcntProjectActivityData); } else { ActivityFinanceMaster activityFinanceMaster = new ActivityFinanceMaster(); activityFinanceMaster.setActFinId(customGroupTab3FieldsDataList.get(0).getDataId()); EmpcntProjectActivityData empcntProjectActivityData = new EmpcntProjectActivityData( empcntClientProjectData.getEmployeeMaster(), activityFinanceMaster, empcntClientProjectData.getCountClassification(), empcntClientProjectData.getTabMonth(), empcntClientProjectData.getProjectMaster(), empcntClientProjectData.getTabYear(), empcntClientProjectData.getCostCentre(), empcntClientProjectData.getAssignedCnt(), empcntClientProjectData.getAssistedCnt(), empcntClientProjectData.getApportionedCnt(), empcntClientProjectData.getTotalCnt()); empcntProjectActivityDataList.add(empcntProjectActivityData); } } } // Calcuate Average count Map<String, EmpcntClientProjectData> openDataMap = new HashMap<String, EmpcntClientProjectData>(); Map<String, EmpcntClientProjectData> closeDataMap = new HashMap<String, EmpcntClientProjectData>(); if (!empOpenCntClientProjectDataList.isEmpty() && !empCloseCntClientProjectDataList.isEmpty()) { // y_m_e_c_p_c_ for (EmpcntClientProjectData openData : empOpenCntClientProjectDataList) { Integer empId = openData.getEmployeeMaster().getEmployeeId(); Integer compId = openData.getCompanyMaster().getCompanyId(); Integer proId = openData.getProjectMaster().getProjectId(); String key = yearId + "-" + monthId + "-" + empId + "-" + compId + "-" + proId + "-" + 1; // logger.debug("Open Map key:"+key); openDataMap.put(key, openData); } for (EmpcntClientProjectData closedata : empCloseCntClientProjectDataList) { Integer empId = closedata.getEmployeeMaster().getEmployeeId(); Integer compId = closedata.getCompanyMaster().getCompanyId(); Integer proId = closedata.getProjectMaster().getProjectId(); String key = yearId + "-" + monthId + "-" + empId + "-" + compId + "-" + proId + "-" + 2; // logger.debug("Close Map key:"+key); closeDataMap.put(key, closedata); } } // Calcuate Average count Map<String, EmpcntClientProjectData> openDatas = new HashMap<String, EmpcntClientProjectData>(); Map<String, EmpcntClientProjectData> closeDatas = new HashMap<String, EmpcntClientProjectData>(); if (empOpenCntClientProjectDataList.isEmpty() || empCloseCntClientProjectDataList.isEmpty()) { // logger.debug("List is empty"); return null; } else if (!openDataMap.isEmpty() && !closeDataMap.isEmpty()) { // y_m_e_c_p_c_ Integer openCount = openDataMap.size(); Integer closeCount = closeDataMap.size(); BigDecimal averageCount = new BigDecimal(2); for (String keyVal : openDataMap.keySet()) { EmpcntClientProjectData openData = openDataMap.get(keyVal); Integer empId = openData.getEmployeeMaster().getEmployeeId(); Integer compId = openData.getCompanyMaster().getCompanyId(); Integer proId = openData.getProjectMaster().getProjectId(); String key = yearId + "-" + monthId + "-" + empId + "-" + compId + "-" + proId + "-" + 2; // logger.debug("Average key:"+key); openDatas.put(key, openData); } for (String keyVal : closeDataMap.keySet()) { logger.debug("Close Map key:" + keyVal); EmpcntClientProjectData closedata = closeDataMap.get(keyVal); Integer empId = closedata.getEmployeeMaster().getEmployeeId(); Integer compId = closedata.getCompanyMaster().getCompanyId(); Integer proId = closedata.getProjectMaster().getProjectId(); String key = yearId + "-" + monthId + "-" + empId + "-" + compId + "-" + proId + "-" + 2; logger.debug("Average key:" + key); closeDatas.put(key, closedata); } if (openCount == closeCount) { for (String key : openDatas.keySet()) { EmpcntClientProjectData avgData = openDatas.get(key); CountClassification avgCount = new CountClassification(); avgCount.setId(3); EmployeeMaster employee = avgData.getEmployeeMaster(); TabMonth month = avgData.getTabMonth(); TabYear year = avgData.getTabYear(); CostCentre costCentre = avgData.getCostCentre(); EmpcntClientProjectData averageEmpcntClientProjectData = new EmpcntClientProjectData(employee, avgData.getCompanyMaster(), avgCount, month, avgData.getProjectMaster(), year, costCentre, avgData.getAssignedCnt(), avgData.getAssistedCnt(), avgData.getApportionedCnt(), avgData.getTotalCnt()); empAverageCntClientProjectDataList.add(averageEmpcntClientProjectData); } } if (openCount < closeCount) { for (String key : closeDatas.keySet()) { if (openDatas.containsKey(key)) { EmpcntClientProjectData avgData = openDatas.get(key); CountClassification avgCount = new CountClassification(); avgCount.setId(3); EmployeeMaster employee = avgData.getEmployeeMaster(); TabMonth month = avgData.getTabMonth(); TabYear year = avgData.getTabYear(); CostCentre costCentre = avgData.getCostCentre(); EmpcntClientProjectData averageEmpcntClientProjectData = new EmpcntClientProjectData( employee, avgData.getCompanyMaster(), avgCount, month, avgData.getProjectMaster(), year, costCentre, avgData.getAssignedCnt(), avgData.getAssistedCnt(), avgData.getApportionedCnt(), avgData.getTotalCnt()); empAverageCntClientProjectDataList.add(averageEmpcntClientProjectData); } else { EmpcntClientProjectData avgData = closeDatas.get(key); CountClassification avgCount = new CountClassification(); avgCount.setId(3); EmployeeMaster employee = avgData.getEmployeeMaster(); TabMonth month = avgData.getTabMonth(); TabYear year = avgData.getTabYear(); CostCentre costCentre = avgData.getCostCentre(); ProjectMaster projectMaster = avgData.getProjectMaster(); CompanyMaster companyMaster = avgData.getCompanyMaster(); BigDecimal assignedCnt = avgData.getAssignedCnt(); assignedCnt = assignedCnt.divide(averageCount); BigDecimal asssistedCnt = avgData.getAssistedCnt(); asssistedCnt = asssistedCnt.divide(averageCount); BigDecimal apportionedCnt = avgData.getApportionedCnt(); apportionedCnt = apportionedCnt.divide(averageCount); BigDecimal totalCnt = avgData.getTotalCnt(); totalCnt = totalCnt.divide(averageCount); EmpcntClientProjectData averageEmpcntClientProjectData = new EmpcntClientProjectData( employee, companyMaster, avgCount, month, projectMaster, year, costCentre, assignedCnt, asssistedCnt, apportionedCnt, totalCnt); empAverageCntClientProjectDataList.add(averageEmpcntClientProjectData); } } } if (openCount > closeCount) { for (String key : openDatas.keySet()) { if (closeDatas.containsKey(key)) { EmpcntClientProjectData avgData = openDatas.get(key); CountClassification avgCount = new CountClassification(); avgCount.setId(3); EmployeeMaster employee = avgData.getEmployeeMaster(); TabMonth month = avgData.getTabMonth(); TabYear year = avgData.getTabYear(); CostCentre costCentre = avgData.getCostCentre(); EmpcntClientProjectData averageEmpcntClientProjectData = new EmpcntClientProjectData( employee, avgData.getCompanyMaster(), avgCount, month, avgData.getProjectMaster(), year, costCentre, avgData.getAssignedCnt(), avgData.getAssistedCnt(), avgData.getApportionedCnt(), avgData.getTotalCnt()); empAverageCntClientProjectDataList.add(averageEmpcntClientProjectData); } else { EmpcntClientProjectData avgData = openDatas.get(key); CountClassification avgCount = new CountClassification(); avgCount.setId(3); EmployeeMaster employee = avgData.getEmployeeMaster(); TabMonth month = avgData.getTabMonth(); TabYear year = avgData.getTabYear(); CostCentre costCentre = avgData.getCostCentre(); ProjectMaster projectMaster = avgData.getProjectMaster(); CompanyMaster companyMaster = avgData.getCompanyMaster(); BigDecimal assignedCnt = avgData.getAssignedCnt(); assignedCnt = assignedCnt.divide(averageCount); BigDecimal asssistedCnt = avgData.getAssistedCnt(); asssistedCnt = asssistedCnt.divide(averageCount); BigDecimal apportionedCnt = avgData.getApportionedCnt(); apportionedCnt = apportionedCnt.divide(averageCount); BigDecimal totalCnt = avgData.getTotalCnt(); totalCnt = totalCnt.divide(averageCount); EmpcntClientProjectData averageEmpcntClientProjectData = new EmpcntClientProjectData( employee, companyMaster, avgCount, month, projectMaster, year, costCentre, assignedCnt, asssistedCnt, apportionedCnt, totalCnt); empAverageCntClientProjectDataList.add(averageEmpcntClientProjectData); } } } } // Delete old values if (!empOpenCntClientProjectDataList.isEmpty() && !empCloseCntClientProjectDataList.isEmpty()) { logger.debug("********************IN DELETE*****************************"); List<EmpcntClientProjectData> empCountClientProjectDataList = empcntClientProjectDataDao .findByYearIdMonthIdCostCentreId(yearId, monthId, costCentreId); logger.debug("empCountClientProjectDataList size ===>" + empCountClientProjectDataList.size()); for (EmpcntClientProjectData empcntClientProjectData : empCountClientProjectDataList) { empcntClientProjectDataDao.delete(empcntClientProjectData); } } logger.debug("----------------------------->Open Map size:" + openDataMap.size()); logger.debug("----------------------------->Close Map size:" + closeDataMap.size()); if (!openDataMap.isEmpty() && !empCloseCntClientProjectDataList.isEmpty()) { logger.debug("**************************************************"); for (String keyVal : openDataMap.keySet()) { EmpcntClientProjectData empcntClientProjectData = openDataMap.get(keyVal); empcntClientProjectDataDao.create(empcntClientProjectData); } for (String keyVal : closeDataMap.keySet()) { EmpcntClientProjectData empcntClientProjectData = closeDataMap.get(keyVal); empcntClientProjectDataDao.create(empcntClientProjectData); } // Save Average count list data if (!empAverageCntClientProjectDataList.isEmpty()) { for (EmpcntClientProjectData empcntClientProjectData : empAverageCntClientProjectDataList) { empcntClientProjectDataDao.create(empcntClientProjectData); } } for (EmpcntProjectActivityData empcntProjectActivityData : empcntProjectActivityDataList) { empcntProjectActivityDataDao.create(empcntProjectActivityData); } } if (!employeePcTagsTeamStructMap.isEmpty()) { for (String key : employeePcTagsTeamStructMap.keySet()) { EmployeePcTagsTeamStruct employeePcTagsTeamStruct = employeePcTagsTeamStructMap.get(key); employeePcTagsTeamStructDao.saveOrUpdate(employeePcTagsTeamStruct); } } else { logger.debug("===>Somthing wrong happen. Please run again"); } Integer typeId = 1; empcntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); empcntClientProjectDataList = empcntClientProjectDataDao.findByYearIdMonthIdCostCentreIdTypeId(yearId, monthId, costCentreId, typeId); for (EmpcntClientProjectData empcntClientProjectData : empcntClientProjectDataList) { EmpcntClientProjectDataVo empcntClientProjectDataVo = new EmpcntClientProjectDataVo( empcntClientProjectData.getTabYear().getYearId(), empcntClientProjectData.getTabMonth().getMonthId(), empcntClientProjectData.getEmployeeMaster().getEmployeeId(), empcntClientProjectData.getCountClassification().getId(), empcntClientProjectData.getProjectMaster().getProjectName(), empcntClientProjectData.getCompanyMaster().getCompanyName(), empcntClientProjectData.getAssignedCnt(), empcntClientProjectData.getAssistedCnt(), empcntClientProjectData.getApportionedCnt(), empcntClientProjectData.getTotalCnt()); empcntClientProjectDataVo.setId(empcntClientProjectData.getId()); empcntClientProjectDataVoList.add(empcntClientProjectDataVo); } List<BigDecimal> apportionCount = employeePcTagsTeamStructDao.findByYearIdMonthIdCostCentreId(yearId, monthId, costCentreId); logger.debug("*************************************===>" + apportionCount.size()); if (!apportionCount.isEmpty()) { BigDecimal count = apportionCount.get(0); EmpcntClientProjectDataVo apportionCountVo = new EmpcntClientProjectDataVo(yearId, monthId, 0, 0, "No-Client", "No-Project", BigDecimal.ZERO, BigDecimal.ZERO, count, count); empcntClientProjectDataVoList.add(apportionCountVo); } return empcntClientProjectDataVoList; } /** * @param yearId * @param monthId * @param costCentreId * @param empcntClientProjectDataVoList * @param empcntClientProjectDataList * @param employeeIdList * @param employeeMonthlyAssignmentCount */ private void defaultRule(Integer yearId, Integer monthId, String costCentreId, List<EmpcntClientProjectDataVo> empcntClientProjectDataVoList, List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpcntClientProjectData> empAverageCntClientProjectDataList, List<Integer> employeeIdList, EmployeeMonthlyAssignment employeeMonthlyAssignmentCount, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { long averageCount = 0; for (Integer i : employeeIdList) { logger.debug("defaultRule employeeId===>" + i); } // get the employee aligned project for opening count List<EmpClientProjectTeamStruct> empClientProjectTeamStructList = empClientProjectTeamStructDao .findByYearMonthTypeEmps(yearId, monthId, countTypeId, employeeIdList); // Get available project under billed project List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao.findByYearIdMonthId(yearId, monthId); // Get all revenue project ids Set<Integer> revenueProjects = new HashSet<Integer>(); for (CollageProjectRevenue collageProjectRevenue : collageProjectRevenueList) { revenueProjects.add(collageProjectRevenue.getProjectMaster().getProjectId()); } EmployeeMaster employee = employeeMonthlyAssignmentCount.getEmployeeMaster(); TabMonth month = employeeMonthlyAssignmentCount.getTabMonth(); TabYear year = employeeMonthlyAssignmentCount.getTabYear(); CostCentre costCentre = employeeMonthlyAssignmentCount.getCostCentre(); CountClassification countType = new CountClassification(); countType.setId(countTypeId); BigDecimal allignedTimeZero = BigDecimal.ZERO; BigDecimal assistedTimeZero = BigDecimal.ZERO; BigDecimal apportionedTimeZero = BigDecimal.ZERO; BigDecimal allignedTimeOne = BigDecimal.ONE; BigDecimal apportionedTimeOne = BigDecimal.ONE; BigDecimal totalTimeOne = BigDecimal.ONE; if (empClientProjectTeamStructList.isEmpty()) { // logger.debug("Assigned count is zero===>"); getZeroProjectsDetail(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, apportionedTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // check for count ==1 else if (empClientProjectTeamStructList.size() == 1) { // logger.debug("Assigned count is one===>"); getSingleProjectDetail(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, empClientProjectTeamStructList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, apportionedTimeZero, allignedTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // check for count >1 else if (empClientProjectTeamStructList.size() > 1) { // logger.debug("Assigned count is greater one===>"); getMultipleProjectDetail(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, empClientProjectTeamStructList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, apportionedTimeZero, allignedTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // Validate result List<EmployeeSummaryCssplit> employeeSummaryCssplitList = employeeSummaryCssplitDao .findByYearIdMonthIdConstCentreId(yearId, monthId, costCentreId); // Validate opening count and closing count and generate Average list EmployeeSummaryCssplit employeeSummaryCssplit = employeeSummaryCssplitList.get(0); } /** * @param empcntClientProjectDataList * @param empClientProjectTeamStructList * @param employee * @param month * @param year * @param costCentre * @param countType * @param allignedTimeZero * @param assistedTimeZero * @param apportionedTimeZero * @param allignedTimeOne * @param totalTimeOne * @return */ private void getMultipleProjectDetail(List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpClientProjectTeamStruct> empClientProjectTeamStructList, EmployeeMaster employee, TabMonth month, TabYear year, CostCentre costCentre, CountClassification countType, BigDecimal allignedTimeZero, BigDecimal assistedTimeZero, BigDecimal apportionedTimeZero, BigDecimal allignedTimeOne, BigDecimal totalTimeOne, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { logger.debug("<====getMultipleProjectDetail START====>"); Integer employeeId = employee.getEmployeeId(); Integer yearId = year.getYearId(); Integer monthId = month.getMonthId(); String costCentreId = costCentre.getCostCentreId(); BigDecimal deviderHour = new BigDecimal(Constants.TOTAL_WORKING_HOURS); logger.debug("getMultipleProjectDetail parameter===>" + employeeId + "::" + yearId + "::" + monthId + "::" + costCentreId + "::" + deviderHour); // 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()); // For all invalid projects calculate count zero if (validEmployeeProjectIds.isEmpty()) { getZeroProjectsDetail(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, totalTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // Get list of project from execution data for that employee List<Integer> projectIdList = executionDataDao.findByPersonYearMonthCostCentre(employeeId, yearId, monthId, costCentreId); // logger.debug("execution data projects===>" + projectIdList.size()); // If List is empty if (projectIdList.isEmpty()) { // logger.debug("Contain InValid projects (: Find by Revenue)===>"); Map<Integer, BigDecimal> projectRevenueMap = new HashMap<Integer, BigDecimal>(); BigDecimal sumOfRevenue = BigDecimal.ZERO; List<Object[]> collageProjectRevenueList = collageProjectRevenueDao.findByCostCentreIdYearIdMonthId( costCentre.getCostCentreId(), year.getYearId(), month.getMonthId()); for (Object[] collageProjectRevenue : collageProjectRevenueList) { Integer projectId = (Integer) collageProjectRevenue[0]; BigDecimal revenue = (BigDecimal) collageProjectRevenue[1]; projectRevenueMap.put(projectId, revenue); } // logger.debug("projectRevenueMap size===>" + // projectRevenueMap.size()); for (Integer key : projectRevenueMap.keySet()) { sumOfRevenue = sumOfRevenue.add(projectRevenueMap.get(key)); } logger.debug("sumOfRevenue===>" + sumOfRevenue); for (Integer projectId : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal revenue = projectRevenueMap.get(projectId); logger.debug("revenue===>" + revenue); BigDecimal projectRevenueCount = revenue.divide(sumOfRevenue, 2, RoundingMode.HALF_EVEN); projectRevenueCount = projectRevenueCount.setScale(2, RoundingMode.CEILING); // logger.debug("685 empOpenCntClientProjectData ProjectId:Revenue===>"+projectId+" : " // + projectRevenueCount); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, projectRevenueCount, BigDecimal.ZERO, BigDecimal.ZERO, projectRevenueCount); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Else Contain Valid projects===>"); Integer validEmployeeProjectCount = validEmployeeProjectIds.size(); // Get valid projects list=>project is both revenue data and // execution data Set<Integer> validAllProjects = new HashSet<Integer>(); for (Integer projectId : projectIdList) { List<CollageProjectRevenue> listValues = collageProjectRevenueDao .findByYearIdMonthIdProjectIdCostCentreId(yearId, monthId, projectId, costCentreId); if (!listValues.isEmpty()) { validAllProjects.add(projectId); } } Integer validAllProjectCount = validAllProjects.size(); // logger.debug("validAllProjects :size===>" + // validAllProjects.size()); // Total hour worked by an Employee List<BigDecimal> toatalHours = executionDataDao.findByPersonIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); BigDecimal toatlTime = toatalHours.get(0); // logger.debug("ToatalHours===>" + toatlTime); // Separate assigned projects from execution data projects Map<Integer, BigDecimal> assignedProjects = new HashMap<Integer, BigDecimal>(); Map<Integer, BigDecimal> unAssignedProjects = new HashMap<Integer, BigDecimal>(); List<Object[]> allProjectTimeList = executionDataDao .findByEmployeeIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); for (Object[] result : allProjectTimeList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; if (validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("UnAssignedProjects===>" + // projectId+"::"+hour+"::"+companyId); assignedProjects.put(projectId, hour); } if (!validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("assignedProjects===>" + // projectId+"::"+hour+"::"+companyId); unAssignedProjects.put(projectId, hour); } } if (validEmployeeProjectCount == validAllProjectCount && validAllProjects.containsAll(validEmployeeProjectIds.keySet()) && unAssignedProjects.isEmpty()) { // logger.debug("validEmployeeProjectCount==validAllProjectCount :(Only in assigned projects)"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); // logger.debug("744 : Worked hours (Only in assigned projects) 1===>"+timeByProject+ // " : "+toatlTime); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("745: Worked hours (Only in assigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, workedHours, assistedTimeZero, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else if (!assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("validEmployeeProjectCount!=validAllProjectCount :(Both in assigned and unassigned projects)"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("768: Aligned hours (Both in assigned and unassigned projects) 1===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, workedHours, assistedTimeZero, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("787: Assisted hours (Both in assigned and unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; // logger.debug("Project Id===>"+key); BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); // Assign to assisted count for unAssignedProjects List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("811: Assisted hours (Both in assigned and unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } totalUnAssingnedHours = BigDecimal.ONE.subtract(totalUnAssingnedHours); // logger.debug("totalUnAssingnedHours===> "+totalUnAssingnedHours); for (Map.Entry<Integer, BigDecimal> entry : assignedProjects.entrySet()) { assingnedHours = assingnedHours.add(entry.getValue()); } // logger.debug("Aligned Hours===> "+assingnedHours); for (Integer key : assignedProjects.keySet()) { Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); // logger.debug("831 :projectId : timeByProject===> "+projectId+" : "+timeByProject); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal averageWorkedHours = timeByProject.divide(assingnedHours, 2, RoundingMode.HALF_EVEN); // logger.debug("834 :averageWorkedHours : assingnedHours===> "+averageWorkedHours+" : "+assingnedHours); BigDecimal actualWorkedHours = averageWorkedHours.multiply(totalUnAssingnedHours); actualWorkedHours = actualWorkedHours.setScale(2, RoundingMode.CEILING); // logger.debug("836: actualWorkedHours : totalUnAssingnedHours 2===>"+actualWorkedHours+" : "+totalUnAssingnedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, actualWorkedHours, assistedTimeZero, apportionedTimeZero, actualWorkedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } } else if (assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("Only in unassigned projects===>"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug(" unassigned projects Worked hours===> >=168"); for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("860: Assisted hours (Both in assigned and unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("unassigned projects Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); // Assign to assisted count for unAssignedProjects List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("884: Assisted hours in unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } // logger.debug("totalUnAssingnedHours===> "+totalUnAssingnedHours); if (totalUnAssingnedHours.compareTo(BigDecimal.ONE) == -1) { BigDecimal remainProportion = BigDecimal.ONE.subtract(totalUnAssingnedHours); getRevenueCountProportion(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, remainProportion, unAssignedProjects, countTypeId, employeePcTagsTeamStructMap); } } } } // logger.debug("<====getMultipleProjectDetail END====>"); } /** * @param empcntClientProjectDataList * @param empClientProjectTeamStructList * @param employee * @param month * @param year * @param costCentre * @param countType * @param allignedTimeZero * @param assistedTimeZero * @param apportionedTimeZero * @param allignedTimeOne * @param totalTimeOne */ private void getSingleProjectDetail(List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, List<EmpClientProjectTeamStruct> empClientProjectTeamStructList, EmployeeMaster employee, TabMonth month, TabYear year, CostCentre costCentre, CountClassification countType, BigDecimal allignedTimeZero, BigDecimal assistedTimeZero, BigDecimal apportionedTimeZero, BigDecimal allignedTimeOne, BigDecimal totalTimeOne, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { /* * Also assign to assisted if project detail present in both assigned * and unassigned list * * Note : Only in unassigned project . do the remaining count as per * revenue to apportion * * If not present in revenue table then go to zero project details */ logger.debug("<====getSingleProjectDetail START====>"); Integer employeeId = employee.getEmployeeId(); Integer yearId = year.getYearId(); Integer monthId = month.getMonthId(); String costCentreId = costCentre.getCostCentreId(); BigDecimal deviderHour = new BigDecimal(Constants.TOTAL_WORKING_HOURS); logger.debug("getSingleProjectDetail parameter===>" + employeeId + "::" + yearId + "::" + monthId + "::" + costCentreId + "::" + deviderHour); // 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()) { getZeroProjectsDetail(yearId, monthId, costCentreId, empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, allignedTimeZero, assistedTimeZero, totalTimeOne, totalTimeOne, countTypeId, employeePcTagsTeamStructMap); } // Get list of project from execution data for that employee List<Integer> projectIdList = executionDataDao.findByPersonYearMonthCostCentre(employeeId, yearId, monthId, costCentreId); // logger.debug("execution data projects===>" + projectIdList.size()); if (projectIdList.isEmpty()) { // logger.debug("Contain InValid projects :(Assign count one)===>"); for (Integer projectId : validEmployeeProjectIds.keySet()) { EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); // logger.debug("978: Contain InValid projects :(Assign count one)===>"+1); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, allignedTimeOne, assistedTimeZero, apportionedTimeZero, allignedTimeOne); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } else if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Else Contain Valid projects===>"); Integer validEmployeeProjectCount = validEmployeeProjectIds.size(); // Get valid projects list=>project is both revenue data and // execution data Set<Integer> validAllProjects = new HashSet<Integer>(); for (Integer projectId : projectIdList) { List<CollageProjectRevenue> listValues = collageProjectRevenueDao .findByYearIdMonthIdProjectIdCostCentreId(yearId, monthId, projectId, costCentreId); if (!listValues.isEmpty()) { validAllProjects.add(projectId); } } Integer validAllProjectCount = validAllProjects.size(); // logger.debug("validAllProjects :size===>" + // validAllProjects.size()); // Total hour worked by an Employee List<BigDecimal> toatalHours = executionDataDao.findByPersonIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); BigDecimal toatlTime = toatalHours.get(0); // logger.debug("ToatalHours===>" + toatlTime); // Separate assigned projects from execution data projects Map<Integer, BigDecimal> assignedProjects = new HashMap<Integer, BigDecimal>(); Map<Integer, BigDecimal> unAssignedProjects = new HashMap<Integer, BigDecimal>(); List<Object[]> allProjectTimeList = executionDataDao .findByEmployeeIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); for (Object[] result : allProjectTimeList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; if (validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("UnAssignedProjects===>" + // projectId+"::"+hour+"::"+companyId); assignedProjects.put(projectId, hour); } if (!validEmployeeProjectIds.containsKey(projectId) && validAllProjects.contains(projectId)) { // logger.debug("assignedProjects===>" + // projectId+"::"+hour+"::"+companyId); unAssignedProjects.put(projectId, hour); } } if (validEmployeeProjectCount == 1 && validAllProjectCount == 1 && validAllProjects.containsAll(validEmployeeProjectIds.keySet()) && unAssignedProjects.isEmpty()) { // logger.debug("validEmployeeProjectCount==validAllProjectCount :(Only in assigned projects)"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); // logger.debug("1034 :validEmployeeProjectCount==validAllProjectCount :(Only in assigned projects)===>1"); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, allignedTimeOne, assistedTimeZero, apportionedTimeZero, allignedTimeOne); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else if (!assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("1047 : Both in assigned and unassigned projects===>"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : assignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1056 :assigned:(Both in assigned and unassigned projects===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, workedHours, assistedTimeZero, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1073 :unassigned :(Both in assigned and unassigned projects===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // Assign to assisted count for unAssignedProjects Integer projectId = key; List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("769: Assisted hours (Both in assigned and unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } totalUnAssingnedHours = BigDecimal.ONE.subtract(totalUnAssingnedHours); // logger.debug("totalUnAssingnedHours===> "+totalUnAssingnedHours); for (Map.Entry<Integer, BigDecimal> entry : assignedProjects.entrySet()) { assingnedHours = assingnedHours.add(entry.getValue()); } // logger.debug("assingnedHours===> "+assingnedHours); for (Integer key : assignedProjects.keySet()) { Integer projectId = key; BigDecimal timeByProject = assignedProjects.get(key); // logger.debug("1119 :projectId : timeByProject===> "+projectId+" : "+timeByProject); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal averageWorkedHours = timeByProject.divide(assingnedHours, 2, RoundingMode.HALF_EVEN); // logger.debug("1121 :assingnedHours : totalUnAssingnedHours===> "+assingnedHours+" : "+totalUnAssingnedHours); BigDecimal actualWorkedHours = averageWorkedHours.multiply(totalUnAssingnedHours); actualWorkedHours = actualWorkedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1124 :averageWorkedHours : actualWorkedHours===> "+averageWorkedHours+" : "+actualWorkedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, actualWorkedHours, assistedTimeZero, apportionedTimeZero, actualWorkedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } } else if (assignedProjects.isEmpty() && !unAssignedProjects.isEmpty()) { // logger.debug("In unassigned projects only===>"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id Integer projectId = key; BigDecimal timeByProject = unAssignedProjects.get(key); EmpClientProjectTeamStruct mapValues = validEmployeeProjectIds.get(projectId); BigDecimal workedHours = timeByProject.divide(toatlTime, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); // logger.debug("1148 :In unassigned projects only===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, mapValues.getCompanyMaster(), countType, month, mapValues.getProjectMaster(), year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal totalUnAssingnedHours = BigDecimal.ZERO; BigDecimal assingnedHours = BigDecimal.ZERO; for (Integer key : unAssignedProjects.keySet()) { // Get time spent on each project by employee id BigDecimal timeByProject = unAssignedProjects.get(key); BigDecimal workedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); workedHours = workedHours.setScale(2, RoundingMode.CEILING); totalUnAssingnedHours = totalUnAssingnedHours.add(workedHours); // Assign to assisted count for unAssignedProjects Integer projectId = key; List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); ProjectMaster projectMaster = projectList.get(0); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); // logger.debug("1173: Assisted hours (In unassigned projects) 2===>"+workedHours); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, apportionedTimeZero, workedHours, apportionedTimeZero, workedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } logger.debug("1209 totalUnAssingnedHours===> " + totalUnAssingnedHours); BigDecimal remainProportion = BigDecimal.ONE.subtract(totalUnAssingnedHours); logger.debug("remainProportion===> " + remainProportion); getRevenueCountProportion(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, remainProportion, unAssignedProjects, countTypeId, employeePcTagsTeamStructMap); } } } // logger.debug("<====getSingleProjectDetail END====>"); } /** * @param yearId * @param monthId * @param costCentreId * @param empcntClientProjectDataList * @param employee * @param month * @param year * @param costCentre * @param countType * @param allignedTimeOne * @param assistedTimeOne * @param apportionedTimeOne * @param totalTimeOne */ private void getZeroProjectsDetail(Integer yearId, Integer monthId, String costCentreId, List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, EmployeeMaster employee, TabMonth month, TabYear year, CostCentre costCentre, CountClassification countType, BigDecimal allignedTimeZero, BigDecimal assistedTimeZero, BigDecimal apportionedTimeOne, BigDecimal totalTimeOne, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { logger.debug("<====getZeroProjectsDetail START====>"); Integer employeeId = employee.getEmployeeId(); BigDecimal deviderHour = new BigDecimal(Constants.TOTAL_WORKING_HOURS); logger.debug("getZeroProjectsDetail parameter===>" + employeeId + "::" + yearId + "::" + monthId + "::" + costCentreId + "::" + deviderHour); // Get list of project from execution data for that employee List<Integer> projectIdList = executionDataDao.findByPersonYearMonthCostCentre(employeeId, yearId, monthId, costCentreId); // logger.debug("execution data projects===>" + projectIdList.size()); if (projectIdList.isEmpty()) { BigDecimal remainProportion = BigDecimal.ONE; Map<Integer, BigDecimal> assignedProjectsHour = new HashMap<Integer, BigDecimal>(); getRevenueCountProportion(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, remainProportion, assignedProjectsHour, countTypeId, employeePcTagsTeamStructMap); } else { // logger.debug("Else Project details present in execution data ===>"); // Get valid projects list=>project is both revenue data and // execution data Set<Integer> validAllProjects = new HashSet<Integer>(); for (Integer projectId : projectIdList) { List<CollageProjectRevenue> listValues = collageProjectRevenueDao .findByYearIdMonthIdProjectIdCostCentreId(yearId, monthId, projectId, costCentreId); if (!listValues.isEmpty()) { validAllProjects.add(projectId); } } // logger.debug("validAllProjects :size===>" + // validAllProjects.size()); // Total hour worked by an Employee List<BigDecimal> toatalHours = executionDataDao.findByPersonIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); BigDecimal toatlTime = toatalHours.get(0); // logger.debug("ToatalHours===>" + toatlTime); // Separate assigned projects from execution data projects Map<Integer, BigDecimal> assignedProjectsHour = new HashMap<Integer, BigDecimal>(); Map<Integer, Integer> assignedProjectsCompany = new HashMap<Integer, Integer>(); List<Object[]> allProjectTimeList = executionDataDao .findByEmployeeIdYearIdMonthIdCostCentreId(employeeId, yearId, monthId, costCentreId); for (Object[] result : allProjectTimeList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; if (validAllProjects.contains(projectId)) { // logger.debug("UnAssignedProjects===>" + // projectId+"::"+hour+"::"+companyId); assignedProjectsHour.put(projectId, hour); assignedProjectsCompany.put(projectId, companyId); } } /* * Do the calculation as per time spent on projects and put it to * assisted count */ // logger.debug("validEmployeeProjectCount!=validAllProjectCount :(Both in assigned and unassigned projects)"); if (toatlTime.compareTo(new BigDecimal(Constants.TOTAL_WORKING_HOURS)) >= 0) { // logger.debug("Worked hours===> >=168"); for (Integer key : assignedProjectsCompany.keySet()) { // Get time spent on each project by employee id Integer projectId = key; Integer companyIdByProject = assignedProjectsCompany.get(key); ProjectMaster projectMaster = new ProjectMaster(); projectMaster.setProjectId(projectId); CompanyMaster companyMaster = new CompanyMaster(); companyMaster.setCompanyId(companyIdByProject); // logger.debug("1254 :Both in assigned and unassigned projects======>"+totalTimeOne); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, allignedTimeZero, assistedTimeZero, apportionedTimeOne, totalTimeOne); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } } else { // logger.debug("Worked hours===> <168"); BigDecimal revenueProportion = BigDecimal.ZERO; for (Integer key : assignedProjectsHour.keySet()) { Integer projectId = key; // logger.debug("projectId===> "+projectId); BigDecimal timeByProject = assignedProjectsHour.get(key); Integer companyIdByProject = assignedProjectsCompany.get(key); ProjectMaster projectMaster = new ProjectMaster(); projectMaster.setProjectId(projectId); CompanyMaster companyMaster = new CompanyMaster(); companyMaster.setCompanyId(companyIdByProject); // logger.debug("timeByProject===> "+timeByProject); BigDecimal assistedHours = timeByProject.divide(deviderHour, 2, RoundingMode.HALF_EVEN); assistedHours = assistedHours.setScale(2, RoundingMode.CEILING); // logger.debug("assignedProjectsHour===> "+assingnedHours); revenueProportion = revenueProportion.add(assistedHours); logger.debug("1338 :======>" + revenueProportion); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, allignedTimeZero, assistedHours, allignedTimeZero, assistedHours); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } } /* * Revenue count put it to apportioned count */ // logger.debug("revenueProportion===> "+revenueProportion); if (revenueProportion.compareTo(BigDecimal.ONE) == -1) { BigDecimal remainProportion = BigDecimal.ONE.subtract(revenueProportion); logger.debug("remainProportion===> " + remainProportion); getRevenueCountProportion(empOpenCntClientProjectDataList, empCloseCntClientProjectDataList, employee, month, year, costCentre, countType, remainProportion, assignedProjectsHour, countTypeId, employeePcTagsTeamStructMap); } } } // logger.debug("<====getZeroProjectDetail END====>"); } /** * */ private void getRevenueCountProportion(List<EmpcntClientProjectData> empOpenCntClientProjectDataList, List<EmpcntClientProjectData> empCloseCntClientProjectDataList, EmployeeMaster employee, TabMonth month, TabYear year, CostCentre costCentre, CountClassification countType, BigDecimal remainProportion, Map<Integer, BigDecimal> unAssignedProjects, Integer countTypeId, Map<String, EmployeePcTagsTeamStruct> employeePcTagsTeamStructMap) { logger.debug("<====getRevenueCountProportion Start====>"); logger.debug("unAssignedProjects:" + unAssignedProjects.size()); // get the EmpCntPcApportionApproach for the employee Integer employeeId = employee.getEmployeeId(); Integer yearId = year.getYearId(); Integer monthId = month.getMonthId(); String costCentreId = costCentre.getCostCentreId(); BigDecimal deviderHour = new BigDecimal(Constants.TOTAL_WORKING_HOURS); Integer apportionApproach = 0; BigDecimal allignedTimeZero = BigDecimal.ZERO; BigDecimal asistededTimeZero = BigDecimal.ZERO; List<EmpCntPcApportionApproach> empCntPcApportionApproachList = empCntPcApportionApproachDao .findByYearIdMonthIdEmployeeId(yearId, monthId, employeeId); if (!empCntPcApportionApproachList.isEmpty()) { apportionApproach = empCntPcApportionApproachList.get(0).getApportionApproach(); } else { return; } // logger.debug("1363 : apportionApproach===> "+apportionApproach); // get the EmployeePcTagsTeamStruct for the employee List<EmployeePcTagsTeamStruct> employeePcTagsTeamStructList = employeePcTagsTeamStructDao .findByYearIdMonthIdEmployeeId(yearId, monthId, employeeId); if (apportionApproach == 1) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { BigDecimal count = BigDecimal.ZERO; Map<Integer, CollageProjectRevenue> revenueMap = new HashMap<Integer, CollageProjectRevenue>(); Map<Integer, ProjectMaster> projectMap = new HashMap<Integer, ProjectMaster>(); BigDecimal proportion = employeePcTagsTeamStruct.getProportion(); String profitcentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); // Calculate for each profit centre BigDecimal pcProportion = proportion.multiply(remainProportion); // asissted projects on count List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdProfitCentreIdCostCentreId(yearId, monthId, profitcentreId, costCentreId); if (!collageProjectRevenueList.isEmpty()) { // Select valid project id for (CollageProjectRevenue proRevenue : collageProjectRevenueList) { Integer projectId = proRevenue.getProjectMaster().getProjectId(); if (unAssignedProjects.isEmpty()) { revenueMap.put(projectId, proRevenue); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); projectMap.put(projectId, projectList.get(0)); } else { if (unAssignedProjects.containsKey(projectId) == false) { revenueMap.put(projectId, proRevenue); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); projectMap.put(projectId, projectList.get(0)); } } } Integer projectCount = revenueMap.size(); count = new BigDecimal(projectCount); if (projectCount > 0) { for (Integer key : revenueMap.keySet()) { BigDecimal projectValue = BigDecimal.ONE.divide(count, 2, RoundingMode.HALF_EVEN); projectValue = projectValue.multiply(pcProportion); ProjectMaster projectMaster = projectMap.get(key); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); projectValue = projectValue.setScale(2, RoundingMode.CEILING); // logger.debug("1406 projectValue:======>"+projectValue); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, allignedTimeZero, asistededTimeZero, projectValue, projectValue); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeId + "-" + profitcentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(projectValue); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } } } else if (apportionApproach == 2) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { BigDecimal count = BigDecimal.ZERO; Map<Integer, BigDecimal> hoursMap = new HashMap<Integer, BigDecimal>(); Map<Integer, Integer> companyMap = new HashMap<Integer, Integer>(); BigDecimal proportion = employeePcTagsTeamStruct.getProportion(); String profitcentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); // Calculate for each profit centre BigDecimal pcProportion = proportion.multiply(remainProportion); BigDecimal hoursSum = BigDecimal.ZERO; List<Object[]> objectList = executionDataDao.findByYearIdMonthIdCostCentreIdProfitCentreId(yearId, monthId, costCentreId, profitcentreId); if (!objectList.isEmpty()) { for (Object[] result : objectList) { Integer projectId = (Integer) result[0]; BigDecimal hour = (BigDecimal) result[1]; Integer companyId = (Integer) result[2]; if (unAssignedProjects.isEmpty()) { hoursMap.put(projectId, hour); companyMap.put(projectId, companyId); hoursSum.add(hour); } else { if (unAssignedProjects.containsKey(projectId) == false) { hoursMap.put(projectId, hour); companyMap.put(projectId, companyId); hoursSum.add(hour); } } } for (Integer projectId : hoursMap.keySet()) { BigDecimal hour = hoursMap.get(projectId); ProjectMaster projectMaster = new ProjectMaster(); projectMaster.setProjectId(projectId); Integer companyId = companyMap.get(projectId); CompanyMaster companyMaster = new CompanyMaster(); companyMaster.setCompanyId(companyId); BigDecimal resultHour = hour.divide(hoursSum, 2, RoundingMode.HALF_EVEN); resultHour = resultHour.multiply(pcProportion); resultHour = resultHour.setScale(2, RoundingMode.CEILING); // logger.debug("1462 :resultHour=====>"+resultHour); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, asistededTimeZero, allignedTimeZero, resultHour, resultHour); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeId + "-" + profitcentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(resultHour); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } } else if (apportionApproach == 3) { for (EmployeePcTagsTeamStruct employeePcTagsTeamStruct : employeePcTagsTeamStructList) { Map<Integer, CollageProjectRevenue> revenueMap = new HashMap<Integer, CollageProjectRevenue>(); Map<Integer, ProjectMaster> projectMap = new HashMap<Integer, ProjectMaster>(); BigDecimal proportion = employeePcTagsTeamStruct.getProportion(); BigDecimal devider = new BigDecimal(100); proportion = proportion.divide(devider); logger.debug("===========================================>" + proportion); String profitcentreId = employeePcTagsTeamStruct.getProfitCentre().getProfitCentreId(); // Calculate for each profit centre BigDecimal pcProportion = proportion.multiply(remainProportion); BigDecimal revenueSum = BigDecimal.ZERO; List<CollageProjectRevenue> collageProjectRevenueList = collageProjectRevenueDao .findByYearIdMonthIdProfitCentreIdCostCentreId(yearId, monthId, profitcentreId, costCentreId); if (!collageProjectRevenueList.isEmpty()) { for (CollageProjectRevenue revenue : collageProjectRevenueList) { if (unAssignedProjects.isEmpty()) { Integer projectId = revenue.getProjectMaster().getProjectId(); logger.debug("1497 =projectId====>" + projectId); revenueMap.put(projectId, revenue); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); projectMap.put(projectId, projectList.get(0)); BigDecimal revenueVal = revenue.getRevenueValue(); // logger.debug("1503 =RevenueValue====>"+revenueVal); revenueSum = revenueSum.add(revenueVal); } else { Integer projectId = revenue.getProjectMaster().getProjectId(); if (unAssignedProjects.containsKey(projectId) == false) { // logger.debug("1507 =projectId====>"+projectId); revenueMap.put(projectId, revenue); List<ProjectMaster> projectList = projectMasterDao.findByProjectId(projectId); projectMap.put(projectId, projectList.get(0)); BigDecimal revenueVal = revenue.getRevenueValue(); // logger.debug("1514 =RevenueValue====>"+revenue.getRevenueValue() // +" : "+revenueVal); revenueSum = revenueSum.add(revenueVal); } } } logger.debug("1543 =revenueSum====>" + revenueSum); for (Integer projectId : revenueMap.keySet()) { CollageProjectRevenue collageProjectRevenue = revenueMap.get(projectId); ProjectMaster projectMaster = projectMap.get(projectId); CompanyMaster companyMaster = projectMaster.getCompanyMaster(); BigDecimal revenueValue = collageProjectRevenue.getRevenueValue(); logger.debug("1516 =revenueSum : revenueValue====>" + revenueSum + " : " + revenueValue); revenueValue = revenueValue.divide(revenueSum, 2, RoundingMode.HALF_EVEN); revenueValue = revenueValue.multiply(pcProportion); revenueValue = revenueValue.setScale(2, RoundingMode.CEILING); logger.debug("1515 :Aportioned Count======>" + revenueValue); EmpcntClientProjectData empcntClientProjectData = new EmpcntClientProjectData(employee, companyMaster, countType, month, projectMaster, year, costCentre, allignedTimeZero, asistededTimeZero, revenueValue, revenueValue); if (countTypeId == 1) { empOpenCntClientProjectDataList.add(empcntClientProjectData); } if (countTypeId == 2) { empCloseCntClientProjectDataList.add(empcntClientProjectData); } // copy proprotion String mapId = yearId + "-" + monthId + "-" + employeeId + "-" + profitcentreId; EmployeePcTagsTeamStruct employeePcTagsTeamStructCopy = employeePcTagsTeamStruct; employeePcTagsTeamStructCopy.setApportionedCnt(revenueValue); employeePcTagsTeamStructMap.put(mapId, employeePcTagsTeamStructCopy); } } } } // logger.debug("<====getRevenueCountProportion End====>"); } /** * @param yearId * @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); } } } } /** * @param yearId * @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); } } } } /** * @param yearId * @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); } } } } /** * @param yearId * @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); } } } } /** * @param yearId * @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); } } } } } /** * @param yearId * @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); } } } } } /* * (non-Javadoc) * * @see com.ugam.collage.plus.service.people_count.PeopleAccountingService# * getEmployeeSummary(java.lang.Integer, java.lang.Integer, * java.lang.String, java.lang.Integer) */ @Override public List<EmpcntClientProjectDataVo> getEmployeeSummary(Integer yearId, Integer monthId, String costCentreId, Integer typeId) { List<EmpcntClientProjectDataVo> empcntClientProjectDataVoList = new ArrayList<EmpcntClientProjectDataVo>(); List<EmpcntClientProjectData> empcntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); empcntClientProjectDataList = empcntClientProjectDataDao.findByYearIdMonthIdCostCentreIdTypeId(yearId, monthId, costCentreId, typeId); for (EmpcntClientProjectData empcntClientProjectData : empcntClientProjectDataList) { EmpcntClientProjectDataVo empcntClientProjectDataVo = new EmpcntClientProjectDataVo( empcntClientProjectData.getTabYear().getYearId(), empcntClientProjectData.getTabMonth().getMonthId(), empcntClientProjectData.getEmployeeMaster().getEmployeeId(), empcntClientProjectData.getCountClassification().getId(), empcntClientProjectData.getProjectMaster().getProjectName(), empcntClientProjectData.getCompanyMaster().getCompanyName(), empcntClientProjectData.getAssignedCnt(), empcntClientProjectData.getAssistedCnt(), empcntClientProjectData.getApportionedCnt(), empcntClientProjectData.getTotalCnt()); empcntClientProjectDataVo.setId(empcntClientProjectData.getId()); empcntClientProjectDataVoList.add(empcntClientProjectDataVo); } // Get apportion count List<BigDecimal> apportionCount = employeePcTagsTeamStructDao.findByYearIdMonthIdCostCentreId(yearId, monthId, costCentreId); logger.debug("*************************************===>" + apportionCount.size()); if (!apportionCount.isEmpty()) { BigDecimal count = apportionCount.get(0); EmpcntClientProjectDataVo apportionCountVo = new EmpcntClientProjectDataVo(yearId, monthId, 0, 0, "No-Client", "No-Project", BigDecimal.ZERO, BigDecimal.ZERO, count, count); empcntClientProjectDataVoList.add(apportionCountVo); } return empcntClientProjectDataVoList; } @Override public List<EmpcntClientProjectDataVo> getProfitEmployeeSummary(Integer yearId, Integer monthId, String costCentreId, Integer typeId, String profitCentreId) { List<EmpcntClientProjectDataVo> empcntClientProjectDataVoList = new ArrayList<EmpcntClientProjectDataVo>(); List<EmpcntClientProjectData> empcntClientProjectDataList = new ArrayList<EmpcntClientProjectData>(); empcntClientProjectDataList = empcntClientProjectDataDao.findByYearMonthCostCentreTypeProfitCentre(yearId, monthId, costCentreId, typeId, profitCentreId); for (EmpcntClientProjectData empcntClientProjectData : empcntClientProjectDataList) { EmpcntClientProjectDataVo empcntClientProjectDataVo = new EmpcntClientProjectDataVo( empcntClientProjectData.getTabYear().getYearId(), empcntClientProjectData.getTabMonth().getMonthId(), empcntClientProjectData.getEmployeeMaster().getEmployeeId(), empcntClientProjectData.getCountClassification().getId(), empcntClientProjectData.getProjectMaster().getProjectName(), empcntClientProjectData.getCompanyMaster().getCompanyName(), empcntClientProjectData.getAssignedCnt(), empcntClientProjectData.getAssistedCnt(), empcntClientProjectData.getApportionedCnt(), empcntClientProjectData.getTotalCnt()); empcntClientProjectDataVo.setId(empcntClientProjectData.getId()); empcntClientProjectDataVoList.add(empcntClientProjectDataVo); } // Get apportion count List<BigDecimal> apportionCount = employeePcTagsTeamStructDao .findByYearIdMonthIdProftCentreIdCostCentreId(yearId, monthId, profitCentreId, costCentreId); logger.debug("*************************************===>" + apportionCount.size()); if (!apportionCount.isEmpty()) { BigDecimal count = apportionCount.get(0); EmpcntClientProjectDataVo apportionCountVo = new EmpcntClientProjectDataVo(yearId, monthId, 0, 0, "No-Client", "No-Project", BigDecimal.ZERO, BigDecimal.ZERO, count, count); empcntClientProjectDataVoList.add(apportionCountVo); } return empcntClientProjectDataVoList; } }