List of usage examples for java.math BigDecimal intValue
@Override public int intValue()
From source file:org.posterita.businesslogic.performanceanalysis.CustomPOSReportManager.java
public static TabularReport generateTabularReportGroupByDate(Properties ctx, String title, String subtitle, int account_id, Timestamp fromDate, Timestamp toDate, String salesGroup, String priceQtyFilter) throws OperationException { boolean isTaxDue = (account_id == Constants.TAX_DUE.intValue()); boolean isTaxCredit = (account_id == Constants.TAX_CREDIT.intValue()); NumberFormat formatter = new DecimalFormat("###,###,##0.00"); String sql = SalesAnalysisReportManager.getTabularDataSetSQL(ctx, account_id, fromDate, toDate, salesGroup); ArrayList<Object[]> tmpData = ReportManager.getReportData(ctx, sql, true); String currency = POSTerminalManager.getDefaultSalesCurrency(ctx).getCurSymbol(); ArrayList<Object[]> reportData = new ArrayList<Object[]>(); Object[] data = null;/*ww w.j a va 2 s.c o m*/ BigDecimal b = null; if (isTaxCredit || isTaxDue) { reportData.add(tmpData.remove(0)); Iterator<Object[]> iter = tmpData.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length == 1) { b = (BigDecimal) data[0]; data[0] = formatter.format(b.doubleValue()); } reportData.add(data); } } else { //---------------------------------------------------------------------------------------------------------------------------------------------------------- TreeMap<String, TabularReportRecordBean> map = new TreeMap<String, TabularReportRecordBean>(); String productName = null; BigDecimal price = null; BigDecimal qty = null; TabularReportRecordBean bean = null; ArrayList<Object[]> reportData2 = new ArrayList<Object[]>(); Object[] headers = tmpData.remove(0); //adding headers reportData2.add(new Object[] { headers[0], //headers[1], headers[2] + "(" + currency + ")", headers[3] }); double totalAmt = 0.0d; int totalQty = 0; for (Object[] record : tmpData) { productName = (String) record[0]; price = (BigDecimal) record[2]; qty = (BigDecimal) record[3]; totalAmt += price.doubleValue(); totalQty += qty.intValue(); bean = map.get(productName); if (bean == null) { bean = new TabularReportRecordBean(); bean.setProductName(productName); bean.setDate(""); bean.setPrice(price); bean.setQty(qty); } else { bean.setPrice(bean.getPrice().add(price)); bean.setQty(bean.getQty().add(qty)); } map.put(productName, bean); } //for Collection<TabularReportRecordBean> c = map.values(); for (TabularReportRecordBean tbean : c) { Object[] obj = new Object[] { tbean.getProductName(), tbean.getPrice(), tbean.getQty() }; reportData2.add(obj); } reportData.add(reportData2.remove(0)); Iterator<Object[]> iter = reportData2.iterator(); while (iter.hasNext()) { data = iter.next(); if (data.length > 2) { b = (BigDecimal) data[1]; data[1] = formatter.format(b.doubleValue()); } reportData.add(data); } reportData.add(new Object[] { "Total", "" + formatter.format(totalAmt), totalQty + "" }); } //style for table String tableStyle = "display"; //style for columns String[] styles = new String[] { "string", "currency", "numeric" }; if (isTaxCredit || isTaxDue) { styles = new String[] { "numeric" }; } //constructing the table TabularReport tReport = new TabularReport(reportData); //tReport.setSortable(true); tReport.setHeaderStyle(styles); tReport.setStyle(tableStyle); tReport.setTitle(title); tReport.setSubtitle(subtitle); tReport.createReport(); return tReport; }
From source file:com.vangent.hieos.empi.match.ScoredRecord.java
/** * /* w ww . ja v a2 s .c o m*/ * @return */ public int getMatchScorePercentage() { // Round-up match score. BigDecimal bd = new BigDecimal(this.getScore() * 100.0); bd = bd.setScale(0, BigDecimal.ROUND_HALF_UP); return bd.intValue(); }
From source file:com.glaf.core.dao.MyBatisEntityDAO.java
public int getCount(String statementId, Object parameterObject) { int totalCount = 0; SqlSession session = getSqlSession(); Object object = null;//w w w . j a v a2 s . co m if (parameterObject != null) { object = session.selectOne(statementId, parameterObject); } else { object = session.selectOne(statementId); } if (object instanceof Integer) { Integer iCount = (Integer) object; totalCount = iCount.intValue(); } else if (object instanceof Long) { Long iCount = (Long) object; totalCount = iCount.intValue(); } else if (object instanceof BigDecimal) { BigDecimal bg = (BigDecimal) object; totalCount = bg.intValue(); } else if (object instanceof BigInteger) { BigInteger bi = (BigInteger) object; totalCount = bi.intValue(); } else { String value = object.toString(); totalCount = Integer.parseInt(value); } return totalCount; }
From source file:ch.algotrader.service.fix.FixOrderServiceImpl.java
/** * {@inheritDoc}/*from ww w. j a va 2 s. c o m*/ */ @Override public void init() { Set<String> sessionQualifiers = getAllSessionQualifiers(); for (String sessionQualifier : sessionQualifiers) { BigDecimal orderId = this.orderDao.findLastIntOrderIdBySessionQualifier(sessionQualifier); this.fixAdapter.setOrderId(sessionQualifier, orderId != null ? orderId.intValue() : 0); if (LOGGER.isDebugEnabled() && orderId != null) { LOGGER.debug("Current order count for session {}: {}", sessionQualifier, orderId.intValue()); } } this.fixAdapter.createSessionForService(getOrderServiceType()); }
From source file:de.appsolve.padelcampus.controller.bookings.BookingsPayMillController.java
private ModelAndView handlePost(ModelAndView mav, Booking booking, String token) { if (StringUtils.isEmpty(token)) { mav.addObject("error", msg.get("MissingRequiredPaymentToken")); return mav; }//w w w . j ava 2 s .co m if (booking.getConfirmed()) { mav.addObject("error", msg.get("BookingAlreadyConfirmed")); return mav; } try { PayMillConfig config = payMillConfigDAO.findFirst(); PaymillContext paymillContext = new PaymillContext(config.getPrivateApiKey()); TransactionService transactionService = paymillContext.getTransactionService(); BigDecimal amount = booking.getAmount().multiply(new BigDecimal("100"), MathContext.DECIMAL128); Transaction transaction = transactionService.createWithToken(token, amount.intValue(), booking.getCurrency().toString(), getBookingDescription(booking)); if (!transaction.getStatus().equals(Transaction.Status.CLOSED)) { throw new Exception("Payment Backend Returned Unexpected Status: [Code: " + transaction.getStatus() + ", Response Code: " + transaction.getResponseCode() + ", Response Code Detail: " + transaction.getResponseCodeDetail() + "]"); } booking.setPaymentConfirmed(true); bookingDAO.saveOrUpdate(booking); } catch (Exception e) { LOG.error(e.getMessage()); mav.addObject("error", e.getMessage()); return mav; } return BookingsController.getRedirectToSuccessView(booking); }
From source file:com.flowzr.budget.holo.widget.CalculatorInput.java
private void doLastOp() { isRestart = true;/* w w w . j a va 2s . co m*/ if (lastOp == '\0' || stack.size() == 1) { return; } String valTwo = stack.pop(); String valOne = stack.pop(); switch (lastOp) { case '+': stack.push(new BigDecimal(valOne).add(new BigDecimal(valTwo)).toPlainString()); break; case '-': stack.push(new BigDecimal(valOne).subtract(new BigDecimal(valTwo)).toPlainString()); break; case '*': stack.push(new BigDecimal(valOne).multiply(new BigDecimal(valTwo)).toPlainString()); break; case '/': BigDecimal d2 = new BigDecimal(valTwo); if (d2.intValue() == 0) { stack.push("0.0"); } else { stack.push(new BigDecimal(valOne).divide(d2, 2, BigDecimal.ROUND_HALF_UP).toPlainString()); } break; default: break; } setDisplay(stack.peek()); if (isInEquals) { stack.push(valTwo); } }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@Override public List<Chart> getDineroVendedores(int idVendedor) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartVenta = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria facturas = getSession().createCriteria(Factura.class); facturas.add(Restrictions.like("estado", "CONFIRMADO")); facturas.add(Restrictions.between("fechaCreacion", fromDate, toDate)); Criteria vendedorFactura = facturas.createCriteria("idVendedor"); vendedorFactura.add(Restrictions.eq("idUsuario", idVendedor)); facturas.setProjection(Projections.sum("total")); BigDecimal counter = (BigDecimal) facturas.uniqueResult(); if (counter != null) { chart.setValue(counter.intValue()); } else {// w w w . ja v a 2 s .c om chart.setValue(0); } chart.setDate(fromDate); chartVenta.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartVenta; }
From source file:com.ar.dev.tierra.api.dao.impl.ChartDAOImpl.java
@Override public List<Chart> getMontoMedioPago(int idMedioPago) { Calendar calendarInitial = Calendar.getInstance(); Calendar calendarClosing = Calendar.getInstance(); calendarInitial.set(Calendar.HOUR_OF_DAY, 0); calendarInitial.set(Calendar.MINUTE, 0); calendarInitial.set(Calendar.SECOND, 0); calendarInitial.set(Calendar.MILLISECOND, 0); Date fromDate = calendarInitial.getTime(); calendarClosing.set(Calendar.HOUR_OF_DAY, 23); calendarClosing.set(Calendar.MINUTE, 59); calendarClosing.set(Calendar.SECOND, 59); calendarClosing.set(Calendar.MILLISECOND, 59); Date toDate = calendarClosing.getTime(); int days = 0; List<Chart> chartMedioPago = new ArrayList<>(); while (days <= 6) { Chart chart = new Chart(); Criteria metodo = getSession().createCriteria(MetodoPagoFactura.class); metodo.add(Restrictions.eq("estado", true)); Criteria planPago = metodo.createCriteria("planPago"); Criteria tarjeta = planPago.createCriteria("tarjeta"); Criteria medioPago = tarjeta.createCriteria("medioPago"); medioPago.add(Restrictions.eq("idMedioPago", idMedioPago)); metodo.add(Restrictions.between("fechaCreacion", fromDate, toDate)); metodo.setProjection(Projections.sum("montoPago")); BigDecimal counter = (BigDecimal) metodo.uniqueResult(); if (counter != null) { chart.setValue(counter.intValue()); } else {/*from w w w .ja v a2 s . c om*/ chart.setValue(0); } chart.setDate(fromDate); chartMedioPago.add(chart); calendarInitial.add(Calendar.DAY_OF_MONTH, -1); fromDate = calendarInitial.getTime(); calendarClosing.add(Calendar.DAY_OF_MONTH, -1); toDate = calendarClosing.getTime(); days++; } return chartMedioPago; }
From source file:siddur.solidtrust.autoscout.AutoscoutService.java
public int averageTimeOnSale(String brand, String model, String build) { String baseJpql = "select avg(datediff(m.dateRegisted, m.dateScraped)) from AutoscoutNl m where m.dateRegisted is not null and m.repetition is null"; if (!StringUtils.isEmpty(brand)) { baseJpql += " and m.brand = '" + brand + "'"; }//w ww .ja v a 2s .c om if (!StringUtils.isEmpty(model)) { baseJpql += " and m.model = '" + model + "'"; } if (!StringUtils.isEmpty(build)) { baseJpql += " and m.build = '" + build + "'"; } BigDecimal avg = (BigDecimal) em.createNativeQuery(baseJpql).getSingleResult(); if (avg == null) { return 0; } return avg.intValue(); }
From source file:org.eclipse.smarthome.binding.fsinternetradio.handler.FSInternetRadioHandler.java
@Override public void initialize() { // Long running initialization should be done asynchronously in background radioLogin();/* ww w. jav a 2s . co m*/ // also schedule a thread for polling with configured refresh rate final BigDecimal period = (BigDecimal) getThing().getConfiguration().get(CONFIG_PROPERTY_REFRESH); if (period != null && period.intValue() > 0) { updateJob = scheduler.scheduleWithFixedDelay(updateRunnable, period.intValue(), period.intValue(), SECONDS); } }