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:com.opensourcestrategies.financials.accounts.GLAccountInTree.java

/**
 * Gets the balance of this GL account given child GL account.
 * @param childAccount a <code>GLAccountInTree</code> value
 * @return a <code>BigDecimal</code> value
 *///from ww w  .j  a v  a 2 s.  c o  m
private BigDecimal getBalanceOfChildrenRec(GLAccountInTree childAccount) {
    if (childAccount == null) {
        return BigDecimal.ZERO;
    }
    BigDecimal balanceOfChildren = childAccount.balance;
    if ((childAccount.isDebitAccount && this.isCreditAccount)
            || (childAccount.isCreditAccount && this.isDebitAccount)) {
        balanceOfChildren = balanceOfChildren.negate();
    }

    for (GLAccountInTree grandchildAccount : childAccount.childAccounts) {
        balanceOfChildren = balanceOfChildren.add(getBalanceOfChildrenRec(grandchildAccount));
    }
    return balanceOfChildren;
}

From source file:de.hybris.platform.accountsummaryaddon.document.populators.B2BAmountBalancePopulator.java

private String totalAmount(final Collection<B2BDocumentModel> documents) {
    CurrencyModel currency = getCommerceCommonI18NService().getCurrentCurrency();
    final LanguageModel currentLanguage = getCommonI18NService().getCurrentLanguage();
    Locale locale = getCommerceCommonI18NService().getLocaleForLanguage(currentLanguage);

    if (locale == null) {
        // Fallback to session locale
        locale = getI18NService().getCurrentLocale();
    }// ww  w .  j ava  2 s .c  o m

    if (documents != null && !documents.isEmpty()) {
        currency = documents.iterator().next().getCurrency();

        return amountFormatter.formatAmount(sumOfOpenAmount(documents), currency, locale);
    }
    return amountFormatter.formatAmount(BigDecimal.ZERO, currency, locale);
}

From source file:org.openvpms.archetype.rules.party.CustomerMergerTestCase.java

/**
 * Tests a merge where the merge-from customer has an account type,
 * and the merge-to customer doesn't./*  w  w w .jav  a 2s.co  m*/
 */
@Test
public void testMergeAccountType() {
    Party from = TestHelper.createCustomer();
    Party to = TestHelper.createCustomer();
    Lookup accountType = FinancialTestHelper.createAccountType(30, DateUnits.DAYS, BigDecimal.ZERO);

    from.addClassification(accountType);

    Party merged = checkMerge(from, to);
    assertEquals(accountType, customerRules.getAccountType(merged));
}

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

public void cleanAttributes() {
    this.setId(BigDecimal.ZERO);
    this.setDescripcion(StringUtils.EMPTY);
    this.setNombre(StringUtils.EMPTY);
    this.setValor(StringUtils.EMPTY);
    this.setActivo(BigDecimal.ONE);
    this.setSelectedParametro(null);
    Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages();
    if (iter.hasNext() == true) {
        iter.remove();/*from  ww  w.ja  v a  2  s  . com*/
        FacesContext.getCurrentInstance().renderResponse();
    }
}

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

@Override
public TBuilder setTaxRate(TaxRateType rateType, BigDecimal amount) {
    BillyValidator.notNull(rateType, TaxBuilderImpl.LOCALIZER.getString("field.tax_rate_type"));
    BillyValidator.notNull(amount, TaxBuilderImpl.LOCALIZER.getString("field.tax_rate_amount"));
    this.getTypeInstance().setTaxRateType(rateType);
    switch (rateType) {
    case FLAT://from  w  w w.j  av a2 s.com
        this.getTypeInstance().setPercentageRateValue(BigDecimal.ZERO);
        this.getTypeInstance().setFlatRateAmount(amount);
        break;
    case PERCENTAGE:
        Validate.inclusiveBetween(BigDecimal.ZERO, new BigDecimal("100"), amount);
        this.getTypeInstance().setPercentageRateValue(amount);
        this.getTypeInstance().setFlatRateAmount(BigDecimal.ZERO);
        break;
    case NONE:
        break;
    default:
        throw new RuntimeException("The tax rate type is unknown");
    }
    return this.getBuilder();
}

From source file:Main.java

public static Duration subtract(XMLGregorianCalendar x1, XMLGregorianCalendar x2) {
    boolean positive = x1.compare(x2) >= 0;

    if (!positive) {
        XMLGregorianCalendar temp = x1;
        x1 = x2;//from  w  w w. j a  v  a  2s . c om
        x2 = temp;
    }

    BigDecimal s1 = getSeconds(x1);
    BigDecimal s2 = getSeconds(x2);
    BigDecimal seconds = s1.subtract(s2);
    if (seconds.compareTo(BigDecimal.ZERO) < 0)
        seconds = seconds.add(BigDecimal.valueOf(60));

    GregorianCalendar g1 = x1.toGregorianCalendar();
    GregorianCalendar g2 = x2.toGregorianCalendar();

    int year = 0;
    for (int f : reverseFields) {
        if (f == Calendar.YEAR) {
            int year1 = g1.get(f);
            int year2 = g2.get(f);
            year = year1 - year2;
        } else {
            subtractField(g1, g2, f);
        }
    }

    return FACTORY.newDuration(positive, BigInteger.valueOf(year), BigInteger.valueOf(g1.get(Calendar.MONTH)),
            BigInteger.valueOf(g1.get(Calendar.DAY_OF_MONTH) - 1),
            BigInteger.valueOf(g1.get(Calendar.HOUR_OF_DAY)), BigInteger.valueOf(g1.get(Calendar.MINUTE)),
            seconds);
}

From source file:org.openmrs.module.billing.web.controller.main.TenderBillEditController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, @RequestParam("tenderBillId") Integer tenderBillId,
        @RequestParam("companyId") Integer companyId, @RequestParam("tenderIds") Integer[] tenderIds,
        @RequestParam("action") String action, HttpServletRequest request, Object command,
        BindingResult binding) {//from w  ww. ja  v a 2 s  .  c  o  m

    validateQty(tenderIds, binding, request);
    if (binding.hasErrors()) {
        model.addAttribute("errors", binding.getAllErrors());
        return "module/billing/main/tenderBillAdd";
    }

    BillingService billingService = (BillingService) Context.getService(BillingService.class);

    TenderBill tenderBill = billingService.getTenderBillById(tenderBillId);
    if ("void".equalsIgnoreCase(action)) {
        tenderBill.setVoided(true);
        tenderBill.setVoidedDate(new Date());
        for (TenderBillItem item : tenderBill.getBillItems()) {
            item.setVoided(true);
            item.setVoidedDate(new Date());
        }
        billingService.saveTenderBill(tenderBill);
        return "redirect:/module/billing/tenderBill.list?companyId=" + companyId;
    }

    tenderBill.setPrinted(false);

    // void old items and reset amount
    Map<Integer, TenderBillItem> mapOldItems = new HashMap<Integer, TenderBillItem>();
    for (TenderBillItem item : tenderBill.getBillItems()) {
        item.setVoided(true);
        item.setVoidedDate(new Date());
        mapOldItems.put(item.getTenderBillItemId(), item);
    }
    tenderBill.setAmount(BigDecimal.ZERO);

    Tender tender = null;
    int quantity = 0;
    Money itemAmount;
    Money totalAmount = new Money(BigDecimal.ZERO);
    TenderBillItem item;
    for (Integer id : tenderIds) {

        tender = billingService.getTenderById(id);
        quantity = Integer.parseInt(request.getParameter(id + "_qty"));
        itemAmount = new Money(tender.getPrice());
        itemAmount = itemAmount.times(quantity);
        totalAmount = totalAmount.plus(itemAmount);

        String sItemId = request.getParameter(id + "_itemId");

        if (sItemId != null) {
            item = mapOldItems.get(Integer.parseInt(sItemId));
            item.setVoided(false);
            item.setVoidedDate(null);
            item.setQuantity(quantity);
            item.setAmount(itemAmount.getAmount());
        } else {
            item = new TenderBillItem();
            item.setName(tender.getName() + "_" + tender.getNumber());
            item.setCreatedDate(new Date());
            item.setTender(tender);
            item.setUnitPrice(tender.getPrice());
            item.setQuantity(quantity);
            item.setTenderBill(tenderBill);
            item.setAmount(itemAmount.getAmount());
            tenderBill.addBillItem(item);
        }
    }
    tenderBill.setAmount(totalAmount.getAmount());
    tenderBill = billingService.saveTenderBill(tenderBill);

    return "redirect:/module/billing/tenderBill.list?companyId=" + companyId + "&tenderBillId="
            + tenderBill.getTenderBillId();
}

From source file:de.hybris.platform.accountsummaryaddon.document.populators.B2BAmountBalancePopulator.java

private BigDecimal sumOfOpenAmount(final Collection<B2BDocumentModel> documents) {
    BigDecimal total = BigDecimal.ZERO;
    for (final B2BDocumentModel document : documents) {
        if (document.getDocumentType().getIncludeInOpenBalance().booleanValue()) {
            if (document.getOpenAmount() != null) {
                total = total.add(document.getOpenAmount());
            }//  w  ww  . j a v a2  s  . c  o m
        }
    }
    return total;
}

From source file:com.redhat.lightblue.metadata.types.DoubleTypeTest.java

@Test
public void testCompareNotEqual() {
    assertEquals(doubleType.compare((Object) BigDecimal.ZERO, (Object) Double.MAX_VALUE), -1);
}

From source file:org.openmrs.module.billing.web.controller.main.BillableServiceBillAddController.java

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, Object command, BindingResult bindingResult, HttpServletRequest request,
        @RequestParam("cons") Integer[] cons, @RequestParam("patientId") Integer patientId) {
    validate(cons, bindingResult, request);
    if (bindingResult.hasErrors()) {
        model.addAttribute("errors", bindingResult.getAllErrors());
        return "module/billing/main/billableServiceBillEdit";
    }/*from ww w  . ja  va  2  s. co m*/

    BillingService billingService = Context.getService(BillingService.class);

    PatientService patientService = Context.getPatientService();

    // Get the BillCalculator to calculate the rate of bill item the patient has to pay
    Patient patient = patientService.getPatient(patientId);
    Map<String, String> attributes = PatientUtils.getAttributes(patient);
    BillCalculatorService calculator = new BillCalculatorService();

    PatientServiceBill bill = new PatientServiceBill();
    bill.setCreatedDate(new Date());
    bill.setPatient(patient);
    bill.setCreator(Context.getAuthenticatedUser());

    PatientServiceBillItem item;
    int quantity = 0;
    Money itemAmount;
    Money mUnitPrice;
    Money totalAmount = new Money(BigDecimal.ZERO);
    BigDecimal totalActualAmount = new BigDecimal(0);
    BigDecimal unitPrice;
    String name;
    BillableService service;

    for (int conceptId : cons) {

        unitPrice = NumberUtils.createBigDecimal(request.getParameter(conceptId + "_unitPrice"));
        quantity = NumberUtils.createInteger(request.getParameter(conceptId + "_qty"));
        name = request.getParameter(conceptId + "_name");
        service = billingService.getServiceByConceptId(conceptId);

        mUnitPrice = new Money(unitPrice);
        itemAmount = mUnitPrice.times(quantity);
        totalAmount = totalAmount.plus(itemAmount);

        item = new PatientServiceBillItem();
        item.setCreatedDate(new Date());
        item.setName(name);
        item.setPatientServiceBill(bill);
        item.setQuantity(quantity);
        item.setService(service);
        item.setUnitPrice(unitPrice);

        item.setAmount(itemAmount.getAmount());

        // Get the ratio for each bill item
        Map<String, Object> parameters = HospitalCoreUtils.buildParameters("patient", patient, "attributes",
                attributes, "billItem", item, "request", request);
        BigDecimal rate = calculator.getRate(parameters);
        item.setActualAmount(item.getAmount().multiply(rate));
        totalActualAmount = totalActualAmount.add(item.getActualAmount());

        bill.addBillItem(item);
    }
    bill.setAmount(totalAmount.getAmount());
    bill.setActualAmount(totalActualAmount);

    bill.setFreeBill(calculator.isFreeBill(HospitalCoreUtils.buildParameters("attributes", attributes)));
    logger.info("Is free bill: " + bill.getFreeBill());

    bill.setReceipt(billingService.createReceipt());
    bill = billingService.savePatientServiceBill(bill);
    return "redirect:/module/billing/patientServiceBill.list?patientId=" + patientId + "&billId="
            + bill.getPatientServiceBillId();

}