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.aoindustries.website.clientarea.accounting.MakePaymentStoredCardForm.java

@Override
public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
    ActionErrors errors = new ActionErrors();
    if (GenericValidator.isBlankOrNull(paymentAmount)) {
        errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.required"));
    } else {/*from w w w  . ja  va  2 s. co m*/
        try {
            BigDecimal pa = new BigDecimal(this.paymentAmount);
            if (pa.compareTo(BigDecimal.ZERO) <= 0) {
                errors.add("paymentAmount",
                        new ActionMessage("makePaymentStoredCardForm.paymentAmount.mustBeGeaterThanZero"));
            } else if (pa.scale() > 2) {
                // Must not have more than 2 decimal places
                errors.add("paymentAmount",
                        new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid"));
            }
        } catch (NumberFormatException err) {
            errors.add("paymentAmount", new ActionMessage("makePaymentStoredCardForm.paymentAmount.invalid"));
        }
    }
    return errors;
}

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

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, @RequestParam("companyId") Integer companyId,
        @RequestParam("tenderIds") Integer[] tenderIds, HttpServletRequest request, Object command,
        BindingResult binding) {/*w  w w .  j a v a  2s .  c  om*/

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

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

    Company company = billingService.getCompanyById(companyId);

    TenderBill tenderBill = new TenderBill();
    tenderBill.setCompany(company);
    tenderBill.setCreatedDate(new Date());
    tenderBill.setCreator(Context.getAuthenticatedUser());

    Tender tender = null;
    int quantity = 0;
    Money itemAmount;
    Money totalAmount = new Money(BigDecimal.ZERO);
    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);

        TenderBillItem 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.setReceipt(billingService.createReceipt());
    tenderBill = billingService.saveTenderBill(tenderBill);

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

From source file:de.jfachwert.post.PLZ.java

private static void validateNumberWith(String plz, int length, String zahl) {
    LengthValidator.validate(plz, length);
    new NumberValidator(BigDecimal.ZERO, BigDecimal.TEN.pow(length)).validate(zahl);
}

From source file:cz.cas.lib.proarc.common.workflow.FilterFindParameterQueryTest.java

@Test
public void testFilter() {
    String taskProfileName = "task.id1";
    TaskParameterView dbParam2 = new TaskParameterView();
    dbParam2.setJobId(BigDecimal.ZERO);
    dbParam2.setParamRef("param.id2");
    dbParam2.setTaskId(BigDecimal.TEN);
    dbParam2.setTaskProfileName(taskProfileName);
    dbParam2.addValueString("testVal");
    List<TaskParameterView> params = Arrays.asList(dbParam2);
    TaskParameterFilter filter = new TaskParameterFilter();
    filter.setTaskId(BigDecimal.TEN);
    filter.setLocale(Locale.ENGLISH);
    List<TaskParameterView> result = new FilterFindParameterQuery(wp).filter(params, filter, null,
            wp.getProfiles());//from w ww  . j av  a2s  . c  om
    assertEquals(2, result.size());
    assertEquals("param.id1", result.get(0).getParamRef());
    assertEquals(DisplayType.TEXT, result.get(0).getDisplayType());
    assertEquals(taskProfileName, result.get(0).getTaskProfileName());
    assertEquals(filter.getTaskId(), result.get(0).getTaskId());

    assertEquals("param.id2", result.get(1).getParamRef());
    assertEquals("testVal", result.get(1).getValue());
    assertEquals(DisplayType.TEXT, result.get(1).getDisplayType());
    assertEquals(taskProfileName, result.get(1).getTaskProfileName());
    assertEquals(filter.getTaskId(), result.get(1).getTaskId());
}

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

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, @RequestParam("driverId") Integer driverId,
        @RequestParam("ambulanceIds") Integer[] ambulanceIds, HttpServletRequest request, Object command,
        BindingResult binding) {/*from   ww w. j a  v  a2s . c o m*/

    validate(ambulanceIds, binding, request);
    if (binding.hasErrors()) {
        model.addAttribute("errors", binding.getAllErrors());
        return "module/billing/main/ambulanceBillAdd";
    }

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

    Driver driver = billingService.getDriverById(driverId);
    AmbulanceBill ambulanceBill = new AmbulanceBill();
    ambulanceBill.setDriver(driver);
    ambulanceBill.setCreatedDate(new Date());
    ambulanceBill.setCreator(Context.getAuthenticatedUser());

    Ambulance ambulance = null;
    Money itemAmount;
    Money totalAmount = new Money(BigDecimal.ZERO);
    for (Integer id : ambulanceIds) {

        ambulance = billingService.getAmbulanceById(id);
        BigDecimal amount = new BigDecimal(request.getParameter(id + "_amount"));
        itemAmount = new Money(amount);
        totalAmount = totalAmount.plus(itemAmount);

        Integer numberOfTrip = Integer.parseInt(request.getParameter(id + "_numOfTrip"));

        //ghanshyam 07/07/2012 New Requirement #305: Additional details in Ambulance Bill
        String patientName = (request.getParameter(id + "_patientName"));
        //ghanshyam 1/08/2012 feedback of New Requirement #305: Additional details in Ambulance Bill
        String receiptNumber = (request.getParameter(id + "_receiptNumber"));
        String origin = (request.getParameter(id + "_origin"));
        String destination = (request.getParameter(id + "_destination"));

        AmbulanceBillItem item = new AmbulanceBillItem();
        item.setName(ambulance.getName());
        item.setCreatedDate(new Date());
        item.setNumberOfTrip(numberOfTrip);
        item.setAmbulance(ambulance);
        item.setAmbulanceBill(ambulanceBill);
        item.setAmount(itemAmount.getAmount());

        //ghanshyam 07/07/2012 New Requirement #305: Additional details in Ambulance Bill
        item.setPatientName(patientName);
        item.setReceiptNumber(receiptNumber);
        item.setOrigin(origin);
        item.setDestination(destination);

        ambulanceBill.addBillItem(item);
    }
    ambulanceBill.setAmount(totalAmount.getAmount());
    ambulanceBill.setReceipt(billingService.createReceipt());
    ambulanceBill = billingService.saveAmbulanceBill(ambulanceBill);

    return "redirect:/module/billing/ambulanceBill.list?driverId=" + driverId + "&ambulanceBillId="
            + ambulanceBill.getAmbulanceBillId();
}

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

@RequestMapping(method = RequestMethod.POST)
public String onSubmit(Model model, @RequestParam(value = "serviceId") Integer miscellaneousServiceId,
        @RequestParam("billId") Integer billId, @RequestParam("name") String name,
        @RequestParam("action") String action, Object command, BindingResult binding,
        HttpServletRequest request) {//from  w  ww .j  a  v  a 2  s.  co m

    BillingService billingService = (BillingService) Context.getService(BillingService.class);
    MiscellaneousServiceBill miscellaneousServiceBill = billingService.getMiscellaneousServiceBillById(billId);

    // if action is void
    if ("void".equalsIgnoreCase(action)) {
        miscellaneousServiceBill.setVoided(true);
        billingService.saveMiscellaneousServiceBill(miscellaneousServiceBill);
        return "redirect:/module/billing/miscellaneousServiceBill.list";
    }

    //07/07/2012:kesavulu: New Requirement #306 Add field quantity in Miscellaneous Services Bill

    MiscellaneousService miscellaneousService = null;
    int quantity = 0;
    Money itemAmount;
    Money totalAmount = new Money(BigDecimal.ZERO);

    miscellaneousService = billingService.getMiscellaneousServiceById(miscellaneousServiceId);
    quantity = Integer.parseInt(request.getParameter(miscellaneousServiceId + "_qty"));
    itemAmount = new Money(new BigDecimal(request.getParameter(miscellaneousServiceId + "_amount")));

    itemAmount = itemAmount.times(quantity);
    totalAmount = totalAmount.plus(itemAmount);
    miscellaneousServiceBill.setLiableName(name);

    miscellaneousService = billingService.getMiscellaneousServiceById(miscellaneousServiceId);
    miscellaneousServiceBill.setAmount(totalAmount.getAmount());
    miscellaneousServiceBill.setService(miscellaneousService);
    miscellaneousServiceBill.setQuantity(quantity);
    miscellaneousServiceBill = billingService.saveMiscellaneousServiceBill(miscellaneousServiceBill);

    return "redirect:/module/billing/miscellaneousServiceBill.list?serviceId=" + miscellaneousServiceId
            + "&billId=" + miscellaneousServiceBill.getId();
}

From source file:com.siapa.managedbean.DetalleMuestreoManagedBean.java

@Override
public void saveNew(ActionEvent event) {
    DetalleMuestreo detallemuestreo = getDetallemuestreo();
    detallemuestreo.setIdMuestreo(muestreo);
    detallemuestreoService.save(detallemuestreo);
    BigInteger cant = detallemuestreoService.cantidad(muestreo.getIdMuestreo());

    BigDecimal dividir = new BigDecimal(cant);
    List<DetalleMuestreo> q = detallemuestreoService.findAll();
    BigDecimal suma = BigDecimal.ZERO;
    BigDecimal promedio = BigDecimal.ZERO;

    for (DetalleMuestreo detalle : q) {
        if (detalle.getIdMuestreo().getIdMuestreo() == muestreo.getIdMuestreo()) {
            suma = suma.add(detalle.getPesoDetalleMuestreo());
        }//  w w  w.  j a  va 2  s .  c  o  m
    }
    int sumaint = suma.intValue();
    int cantint = cant.intValue();
    //int prom=sumaint/cantint;
    //  promedio=new BigDecimal(prom);
    //  System.out.println(prom);
    promedio = suma.divide(dividir);
    Muestreo newMuestreo = getMuestreo();
    newMuestreo.setPesoPromedioMuestreo(suma.divide(dividir));
    //  muestreo.setPesoPromedioMuestreo(suma);
    System.out.println(promedio);
    muestreoService.merge(newMuestreo);

    loadLazyModels();
    FacesContext context = FacesContext.getCurrentInstance();
    context.addMessage(null, new FacesMessage("Successful"));
    try {
        FacesContext context1 = FacesContext.getCurrentInstance();
        context1.getExternalContext().redirect("/siapa/views/detalleMuestreo/index.xhtml");
    } catch (IOException e) {

    }

}

From source file:com.prowidesoftware.swift.model.CurrencyAmount.java

/**
 * @param currency a not null currency code
 * @param value the value for the amount, may be <code>null</code>
 *//*from  w  w w  . j  av  a  2s.c  o  m*/
CurrencyAmount(final String currency, Number amount) {
    super();
    this.currency = currency;
    if (amount == null) {
        this.amount = BigDecimal.ZERO;
    } else {
        if (amount instanceof BigDecimal) {
            this.amount = (BigDecimal) amount;
        } else if (amount instanceof Long) {
            this.amount = new BigDecimal(((Long) amount).longValue());
        } else if (amount instanceof Integer) {
            this.amount = new BigDecimal(((Integer) amount).intValue());
        } else if (amount instanceof Short) {
            this.amount = new BigDecimal(((Short) amount).intValue());
        } else if (amount instanceof Double) {
            /*
             * we use valueOf instead of constructor because it uses a string under the covers to eliminate floating point rounding errors
             */
            this.amount = BigDecimal.valueOf(((Double) amount).doubleValue());
        } else {
            throw new IllegalArgumentException("class " + amount.getClass().getName() + " is not supported");
        }
    }
}

From source file:com.cubeia.backoffice.accounting.core.entity.Transaction.java

private void ensureEntrySumIsZero(Entry[] entries) throws TransactionNotBalancedException {
    //BigDecimal sum = BigDecimal.ZERO;
    Map<String, BigDecimal> sums = new HashMap<String, BigDecimal>(2);
    for (Entry e : entries) {
        //sum = sum.add(e.getAmount());
        Account a = e.getAccount();//from   w ww. j a va 2s . c  o m
        String curr = a.getCurrencyCode();
        BigDecimal sum = sums.get(curr);
        if (sum == null) {
            sum = BigDecimal.ZERO;
        }
        sums.put(curr, sum.add(e.getAmount()));
    }

    for (String curr : sums.keySet()) {
        BigDecimal sum = sums.get(curr);
        if (sum.signum() != 0) {
            throw new TransactionNotBalancedException("Transaction balance is not zero for currency '" + curr
                    + "', sum = " + sum + ". Entries: " + Arrays.toString(entries));
        }
    }
}

From source file:com.jlfex.hermes.main.AccountPersonalController.java

/**
 * ?// w w w .  j a  v  a  2s .c  o m
 * 
 * @param model
 * @return
 */
@RequestMapping("/getUserInfo")
public String getUserInfo(Model model) {
    AppUser curUser = App.current().getUser();
    App.checkUser();
    User user = userInfoService.findByUserId(curUser.getId());

    List<UserAccount> userAccounts = userInfoService.findAccountByUserId(curUser.getId());
    BigDecimal allBalance = BigDecimal.ZERO;// ?
    BigDecimal cashBalance = BigDecimal.ZERO;// ?
    BigDecimal freezeBalance = BigDecimal.ZERO;// ?
    for (UserAccount userAcc : userAccounts) {
        if (userAcc.getType().equals(Type.CASH)) {
            cashBalance = userAcc.getBalance();// ?
        } else {
            freezeBalance = userAcc.getBalance();// ?

        }
        allBalance = allBalance.add(userAcc.getBalance());
    }
    model.addAttribute("cashBalance", cashBalance);// ?
    model.addAttribute("freezeBalance", freezeBalance);// ?
    model.addAttribute("allBalance", allBalance);
    model.addAttribute("email", curUser.getAccount());
    // model.addAttribute("email", user.getEmail());
    // ??
    UserImage avatar = new UserImage();
    avatar = userInfoService.findImageByUserIdAndType(curUser.getId(),
            com.jlfex.hermes.model.UserImage.Type.AVATAR_LG);
    model.addAttribute("avatar", avatar);

    // ?
    UserProperties userPro = userInfoService.getProByUser(user);
    model.addAttribute("userPro", userPro);

    return "account/personalnew";
}