Example usage for java.math BigDecimal ONE

List of usage examples for java.math BigDecimal ONE

Introduction

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

Prototype

BigDecimal ONE

To view the source code for java.math BigDecimal ONE.

Click Source Link

Document

The value 1, with a scale of 0.

Usage

From source file:org.apache.fineract.portfolio.servicecharge.service.ServiceChargeJournalDetailsReadPlatformServiceImpl.java

private Map<GLExpenseTagsForServiceCharge, BigDecimal> apportionMobilization(
        Map<GLExpenseTagsForServiceCharge, BigDecimal> dataMap) {
    Map<GLExpenseTagsForServiceCharge, BigDecimal> resultMap = new HashMap<>();
    BigDecimal mobilizationAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.MOBILIZATION).toPlainString());
    BigDecimal servicingAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.SERVICING).toPlainString());
    BigDecimal investmentAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.INVESTMENT).toPlainString());
    BigDecimal dlAmount = BigDecimal.ONE;
    BigDecimal outstandingLoanAmount = BigDecimal.ONE;

    BigDecimal multiplicand = BigDecimal.ONE.multiply(dlAmount);
    multiplicand = ServiceChargeOperationUtils.divideNonZeroValues(multiplicand, outstandingLoanAmount);

    servicingAmount = mobilizationAmount.multiply(multiplicand);
    investmentAmount = mobilizationAmount.subtract(servicingAmount);

    resultMap.put(GLExpenseTagsForServiceCharge.SERVICING, servicingAmount);
    resultMap.put(GLExpenseTagsForServiceCharge.INVESTMENT, investmentAmount);

    return resultMap;
}

From source file:org.yes.cart.web.support.service.impl.ProductServiceFacadeImplTest.java

@Test
public void testGetSkuPriceSearchAndProductDetailsEmptyPriceNoTaxInfo() throws Exception {

    final PriceService priceService = context.mock(PriceService.class, "priceService");
    final PricingPolicyProvider pricingPolicyProvider = context.mock(PricingPolicyProvider.class,
            "pricingPolicyProvider");
    final ShopService shopService = context.mock(ShopService.class, "shopService");

    final ShoppingCart cart = context.mock(ShoppingCart.class, "cart");
    final ShoppingContext cartCtx = context.mock(ShoppingContext.class, "cartCtx");
    final PricingPolicyProvider.PricingPolicy policy = context.mock(PricingPolicyProvider.PricingPolicy.class,
            "policy");

    final SkuPrice skuPrice = context.mock(SkuPrice.class, "skuPrice");

    final Shop shop = context.mock(Shop.class, "shop");

    context.checking(new Expectations() {
        {/*from w  w w  .  jav a 2  s .co m*/
            allowing(cart).getShoppingContext();
            will(returnValue(cartCtx));
            allowing(cartCtx).getShopId();
            will(returnValue(234L));
            allowing(cartCtx).getCustomerShopId();
            will(returnValue(234L));
            allowing(cartCtx).getShopCode();
            will(returnValue("SHOP10"));
            allowing(cartCtx).getCountryCode();
            will(returnValue("GB"));
            allowing(cartCtx).getStateCode();
            will(returnValue("GB-LON"));
            allowing(cart).getCustomerEmail();
            will(returnValue("bob@doe.com"));
            allowing(cart).getCurrencyCode();
            will(returnValue("EUR"));
            allowing(pricingPolicyProvider).determinePricingPolicy("SHOP10", "EUR", "bob@doe.com", "GB",
                    "GB-LON");
            will(returnValue(policy));
            allowing(policy).getID();
            will(returnValue("P1"));
            allowing(priceService).getMinimalPrice(123L, "ABC", 234L, null, "EUR", BigDecimal.ONE, false, "P1");
            will(returnValue(skuPrice));
            allowing(skuPrice).getSkuCode();
            will(returnValue(null));
            allowing(skuPrice).getQuantity();
            will(returnValue(null));
            allowing(skuPrice).getRegularPrice();
            will(returnValue(null));
            allowing(skuPrice).getSalePriceForCalculation();
            will(returnValue(null));
            allowing(shopService).getById(234L);
            will(returnValue(shop));
            allowing(cartCtx).isTaxInfoEnabled();
            will(returnValue(false));
        }
    });

    final ProductServiceFacade facade = new ProductServiceFacadeImpl(null, null, null, null, null, null,
            pricingPolicyProvider, priceService, null, null, null, shopService, null);

    final ProductPriceModel model = facade.getSkuPrice(cart, 123L, "ABC", BigDecimal.ONE);

    assertNotNull(model);

    assertNull(model.getRef());

    assertEquals("EUR", model.getCurrency());
    assertNull(model.getQuantity());

    assertNull(model.getRegularPrice());
    assertNull(model.getSalePrice());

    assertFalse(model.isTaxInfoEnabled());
    assertFalse(model.isTaxInfoUseNet());
    assertFalse(model.isTaxInfoShowAmount());

    assertNull(model.getPriceTaxCode());
    assertNull(model.getPriceTaxRate());
    assertFalse(model.isPriceTaxExclusive());
    assertNull(model.getPriceTax());

    context.assertIsSatisfied();

}

From source file:com.qcadoo.mes.operationTimeCalculations.OrderRealizationTimeServiceImpl.java

private BigDecimal getQuantityCyclesNeededToProducedNextOperationAfterProducedQuantity(
        final Entity operationComponent, final BigDecimal nextOperationAfterProducedQuantity) {
    MathContext mc = numberService.getMathContext();
    Entity technology = operationComponent.getBelongsToField("technology");

    Map<Long, BigDecimal> operationRunsFromProductionQuantities = Maps.newHashMap();

    OperationProductComponentWithQuantityContainer productQuantities = productQuantitiesService
            .getProductComponentQuantities(technology, BigDecimal.ONE, operationRunsFromProductionQuantities);

    BigDecimal operationsRunsForOneMainProduct = operationRunsFromProductionQuantities
            .get(operationComponent.getId());
    BigDecimal quantityOutputProductProduced = productQuantities.get(getOutputProduct(operationComponent));
    BigDecimal cycles = operationsRunsForOneMainProduct.multiply(nextOperationAfterProducedQuantity, mc)
            .divide(quantityOutputProductProduced, mc);

    return numberService.setScale(cycles);
}

From source file:org.projectforge.plugins.ffp.wicket.FFPEventEditForm.java

private FFPAccountingDO getNewFfpAccountingDO(PFUserDO user) {
    FFPAccountingDO accounting = new FFPAccountingDO();
    accounting.setEvent(getData());/*from www.  ja  v  a  2  s  .  co  m*/
    accounting.setAttendee(user);
    accounting.setValue(BigDecimal.ZERO);
    accounting.setWeighting(BigDecimal.ONE);
    return accounting;
}

From source file:pe.gob.mef.gescon.web.ui.EntidadMB.java

public void activar(ActionEvent event) {
    try {//from  w  w w  .  j  av  a 2  s  .  c  om
        if (event != null) {
            if (this.getSelectedEntidad() != null) {
                LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
                User user = loginMB.getUser();
                EntidadService service = (EntidadService) ServiceFinder.findBean("EntidadService");
                this.getSelectedEntidad().setNactivo(BigDecimal.ONE);
                this.getSelectedEntidad().setDfechamodificacion(new Date());
                this.getSelectedEntidad().setVusuariomodificacion(user.getVlogin());
                service.saveOrUpdate(this.getSelectedEntidad());
                this.setListaEntidad(service.getEntidades());
            } else {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Debe seleccionar la entidad a activar.");
                FacesContext.getCurrentInstance().addMessage(null, message);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openconcerto.sql.model.SQLRow.java

/**
 * The free order just after or before this row.
 * //w ww  .  ja  va  2 s  .  c  o  m
 * @param after whether to look before or after this row.
 * @return a free order, or <code>null</code> if there's no room left.
 */
public final BigDecimal getOrder(boolean after) {
    final BigDecimal destOrder = this.getOrder();
    final SQLRow otherRow = this.getRow(after);
    final BigDecimal otherOrder;
    if (otherRow != null) {
        otherOrder = otherRow.getOrder();
    } else if (after) {
        // dernire ligne de la table
        otherOrder = destOrder.add(ReOrder.DISTANCE);
    } else {
        // premire ligne
        otherOrder = ReOrder.MIN_ORDER;
    }

    final int decDigits = this.getTable().getOrderDecimalDigits();
    final BigDecimal least = BigDecimal.ONE.scaleByPowerOfTen(-decDigits);
    final BigDecimal distance = destOrder.subtract(otherOrder).abs();
    if (distance.compareTo(least) <= 0)
        return null;
    else {
        final BigDecimal mean = destOrder.add(otherOrder).divide(BigDecimal.valueOf(2));
        return DecimalUtils.round(mean, decDigits);
    }
}

From source file:org.yes.cart.web.page.component.SkuCentralView.java

/**
 * Get product or his sku price./*w  ww .j  a v  a 2  s  .  com*/
 * In case of multisku product the minimal regular price from multiple sku was used for single item.
 *
 * @return {@link SkuPrice}
 */
private SkuPrice getSkuPrice() {
    return productServiceFacade.getSkuPrice(null, sku.getCode(), /* We always preselect a SKU */
            BigDecimal.ONE, ApplicationDirector.getShoppingCart().getCurrencyCode(),
            ApplicationDirector.getCurrentShop().getShopId());
}

From source file:org.efaps.esjp.accounting.transaction.FieldUpdate_Base.java

/**
 * Method is executed on update trigger for the rate field in the debit
 * and credit table inside the transaction form.
 *
 * @param _parameter Parameter as passed from the eFaps API
 * @return list for update trigger//from   w  w  w .  jav  a  2  s . c om
 * @throws EFapsException on error
 */
public Return update4Rate(final Parameter _parameter) throws EFapsException {
    final Return retVal = new Return();

    try {
        final String postfix = getProperty(_parameter, "TypePostfix");

        final String[] amounts = _parameter.getParameterValues("amount_" + postfix);
        final String[] rates = _parameter.getParameterValues("rate_" + postfix);
        final String[] ratesInv = _parameter.getParameterValues("rate_" + postfix + RateUI.INVERTEDSUFFIX);

        final int pos = getSelectedRow(_parameter);
        final DecimalFormat rateFormater = NumberFormatter.get().getFormatter(0, 8);
        final DecimalFormat formater = NumberFormatter.get().getTwoDigitsFormatter();
        final BigDecimal amount = amounts[pos].isEmpty() ? BigDecimal.ZERO
                : (BigDecimal) rateFormater.parse(amounts[pos]);
        BigDecimal rate = rates[pos].isEmpty() ? BigDecimal.ONE : (BigDecimal) rateFormater.parse(rates[pos]);
        final boolean rateInv = "true".equalsIgnoreCase(ratesInv[pos]);
        if (rateInv && rate.compareTo(BigDecimal.ZERO) != 0) {
            rate = BigDecimal.ONE.divide(rate, 12, BigDecimal.ROUND_HALF_UP);
        }
        final List<Map<String, String>> list = new ArrayList<>();
        final Instance periodInstance = new Period().evaluateCurrentPeriod(_parameter);

        final BigDecimal sum = getSum4UI(_parameter, postfix, null, null);
        final String postfix2 = "Debit".equals(postfix) ? "Credit" : "Debit";
        final BigDecimal sum2 = getSum4UI(_parameter, postfix2, null, null);
        final String sumStr = formater.format(sum) + " " + new Period().getCurrency(periodInstance).getSymbol();
        final String sumStr2 = formater.format(sum.subtract(sum2).abs()) + " "
                + new Period().getCurrency(periodInstance).getSymbol();

        final Map<String, String> map = new HashMap<>();
        map.put("sum" + postfix, sumStr);
        map.put("amountRate_" + postfix,
                formater.format(amount.setScale(8).divide(rate, BigDecimal.ROUND_HALF_UP)));
        map.put("sumTotal", sumStr2);
        list.add(map);

        retVal.put(ReturnValues.VALUES, list);
    } catch (final ParseException e) {
        throw new EFapsException(Transaction_Base.class, "update4Rate.ParseException", e);
    }
    return retVal;
}

From source file:pe.gob.mef.gescon.hibernate.impl.ConsultaDaoImpl.java

@Override
public BigDecimal countDestacadosByTipoConocimiento(HashMap filters) {
    String ntipoconocimientoid = ((BigDecimal) filters.get("ntipoconocimientoid")).toString();
    final StringBuilder sql = new StringBuilder();
    Object object = null;//from www  .  j  a va 2  s.c  o m
    try {
        if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("1")) {
            sql.append("SELECT DISTINCT COUNT(a.nbaselegalid) AS CID ");
            sql.append("FROM TBASELEGAL a ");
            sql.append("WHERE a.nactivo = :ACTIVO ");
            sql.append("AND a.ndestacado = :DESTACADO ");
            sql.append("AND a.nestadoid IN (3,5,6) "); // Publicada, Concordada y Modificada.
        }
        if (StringUtils.isNotBlank(ntipoconocimientoid) && ntipoconocimientoid.equals("2")) {
            sql.append("SELECT DISTINCT COUNT(a.npreguntaid) AS CID ");
            sql.append("FROM TPREGUNTA a ");
            sql.append("WHERE a.nactivo = :ACTIVO ");
            sql.append("AND a.ndestacado = :DESTACADO ");
            sql.append("AND a.nsituacionid = 6 "); // Publicada
        }
        if (StringUtils.isNotBlank(ntipoconocimientoid)
                && (ntipoconocimientoid.equals("3") || ntipoconocimientoid.equals("4")
                        || ntipoconocimientoid.equals("5") || ntipoconocimientoid.equals("6"))) {
            sql.append("SELECT DISTINCT COUNT(a.nconocimientoid) AS CID ");
            sql.append("FROM TCONOCIMIENTO a ");
            sql.append("WHERE a.nactivo = :ACTIVO ");
            sql.append("AND a.ndestacado = :DESTACADO ");
            sql.append("AND a.nsituacionid = 6 AND a.NTPOCONOCIMIENTOID = ").append(ntipoconocimientoid)
                    .append(" "); // Publicado
        }

        object = getHibernateTemplate().execute(new HibernateCallback() {
            @Override
            public Object doInHibernate(Session session) throws HibernateException {
                Query query = session.createSQLQuery(sql.toString());
                query.setParameter("ACTIVO", BigDecimal.ONE);
                query.setParameter("DESTACADO", BigDecimal.ONE);
                return query.uniqueResult();
            }
        });
    } catch (DataAccessException e) {
        e.getMessage();
        e.printStackTrace();
    }
    return (BigDecimal) object;
}

From source file:org.openvpms.archetype.rules.product.ProductPriceRules.java

/**
 * Returns the service ratio for a product.
 * <p/>//from   w w  w  .  ja  va  2  s .  co m
 * This is a factor that is applied to a product's prices when the product is charged at a particular practice
 * location. It is determined by the <em>entityLink.locationProductType</em> relationship between the location and
 * the product's type.
 *
 * @param product  the product
 * @param location the practice location
 * @return the service ratio. If there is no relationship, returns {@code 1.0}
 */
public BigDecimal getServiceRatio(Product product, Party location) {
    BigDecimal ratio = BigDecimal.ONE;
    IMObjectBean bean = new IMObjectBean(product, service);
    IMObjectReference productType = bean.getNodeSourceObjectRef("type");
    if (productType != null) {
        IMObjectBean locationBean = new IMObjectBean(location, service);
        Predicate predicate = AndPredicate.getInstance(isActiveNow(), getTargetEquals(productType));
        EntityLink link = (EntityLink) locationBean.getValue("serviceRatios", predicate);
        if (link != null) {
            IMObjectBean linkBean = new IMObjectBean(link, service);
            ratio = linkBean.getBigDecimal("ratio", BigDecimal.ONE);
        }
    }
    return ratio;
}