Example usage for java.math RoundingMode CEILING

List of usage examples for java.math RoundingMode CEILING

Introduction

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

Prototype

RoundingMode CEILING

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

Click Source Link

Document

Rounding mode to round towards positive infinity.

Usage

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

/**
 *
 *//* w  ww .jav  a  2  s  .  co m*/
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====>");
}

From source file:org.mifos.accounts.loan.business.LoanCalculationIntegrationTest.java

@Test
public void testOneExampleOfTestCaseFromSpreadSheet()
        throws NumberFormatException, PropertyNotFoundException, SystemException, ApplicationException {

    // set up config
    InternalConfiguration config = new InternalConfiguration();
    config.setDaysInYear(365);/*from w  w w. j a va  2 s . c om*/
    config.setFinalRoundingMode(RoundingMode.CEILING);
    config.setFinalRoundOffMultiple("0.01");
    config.setInitialRoundingMode(RoundingMode.CEILING);
    config.setInitialRoundOffMultiple("1");
    config.setCurrencyRoundingMode(RoundingMode.CEILING);
    config.setInternalPrecision(13);
    config.setDigitsAfterDecimal(3);

    // set up loan params
    LoanParameters loanParams = new LoanParameters();
    loanParams.setLoanType(InterestType.FLAT);
    loanParams.setNumberOfPayments((short) 5);
    loanParams.setPaymentFrequency(RecurrenceType.WEEKLY);
    loanParams.setAnnualInterest("12.00");
    loanParams.setPrincipal("1002");

    // set up expected results
    Results expectedResult = new Results();
    expectedResult.setTotalInterest(new Money(getCurrency(), "11.53"));
    expectedResult.setTotalPayments(new Money(getCurrency(), "1013.53"));
    expectedResult.setTotalPrincipal(new Money(getCurrency(), "1002")); // this loan amount
    List<PaymentDetail> list = new ArrayList<PaymentDetail>();
    // 1st payment
    PaymentDetail payment = new PaymentDetail();
    payment.setPayment(new Money(getCurrency(), "203.000"));
    payment.setInterest(new Money(getCurrency(), "2.306"));
    payment.setBalance(new Money(getCurrency(), "810.530"));
    payment.setPrincipal(new Money(getCurrency(), "200.694"));
    list.add(payment);
    // 2nd payment
    payment = new PaymentDetail();
    payment.setPayment(new Money(getCurrency(), "203.000"));
    payment.setInterest(new Money(getCurrency(), "2.306"));
    payment.setBalance(new Money(getCurrency(), "607.530"));
    payment.setPrincipal(new Money(getCurrency(), "200.694"));
    list.add(payment);
    // 3rd payment
    payment = new PaymentDetail();
    payment.setPayment(new Money(getCurrency(), "203.000"));
    payment.setInterest(new Money(getCurrency(), "2.306"));
    payment.setBalance(new Money(getCurrency(), "404.530"));
    payment.setPrincipal(new Money(getCurrency(), "200.694"));
    list.add(payment);
    // 4th payment
    payment = new PaymentDetail();
    payment.setPayment(new Money(getCurrency(), "203.000"));
    payment.setInterest(new Money(getCurrency(), "2.306"));
    payment.setBalance(new Money(getCurrency(), "201.530"));
    payment.setPrincipal(new Money(getCurrency(), "200.694"));
    list.add(payment);
    // last payment
    payment = new PaymentDetail();
    payment.setPayment(new Money(getCurrency(), "201.530"));
    payment.setInterest(new Money(getCurrency(), "2.306"));
    payment.setBalance(new Money(getCurrency(), "0"));
    payment.setPrincipal(new Money(getCurrency(), "199.224"));
    list.add(payment);
    expectedResult.setPayments(list);

    expectedResult.setPayments(list);

    accountBO = setUpLoan(config, loanParams);

    // calculated results
    Results calculatedResult = calculatePayments(config, accountBO, loanParams);
    compareResults(expectedResult, calculatedResult, "testOneExampleOfTestCaseFromSpreadSheet");

}

From source file:org.egov.ptis.service.es.CollectionIndexElasticSearchService.java

/**
 * Sets the Demand and Collection values
 * @param ulbWiseDetails//  www. j  av  a2  s  .c  om
 * @param weeklyCollMap
 */
private void setWeeklyDCBValues(final List<WeeklyDCB> ulbWiseDetails,
        final Map<String, Map<String, Object[]>> weeklyCollMap,
        Map<String, BillCollectorIndex> wardWiseBillCollectors) {
    WeeklyDCB weeklyDCB;
    DemandCollectionMIS demandCollectionMIS;
    int count;
    for (final Map.Entry<String, Map<String, Object[]>> entry : weeklyCollMap.entrySet()) {
        weeklyDCB = new WeeklyDCB();
        count = 1;
        weeklyDCB.setBoundaryName(entry.getKey());
        weeklyDCB.setBillCollectorName(wardWiseBillCollectors.get(entry.getKey()) == null ? StringUtils.EMPTY
                : wardWiseBillCollectors.get(entry.getKey()).getBillCollector());
        for (final Map.Entry<String, Object[]> weeklyMap : entry.getValue().entrySet()) {
            demandCollectionMIS = new DemandCollectionMIS();
            demandCollectionMIS.setCollection(new BigDecimal(weeklyMap.getValue()[0].toString()));
            demandCollectionMIS.setDemand(new BigDecimal(weeklyMap.getValue()[1].toString()));
            if (demandCollectionMIS.getDemand().compareTo(BigDecimal.ZERO) > 0)
                demandCollectionMIS.setPercent(demandCollectionMIS.getCollection()
                        .divide(demandCollectionMIS.getDemand(), 2, RoundingMode.CEILING)
                        .multiply(BIGDECIMAL_100));
            if (count == 1)
                weeklyDCB.setWeek1DCB(demandCollectionMIS);
            else if (count == 2)
                weeklyDCB.setWeek2DCB(demandCollectionMIS);
            else if (count == 3)
                weeklyDCB.setWeek3DCB(demandCollectionMIS);
            else if (count == 4)
                weeklyDCB.setWeek4DCB(demandCollectionMIS);
            else if (count == 5)
                weeklyDCB.setWeek5DCB(demandCollectionMIS);
            count++;

        }
        ulbWiseDetails.add(weeklyDCB);
    }
}

From source file:org.egov.ptis.service.es.CollectionIndexElasticSearchService.java

/**
 * Sets the Demand and Collection values
 * @param ulbWiseDetails//from   w  w  w  .java 2 s  . co  m
 * @param monthlyCollMap
 */
private void setMonthlyDCBValues(final List<MonthlyDCB> ulbWiseDetails,
        final Map<String, Map<String, Object[]>> yearwiseMonthlyCollMap,
        Map<String, BillCollectorIndex> wardWiseBillCollectors) {
    MonthlyDCB monthlyDCB;
    DemandCollectionMIS demandCollectionMIS;
    String month;
    for (final Map.Entry<String, Map<String, Object[]>> entry : yearwiseMonthlyCollMap.entrySet()) {
        monthlyDCB = new MonthlyDCB();
        monthlyDCB.setBoundaryName(entry.getKey());
        monthlyDCB.setBillCollectorName(wardWiseBillCollectors.get(entry.getKey()) == null ? StringUtils.EMPTY
                : wardWiseBillCollectors.get(entry.getKey()).getBillCollector());
        for (final Map.Entry<String, Object[]> monthMap : entry.getValue().entrySet()) {
            demandCollectionMIS = new DemandCollectionMIS();
            month = monthMap.getKey();
            demandCollectionMIS.setCollection(new BigDecimal(monthMap.getValue()[0].toString()));
            demandCollectionMIS.setDemand(new BigDecimal(monthMap.getValue()[1].toString()));
            if (demandCollectionMIS.getDemand().compareTo(BigDecimal.ZERO) > 0)
                demandCollectionMIS.setPercent(demandCollectionMIS.getCollection()
                        .divide(demandCollectionMIS.getDemand(), 2, RoundingMode.CEILING)
                        .multiply(BIGDECIMAL_100));
            setDCBForMonth(monthlyDCB, demandCollectionMIS, month);
        }
        ulbWiseDetails.add(monthlyDCB);
    }
}