Example usage for java.math BigDecimal divide

List of usage examples for java.math BigDecimal divide

Introduction

In this page you can find the example usage for java.math BigDecimal divide.

Prototype

public BigDecimal divide(BigDecimal divisor, int scale, RoundingMode roundingMode) 

Source Link

Document

Returns a BigDecimal whose value is (this / divisor) , and whose scale is as specified.

Usage

From source file:org.ofbiz.accounting.invoice.InvoiceServices.java

private static BigDecimal calcHeaderAdj(Delegator delegator, GenericValue adj, String invoiceTypeId,
        String invoiceId, String invoiceItemSeqId, BigDecimal divisor, BigDecimal multiplier,
        BigDecimal baseAmount, int decimals, int rounding, GenericValue userLogin, LocalDispatcher dispatcher,
        Locale locale) {// w  w  w .  j av  a  2 s  .  com
    BigDecimal adjAmount = ZERO;
    if (adj.get("amount") != null) {

        // pro-rate the amount
        BigDecimal amount = ZERO;
        // make sure the divisor is not 0 to avoid NaN problems; just leave the amount as 0 and skip it in essense
        if (divisor.signum() != 0) {
            // multiply first then divide to avoid rounding errors
            amount = baseAmount.multiply(multiplier).divide(divisor, decimals, rounding);
        }
        if (amount.signum() != 0) {
            Map<String, Object> createInvoiceItemContext = FastMap.newInstance();
            createInvoiceItemContext.put("invoiceId", invoiceId);
            createInvoiceItemContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createInvoiceItemContext.put("invoiceItemTypeId", getInvoiceItemType(delegator,
                    adj.getString("orderAdjustmentTypeId"), null, invoiceTypeId, "INVOICE_ADJ"));
            createInvoiceItemContext.put("description", adj.get("description"));
            createInvoiceItemContext.put("quantity", BigDecimal.ONE);
            createInvoiceItemContext.put("amount", amount);
            createInvoiceItemContext.put("overrideGlAccountId", adj.get("overrideGlAccountId"));
            //createInvoiceItemContext.put("productId", orderItem.get("productId"));
            //createInvoiceItemContext.put("productFeatureId", orderItem.get("productFeatureId"));
            //createInvoiceItemContext.put("uomId", "");
            //createInvoiceItemContext.put("taxableFlag", product.get("taxable"));
            createInvoiceItemContext.put("taxAuthPartyId", adj.get("taxAuthPartyId"));
            createInvoiceItemContext.put("taxAuthGeoId", adj.get("taxAuthGeoId"));
            createInvoiceItemContext.put("taxAuthorityRateSeqId", adj.get("taxAuthorityRateSeqId"));
            createInvoiceItemContext.put("userLogin", userLogin);

            Map<String, Object> createInvoiceItemResult = null;
            try {
                createInvoiceItemResult = dispatcher.runSync("createInvoiceItem", createInvoiceItemContext);
            } catch (GenericServiceException e) {
                Debug.logError(e, "Service/other problem creating InvoiceItem from order header adjustment",
                        module);
                return adjAmount;
            }
            if (ServiceUtil.isError(createInvoiceItemResult)) {
                return adjAmount;
            }

            // Create the OrderAdjustmentBilling record
            Map<String, Object> createOrderAdjustmentBillingContext = FastMap.newInstance();
            createOrderAdjustmentBillingContext.put("orderAdjustmentId", adj.getString("orderAdjustmentId"));
            createOrderAdjustmentBillingContext.put("invoiceId", invoiceId);
            createOrderAdjustmentBillingContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createOrderAdjustmentBillingContext.put("amount", amount);
            createOrderAdjustmentBillingContext.put("userLogin", userLogin);

            try {
                dispatcher.runSync("createOrderAdjustmentBilling", createOrderAdjustmentBillingContext);
            } catch (GenericServiceException e) {
                return adjAmount;
            }

        }
        amount = amount.setScale(decimals, rounding);
        adjAmount = amount;
    } else if (adj.get("sourcePercentage") != null) {
        // pro-rate the amount
        BigDecimal percent = adj.getBigDecimal("sourcePercentage");
        percent = percent.divide(new BigDecimal(100), 100, rounding);
        BigDecimal amount = ZERO;
        // make sure the divisor is not 0 to avoid NaN problems; just leave the amount as 0 and skip it in essense
        if (divisor.signum() != 0) {
            // multiply first then divide to avoid rounding errors
            amount = percent.multiply(divisor);
        }
        if (amount.signum() != 0) {
            Map<String, Object> createInvoiceItemContext = FastMap.newInstance();
            createInvoiceItemContext.put("invoiceId", invoiceId);
            createInvoiceItemContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createInvoiceItemContext.put("invoiceItemTypeId", getInvoiceItemType(delegator,
                    adj.getString("orderAdjustmentTypeId"), null, invoiceTypeId, "INVOICE_ADJ"));
            createInvoiceItemContext.put("description", adj.get("description"));
            createInvoiceItemContext.put("quantity", BigDecimal.ONE);
            createInvoiceItemContext.put("amount", amount);
            createInvoiceItemContext.put("overrideGlAccountId", adj.get("overrideGlAccountId"));
            //createInvoiceItemContext.put("productId", orderItem.get("productId"));
            //createInvoiceItemContext.put("productFeatureId", orderItem.get("productFeatureId"));
            //createInvoiceItemContext.put("uomId", "");
            //createInvoiceItemContext.put("taxableFlag", product.get("taxable"));
            createInvoiceItemContext.put("taxAuthPartyId", adj.get("taxAuthPartyId"));
            createInvoiceItemContext.put("taxAuthGeoId", adj.get("taxAuthGeoId"));
            createInvoiceItemContext.put("taxAuthorityRateSeqId", adj.get("taxAuthorityRateSeqId"));
            createInvoiceItemContext.put("userLogin", userLogin);

            Map<String, Object> createInvoiceItemResult = null;
            try {
                createInvoiceItemResult = dispatcher.runSync("createInvoiceItem", createInvoiceItemContext);
            } catch (GenericServiceException e) {
                Debug.logError(e, "Service/other problem creating InvoiceItem from order header adjustment",
                        module);
                return adjAmount;
            }
            if (ServiceUtil.isError(createInvoiceItemResult)) {
                return adjAmount;
            }

            // Create the OrderAdjustmentBilling record
            Map<String, Object> createOrderAdjustmentBillingContext = FastMap.newInstance();
            createOrderAdjustmentBillingContext.put("orderAdjustmentId", adj.getString("orderAdjustmentId"));
            createOrderAdjustmentBillingContext.put("invoiceId", invoiceId);
            createOrderAdjustmentBillingContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createOrderAdjustmentBillingContext.put("amount", amount);
            createOrderAdjustmentBillingContext.put("userLogin", userLogin);

            try {
                dispatcher.runSync("createOrderAdjustmentBilling", createOrderAdjustmentBillingContext);
            } catch (GenericServiceException e) {
                return adjAmount;
            }

        }
        amount = amount.setScale(decimals, rounding);
        adjAmount = amount;
    }

    Debug.logInfo("adjAmount: " + adjAmount + ", divisor: " + divisor + ", multiplier: " + multiplier
            + ", invoiceTypeId: " + invoiceTypeId + ", invoiceId: " + invoiceId + ", itemSeqId: "
            + invoiceItemSeqId + ", decimals: " + decimals + ", rounding: " + rounding + ", adj: " + adj,
            module);
    return adjAmount;
}

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

/**
 * @param empcntClientProjectDataList/*from   ww w.  java 2s  .  c o m*/
 * @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====>");
}

From source file:net.sourceforge.fenixedu.domain.reports.TutorshipProgramReportFile.java

@Override
public void renderReport(final Spreadsheet spreadsheet) throws Exception {
    spreadsheet.setHeader("Nmero");
    spreadsheet.setHeader("Sexo");
    spreadsheet.setHeader("Mdia");
    spreadsheet.setHeader("Mdia Anual");
    spreadsheet.setHeader("Nmero Inscries");
    spreadsheet.setHeader("Nmero Aprovaes");
    spreadsheet.setHeader("Nota de Seriao");
    spreadsheet.setHeader("Local de Origem");

    final ExecutionYear executionYear = getExecutionYear();
    for (final Degree degree : Degree.readNotEmptyDegrees()) {
        if (checkDegreeType(getDegreeType(), degree)) {
            if (isActive(degree)) {
                for (final Registration registration : degree.getRegistrationsSet()) {
                    if (registration.isRegistered(getExecutionYear())) {

                        int enrolmentCounter = 0;
                        int aprovalCounter = 0;
                        BigDecimal bigDecimal = null;
                        double totalCredits = 0;

                        for (final Registration otherRegistration : registration.getStudent()
                                .getRegistrationsSet()) {
                            if (otherRegistration.getDegree() == registration.getDegree()) {
                                for (final StudentCurricularPlan studentCurricularPlan : otherRegistration
                                        .getStudentCurricularPlansSet()) {
                                    for (final Enrolment enrolment : studentCurricularPlan.getEnrolmentsSet()) {
                                        final ExecutionSemester executionSemester = enrolment
                                                .getExecutionPeriod();
                                        if (executionSemester.getExecutionYear() == executionYear) {
                                            enrolmentCounter++;
                                            if (enrolment.isApproved()) {
                                                aprovalCounter++;
                                                final Grade grade = enrolment.getGrade();
                                                if (grade.isNumeric()) {
                                                    final double credits = enrolment
                                                            .getEctsCreditsForCurriculum().doubleValue();
                                                    totalCredits += credits;
                                                    bigDecimal = bigDecimal == null
                                                            ? grade.getNumericValue()
                                                                    .multiply(new BigDecimal(credits))
                                                            : bigDecimal.add(grade.getNumericValue()
                                                                    .multiply(new BigDecimal(credits)));
                                                }
                                            }
                                        }
                                    }// w  w w .  j a v  a 2  s . c  om
                                }
                            }
                        }

                        final Row row = spreadsheet.addRow();
                        row.setCell(registration.getNumber().toString());
                        row.setCell(registration.getPerson().getGender().toLocalizedString());
                        row.setCell(registration.getAverage(executionYear));
                        if (bigDecimal == null) {
                            row.setCell("");
                        } else {
                            row.setCell(
                                    bigDecimal.divide(new BigDecimal(totalCredits), 5, RoundingMode.HALF_UP));
                        }
                        row.setCell(Integer.toString(enrolmentCounter));
                        row.setCell(Integer.toString(aprovalCounter));
                        row.setCell(
                                registration.getEntryGrade() != null ? registration.getEntryGrade().toString()
                                        : StringUtils.EMPTY);
                        Boolean dislocated = null;
                        if (registration.getStudentCandidacy() != null) {
                            dislocated = registration.getStudentCandidacy()
                                    .getDislocatedFromPermanentResidence();
                        }

                        final String dislocatedString = dislocated == null ? ""
                                : (dislocated.booleanValue() ? "Deslocado" : "No Deslocado");
                        row.setCell(dislocatedString);
                    }
                }
            }
        }
    }
}

From source file:com.selfsoft.business.action.TbFixEntrustAction.java

public String findTbFixEntrust() {
    if (null == tbFixEntrust) {

        tbFixEntrust = new TbFixEntrust();

        tbFixEntrust.setIsvalid(Constants.ISVALIDVALUE);

        tbFixEntrust.setFixDateStart(CommonMethod.parseStringToDate(
                CommonMethod.parseDateToString(CommonMethod.addDate(new Date(), -14), "yyyy-MM-dd"),
                "yyyy-MM-dd"));

        tbFixEntrust.setFixDateEnd(CommonMethod
                .parseStringToDate(CommonMethod.parseDateToString(new Date(), "yyyy-MM-dd"), "yyyy-MM-dd"));
    }/*w w w .j  a  v a 2s.c o m*/

    String wjg = request.getParameter("wjg");

    tbFixEntrust.setWjg(wjg);

    String jsqk = request.getParameter("jsqk");

    tbFixEntrust.setJsqk(jsqk);

    List<TbFixEntrust> tbFixEntrustList = tbFixEntrustService.findByTbFixEntrust(tbFixEntrust);

    List<TbFixEntrust> tbFixEntrustListPage = new ArrayList<TbFixEntrust>();

    BigDecimal pjcbTotal = new BigDecimal("0.00");

    if (null != tbFixEntrustList && tbFixEntrustList.size() > 0) {

        for (TbFixEntrust _tbFixEntrust : tbFixEntrustList) {

            _tbFixEntrust.setFixHourTotal(new BigDecimal(
                    tbFixEntrustContentService.countTbFixEnTrustContentByTbFixEntrustId(_tbFixEntrust.getId()))
                            .setScale(2, BigDecimal.ROUND_HALF_UP));

            List<TbMaintainPartContent> tcList = tbMaintainPartContentService
                    .getViewEntrustMaintianContent(_tbFixEntrust.getId());

            if (null != tcList && tcList.size() > 0) {

                _tbFixEntrust.setStockOutPartTotal(
                        new BigDecimal(tcList.get(0).getTotalPrice()).setScale(2, BigDecimal.ROUND_HALF_UP));

            }

            _tbFixEntrust.setPjcb(
                    new BigDecimal(statisticsStockInOutService.sumStockDetailByEntrustId(_tbFixEntrust.getId()))
                            .divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP));

            pjcbTotal = pjcbTotal.add(_tbFixEntrust.getPjcb());

            _tbFixEntrust.setSolePartTotal(
                    new BigDecimal(tmStockOutService.getTotalPriceByEntrustCode(_tbFixEntrust.getEntrustCode()))
                            .setScale(2, BigDecimal.ROUND_HALF_UP));

            _tbFixEntrust.setAllTotal(_tbFixEntrust.getFixHourTotal()
                    .add(_tbFixEntrust.getStockOutPartTotal().add(_tbFixEntrust.getSolePartTotal())));

            _tbFixEntrust.setZlr(_tbFixEntrust.getFixHourTotal().add(_tbFixEntrust.getStockOutPartTotal()
                    .add(_tbFixEntrust.getSolePartTotal()).subtract(_tbFixEntrust.getPjcb())));

            tbFixEntrustListPage.add(_tbFixEntrust);

        }

    }

    ActionContext.getContext().put("pjcbTotal",
            pjcbTotal.divide(new BigDecimal("1.00"), 2, BigDecimal.ROUND_HALF_UP));

    ActionContext.getContext().put("tmUserMap", tmUserService.findAllTmUserMap());

    ActionContext.getContext().put("tbFixEntrustList", tbFixEntrustListPage);

    ActionContext.getContext().getSession().put("tbFixEntrustListSession", tbFixEntrustListPage);

    return Constants.SUCCESS;
}

From source file:org.apache.ofbiz.accounting.invoice.InvoiceServices.java

private static BigDecimal calcHeaderAdj(Delegator delegator, GenericValue adj, String invoiceTypeId,
        String invoiceId, String invoiceItemSeqId, BigDecimal divisor, BigDecimal multiplier,
        BigDecimal baseAmount, int decimals, int rounding, GenericValue userLogin, LocalDispatcher dispatcher,
        Locale locale) {//w w  w  .j a  v  a 2 s  . c  o m
    BigDecimal adjAmount = ZERO;
    if (adj.get("amount") != null) {

        // pro-rate the amount
        BigDecimal amount = ZERO;
        if ("DONATION_ADJUSTMENT".equals(adj.getString("orderAdjustmentTypeId"))) {
            amount = baseAmount;
        } else if (divisor.signum() != 0) { // make sure the divisor is not 0 to avoid NaN problems; just leave the amount as 0 and skip it in essense
            // multiply first then divide to avoid rounding errors
            amount = baseAmount.multiply(multiplier).divide(divisor, decimals, rounding);
        }
        if (amount.signum() != 0) {
            Map<String, Object> createInvoiceItemContext = new HashMap<String, Object>();
            createInvoiceItemContext.put("invoiceId", invoiceId);
            createInvoiceItemContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createInvoiceItemContext.put("invoiceItemTypeId", getInvoiceItemType(delegator,
                    adj.getString("orderAdjustmentTypeId"), null, invoiceTypeId, "INVOICE_ADJ"));
            createInvoiceItemContext.put("description", adj.get("description"));
            createInvoiceItemContext.put("quantity", BigDecimal.ONE);
            createInvoiceItemContext.put("amount", amount);
            createInvoiceItemContext.put("overrideGlAccountId", adj.get("overrideGlAccountId"));
            createInvoiceItemContext.put("taxAuthPartyId", adj.get("taxAuthPartyId"));
            createInvoiceItemContext.put("taxAuthGeoId", adj.get("taxAuthGeoId"));
            createInvoiceItemContext.put("taxAuthorityRateSeqId", adj.get("taxAuthorityRateSeqId"));
            createInvoiceItemContext.put("userLogin", userLogin);

            Map<String, Object> createInvoiceItemResult = null;
            try {
                createInvoiceItemResult = dispatcher.runSync("createInvoiceItem", createInvoiceItemContext);
            } catch (GenericServiceException e) {
                Debug.logError(e, "Service/other problem creating InvoiceItem from order header adjustment",
                        module);
                return adjAmount;
            }
            if (ServiceUtil.isError(createInvoiceItemResult)) {
                return adjAmount;
            }

            // Create the OrderAdjustmentBilling record
            Map<String, Object> createOrderAdjustmentBillingContext = new HashMap<String, Object>();
            createOrderAdjustmentBillingContext.put("orderAdjustmentId", adj.getString("orderAdjustmentId"));
            createOrderAdjustmentBillingContext.put("invoiceId", invoiceId);
            createOrderAdjustmentBillingContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createOrderAdjustmentBillingContext.put("amount", amount);
            createOrderAdjustmentBillingContext.put("userLogin", userLogin);

            try {
                dispatcher.runSync("createOrderAdjustmentBilling", createOrderAdjustmentBillingContext);
            } catch (GenericServiceException e) {
                return adjAmount;
            }

        }
        amount = amount.setScale(decimals, rounding);
        adjAmount = amount;
    } else if (adj.get("sourcePercentage") != null) {
        // pro-rate the amount
        BigDecimal percent = adj.getBigDecimal("sourcePercentage");
        percent = percent.divide(new BigDecimal(100), 100, rounding);
        BigDecimal amount = ZERO;
        // make sure the divisor is not 0 to avoid NaN problems; just leave the amount as 0 and skip it in essense
        if (divisor.signum() != 0) {
            // multiply first then divide to avoid rounding errors
            amount = percent.multiply(divisor);
        }
        if (amount.signum() != 0) {
            Map<String, Object> createInvoiceItemContext = new HashMap<String, Object>();
            createInvoiceItemContext.put("invoiceId", invoiceId);
            createInvoiceItemContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createInvoiceItemContext.put("invoiceItemTypeId", getInvoiceItemType(delegator,
                    adj.getString("orderAdjustmentTypeId"), null, invoiceTypeId, "INVOICE_ADJ"));
            createInvoiceItemContext.put("description", adj.get("description"));
            createInvoiceItemContext.put("quantity", BigDecimal.ONE);
            createInvoiceItemContext.put("amount", amount);
            createInvoiceItemContext.put("overrideGlAccountId", adj.get("overrideGlAccountId"));
            createInvoiceItemContext.put("taxAuthPartyId", adj.get("taxAuthPartyId"));
            createInvoiceItemContext.put("taxAuthGeoId", adj.get("taxAuthGeoId"));
            createInvoiceItemContext.put("taxAuthorityRateSeqId", adj.get("taxAuthorityRateSeqId"));
            createInvoiceItemContext.put("userLogin", userLogin);

            Map<String, Object> createInvoiceItemResult = null;
            try {
                createInvoiceItemResult = dispatcher.runSync("createInvoiceItem", createInvoiceItemContext);
            } catch (GenericServiceException e) {
                Debug.logError(e, "Service/other problem creating InvoiceItem from order header adjustment",
                        module);
                return adjAmount;
            }
            if (ServiceUtil.isError(createInvoiceItemResult)) {
                return adjAmount;
            }

            // Create the OrderAdjustmentBilling record
            Map<String, Object> createOrderAdjustmentBillingContext = new HashMap<String, Object>();
            createOrderAdjustmentBillingContext.put("orderAdjustmentId", adj.getString("orderAdjustmentId"));
            createOrderAdjustmentBillingContext.put("invoiceId", invoiceId);
            createOrderAdjustmentBillingContext.put("invoiceItemSeqId", invoiceItemSeqId);
            createOrderAdjustmentBillingContext.put("amount", amount);
            createOrderAdjustmentBillingContext.put("userLogin", userLogin);

            try {
                dispatcher.runSync("createOrderAdjustmentBilling", createOrderAdjustmentBillingContext);
            } catch (GenericServiceException e) {
                return adjAmount;
            }

        }
        amount = amount.setScale(decimals, rounding);
        adjAmount = amount;
    }

    Debug.logInfo("adjAmount: " + adjAmount + ", divisor: " + divisor + ", multiplier: " + multiplier
            + ", invoiceTypeId: " + invoiceTypeId + ", invoiceId: " + invoiceId + ", itemSeqId: "
            + invoiceItemSeqId + ", decimals: " + decimals + ", rounding: " + rounding + ", adj: " + adj,
            module);
    return adjAmount;
}

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

/**
 * @param yearId/*from  w  w w  .  j av a 2 s  . c o  m*/
 * @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====>");
}

From source file:org.kuali.ole.select.document.service.impl.OleCreditMemoServiceImpl.java

public void calculateProrateItemSurcharge(OleVendorCreditMemoDocument vendorCreditMemoDocument) {
    LOG.debug("Inside Calculation for ProrateItemSurcharge");
    vendorCreditMemoDocument.setProrateBy(vendorCreditMemoDocument.isProrateQty() ? OLEConstants.PRORATE_BY_QTY
            : vendorCreditMemoDocument.isProrateManual() ? OLEConstants.MANUAL_PRORATE
                    : vendorCreditMemoDocument.isProrateDollar() ? OLEConstants.PRORATE_BY_DOLLAR
                            : vendorCreditMemoDocument.isNoProrate() ? OLEConstants.NO_PRORATE : null);
    BigDecimal addChargeItem = BigDecimal.ZERO;
    List<OleCreditMemoItem> item = (List<OleCreditMemoItem>) vendorCreditMemoDocument.getItems();
    for (OleCreditMemoItem items : item) {
        if (!items.getItemType().isQuantityBasedGeneralLedgerIndicator()
                && !items.getItemTypeCode()
                        .equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE)
                && items.getItemUnitPrice() != null) {
            addChargeItem = addChargeItem.add(items.getItemUnitPrice());
        }/*from  w  ww . j a  v a 2s. c  o m*/
    }
    List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>();
    BigDecimal totalExtPrice = new BigDecimal(0);
    BigDecimal newUnitPrice = new BigDecimal(0);
    BigDecimal extPrice = new BigDecimal(0);
    BigDecimal unitPricePercent = new BigDecimal(0);
    BigDecimal hundred = new BigDecimal(100);
    BigDecimal one = new BigDecimal(1);
    BigDecimal totalSurCharge = new BigDecimal(0);
    BigDecimal totalItemQuantity = new BigDecimal(0);
    BigDecimal itemSurchargeCons = new BigDecimal(0);
    for (int i = 0; item.size() > i; i++) {
        OleCreditMemoItem items = (OleCreditMemoItem) vendorCreditMemoDocument.getItem(i);
        if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())
                && !ObjectUtils.isNull(items.getItemQuantity())) {
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                totalItemQuantity = totalItemQuantity.add(items.getItemQuantity().bigDecimalValue());
            }
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)
                    || vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)
                    || vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                /*if (items.getItemDiscount() == null) {
                items.setItemDiscount(KualiDecimal.ZERO);
                }
                if (items.getItemDiscountType() != null && items.getItemDiscountType().equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
                newUnitPrice = (hundred.subtract(items.getItemDiscount().bigDecimalValue())).divide(hundred).multiply(items.getItemListPrice().bigDecimalValue());
                }
                else {
                newUnitPrice = items.getItemListPrice().bigDecimalValue().subtract(items.getItemDiscount().bigDecimalValue());
                }*/
                newUnitPrice = items.getItemUnitPrice();
                newUnitPriceList.add(newUnitPrice);
                extPrice = newUnitPrice.multiply(items.getItemQuantity().bigDecimalValue());
                totalExtPrice = totalExtPrice.add(extPrice);
            }
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) {
                if (items.getItemSurcharge() == null) {
                    items.setItemSurcharge(BigDecimal.ZERO);
                }
                totalSurCharge = totalSurCharge
                        .add(items.getItemQuantity().bigDecimalValue().multiply(items.getItemSurcharge()));
            }
        }

    }
    if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
        if (totalItemQuantity.compareTo(BigDecimal.ZERO) != 0) {
            itemSurchargeCons = one.divide(totalItemQuantity, 8, RoundingMode.HALF_UP);
        }
    }
    for (int i = 0, j = 0; item.size() > i; i++) {
        OleCreditMemoItem items = (OleCreditMemoItem) vendorCreditMemoDocument.getItem(i);
        if (items.getItemType().isQuantityBasedGeneralLedgerIndicator() && newUnitPriceList.size() > j
                && !ObjectUtils.isNull(items.getItemQuantity())) {
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)) {
                if (totalExtPrice.compareTo(BigDecimal.ZERO) != 0) {
                    unitPricePercent = newUnitPriceList.get(j).divide(totalExtPrice, 8, RoundingMode.HALF_UP);
                }
                items.setItemSurcharge(
                        unitPricePercent.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP));
                items.setExtendedPrice(
                        (new KualiDecimal((newUnitPriceList.get(j).add(items.getItemSurcharge()).toString())))
                                .multiply(items.getItemQuantity()));
            }
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                items.setItemSurcharge(
                        itemSurchargeCons.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP));
                items.setExtendedPrice(
                        new KualiDecimal(((newUnitPriceList.get(j).add(items.getItemSurcharge()).toString())))
                                .multiply(items.getItemQuantity()));
            }
            if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)
                    && items.getItemSurcharge() != null) {
                items.setExtendedPrice(
                        new KualiDecimal(((newUnitPriceList.get(j).add(items.getItemSurcharge()).toString())))
                                .multiply(items.getItemQuantity()));
            }
            j++;
        }
    }
    if (vendorCreditMemoDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) {
        if (totalSurCharge.compareTo(addChargeItem) != 0) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
                    OLEKeyConstants.ERROR_PAYMENT_REQUEST_TOTAL_MISMATCH);
        }
    }
    LOG.debug("Leaving Calculation for ProrateItemSurcharge");
}

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

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

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

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

From source file:org.kuali.ole.select.document.service.impl.OlePaymentRequestServiceImpl.java

/**
 * @see org.kuali.ole.select.document.service.OlePaymentRequestService#calculateProrateItemSurcharge(org.kuali.ole.select.document.OlePaymentRequestDocument)
 *//*from w w  w .ja  va  2  s  .  co m*/
@Override
public void calculateProrateItemSurcharge(OlePaymentRequestDocument paymentRequestDocument) {
    LOG.debug("Inside Calculation for ProrateItemSurcharge");
    //  KualiDecimal addChargeItem = paymentRequestDocument.getGrandPreTaxTotalExcludingDiscount().subtract(paymentRequestDocument.getLineItemPreTaxTotal());
    BigDecimal addChargeItem = BigDecimal.ZERO;
    List<OlePaymentRequestItem> item = paymentRequestDocument.getItems();

    for (OlePaymentRequestItem items : item) {
        if (!items.getItemType().isQuantityBasedGeneralLedgerIndicator()
                && !items.getItemTypeCode()
                        .equalsIgnoreCase(PurapConstants.ItemTypeCodes.ITEM_TYPE_PMT_TERMS_DISCOUNT_CODE)
                && items.getItemUnitPrice() != null) {
            addChargeItem = addChargeItem.add(items.getItemUnitPrice());
        }
    }
    List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>();
    BigDecimal totalExtPrice = new BigDecimal(0);
    BigDecimal newUnitPrice = new BigDecimal(0);
    BigDecimal extPrice = new BigDecimal(0);
    BigDecimal unitPricePercent = new BigDecimal(0);
    BigDecimal hundred = new BigDecimal(100);
    BigDecimal one = new BigDecimal(1);
    BigDecimal totalSurCharge = new BigDecimal(0);
    BigDecimal totalItemQuantity = new BigDecimal(0);
    BigDecimal itemSurchargeCons = new BigDecimal(0);
    for (int i = 0; item.size() > i; i++) {
        OlePaymentRequestItem items = (OlePaymentRequestItem) paymentRequestDocument.getItem(i);
        if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())
                && !ObjectUtils.isNull(items.getItemQuantity())) {
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                totalItemQuantity = totalItemQuantity.add(items.getItemQuantity().bigDecimalValue());
            }
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)
                    || paymentRequestDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)
                    || paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                if (items.getItemDiscount() == null) {
                    items.setItemDiscount(KualiDecimal.ZERO);
                }
                if (items.getItemDiscountType() != null && items.getItemDiscountType()
                        .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) {
                    newUnitPrice = (hundred.subtract(items.getItemDiscount().bigDecimalValue())).divide(hundred)
                            .multiply(items.getItemListPrice().bigDecimalValue());
                } else {
                    newUnitPrice = items.getItemListPrice().bigDecimalValue()
                            .subtract(items.getItemDiscount().bigDecimalValue());
                }
                newUnitPriceList.add(newUnitPrice);
                extPrice = newUnitPrice.multiply(items.getItemQuantity().bigDecimalValue());
                totalExtPrice = totalExtPrice.add(extPrice);
            }
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) {
                if (items.getItemSurcharge() == null) {
                    items.setItemSurcharge(BigDecimal.ZERO);
                }
                totalSurCharge = totalSurCharge
                        .add(items.getItemQuantity().bigDecimalValue().multiply(items.getItemSurcharge()));
            }
        }

    }
    if (paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
        if (totalItemQuantity.compareTo(BigDecimal.ZERO) != 0) {
            itemSurchargeCons = one.divide(totalItemQuantity, 8, RoundingMode.HALF_UP);
        }
    }
    for (int i = 0, j = 0; item.size() > i; i++) {
        OlePaymentRequestItem items = (OlePaymentRequestItem) paymentRequestDocument.getItem(i);
        if (items.getItemType().isQuantityBasedGeneralLedgerIndicator() && newUnitPriceList.size() > j
                && !ObjectUtils.isNull(items.getItemQuantity())) {
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)) {
                if (totalExtPrice.compareTo(BigDecimal.ZERO) != 0) {
                    unitPricePercent = newUnitPriceList.get(j).divide(totalExtPrice, 8, RoundingMode.HALF_UP);
                }
                items.setItemSurcharge(
                        unitPricePercent.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP));
                items.setItemUnitPrice(newUnitPriceList.get(j).add(items.getItemSurcharge()));
            }
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) {
                items.setItemSurcharge(
                        itemSurchargeCons.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP));
                items.setItemUnitPrice(newUnitPriceList.get(j).add(items.getItemSurcharge()));
            }
            if (paymentRequestDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)
                    && items.getItemSurcharge() != null) {
                items.setItemUnitPrice(newUnitPriceList.get(j).add(items.getItemSurcharge()));
            }
            j++;
        }
    }
    if (paymentRequestDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) {
        if (totalSurCharge.compareTo(addChargeItem) != 0) {
            GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY,
                    OLEKeyConstants.ERROR_PAYMENT_REQUEST_TOTAL_MISMATCH);
        }
    }
    LOG.debug("Leaving Calculation for ProrateItemSurcharge");
}

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

/**
 * @param yearId/*from   w  w  w.j  ava 2s.c om*/
 * @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);
                }
            }

        }

    }
}