List of usage examples for java.math BigDecimal ZERO
BigDecimal ZERO
To view the source code for java.math BigDecimal ZERO.
Click Source Link
From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java
/** * Verifies that an act doesn't get added to a new till balance if it * is subsequently saved after the till has been cleared. *///from ww w . j av a2 s . c o m @Test public void testClearTillAndReSave() { List<FinancialAct> payment = createPayment(till); payment.get(0).setStatus(POSTED); FinancialAct balance = checkAddToTillBalance(till, payment, false, BigDecimal.ONE); // clear the till Party account = DepositTestHelper.createDepositAccount(); rules.clearTill(balance, BigDecimal.ZERO, account); // reload the act and save it to force TillRules.addToTill() to run // again. However the act should not be added to a new balance as // there is an existing actRelationship.tillBalanceItem relationship. Act latest = get(payment.get(0)); save(latest); latest = get(latest); ActBean bean = new ActBean(latest); List<ActRelationship> relationships = bean.getRelationships("actRelationship.tillBalanceItem"); assertEquals(1, relationships.size()); }
From source file:org.openvpms.archetype.rules.party.CustomerMergerTestCase.java
/** * Tests a merge where both customers have different account types. * The merge-to customer's account type should take precedence. *//*from w w w . j a v a 2 s.c om*/ @Test public void testMergeAccountTypes() { Party from = TestHelper.createCustomer(); Party to = TestHelper.createCustomer(); Lookup accountType1 = FinancialTestHelper.createAccountType(30, DateUnits.DAYS, BigDecimal.ZERO); Lookup accountType2 = FinancialTestHelper.createAccountType(15, DateUnits.DAYS, BigDecimal.ZERO); from.addClassification(accountType1); to.addClassification(accountType2); Lookup fromAccountType = customerRules.getAccountType(from); Lookup toAccountType = customerRules.getAccountType(to); assertEquals(accountType1, fromAccountType); assertEquals(accountType2, toAccountType); Party merged = checkMerge(from, to); assertEquals(accountType2, customerRules.getAccountType(merged)); }
From source file:dk.clanie.money.Money.java
/** * Divide evenly into parts.//from ww w. j av a2 s . c o m * * Divides an amount into parts of approximately the same size while * ensuring that the sum of all the parts equals the whole. * <p> * Parts of unequal size will be distributed evenly in the returned array. * <p> * For example, if asked to divede 20 into 6 parts the result will be {3.33, * 3.34, 3.33, 3.33, 3.34, 3.33} * * @param parts - * number of parts * @return Money[] with the parts */ public Money[] divideEvenlyIntoParts(int parts) { Money[] res = new Money[parts]; final BigDecimal bdParts = new BigDecimal(parts); final MathContext mc = MathContext.DECIMAL128; BigDecimal sumOfPreviousParts = BigDecimal.ZERO; for (int i = 0; i < parts; i++) { Money part = new Money(); BigDecimal sumOfParts = amount.multiply(new BigDecimal(i + 1)); sumOfParts = sumOfParts.divide(bdParts, mc); sumOfParts = sumOfParts.setScale(amount.scale(), mc.getRoundingMode()); part.amount = sumOfParts.subtract(sumOfPreviousParts); sumOfPreviousParts = sumOfParts; part.currency = currency; res[i] = part; } return res; }
From source file:org.openmrs.module.billing.web.controller.main.BillableServiceBillAddForBDController.java
@RequestMapping(method = RequestMethod.POST) public String onSubmit(Model model, Object command, BindingResult bindingResult, HttpServletRequest request, @RequestParam("cons") Integer[] cons, @RequestParam("patientId") Integer patientId, @RequestParam(value = "comment", required = false) String comment, @RequestParam(value = "billType", required = false) String billType) { validate(cons, bindingResult, request); if (bindingResult.hasErrors()) { model.addAttribute("errors", bindingResult.getAllErrors()); return "module/billing/main/billableServiceBillEdit"; }// w w w . j a v a 2 s . c om 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); BillCalculatorForBDService calculator = new BillCalculatorForBDService(); 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, billType); item.setActualAmount(item.getAmount().multiply(rate)); totalActualAmount = totalActualAmount.add(item.getActualAmount()); bill.addBillItem(item); } bill.setAmount(totalAmount.getAmount()); bill.setActualAmount(totalActualAmount); bill.setComment(comment); bill.setFreeBill(calculator.isFreeBill(billType)); logger.info("Is free bill: " + bill.getFreeBill()); bill.setReceipt(billingService.createReceipt()); bill = billingService.savePatientServiceBill(bill); return "redirect:/module/billing/patientServiceBillForBD.list?patientId=" + patientId + "&billId=" + bill.getPatientServiceBillId() + "&billType=" + billType; }
From source file:br.com.webbudget.domain.model.service.PeriodDetailService.java
/** * Monta o model do grafico de consumo por centro de custo * * @param periods os periodos//from w w w . j av a 2 s . c o m * @param direction a direcao que vamos montar no grafico, entrada ou saida * @return o modelo do grafico para a view */ public DonutChartModel buidCostCenterChart(List<FinancialPeriod> periods, MovementClassType direction) { // lista os movimentos final List<Movement> movements = this.listMovementsFrom(periods, direction); // mapeia para cada centro de custo, seus movimentos final Map<CostCenter, List<Movement>> costCentersAndMovements = this.mapCostCenterAndMovements(movements); final DonutChartModel donutChartModel = new DonutChartModel(); // para cada CC adiciona os dados do grafico costCentersAndMovements.keySet().stream().forEach(costCenter -> { final List<Movement> grouped = costCentersAndMovements.get(costCenter); BigDecimal total = grouped.stream().map(Movement::getValue).reduce(BigDecimal.ZERO, BigDecimal::add); // pega a cor para este CC caso tenha, senao randomiza uma cor final Color color = costCenter.getColor() != null ? costCenter.getColor() : Color.randomize(); donutChartModel.addData(new DonutChartDataset<>(total, color.lighter().toString(), color.toString(), costCenter.getName())); }); return donutChartModel; }
From source file:org.key2gym.business.services.CashServiceBean.java
@Override public CashAdjustmentDTO getAdjustmentByDate(DateMidnight date) throws SecurityViolationException { if (!callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Access.Denied")); }//from w w w . jav a 2 s . com if (date == null) { throw new NullPointerException("The date is null."); //NOI18N } CashAdjustment cashAdjustmentEntity = em.find(CashAdjustment.class, date.toDate()); if (cashAdjustmentEntity == null) { cashAdjustmentEntity = new CashAdjustment(); cashAdjustmentEntity.setAmount(BigDecimal.ZERO); cashAdjustmentEntity.setDateRecorded(date.toDate()); cashAdjustmentEntity.setNote(""); em.persist(cashAdjustmentEntity); } CashAdjustmentDTO cashAdjustmentDTO = new CashAdjustmentDTO(); cashAdjustmentDTO.setAmount(cashAdjustmentEntity.getAmount()); cashAdjustmentDTO.setDate(new DateMidnight(cashAdjustmentEntity.getDateRecorded())); cashAdjustmentDTO.setNote(cashAdjustmentEntity.getNote()); return cashAdjustmentDTO; }
From source file:com.willetinc.hadoop.mapreduce.dynamodb.BinarySplitter.java
/** * Return a BigDecimal representation of byte[] array suitable for use in a * numerically-sorting order.//from w w w . j ava 2s . c o m */ static BigDecimal byteArrayToBigDecimal(byte[] array, int maxBytes) { BigDecimal result = BigDecimal.ZERO; BigDecimal curPlace = ONE_PLACE; // start with 1/16 to compute the // first digit. int len = Math.min(array.length, maxBytes); for (int i = 0; i < len; i++) { byte codePoint = array[i]; result = result.add(tryDivide(new BigDecimal(codePoint), curPlace)); // advance to the next less significant place. e.g., 1/(16^2) for // the second char. curPlace = curPlace.multiply(ONE_PLACE); } return result; }
From source file:org.stockwatcher.data.cassandra.DailySummaryGenerator.java
private List<ResultSetFuture> processTradesForSymbol(List<ResultSetFuture> selectFutures) { List<ResultSetFuture> insertFutures = new ArrayList<ResultSetFuture>(); for (ResultSetFuture future : selectFutures) { String symbol = null;// w w w.ja v a 2 s . co m Date tradeDate = null; BigDecimal open = BigDecimal.ZERO; BigDecimal high = BigDecimal.ZERO; BigDecimal low = BigDecimal.valueOf(Long.MAX_VALUE); BigDecimal close = BigDecimal.ZERO; BigDecimal sharePrice = null; int volume = 0; for (Row row : future.getUninterruptibly()) { if (symbol == null) { symbol = row.getString("stock_symbol"); tradeDate = row.getDate("trade_date"); open = row.getDecimal("share_price"); LOGGER.debug("Processing trades for symbol {} on {}", symbol, tradeDate); } sharePrice = row.getDecimal("share_price"); if (sharePrice.compareTo(high) > 0) { high = sharePrice; } if (sharePrice.compareTo(low) < 0) { low = sharePrice; } close = sharePrice; volume += row.getInt("share_quantity"); } if (volume > 0) { insertFutures.add(insert(symbol, tradeDate, open, high, low, close, volume)); } } selectFutures.clear(); return insertFutures; }
From source file:py.una.pol.karaku.test.test.math.QuantityTest.java
@Test public void testSubtract() { assertQuantity(p0000.subtract(p0009), p0009.negate()); assertQuantity(p0000.subtract(P0010), P0010.negate()); assertQuantity(p0000.subtract(p0000), BigDecimal.ZERO); assertQuantity(d200000.subtract(d100000), d100000); assertQuantity(d100000.subtract(d100000), BigDecimal.ZERO); assertQuantity(d100000.subtract(d3p5346), bd("99996.4654")); assertQuantity(new Quantity("100.0059111").subtract(new Quantity("100.0059")), BigDecimal.ZERO); }
From source file:com.opensourcestrategies.financials.accounts.GLAccountInTree.java
/** * Gets the credit of this GL account given child GL account. * @param childAccount a <code>GLAccountInTree</code> value * @return a <code>BigDecimal</code> value *//*from www. j av a 2 s . co m*/ private BigDecimal getCreditOfChildrenRec(GLAccountInTree childAccount) { if (childAccount == null) { return BigDecimal.ZERO; } BigDecimal creditOfChildren = BigDecimal.ZERO; if (childAccount.isCreditAccount) { creditOfChildren = childAccount.balance; } for (GLAccountInTree grandchildAccount : childAccount.childAccounts) { creditOfChildren = creditOfChildren.add(getCreditOfChildrenRec(grandchildAccount)); } return creditOfChildren; }