Example usage for java.math BigDecimal add

List of usage examples for java.math BigDecimal add

Introduction

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

Prototype

public BigDecimal add(BigDecimal augend) 

Source Link

Document

Returns a BigDecimal whose value is (this + augend) , and whose scale is max(this.scale(), augend.scale()) .

Usage

From source file:org.kuali.coeus.s2sgen.impl.generate.support.PHS398ChecklistV1_0Generator.java

private void setProjectIncome(PHS398Checklist phsChecklist, BudgetContract budget) {
    phsChecklist.setProgramIncome(YesNoDataType.YES);

    //TreeMap Used to maintain the order of the Budget periods.
    Map<Integer, IncomeBudgetPeriod> incomeBudgetPeriodMap = new TreeMap<>();
    BigDecimal anticipatedAmount;
    for (BudgetProjectIncomeContract projectIncome : budget.getBudgetProjectIncomes()) {
        Integer budgetPeriodNumber = projectIncome.getBudgetPeriodNumber();
        IncomeBudgetPeriod incomeBudgPeriod = incomeBudgetPeriodMap.get(budgetPeriodNumber);
        if (incomeBudgPeriod == null) {
            incomeBudgPeriod = IncomeBudgetPeriod.Factory.newInstance();
            incomeBudgPeriod.setBudgetPeriod(budgetPeriodNumber);
            anticipatedAmount = BigDecimal.ZERO;
        } else {/*from w ww.j a va 2s .co  m*/
            anticipatedAmount = incomeBudgPeriod.getAnticipatedAmount();
        }
        anticipatedAmount = anticipatedAmount.add(projectIncome.getProjectIncome().bigDecimalValue());
        incomeBudgPeriod.setAnticipatedAmount(anticipatedAmount);
        String description = getProjectIncomeDescription(projectIncome);
        if (description != null) {
            if (incomeBudgPeriod.getSource() != null) {
                incomeBudgPeriod.setSource(incomeBudgPeriod.getSource() + ";" + description);
            } else {
                incomeBudgPeriod.setSource(description);
            }
        }
        incomeBudgetPeriodMap.put(budgetPeriodNumber, incomeBudgPeriod);
    }
    Collection<IncomeBudgetPeriod> incomeBudgetPeriodCollection = incomeBudgetPeriodMap.values();
    phsChecklist.setIncomeBudgetPeriodArray(incomeBudgetPeriodCollection.toArray(new IncomeBudgetPeriod[0]));
}

From source file:ch.algotrader.simulation.Simulator.java

/**
 * {@link ch.algotrader.service.PortfolioService#getPortfolioValue()}
 *//*from   w ww .ja  v  a2  s .  c om*/
public PortfolioValue getPortfolioValue() {

    BigDecimal cashBalance = RoundUtil.getBigDecimal(getCashBalanceDoubleInternal(this.cashBalances.values()));
    BigDecimal marketValue = RoundUtil
            .getBigDecimal(getMarketValueDoubleInternal(this.positionsByStrategyAndSecurity.values()));

    PortfolioValue portfolioValue = PortfolioValue.Factory.newInstance();

    portfolioValue.setDateTime(getCurrentTime());
    portfolioValue.setCashBalance(cashBalance);
    portfolioValue.setMarketValue(marketValue); // might be null if there was no last tick for a particular security
    portfolioValue.setNetLiqValue(marketValue != null ? cashBalance.add(marketValue) : null); // add here to prevent another lookup

    return portfolioValue;
}

From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java

public Map<Groepen, Map<String, BigDecimal>> OverviewRekeningGroep(List<? extends Bedragen> bedragen) {
    Map<Groepen, Map<String, BigDecimal>> overviewRekeningGroep = new LinkedHashMap<Groepen, Map<String, BigDecimal>>();

    for (Bedragen bedrag : bedragen) {
        if (bedrag.getGroep().getCodeId() == null || !bedrag.getGroep().getCodeId().equals("INTER_REKENING")) {
            Groepen hoofdGroep = GroepenSrvImpl.getHoofdGroep(bedrag.getGroep());
            Map<String, BigDecimal> bedragInGroep = (Map<String, BigDecimal>) overviewRekeningGroep
                    .get(hoofdGroep);/*from ww  w . j a va2  s.  c o  m*/

            if (bedragInGroep == null) {
                bedragInGroep = new LinkedHashMap<String, BigDecimal>();
                bedragInGroep.put(POSITIEF, new BigDecimal(0));
                bedragInGroep.put(NEGATIEF, new BigDecimal(0));
            }

            BigDecimal bedragNegatief = (BigDecimal) bedragInGroep.get(NEGATIEF);
            BigDecimal bedragPositief = (BigDecimal) bedragInGroep.get(POSITIEF);

            if (bedrag.getGroep().getNegatief().equals(1)) {
                bedragNegatief = bedragNegatief.add(bedrag.getBedrag());
            } else {
                bedragPositief = bedragPositief.add(bedrag.getBedrag());
            }

            bedragInGroep.put(POSITIEF, bedragPositief);
            bedragInGroep.put(NEGATIEF, bedragNegatief);

            overviewRekeningGroep.put(hoofdGroep, bedragInGroep);
        }
    }

    return overviewRekeningGroep;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.java

@Override
@Transactional(rollbackFor = { NoEstaAbiertaException.class, NoHayExistenciasSuficientes.class,
        NoSePuedeCerrarException.class })
public Salida cierra(Salida salida, Usuario usuario)
        throws NoSePuedeCerrarException, NoHayExistenciasSuficientes, NoEstaAbiertaException {
    if (salida != null) {
        if (salida.getEstatus().getNombre().equals(Constantes.ABIERTA)) {
            if (usuario != null) {
                salida.setAlmacen(usuario.getAlmacen());
            }// w ww  .ja  va  2  s  .co m

            salida.setIva(BigDecimal.ZERO);
            salida.setTotal(BigDecimal.ZERO);
            Date fecha = new Date();
            for (LoteSalida lote : salida.getLotes()) {
                Producto producto = lote.getProducto();
                if (producto.getExistencia().subtract(lote.getCantidad()).compareTo(BigDecimal.ZERO) < 0) {
                    throw new NoHayExistenciasSuficientes(
                            "No existen existencias suficientes de " + producto.getNombre(), producto);
                }
                lote.setPrecioUnitario(producto.getPrecioUnitario());
                currentSession().update(lote);
                producto.setExistencia(producto.getExistencia().subtract(lote.getCantidad()));
                producto.setFechaModificacion(fecha);
                currentSession().update(producto);
                auditaProducto(producto, usuario, Constantes.ACTUALIZAR, salida.getId(), null, fecha);

                BigDecimal subtotal = lote.getPrecioUnitario().multiply(lote.getCantidad());
                salida.setIva(salida.getIva().add(lote.getIva()));
                salida.setTotal(salida.getTotal().add(subtotal.add(lote.getIva())));
            }

            Query query = currentSession().createQuery("select e from Estatus e where e.nombre = :nombre");
            query.setString("nombre", Constantes.CERRADA);
            Estatus estatus = (Estatus) query.uniqueResult();
            salida.setEstatus(estatus);
            salida.setFolio(getFolio(salida.getAlmacen()));
            salida.setAtendio(usuario.getApellido() + ", " + usuario.getNombre());
            salida.setFechaModificacion(fecha);

            currentSession().update(salida);

            audita(salida, usuario, Constantes.ACTUALIZAR, fecha, true);

            currentSession().flush();
            return salida;
        } else {
            throw new NoEstaAbiertaException("No se puede actualizar una salida que no este abierta");
        }
    } else {
        throw new NoSePuedeCerrarException("No se puede cerrar la salida pues no existe");
    }
}

From source file:com.inkubator.hrm.service.impl.PayTempKalkulasiServiceImpl.java

private BigDecimal calculateTotalIncome(BigDecimal totalIncome, PayTempKalkulasi payTempKalkulasi) {

    return totalIncome
            .add((payTempKalkulasi.getNominal().multiply(new BigDecimal(payTempKalkulasi.getFactor()))));
}

From source file:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java

/**
 * Fetch all orders by PartyUid and ordered by Date ascending
 *
 * @param partyUid a valid party id//  w  ww.j  a v a 2 s. c o  m
 * @return a structure of orders history ordered by Date
 *
 * @throws com.oncore.calorders.core.exceptions.DataAccessException
 */
@GET
@Path("findAllOrderHistoryByPartyUid/{partyUid}")
@Produces({ MediaType.APPLICATION_JSON })
public List<OrderHistoryData> findAllOrderHistoryByPartyUid(@PathParam("partyUid") Integer partyUid)
        throws DataAccessException {
    List<OrderHistoryData> orderHistoryDatas = new ArrayList<OrderHistoryData>();
    List<OrderHistory> orderHistorys = new ArrayList<OrderHistory>();

    orderHistorys = getEntityManager().createQuery(
            "SELECT oh FROM OrderHistory oh join oh.ordStatusCd os join oh.ptyUidFk pt join pt.groupPartyAssocCollection gpa join gpa.grpUidFk g join g.depUidFk d join oh.orderProductAssocCollection opa WHERE pt.ptyUid = :partyUid ORDER BY oh.createTs DESC",
            OrderHistory.class).setParameter("partyUid", partyUid).getResultList();
    if (orderHistorys != null && orderHistorys.size() > 0) {
        for (OrderHistory orderHistory : orderHistorys) {
            OrderHistoryData data = new OrderHistoryData();

            data.setOrderHistoryId(orderHistory.getOrdUid());
            if (orderHistory.getPtyUidFk() != null
                    && orderHistory.getPtyUidFk().getGroupPartyAssocCollection() != null
                    && orderHistory.getPtyUidFk().getGroupPartyAssocCollection().size() > 0) {
                for (GroupPartyAssoc assoc : orderHistory.getPtyUidFk().getGroupPartyAssocCollection()) {
                    if (assoc.getGrpUidFk() != null && assoc.getGrpUidFk().getDepUidFk() != null) {
                        data.setOrderAgency(assoc.getGrpUidFk().getDepUidFk().getDepName());
                        break;
                    }
                }
            }

            data.setOrderDate(orderHistory.getCreateTs());

            if (orderHistory.getOrderProductAssocCollection() != null
                    && orderHistory.getOrderProductAssocCollection().size() > 0) {
                String skuConcat = new String();
                BigDecimal totalPrice = new BigDecimal(BigInteger.ZERO);
                List<OrderProductAssoc> productAssocs = new ArrayList<OrderProductAssoc>();

                for (OrderProductAssoc assoc : orderHistory.getOrderProductAssocCollection()) {
                    productAssocs.add(assoc);
                    totalPrice = totalPrice.add(assoc.getOpaPrice());
                }

                data.setOrderPrice(totalPrice);

                for (int i = 0; i < productAssocs.size(); i++) {

                    if (skuConcat.length() > 25) {
                        skuConcat = skuConcat + "...";
                        break;
                    }

                    if (productAssocs.get(i).getPrdUidFk() != null
                            && productAssocs.get(i).getPrdUidFk().getPrdSku() != null) {
                        if (i == 0) {
                            skuConcat = productAssocs.get(i).getPrdUidFk().getPrdSku();
                        } else {
                            skuConcat = skuConcat + ", " + productAssocs.get(i).getPrdUidFk().getPrdSku();
                        }
                    }
                }
                data.setOrderDescription(skuConcat.trim());
            }

            data.setOrderPoNumber(null);

            if (orderHistory.getOrdStatusCd() != null) {
                data.setOrderStatus(orderHistory.getOrdStatusCd().getShortDesc());
            }
            orderHistoryDatas.add(data);
        }

    }

    return orderHistoryDatas;
}

From source file:com.oncore.calorders.rest.service.extension.OrderHistoryFacadeRESTExtension.java

/**
 * Fetch all orders by DepartmentUid and ordered by Date ascending
 *
 * @param departmentId a valid department id
 * @return a structure of orders history ordered by Date
 *
 * @throws com.oncore.calorders.core.exceptions.DataAccessException
 *//*  w  ww. jav  a 2 s. c  o  m*/
@GET
@Path("findAllOrderHistory/{departmentId}")
@Produces({ MediaType.APPLICATION_JSON })
public List<OrderHistoryData> findAllOrderHistory(@PathParam("departmentId") Integer departmentId)
        throws DataAccessException {
    List<OrderHistoryData> orderHistoryDatas = new ArrayList<OrderHistoryData>();
    List<OrderHistory> orderHistorys = new ArrayList<OrderHistory>();

    orderHistorys = getEntityManager().createQuery(
            "SELECT oh FROM OrderHistory oh join oh.ordStatusCd os join oh.ptyUidFk pt join pt.groupPartyAssocCollection gpa join gpa.grpUidFk g join g.depUidFk d join oh.orderProductAssocCollection opa where d.depUid = :depUid ORDER BY oh.createTs DESC",
            OrderHistory.class).setParameter("depUid", departmentId).getResultList();
    if (orderHistorys != null && orderHistorys.size() > 0) {
        for (OrderHistory orderHistory : orderHistorys) {
            OrderHistoryData data = new OrderHistoryData();

            data.setOrderHistoryId(orderHistory.getOrdUid());
            if (orderHistory.getPtyUidFk() != null
                    && orderHistory.getPtyUidFk().getGroupPartyAssocCollection() != null
                    && orderHistory.getPtyUidFk().getGroupPartyAssocCollection().size() > 0) {
                for (GroupPartyAssoc assoc : orderHistory.getPtyUidFk().getGroupPartyAssocCollection()) {
                    if (assoc.getGrpUidFk() != null && assoc.getGrpUidFk().getDepUidFk() != null) {
                        data.setOrderAgency(assoc.getGrpUidFk().getDepUidFk().getDepName());
                        break;
                    }
                }
            }

            data.setOrderDate(orderHistory.getCreateTs());

            if (orderHistory.getOrderProductAssocCollection() != null
                    && orderHistory.getOrderProductAssocCollection().size() > 0) {
                String skuConcat = new String();
                BigDecimal totalPrice = new BigDecimal(BigInteger.ZERO);
                List<OrderProductAssoc> productAssocs = new ArrayList<OrderProductAssoc>();

                for (OrderProductAssoc assoc : orderHistory.getOrderProductAssocCollection()) {
                    productAssocs.add(assoc);
                    totalPrice = totalPrice.add(assoc.getOpaPrice());
                }

                data.setOrderPrice(totalPrice);

                for (int i = 0; i < productAssocs.size(); i++) {

                    if (skuConcat.length() > 25) {
                        skuConcat = skuConcat + "...";
                        break;
                    }

                    if (productAssocs.get(i).getPrdUidFk() != null
                            && productAssocs.get(i).getPrdUidFk().getPrdSku() != null) {
                        if (i == 0) {
                            skuConcat = productAssocs.get(i).getPrdUidFk().getPrdSku();
                        } else {
                            skuConcat = skuConcat + ", " + productAssocs.get(i).getPrdUidFk().getPrdSku();
                        }
                    }
                }
                data.setOrderDescription(skuConcat.trim());
            }

            data.setOrderPoNumber(null);

            if (orderHistory.getOrdStatusCd() != null) {
                data.setOrderStatus(orderHistory.getOrdStatusCd().getShortDesc());
            }
            orderHistoryDatas.add(data);
        }

    }

    return orderHistoryDatas;
}

From source file:net.sourceforge.fenixedu.presentationTier.Action.directiveCouncil.SummariesControlAction.java

private BigDecimal getSummariesGiven(Professorship professorship, Shift shift, BigDecimal summariesGiven,
        LocalDate oneWeekBeforeToday) {
    for (Summary summary : shift.getAssociatedSummariesSet()) {
        if (summary.getProfessorship() != null && summary.getProfessorship() == professorship
                && !summary.getIsExtraLesson()
                && !summary.getLessonInstance().getBeginDateTime().toLocalDate().isAfter(oneWeekBeforeToday)) {
            summariesGiven = summariesGiven.add(BigDecimal.ONE);
        }//  ww  w  .java 2  s.c  om
    }
    return summariesGiven;
}

From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRSF424V1_2Generator.java

private BigDecimal getTotalProjectIncome(BudgetContract budget) {
    BigDecimal totalProjectIncome = BigDecimal.ZERO;
    for (BudgetProjectIncomeContract budgetProjectIncome : budget.getBudgetProjectIncomes()) {
        totalProjectIncome = totalProjectIncome.add(budgetProjectIncome.getProjectIncome().bigDecimalValue());
    }//from   w ww . j a  v a2  s .  com
    return totalProjectIncome;
}

From source file:mx.edu.um.mateo.inventario.dao.impl.SalidaDaoHibernate.java

@Override
@Transactional(rollbackFor = { NoEstaAbiertaException.class, ProductoNoSoportaFraccionException.class })
public LoteSalida creaLote(LoteSalida lote) throws ProductoNoSoportaFraccionException, NoEstaAbiertaException {
    if (lote.getSalida().getEstatus().getNombre().equals(Constantes.ABIERTA)) {
        if (!lote.getProducto().getFraccion()) {
            BigDecimal[] resultado = lote.getCantidad().divideAndRemainder(new BigDecimal("1"));
            if (resultado[1].doubleValue() > 0) {
                throw new ProductoNoSoportaFraccionException();
            }// w w w.j  av  a2s.  c  o  m
        }

        lote.setPrecioUnitario(lote.getProducto().getPrecioUnitario());

        BigDecimal subtotal = lote.getPrecioUnitario().multiply(lote.getCantidad());
        BigDecimal iva = subtotal.multiply(lote.getProducto().getIva()).setScale(2, RoundingMode.HALF_UP);
        lote.setIva(iva);
        BigDecimal total = subtotal.add(iva).setScale(2, RoundingMode.HALF_UP);
        lote.setFechaCreacion(new Date());
        currentSession().save(lote);

        Salida salida = lote.getSalida();
        salida.setIva(salida.getIva().add(iva));
        salida.setTotal(salida.getTotal().add(total));
        currentSession().save(salida);

        currentSession().flush();

        return lote;
    } else {
        throw new NoEstaAbiertaException("No se puede crear un lote en una salida que no este abierta");
    }
}