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:com.iisigroup.cap.report.AbstractReportExcelService.java
@SuppressWarnings("unchecked") @Override//from ww w . j av a 2 s.co m public ByteArrayOutputStream generateReport(Request request) throws CapException { ByteArrayOutputStream out = new ByteArrayOutputStream(); Workbook t = null; try { t = readTemplate(); // Define the cell format // ?? NumberFormat nf = new NumberFormat("#,##0_"); // ?? NumberFormat nf2 = new NumberFormat("#,##0.00"); // ? WritableFont titleWf = new WritableFont(WritableFont.createFont(""), 12); // WritableFont titleWf = new WritableFont(WritableFont.createFont("DFKai-sb"),12); WritableCellFormat timesString = new WritableCellFormat(defaultFont); WritableCellFormat timesNumber = new WritableCellFormat(nf); WritableCellFormat timesDouble = new WritableCellFormat(nf2); timesNumber.setFont(titleWf); timesDouble.setFont(titleWf); // timesNumber.setAlignment(Alignment.RIGHT); timesDouble.setAlignment(Alignment.CENTRE); timesString.setAlignment(Alignment.CENTRE); // timesNumber.setVerticalAlignment(VerticalAlignment.CENTRE); timesDouble.setVerticalAlignment(VerticalAlignment.CENTRE); timesString.setVerticalAlignment(VerticalAlignment.CENTRE); // timesNumber.setBorder(Border.ALL, BorderLineStyle.THIN, Colour.BLACK); timesDouble.setBorder(Border.BOTTOM, BorderLineStyle.THIN, Colour.BLACK); // Lets automatically wrap the cells timesNumber.setWrap(true); timesDouble.setWrap(true); timesString.setWrap(true); Map<String, Object> reportData = execute(request); WorkbookSettings wbSettings = new WorkbookSettings(); wbSettings.setRationalization(false); wbSettings.setLocale(new Locale("zh", "TW")); WritableWorkbook workbook = Workbook.createWorkbook(out, t, wbSettings); WritableSheet sheet = workbook.getSheet(0); // ? for (Entry<String, Object> entry : reportData.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); if (!key.endsWith(OFFSET_SUFFIX) && !key.endsWith(POSITION_SUFFIX)) { // it's data int[] pos = (int[]) reportData.get(key + POSITION_SUFFIX); if (pos != null) { int x = pos[0]; int y = pos[1]; if (value instanceof List) { // grid data JsonObject offset = (JsonObject) reportData.get(key + OFFSET_SUFFIX); List<Map<String, Object>> l = (List<Map<String, Object>>) value; for (Map<String, Object> m : l) { for (Entry<String, Object> e : m.entrySet()) { if (offset.get(e.getKey()) != null) { String cellVal = ""; if (e.getValue() != null) { if (e.getValue() instanceof Timestamp) { cellVal = CapDate.convertDateTimeFromF1ToF2( CapDate.getDateTimeFormat((Timestamp) e.getValue()), "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd"); } else { cellVal = e.getValue().toString(); } } Label label = new Label(x + offset.get(e.getKey()).getAsInt(), y, cellVal, timesString); sheet.addCell(label); } } y++; } } else { if (value instanceof BigDecimal) { jxl.write.Number number = new jxl.write.Number(x, y, ((BigDecimal) value).doubleValue(), timesNumber); // ?? if (!((BigDecimal) value).divideAndRemainder(new BigDecimal(2))[1] .equals(BigDecimal.ZERO) && !((BigDecimal) value).divideAndRemainder(new BigDecimal(2))[1] .equals(BigDecimal.ONE)) { number = new jxl.write.Number(x, y, ((BigDecimal) value).doubleValue(), timesDouble); } sheet.addCell(number); } else if (value instanceof Integer) { jxl.write.Number number = new jxl.write.Number(x, y, (Integer) value, timesNumber); sheet.addCell(number); } else { Label label = new Label(x, y, (String) value, timesString); sheet.addCell(label); } } } } } workbook.write(); workbook.close(); IOUtils.closeQuietly(out); } catch (Exception e) { e.printStackTrace(); if (e.getCause() != null) { throw new CapException(e.getCause(), e.getClass()); } else { throw new CapException(e, e.getClass()); } } finally { if (t != null) { t.close(); } } return out; }
From source file:org.openvpms.archetype.rules.finance.account.CustomerBalanceGeneratorTestCase.java
/** * Verifies that a debit is offset by a credit of the same amount. * * @param debits the debit acts/*from w ww.j a v a2 s. co m*/ * @param credits the credit acts */ private void checkCalculateBalanceForSameAmount(List<FinancialAct> debits, List<FinancialAct> credits) { Party customer = getCustomer(); // initial balance is zero checkEquals(BigDecimal.ZERO, rules.getBalance(customer)); assertTrue(checkBalance(customer)); // save the debit act, and verify the balance is the same as the debit // total save(debits); // definitive balance out of sync with balance until generate invoked assertFalse(checkBalance(customer)); FinancialAct debit = debits.get(0); checkEquals(debit.getTotal(), generate(customer)); checkEquals(debit.getTotal(), rules.getBalance(customer)); assertTrue(checkBalance(customer)); // should now be in sync // verify an participation.customerAccountBalance has been added to // the debit act debit = get(debit); Participation balanceParticipation1 = getAccountBalanceParticipation(debit); assertNotNull(balanceParticipation1); // regenerate the balance. This should remove the existing participation // and add a new one checkEquals(debit.getTotal(), generate(customer)); // verify the participation has changed debit = get(debit); Participation balanceParticipation2 = getAccountBalanceParticipation(debit); assertNotNull(balanceParticipation2); assertFalse(balanceParticipation1.equals(balanceParticipation2)); // save the credit act and update the balance. Balance should be zero save(credits); checkEquals(BigDecimal.ZERO, generate(customer)); checkEquals(BigDecimal.ZERO, rules.getBalance(customer)); // verify there is an actRelationship.customerAccountAllocation // linking the acts debit = get(debit); FinancialAct credit = get(credits.get(0)); ActRelationship debitAlloc = getAccountAllocationRelationship(debit); ActRelationship creditAlloc = getAccountAllocationRelationship(credit); checkAllocation(debitAlloc, debit, credit, debit.getTotal()); checkAllocation(creditAlloc, debit, credit, debit.getTotal()); assertTrue(checkBalance(customer)); // Now delete the credit. The balance will not be updated to reflect // the deletion. remove(credit); checkEquals(BigDecimal.ZERO, rules.getBalance(customer)); // need to regenerate to get the correct balance checkEquals(debit.getTotal(), generate(customer)); checkEquals(debit.getTotal(), debit.getAllocatedAmount()); debit = get(debit); checkEquals(BigDecimal.ZERO, debit.getAllocatedAmount()); checkEquals(debit.getTotal(), rules.getBalance(customer)); assertTrue(checkBalance(customer)); // participation.customerAccountBalance will have been recreated Participation balanceParticipation3 = getAccountBalanceParticipation(debit); assertNotNull(balanceParticipation3); assertFalse(balanceParticipation3.equals(balanceParticipation2)); // actRelationship.customerAccountAllocation will have been removed assertNull(getAccountAllocationRelationship(debit)); }
From source file:org.fineract.module.stellar.TestPaymentInSimpleNetwork.java
@Test public void overlappingPayments() throws Exception { logger.info("overlappingPayments test begin"); final AccountListener accountListener = new AccountListener(serverAddress, firstTenantId, secondTenantId); final BigDecimal transferAmount = BigDecimal.TEN; final BigDecimal doubleTransferAmount = transferAmount.add(transferAmount); makePayment(firstTenantId, firstTenantApiKey, secondTenantId, ASSET_CODE, transferAmount); makePayment(secondTenantId, secondTenantApiKey, firstTenantId, ASSET_CODE, doubleTransferAmount); accountListener.waitForCredits(PAY_WAIT, creditMatcher(firstTenantId, doubleTransferAmount, ASSET_CODE, secondTenantId), creditMatcher(secondTenantId, transferAmount, ASSET_CODE, vaultMatcher(firstTenantId, secondTenantId)), creditMatcher(secondTenantId, transferAmount, ASSET_CODE, secondTenantId)); checkBalance(firstTenantId, firstTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(secondTenantId), transferAmount);/* w w w . j a v a 2 s . c o m*/ checkBalance(secondTenantId, secondTenantApiKey, ASSET_CODE, tenantVaultStellarAddress(firstTenantId), BigDecimal.ZERO); //Return balances to zero for next test. makePayment(firstTenantId, firstTenantApiKey, secondTenantId, ASSET_CODE, transferAmount); accountListener.waitForCredits(PAY_WAIT, creditMatcher(secondTenantId, transferAmount, ASSET_CODE, vaultMatcher(firstTenantId, secondTenantId))); }
From source file:com.coinblesk.server.service.UserAccountService.java
@Transactional(readOnly = false) public UserAccountTO transferP2SH(ECKey clientKey, String email) { final NetworkParameters params = appConfig.getNetworkParameters(); final UserAccount userAccount = repository.findByEmail(email); if (userAccount == null) { return new UserAccountTO().type(Type.NO_ACCOUNT); }/*from w w w . ja v a 2 s . co m*/ final ECKey pot = appConfig.getPotPrivateKeyAddress(); long satoshi = userAccount.getBalance().multiply(new BigDecimal(BitcoinUtils.ONE_BITCOIN_IN_SATOSHI)) .longValue(); List<TransactionOutput> outputs = walletService.potTransactionOutput(params); // TODO: get current timelocked multisig address Keys keys = keyService.getByClientPublicKey(clientKey.getPubKey()); Transaction tx; try { tx = BitcoinUtils.createTx(params, outputs, pot.toAddress(params), keys.latestTimeLockedAddresses().toAddress(params), satoshi, false); tx = BitcoinUtils.sign(params, tx, pot); BitcoinUtils.verifyTxFull(tx); LOG.debug("About tot zero balance with tx {}", tx); userAccount.setBalance(BigDecimal.ZERO); LOG.debug("About to broadcast tx"); walletService.broadcast(tx); LOG.debug("Broadcast done"); long satoshiNew = userAccount.getBalance().multiply(new BigDecimal(BitcoinUtils.ONE_BITCOIN_IN_SATOSHI)) .longValue(); final UserAccountTO userAccountTO = new UserAccountTO(); userAccountTO.email(userAccount.getEmail()).balance(satoshiNew); return userAccountTO; } catch (CoinbleskException | InsufficientFunds e) { LOG.error("Cannot create transaction", e); mailService.sendAdminMail("transfer-p2sh error", "Cannot create transaction: " + e.getMessage()); return new UserAccountTO().type(Type.ACCOUNT_ERROR).message(e.getMessage()); } }
From source file:com.roncoo.pay.account.service.impl.RpAccountTransactionServiceImpl.java
/** * ?:?/*from ww w .j a v a2 s . co m*/ * * @param userNo * ? * @param amount * ?? * @param requestNo * ? * @param trxType * * @param remark * */ @Transactional(rollbackFor = Exception.class) public RpAccount debitToAccount(String userNo, BigDecimal amount, String requestNo, String bankTrxNo, String trxType, String remark) { RpAccount account = this.getByUserNo_IsPessimist(userNo, true); if (account == null) { throw AccountBizException.ACCOUNT_NOT_EXIT; } // ??? BigDecimal availableBalance = account.getAvailableBalance(); String isAllowSett = PublicEnum.YES.name(); String completeSett = PublicEnum.NO.name(); if (availableBalance.compareTo(amount) == -1) { throw AccountBizException.ACCOUNT_SUB_AMOUNT_OUTLIMIT; } /** ?? **/ account.setBalance(account.getBalance().subtract(amount)); Date lastModifyDate = account.getEditTime(); // ??0 if (!DateUtils.isSameDayWithToday(lastModifyDate)) { account.setTodayExpend(BigDecimal.ZERO); account.setTodayIncome(BigDecimal.ZERO); account.setTodayExpend(amount); } else { account.setTodayExpend(account.getTodayExpend().add(amount)); } account.setTotalExpend(account.getTodayExpend().add(amount)); account.setEditTime(new Date()); // ? RpAccountHistory accountHistoryEntity = new RpAccountHistory(); accountHistoryEntity.setCreateTime(new Date()); accountHistoryEntity.setEditTime(new Date()); accountHistoryEntity.setIsAllowSett(isAllowSett); accountHistoryEntity.setAmount(amount); accountHistoryEntity.setBalance(account.getBalance()); accountHistoryEntity.setRequestNo(requestNo); accountHistoryEntity.setBankTrxNo(bankTrxNo); accountHistoryEntity.setIsCompleteSett(completeSett); accountHistoryEntity.setRemark(remark); accountHistoryEntity.setFundDirection(AccountFundDirectionEnum.SUB.name()); accountHistoryEntity.setAccountNo(account.getAccountNo()); accountHistoryEntity.setTrxType(trxType); accountHistoryEntity.setId(StringUtil.get32UUID()); accountHistoryEntity.setUserNo(userNo); this.rpAccountHistoryDao.insert(accountHistoryEntity); this.rpAccountDao.update(account); return account; }
From source file:pe.gob.mef.gescon.web.ui.EntidadMB.java
public void cleanAttributes() { this.setId(BigDecimal.ZERO); this.setDescripcion(StringUtils.EMPTY); this.setNombre(StringUtils.EMPTY); this.setCodigo(null); this.setActivo(BigDecimal.ONE); this.setSelectedEntidad(null); this.setListaProvincia(new ArrayList()); this.setListaDistrito(new ArrayList()); this.setListaTipoEntidad(new ArrayList()); this.setDepartamento(StringUtils.EMPTY); this.setProvincia(StringUtils.EMPTY); this.setDistrito(StringUtils.EMPTY); this.setTipoentidad(StringUtils.EMPTY); Iterator<FacesMessage> iter = FacesContext.getCurrentInstance().getMessages(); if (iter.hasNext() == true) { iter.remove();// www . j ava 2 s. c om FacesContext.getCurrentInstance().renderResponse(); } }
From source file:com.axelor.apps.account.service.MoveLineExportService.java
public BigDecimal getTotalAmount(List<MoveLine> moveLinelst) { BigDecimal totDebit = BigDecimal.ZERO; BigDecimal totCredit = BigDecimal.ZERO; for (MoveLine moveLine : moveLinelst) { totDebit = totDebit.add(moveLine.getDebit()); totCredit = totCredit.add(moveLine.getCredit()); }//w ww . j av a 2s . c o m return totCredit.subtract(totDebit); }
From source file:org.kuali.coeus.s2sgen.impl.generate.support.RRBudgetV1_4Generator.java
private BudgetSummary getBudgetSummary(BudgetSummaryDto budgetSummaryData) { BudgetSummary budgetSummary = BudgetSummary.Factory.newInstance(); OtherDirectCostInfoDto otherDirectCosts = null; if (budgetSummaryData != null) { if (budgetSummaryData.getOtherDirectCosts() != null && budgetSummaryData.getOtherDirectCosts().size() > 0) { otherDirectCosts = budgetSummaryData.getOtherDirectCosts().get(0); }// ww w .j av a 2 s. c o m if (otherDirectCosts != null) { budgetSummary.setCumulativeTotalFundsRequestedSeniorKeyPerson(BigDecimal.ZERO); budgetSummary.setCumulativeTotalFundsRequestedPersonnel(BigDecimal.ZERO); if (budgetSummaryData.getCumTotalFundsForSrPersonnel() != null) { budgetSummary.setCumulativeTotalFundsRequestedSeniorKeyPerson( budgetSummaryData.getCumTotalFundsForSrPersonnel().bigDecimalValue()); } if (budgetSummaryData.getCumTotalFundsForOtherPersonnel() != null && budgetSummaryData .getCumTotalFundsForOtherPersonnel().isGreaterThan(ScaleTwoDecimal.ZERO)) { budgetSummary.setCumulativeTotalFundsRequestedOtherPersonnel( budgetSummaryData.getCumTotalFundsForOtherPersonnel().bigDecimalValue()); } if (budgetSummaryData.getCumNumOtherPersonnel() != null) { budgetSummary.setCumulativeTotalNoOtherPersonnel( budgetSummaryData.getCumNumOtherPersonnel().intValue()); } if (budgetSummaryData.getCumTotalFundsForPersonnel() != null) { budgetSummary.setCumulativeTotalFundsRequestedPersonnel( budgetSummaryData.getCumTotalFundsForPersonnel().bigDecimalValue()); } budgetSummary.setCumulativeTotalFundsRequestedEquipment( budgetSummaryData.getCumEquipmentFunds().bigDecimalValue()); budgetSummary .setCumulativeTotalFundsRequestedTravel(budgetSummaryData.getCumTravel().bigDecimalValue()); budgetSummary.setCumulativeDomesticTravelCosts( budgetSummaryData.getCumDomesticTravel().bigDecimalValue()); budgetSummary .setCumulativeForeignTravelCosts(budgetSummaryData.getCumForeignTravel().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedTraineeCosts(budgetSummaryData.getpartOtherCost() .add(budgetSummaryData.getpartStipendCost().add(budgetSummaryData.getpartTravelCost().add( budgetSummaryData.getPartTuition().add(budgetSummaryData.getPartSubsistence())))) .bigDecimalValue()); budgetSummary.setCumulativeTraineeStipends(otherDirectCosts.getPartStipends().bigDecimalValue()); budgetSummary .setCumulativeTraineeSubsistence(otherDirectCosts.getPartSubsistence().bigDecimalValue()); budgetSummary.setCumulativeTraineeTravel(otherDirectCosts.getPartTravel().bigDecimalValue()); budgetSummary.setCumulativeTraineeTuitionFeesHealthInsurance( otherDirectCosts.getPartTuition().bigDecimalValue()); budgetSummary.setCumulativeOtherTraineeCost(budgetSummaryData.getpartOtherCost().bigDecimalValue()); budgetSummary.setCumulativeNoofTrainees(budgetSummaryData.getparticipantCount()); budgetSummary.setCumulativeTotalFundsRequestedOtherDirectCosts( otherDirectCosts.gettotalOtherDirect().bigDecimalValue()); budgetSummary.setCumulativeMaterialAndSupplies(otherDirectCosts.getmaterials().bigDecimalValue()); budgetSummary.setCumulativePublicationCosts(otherDirectCosts.getpublications().bigDecimalValue()); budgetSummary.setCumulativeConsultantServices(otherDirectCosts.getConsultants().bigDecimalValue()); budgetSummary.setCumulativeADPComputerServices(otherDirectCosts.getcomputer().bigDecimalValue()); budgetSummary.setCumulativeSubawardConsortiumContractualCosts( otherDirectCosts.getsubAwards().bigDecimalValue()); budgetSummary.setCumulativeEquipmentFacilityRentalFees( otherDirectCosts.getEquipRental().bigDecimalValue()); budgetSummary.setCumulativeAlterationsAndRenovations( otherDirectCosts.getAlterations().bigDecimalValue()); List<Map<String, String>> cvOthers = otherDirectCosts.getOtherCosts(); for (int j = 0; j < cvOthers.size(); j++) { Map<String, String> hmCosts = cvOthers.get(j); if (j == 0) { budgetSummary .setCumulativeOther1DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } else if (j == 1) { budgetSummary .setCumulativeOther2DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } else { budgetSummary .setCumulativeOther3DirectCost(new BigDecimal(hmCosts.get(CostConstants.KEY_COST))); } } budgetSummary.setCumulativeTotalFundsRequestedDirectCosts( budgetSummaryData.getCumTotalDirectCosts().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedIndirectCost( budgetSummaryData.getCumTotalIndirectCosts().bigDecimalValue()); budgetSummary.setCumulativeTotalFundsRequestedDirectIndirectCosts( budgetSummaryData.getCumTotalCosts().bigDecimalValue()); if (budgetSummaryData.getCumFee() != null) { budgetSummary.setCumulativeFee(budgetSummaryData.getCumFee().bigDecimalValue()); } budgetSummary.setCumulativeTotalCostsFee(budgetSummary.getCumulativeFee() != null ? budgetSummary.getCumulativeFee() .add(budgetSummary.getCumulativeTotalFundsRequestedDirectIndirectCosts()) : budgetSummary.getCumulativeTotalFundsRequestedDirectIndirectCosts()); } } return budgetSummary; }
From source file:org.fineract.module.stellar.horizonadapter.HorizonServerUtilities.java
public void removeVaultAccount(final StellarAccountId stellarAccountId, final char[] stellarAccountPrivateKey, final StellarAccountId stellarVaultAccountId, final char[] stellarVaultAccountPrivateKey) throws InvalidConfigurationException, StellarPaymentFailedException, StellarTrustlineAdjustmentFailedException, AccountMergerFailedException { final KeyPair accountKeyPair = KeyPair.fromAccountId(stellarAccountId.getPublicKey()); StellarAccountHelpers account = getAccount(accountKeyPair); account.getVaultBalancesStream(stellarVaultAccountId.getPublicKey()) .forEach(balance -> adjustVaultIssuedAssets(stellarAccountId, stellarAccountPrivateKey, stellarVaultAccountId, stellarVaultAccountPrivateKey, balance.getAssetCode(), BigDecimal.ZERO)); account = getAccount(accountKeyPair); //Get the new balances. if (0 != account.getVaultBalancesStream(stellarVaultAccountId.getPublicKey()).count()) throw AccountMergerFailedException.vaultIssuedAssetsAreStillInCirculation(); mergeAccount(accountKeyPair, KeyPair.fromSecretSeed(stellarVaultAccountPrivateKey)); }
From source file:org.businessmanager.web.controller.page.invoice.InvoiceEditController.java
public BigDecimal getTotalGrossPrice() { BigDecimal totalGrossPrice = BigDecimal.ZERO; for (LineItemBean lineItem : bean.getLineItems()) { BigDecimal sumPrice = lineItem.getSumPriceGross(); totalGrossPrice = totalGrossPrice.add(sumPrice); }//from ww w. j av a 2 s. c o m return totalGrossPrice.setScale(2, RoundingMode.HALF_UP); }