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:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getShortTermLiabilityVar1() {
    try {//from  w  ww  . j  av  a2 s.  c om
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompOne.getShortTermLiability(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getShortTermLiabilityVar2() {
    try {//  ww  w.  ja  v  a2  s  .c om
        BigDecimal res = new BigDecimal(financialRatio.getShortTermLiability().doubleValue());
        res = res.divide(financialRatioCompTwo.getShortTermLiability(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTotalOtherResourcesVar1() {
    try {//  w ww  .  j a v  a 2 s . com
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompOne.getTotalOtherResources(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getTotalOtherResourcesVar2() {
    try {//from w w w. j a v a  2 s.c o m
        BigDecimal res = new BigDecimal(financialRatio.getTotalOtherResources().doubleValue());
        res = res.divide(financialRatioCompTwo.getTotalOtherResources(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getOtherExploitationExpensesVar1() {
    try {//from ww  w  .  j a  v  a2s.c  o m
        BigDecimal res = new BigDecimal(financialRatio.getOtherExploitationExpenses().doubleValue());
        res = res.divide(financialRatioCompOne.getOtherExploitationExpenses(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:com.autentia.intra.bean.billing.FinancialRatioBean.java

public BigDecimal getOtherExploitationExpensesVar2() {
    try {//  w  w w . j  a va2s . co m
        BigDecimal res = new BigDecimal(financialRatio.getOtherExploitationExpenses().doubleValue());
        res = res.divide(financialRatioCompTwo.getOtherExploitationExpenses(), 4, RoundingMode.HALF_UP);
        res = res.subtract(new BigDecimal(1));
        return res;

    } catch (Exception e) {
        return new BigDecimal(0);
    }
}

From source file:mx.edu.um.mateo.activos.dao.impl.ActivoDaoHibernate.java

private Activo deprecia(Activo activo, Date fecha) {
    // depreciacion anual
    BigDecimal porciento = activo.getPorciento();
    log.trace("Activo - MOI - Porciento: {} - {} - {}",
            new Object[] { activo.getId(), activo.getMoi(), porciento });
    BigDecimal depreciacionAnual = activo.getMoi().multiply(porciento);
    log.trace("DepreciacionAnual: {}", depreciacionAnual);

    // depreciacion mensual
    BigDecimal depreciacionMensual = BigDecimal.ZERO;
    Date fechaCompra = activo.getFechaCompra();
    if (fechaCompra.before(fecha) && days360(fechaCompra, fecha) / 30 < activo.getVidaUtil()) {
        depreciacionMensual = depreciacionAnual.divide(new BigDecimal("12"), 2, RoundingMode.HALF_UP);
    }//w  w  w.j  ava 2 s  .c o m
    log.trace("DepreciacionMensual: {}", depreciacionMensual);

    // depreciacion acumulada
    BigDecimal depreciacionAcumulada;
    Long meses = 0L;
    if ((fechaCompra.before(fecha) && !activo.getInactivo())
            || (fechaCompra.before(fecha) && activo.getInactivo() && activo.getFechaInactivo().after(fecha))) {
        meses = days360(fechaCompra, fecha) / 30;
    } else if (fechaCompra.before(fecha) && activo.getInactivo() && activo.getFechaInactivo().before(fecha)) {
        meses = days360(fechaCompra, activo.getFechaInactivo()) / 30;
    }
    if (meses < activo.getVidaUtil()) {
        depreciacionAcumulada = depreciacionMensual.multiply(new BigDecimal(meses));
    } else {
        depreciacionAcumulada = activo.getMoi();
    }
    log.trace("DepreciacionAcumulada: {}", depreciacionAcumulada);

    // valor neto
    BigDecimal valorNeto = activo.getMoi().subtract(depreciacionAcumulada);
    log.trace("ValorNeto: {}", valorNeto);

    activo.setFechaDepreciacion(fecha);
    activo.setDepreciacionAnual(depreciacionAnual);
    activo.setDepreciacionMensual(depreciacionMensual);
    activo.setDepreciacionAcumulada(depreciacionAcumulada);
    activo.setValorNeto(valorNeto);

    return activo;
}

From source file:autoInsurance.BeiJPiccImpl.java

String round(String num) {
    BigDecimal big = new BigDecimal(num);
    BigDecimal result = big.divide(new BigDecimal(1), 2, BigDecimal.ROUND_HALF_UP);
    return result.toString();
}

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

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

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

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

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

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

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

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

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

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

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

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

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

    }

}

From source file:org.mifos.accounts.servicefacade.WebTierAccountServiceFacade.java

@Override
public void applyGroupCharge(Map<Integer, String> idsAndValues, Short chargeId, boolean isPenaltyType) {
    MifosUser user = (MifosUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    UserContext userContext = toUserContext(user);
    TreeMap<Integer, String> idsAndValueAsTreeMap = new TreeMap<Integer, String>(idsAndValues);

    try {// w  w  w.  jav a2  s  .  c  om
        AccountBO parentAccount = ((LoanBO) legacyAccountDao.getAccount(
                new AccountBusinessService().getAccount(idsAndValueAsTreeMap.firstKey()).getAccountId()))
                        .getParentAccount();
        BigDecimal parentAmount = ((LoanBO) parentAccount).getLoanAmount().getAmount();
        BigDecimal membersAmount = BigDecimal.ZERO;

        for (Map.Entry<Integer, String> entry : idsAndValues.entrySet()) {
            LoanBO individual = loanDao.findById(entry.getKey());
            Double chargeAmount = Double.valueOf(entry.getValue());
            if (chargeAmount.equals(0.0)) {
                continue;
            }
            membersAmount = membersAmount.add(individual.getLoanAmount().getAmount());
            individual.updateDetails(userContext);

            if (isPenaltyType && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                individual.addAccountPenalty(new AccountPenaltiesEntity(individual, penalty, chargeAmount));
            } else {
                individual.applyCharge(chargeId, chargeAmount);
            }
        }

        boolean isRateCharge = false;

        if (!chargeId.equals(Short.valueOf(AccountConstants.MISC_FEES))
                && !chargeId.equals(Short.valueOf(AccountConstants.MISC_PENALTY))) {

            if (isPenaltyType) {
                PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
                if (penalty instanceof RatePenaltyBO) {
                    isRateCharge = true;
                }
            } else {
                FeeBO fee = feeDao.findById(chargeId);
                if (fee.getFeeType().equals(RateAmountFlag.RATE)) {
                    isRateCharge = true;
                }
            }
        }

        Double chargeAmount = null;

        if (!isRateCharge) {
            chargeAmount = sumCharge(idsAndValues);
        } else {
            chargeAmount = Double.valueOf(idsAndValueAsTreeMap.firstEntry().getValue());
            BigDecimal chargeAmountBig = new BigDecimal(chargeAmount);
            membersAmount = membersAmount.multiply(chargeAmountBig);
            int scale = Money.getInternalPrecision();
            chargeAmountBig = membersAmount.divide(parentAmount, scale, RoundingMode.HALF_EVEN);
            chargeAmount = chargeAmountBig.doubleValue();
        }

        parentAccount.updateDetails(userContext);

        CustomerLevel customerLevel = null;
        if (parentAccount.isCustomerAccount()) {
            customerLevel = parentAccount.getCustomer().getLevel();
        }
        if (parentAccount.getPersonnel() != null) {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext,
                    parentAccount.getOffice().getOfficeId(), parentAccount.getPersonnel().getPersonnelId());
        } else {
            checkPermissionForApplyCharges(parentAccount.getType(), customerLevel, userContext,
                    parentAccount.getOffice().getOfficeId(), userContext.getId());
        }

        this.transactionHelper.startTransaction();

        if (isPenaltyType && parentAccount instanceof LoanBO) {
            PenaltyBO penalty = this.penaltyDao.findPenaltyById(chargeId.intValue());
            ((LoanBO) parentAccount)
                    .addAccountPenalty(new AccountPenaltiesEntity(parentAccount, penalty, chargeAmount));
        } else {
            parentAccount.applyCharge(chargeId, chargeAmount);
        }

        this.transactionHelper.commitTransaction();
    } catch (ServiceException e) {
        this.transactionHelper.rollbackTransaction();
        throw new MifosRuntimeException(e);
    } catch (ApplicationException e) {
        this.transactionHelper.rollbackTransaction();
        throw new BusinessRuleException(e.getKey(), e);
    }

}