Example usage for java.math BigDecimal ZERO

List of usage examples for java.math BigDecimal ZERO

Introduction

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

Prototype

BigDecimal ZERO

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

Click Source Link

Document

The value 0, with a scale of 0.

Usage

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

public void desactivar(ActionEvent event) {
    try {/*from  ww w .j av a 2s . c  om*/
        if (event != null) {
            if (this.getSelectedPolitica() != null) {
                LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
                User user = loginMB.getUser();
                PoliticaService service = (PoliticaService) ServiceFinder.findBean("PoliticaService");
                this.getSelectedPolitica().setNactivo(BigDecimal.ZERO);
                this.getSelectedPolitica().setDfechamodificacion(new Date());
                this.getSelectedPolitica().setVusuariomodificacion(user.getVlogin());
                service.saveOrUpdate(this.getSelectedPolitica());
                this.setListaPolitica(service.getPoliticas());
            } else {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Debe seleccionar politica a desactivar.");
                FacesContext.getCurrentInstance().addMessage(null, message);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java

/**
 * Tests the {@link TillRules#startClearTill(FinancialAct, BigDecimal)} method.
 *//* w  w  w  . ja  v  a 2s.  c o m*/
@Test
public void testStartClearTill() {
    FinancialAct balance1 = (FinancialAct) createBalance(till, TillBalanceStatus.UNCLEARED).getAct();
    rules.startClearTill(balance1, BigDecimal.ZERO);
    balance1 = get(balance1);
    assertEquals(TillBalanceStatus.IN_PROGRESS, balance1.getStatus());

    List<FinancialAct> payment = createPayment(till);
    payment.get(0).setStatus(POSTED);
    save(payment);

    // make sure the payment went into a new till balance
    FinancialAct balance2 = TillHelper.getUnclearedTillBalance(till, getArchetypeService());
    assertNotNull(balance2);
    assertFalse(balance1.getId() == balance2.getId());
    ActBean bean = new ActBean(balance2);
    assertTrue(bean.hasNodeTarget("items", payment.get(0)));
}

From source file:com.teamj.distribuidas.web.ExcursionUserBean.java

public void loadExcursionSelectedData(SelectEvent event) {
    this.excursionArticulos = ((Excursion) event.getObject()).getExcursionArticulos();
    try {//from   w  ww .  ja va  2  s .  co  m
        BeanUtils.copyProperties(this.excursion, this.excursionSelected);
        // FacesContext.getCurrentInstance().addMessage(null, msg);
    } catch (IllegalAccessException | InvocationTargetException ex) {
        Logger.getLogger(ExcursionUserBean.class.getName()).log(Level.SEVERE, null, ex);
    }
    this.totalArticulos = 0;
    this.subtotal = new BigDecimal(BigInteger.ZERO);
    this.derechoExcursionSeleccionada = BigDecimal.ZERO;
    if (this.excursionArticulosSelected != null) {
        this.excursionArticulosSelected.clear();
    }
}

From source file:com.gst.portfolio.savings.domain.SavingsAccountCharge.java

private void populateDerivedFields(final BigDecimal transactionAmount, final BigDecimal chargeAmount) {

    switch (ChargeCalculationType.fromInt(this.chargeCalculation)) {
    case INVALID:
        this.percentage = null;
        this.amount = null;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        this.amountOutstanding = BigDecimal.ZERO;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;//  ww  w.  ja va  2 s  .com
    case FLAT:
        this.percentage = null;
        this.amount = chargeAmount;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        this.amountOutstanding = chargeAmount;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
    case PERCENT_OF_AMOUNT:
        this.percentage = chargeAmount;
        this.amountPercentageAppliedTo = transactionAmount;
        this.amount = percentageOf(this.amountPercentageAppliedTo, this.percentage);
        this.amountPaid = null;
        this.amountOutstanding = calculateOutstanding();
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
    case PERCENT_OF_AMOUNT_AND_INTEREST:
        this.percentage = null;
        this.amount = null;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        this.amountOutstanding = BigDecimal.ZERO;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
    case PERCENT_OF_INTEREST:
        this.percentage = null;
        this.amount = null;
        this.amountPercentageAppliedTo = null;
        this.amountPaid = null;
        this.amountOutstanding = BigDecimal.ZERO;
        this.amountWaived = null;
        this.amountWrittenOff = null;
        break;
    }
}

From source file:net.shopxx.controller.shop.OrderController.java

@RequestMapping(value = "/calculate", method = RequestMethod.GET)
public @ResponseBody Map<String, Object> calculate(Long receiverId, Long paymentMethodId, Long shippingMethodId,
        String code, String invoiceTitle, BigDecimal balance, String memo) {
    Map<String, Object> data = new HashMap<String, Object>();
    Cart cart = cartService.getCurrent();
    if (cart == null || cart.isEmpty()) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }/*from   ww  w .j  a  va 2 s  .c  o  m*/
    Member member = memberService.getCurrent();
    Receiver receiver = receiverService.find(receiverId);
    if (receiver != null && !member.equals(receiver.getMember())) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }
    if (balance != null && balance.compareTo(BigDecimal.ZERO) < 0) {
        data.put("message", ERROR_MESSAGE);
        return data;
    }
    if (balance != null && balance.compareTo(member.getBalance()) > 0) {
        data.put("message", Message.warn("shop.order.insufficientBalance"));
        return data;
    }

    PaymentMethod paymentMethod = paymentMethodService.find(paymentMethodId);
    ShippingMethod shippingMethod = shippingMethodService.find(shippingMethodId);
    CouponCode couponCode = couponCodeService.findByCode(code);
    Invoice invoice = StringUtils.isNotEmpty(invoiceTitle) ? new Invoice(invoiceTitle, null) : null;
    Order order = orderService.generate(Order.Type.general, cart, receiver, paymentMethod, shippingMethod,
            couponCode, invoice, balance, memo);

    data.put("message", SUCCESS_MESSAGE);
    data.put("price", order.getPrice());
    data.put("fee", order.getFee());
    data.put("freight", order.getFreight());
    data.put("tax", order.getTax());
    data.put("promotionDiscount", order.getPromotionDiscount());
    data.put("couponDiscount", order.getCouponDiscount());
    data.put("amount", order.getAmount());
    data.put("amountPayable", order.getAmountPayable());
    return data;
}

From source file:com.premiumminds.billy.core.services.builders.impl.GenericInvoiceEntryBuilderImpl.java

protected void validateValues() throws ValidationException {
    MathContext mc = BillyMathContext.get();

    GenericInvoiceEntryEntity e = this.getTypeInstance();

    for (Tax t : e.getProduct().getTaxes()) {
        if (this.daoContext.isSubContext(t.getContext(), this.context)) {
            Date taxDate = e.getTaxPointDate() == null ? new Date() : e.getTaxPointDate();
            if (DateUtils.isSameDay(t.getValidTo(), taxDate) || t.getValidTo().after(taxDate)) {
                e.getTaxes().add(t);//from  w  w w .  j  a  v  a2s. co  m
            }
        }
    }
    if (e.getTaxes().isEmpty()) {
        throw new ValidationException(
                GenericInvoiceEntryBuilderImpl.LOCALIZER.getString("exception.invalid_taxes"));
    }

    e.setUnitDiscountAmount(BigDecimal.ZERO); // TODO

    if (e.getUnitAmountWithTax() != null) {
        BigDecimal unitAmountWithoutTax = e.getUnitAmountWithTax();
        BigDecimal unitTaxAmount = BigDecimal.ZERO;
        for (Tax t : this.getTypeInstance().getTaxes()) {
            switch (t.getTaxRateType()) {
            case FLAT:
                unitAmountWithoutTax = unitAmountWithoutTax.subtract(t.getValue(), mc);
                unitTaxAmount = unitTaxAmount.add(t.getValue(), mc);
                break;
            case PERCENTAGE:
                unitAmountWithoutTax = e.getUnitAmountWithTax().divide(
                        BigDecimal.ONE.add(t.getPercentageRateValue().divide(new BigDecimal("100"), mc), mc),
                        mc);
                unitTaxAmount = unitTaxAmount.add(e.getUnitAmountWithTax().subtract(unitAmountWithoutTax, mc),
                        mc);

                break;
            default:
                break;
            }
        }
        e.setUnitAmountWithoutTax(unitAmountWithoutTax);
        e.setUnitTaxAmount(unitTaxAmount);

        // Minus discounts
        e.setUnitAmountWithoutTax(unitAmountWithoutTax.subtract(e.getUnitDiscountAmount(), mc));
    } else {
        BigDecimal unitAmountWithTax = e.getUnitAmountWithoutTax();
        BigDecimal unitTaxAmount = BigDecimal.ZERO;

        for (Tax t : this.getTypeInstance().getTaxes()) {
            switch (t.getTaxRateType()) {
            case FLAT:
                unitAmountWithTax = unitAmountWithTax.add(t.getValue(), mc);
                unitTaxAmount = unitTaxAmount.add(t.getValue(), mc);
                break;
            case PERCENTAGE:
                unitTaxAmount = unitTaxAmount.add(e.getUnitAmountWithoutTax()
                        .multiply(t.getPercentageRateValue(), mc).divide(new BigDecimal("100"), mc), mc);
                unitAmountWithTax = unitAmountWithTax.add(unitTaxAmount, mc);
                break;
            default:
                break;
            }
        }

        e.setUnitAmountWithTax(unitAmountWithTax);
        e.setUnitTaxAmount(unitTaxAmount);

    }

    e.setAmountWithTax(this.getTypeInstance().getUnitAmountWithTax().multiply(e.getQuantity(), mc));
    e.setAmountWithoutTax(this.getTypeInstance().getUnitAmountWithoutTax().multiply(e.getQuantity(), mc));
    e.setTaxAmount(this.getTypeInstance().getUnitTaxAmount().multiply(e.getQuantity(), mc));
    e.setDiscountAmount(this.getTypeInstance().getUnitDiscountAmount().multiply(e.getQuantity(), mc));
}

From source file:com.aoindustries.creditcards.TransactionRequest.java

/**
 * Sets the shipping amount of the transaction.
 *
 * The amount is normalized to the proper number of decimal places for the selected currency.
 *
 * @throws  IllegalArgumentException  if shippingAmount < 0 or is incorrectly formatted for the currency.
 *//*from   w w  w.  j a  v  a  2  s.  co  m*/
public void setShippingAmount(BigDecimal shippingAmount) {
    if (shippingAmount == null) {
        this.shippingAmount = null;
    } else {
        if (shippingAmount.compareTo(BigDecimal.ZERO) < 0)
            throw new LocalizedIllegalArgumentException(accessor,
                    "TransactionRequest.setShippingAmount.shippingAmount.lessThanZero");
        try {
            this.shippingAmount = shippingAmount.setScale(currency.getDefaultFractionDigits());
        } catch (ArithmeticException err) {
            throw new LocalizedIllegalArgumentException(err, accessor,
                    "TransactionRequest.setShippingAmount.shippingAmount.cannotNormalize");
        }
    }
}

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

public void desactivar(ActionEvent event) {
    try {// w  w w.j a  v  a  2  s. co  m
        if (event != null) {
            if (this.getSelectedParametro() != null) {
                LoginMB loginMB = (LoginMB) JSFUtils.getSessionAttribute("loginMB");
                User user = loginMB.getUser();
                ParametroService service = (ParametroService) ServiceFinder.findBean("ParametroService");
                this.getSelectedParametro().setNactivo(BigDecimal.ZERO);
                this.getSelectedParametro().setDfechamodificacion(new Date());
                this.getSelectedParametro().setVusuariomodificacion(user.getVlogin());
                service.saveOrUpdate(this.getSelectedParametro());
                this.setListaParametro(service.getParametros());
            } else {
                FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, Constante.SEVERETY_ALERTA,
                        "Debe seleccionar el parametro a desactivar.");
                FacesContext.getCurrentInstance().addMessage(null, message);
            }
        }
    } catch (Exception e) {
        log.error(e.getMessage());
        e.printStackTrace();
    }
}

From source file:net.sourceforge.fenixedu.domain.Shift.java

public BigDecimal getCourseLoadWeeklyAverage() {
    BigDecimal weeklyHours = BigDecimal.ZERO;
    for (CourseLoad courseLoad : getCourseLoadsSet()) {
        weeklyHours = weeklyHours.add(courseLoad.getWeeklyHours());
    }//from   w ww. j  a v  a 2  s .  c o  m
    return weeklyHours;
}

From source file:com.axelor.apps.account.service.payment.PayboxService.java

public void checkPaidAmount(PaymentVoucher paymentVoucher) throws AxelorException {

    if (paymentVoucher.getRemainingAmount().compareTo(BigDecimal.ZERO) > 0) {
        throw new AxelorException(
                String.format(I18n.get(IExceptionMessage.PAYBOX_3), GeneralServiceImpl.EXCEPTION),
                IException.INCONSISTENCY);
    }//from   w  w  w .java 2 s . c om

}