List of usage examples for java.math BigDecimal add
public BigDecimal add(BigDecimal augend)
From source file:org.openvpms.archetype.rules.stock.ChargeStockUpdaterTestCase.java
private BigDecimal getQuantity(BigDecimal current, BigDecimal change, boolean credit) { return (credit) ? current.add(change) : current.subtract(change); }
From source file:com.github.totyumengr.minicubes.core.MiniCubeTest.java
@Test public void test_6_1_merge() { FactTableBuilder builder = new FactTableBuilder().build("MiniCubeTest-merge") .addDimColumns(Arrays.asList(new String[] { "the_date", "tradeId", "productLineId", "postId" })) .addIndColumns(Arrays.asList(new String[] { "csm", "cash", "click", "shw" })); builder.addDimDatas(Integer.MAX_VALUE, Arrays.asList(new Integer[] { 20140607, 1, 1, 1 })); builder.addIndDatas(Integer.MAX_VALUE, Arrays.asList(new DoubleDouble[] { new DoubleDouble(123.123), new DoubleDouble(124.124), new DoubleDouble(123), new DoubleDouble(124) })); FactTable merge = builder.done();//from w ww . ja v a 2 s . com // Do merge BigDecimal original = miniCube.sum("csm"); miniCube.merge(new MiniCube(merge)); Assert.assertEquals( original.add(new BigDecimal(123.123).setScale(Aggregations.IND_SCALE, BigDecimal.ROUND_HALF_UP)), miniCube.sum("csm")); Map<String, List<Integer>> filter = new HashMap<String, List<Integer>>(1); filter.put("the_date", Arrays.asList(new Integer[] { 20140606 })); miniCube.setParallelMode(false); Assert.assertEquals("138240687.91500000", miniCube.sum("csm", filter).toString()); }
From source file:UserInterface.FinanceRole.DonationsReceivedJPanel.java
private void generateDonationAnalysis() { DefaultCategoryDataset dataSet = new DefaultCategoryDataset(); for (Organization objDonorOrganization : objWorldEnterprise.getObjOrganizationDirectory() .getOrganizationList()) {/*from w w w . j a v a2 s .c om*/ if (objDonorOrganization instanceof DonorOrganization) { for (Person objPerson : objDonorOrganization.getObjPersonDirectory().getPersonList()) { BigDecimal totalAmount = new BigDecimal(0); for (Transaction objTransaction : objPerson.getObjDonorTransactionDirectory() .getTransactionList()) { totalAmount = totalAmount.add(objTransaction.getTransactionBDAmount()); } dataSet.setValue(totalAmount, "Donation", objPerson.getPersonFirstName()); } } } JFreeChart chart = ChartFactory.createBarChart3D("Overview of entire donation", "Donor Name", "Total donation in USD $", dataSet, PlotOrientation.VERTICAL, false, true, false); CategoryPlot plot = chart.getCategoryPlot(); plot.setRangeGridlinePaint(Color.black); ChartPanel myChart = new ChartPanel(chart); donationJPanel.setLayout(new java.awt.BorderLayout()); donationJPanel.add(myChart, BorderLayout.CENTER); donationJPanel.validate(); }
From source file:com.ar.dev.tierra.api.controller.DetalleFacturaController.java
@RequestMapping(value = "/delete", method = RequestMethod.POST) public ResponseEntity<?> delete(OAuth2Authentication authentication, @RequestBody DetalleFactura detalleFactura, @RequestParam("dni") int dni, @RequestParam("password") String password) { Usuarios userAuth = facadeService.getUsuariosDAO().findUsuarioByDNI(dni); boolean permiso = passwordEncoder.matches(password, userAuth.getPassword()); Usuarios user = facadeService.getUsuariosDAO().findUsuarioByUsername(authentication.getName()); if (permiso) { if (userAuth.getRoles().getIdRol() == 1 || userAuth.getRoles().getIdRol() == 6) { detalleFactura.setEstadoDetalle(false); detalleFactura.setUsuarioModificacion(user.getIdUsuario()); detalleFactura.setFechaModificacion(new Date()); facadeService.getDetalleFacturaDAO().update(detalleFactura); /*Traemos lista de detalles, calculamos su nuevo total y actualizamos*/ Factura factura = facadeService.getFacturaDAO() .searchById(detalleFactura.getFactura().getIdFactura()); List<DetalleFactura> detallesFactura = facadeService.getDetalleFacturaDAO() .facturaDetalle(detalleFactura.getFactura().getIdFactura()); BigDecimal sumMonto = new BigDecimal(BigInteger.ZERO); for (DetalleFactura detailList : detallesFactura) { sumMonto = sumMonto.add(detailList.getTotalDetalle()); }//from w w w . j av a 2 s . co m factura.setTotal(sumMonto); factura.setFechaModificacion(new Date()); factura.setUsuarioModificacion(user.getIdUsuario()); facadeService.getFacturaDAO().update(factura); @SuppressWarnings("UnusedAssignment") int cantidadActual = 0; WrapperStock stock = facadeService.getStockDAO().searchStockById(detalleFactura.getIdStock(), user.getUsuarioSucursal().getIdSucursal()); if (stock.getStockTierra() != null) { cantidadActual = stock.getStockTierra().getCantidad(); stock.getStockTierra().setCantidad(cantidadActual + detalleFactura.getCantidadDetalle()); } else if (stock.getStockBebelandia() != null) { cantidadActual = stock.getStockBebelandia().getCantidad(); stock.getStockBebelandia().setCantidad(cantidadActual + detalleFactura.getCantidadDetalle()); } else { cantidadActual = stock.getStockLibertador().getCantidad(); stock.getStockLibertador().setCantidad(cantidadActual + detalleFactura.getCantidadDetalle()); } facadeService.getStockDAO().update(stock); Producto prodRest = facadeService.getProductoDAO() .findById(detalleFactura.getProducto().getIdProducto()); int cantProd = prodRest.getCantidadTotal(); prodRest.setCantidadTotal(cantProd + detalleFactura.getCantidadDetalle()); facadeService.getProductoDAO().update(prodRest); JsonResponse msg = new JsonResponse("Success", "Detalle eliminado con exito"); return new ResponseEntity<>(msg, HttpStatus.OK); } else { JsonResponse msg = new JsonResponse("Error", "No tienes los permisos necesarios para realizar esta operacion."); return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST); } } else { JsonResponse msg = new JsonResponse("Error", "No tienes los permisos necesarios para realizar esta operacion."); return new ResponseEntity<>(msg, HttpStatus.BAD_REQUEST); } }
From source file:churashima.action.manage.ExpensesAction.java
@Execute(validator = false) public String searchInit() { ExpensesDao expensesDao = SingletonS2Container.getComponent(ExpensesDao.class); List<Expenses> expensesList = expensesDao.selectForSearch(null, null, null, null, null, null, expensesForm.searchPrice, null, null); expensesForm.expensesList = expensesList; // ??// w w w . ja va 2 s . c om BigDecimal sumPriceTotal = BigDecimal.valueOf(0); for (Expenses expenses : expensesList) { sumPriceTotal = sumPriceTotal.add(expenses.price); } expensesForm.sumPriceTotal = sumPriceTotal; SubjectDao subjectDao = SingletonS2Container.getComponent(SubjectDao.class); expensesForm.subjectList = subjectDao.selectForSearch(null, null); return "expensesList.jsp"; }
From source file:com.redhat.rhtracking.core.services.DeliveryMatrixServiceHandler.java
@Override public Map<String, Object> saveOpportunity(Map<String, Object> event) { Map<String, Object> opportunity = new HashMap<>(); opportunity.put("identifier", (String) event.get("identifier")); opportunity.put("project", (String) event.get("project")); opportunity.put("opportunityType", (String) event.get("opportunityType")); opportunity.put("customerId", (long) event.get("customer")); opportunity.put("customerBillingId", (long) event.get("customerBilling")); opportunity.put("currency", (String) event.get("currency")); opportunity.put("exchangeRate", event.get("exchangeRate")); int totalHours = (int) event.get("platformHours") + (int) event.get("middlewareHours") + (int) event.get("workshopHours"); opportunity.put("totalHours", totalHours); opportunity.put("hoursToBill", 0); BigDecimal billingAmount = ((BigDecimal) event.get("platformPrice")) .multiply(new BigDecimal((int) event.get("platformHours"))); billingAmount = billingAmount.add(((BigDecimal) event.get("middlewarePrice")) .multiply(new BigDecimal((int) event.get("middlewareHours")))); billingAmount = billingAmount.add(((BigDecimal) event.get("workshopPrice")) .multiply(new BigDecimal((int) event.get("workshopHours")))); opportunity.put("billingAmount", billingAmount); opportunity.put("costAmount", BigDecimal.ZERO); Map<String, Object> addOpportunityResponse = opportunityPersistanceService.saveOpportunity(opportunity); if (addOpportunityResponse.get("status") != EventStatus.SUCCESS) { return addOpportunityResponse; }//from ww w . j av a 2 s . co m for (HourType type : HourType.values()) { if ((int) event.get(type.toString().toLowerCase() + "Hours") < 1) { continue; } Map<String, Object> newHours = new HashMap<>(); newHours.put("opportunityId", (long) addOpportunityResponse.get("id")); newHours.put("type", type.toString()); newHours.put("quantity", (int) event.get(type.toString().toLowerCase() + "Hours")); newHours.put("hoursToBill", 0); newHours.put("unitPrice", event.get(type.toString().toLowerCase() + "Price")); Map<String, Object> hourResponse = opportunityPersistanceService.saveOpportunityHours(newHours); if (hourResponse.get("status") != com.redhat.rhtracking.events.EventStatus.SUCCESS) { throw new UnsupportedOperationException("Exception when creating the opportunity"); } } Map<String, Object> result = new HashMap<>(); result.put("status", com.redhat.rhtracking.events.EventStatus.SUCCESS); result.put("id", addOpportunityResponse.get("id")); return result; }
From source file:org.eqaula.glue.controller.accounting.PostingHome.java
public BigDecimal totalCredit(Long id) { BigDecimal total = new BigDecimal(0); try {/*w w w . j a v a2 s . co m*/ Posting p = postingService.find(id); for (Entry e : p.getEntries()) { if (e.getCredit() != null) { total = total.add(e.getCredit()); } } } catch (Exception e) { } return total; }
From source file:egovframework.rte.fdl.idgnr.impl.EgovUUIdGnrService.java
/** * BigDecimal ? ? /* ww w . j a va2 s . c o m*/ * @return BigDecimal ID * @throws FdlException * ? ?? */ public BigDecimal getNextBigDecimalId() throws FdlException { String newId = getNextStringId(); byte[] bytes = newId.getBytes(); // get 16 // bytes BigDecimal bd = new BigDecimal(0); for (int i = 0; i < bytes.length; i++) { bd = bd.multiply(new BigDecimal(256)); bd = bd.add(new BigDecimal(((int) bytes[i]) & 0xFF)); } return bd; }
From source file:org.eqaula.glue.controller.accounting.PostingHome.java
public BigDecimal totalDebit(Long id) { BigDecimal total = new BigDecimal(0); try {//from w w w .j ava 2 s .c o m Posting p = postingService.find(id); for (Entry e : p.getEntries()) { if (e.getDebit() != null) { total = total.add(e.getDebit()); } } } catch (Exception e) { log.info("se ejecut una excepcin"); log.info("se ejecut una excepcin"); } return total; }
From source file:com.autentia.tnt.manager.billing.BillManager.java
public void calculateBillIsPaid(final Bill bill) { if (bill.getState() != BillState.PAID) { BigDecimal accountEntryTotal = new BigDecimal(0); for (AccountEntry accountEntry : bill.getEntries()) { accountEntryTotal = accountEntryTotal.add(accountEntry.getAmount()); }/*from ww w . j a v a 2 s . c om*/ if (accountEntryTotal.abs().compareTo(bill.getTotal()) >= 0) { bill.setState(BillState.PAID); updateEntity(bill); } } }