List of usage examples for java.math BigDecimal subtract
public BigDecimal subtract(BigDecimal subtrahend)
From source file:models.finance.WorkOrder.java
/** * Get the open amount./*from w ww .ja v a 2s .c om*/ * * if the work order is not engaged: return null * * if the work order is engaged and the amount/received amount are defined * then return the difference * * @param usePurchaseOrder * true if the purchase order are enabled */ public BigDecimal getAmountOpen(boolean usePurchaseOrder) { if (getComputedIsEngaged(usePurchaseOrder)) { BigDecimal a = getComputedAmount(usePurchaseOrder); BigDecimal ar = getComputedAmountReceived(usePurchaseOrder); if (a != null && ar != null) { BigDecimal ao = a.subtract(ar); return ao; } else { return null; } } else { return null; } }
From source file:org.egov.wtms.web.controller.application.MeterDemandNoticeController.java
public BigDecimal getTotalDue(final WaterConnectionDetails waterConnectionDetails, final Date givenDate) { BigDecimal balance; balance = waterConnectionDetailsService.getTotalAmount(waterConnectionDetails); final BigDecimal demnadDetCurrentamount = getCurrentMonthDemandAmount(waterConnectionDetails, givenDate); balance = balance.subtract(demnadDetCurrentamount); return balance; }
From source file:org.openvpms.archetype.rules.finance.till.TillRules.java
/** * Adds an adjustment to a till, if required. * * @param balance the till balance act * @param cashFloat the new cash float//from w w w .j ava 2s .c om */ private void addAdjustment(FinancialAct balance, BigDecimal cashFloat, Till till) { BigDecimal lastCashFloat = till.getTillFloat(); BigDecimal diff = cashFloat.subtract(lastCashFloat); if (diff.compareTo(BigDecimal.ZERO) != 0) { // need to generate an adjustment, and associate it with the balance boolean credit = (lastCashFloat.compareTo(cashFloat) > 0); Act adjustment = createTillBalanceAdjustment(till.getEntity(), diff.abs(), credit); ActBean balanceBean = new ActBean(balance); balanceBean.addNodeRelationship("items", adjustment); service.save(adjustment); // NOTE that this will trigger TillBalanceRules.addToTill(), but will have no effect TillHelper.updateBalance(balanceBean, service); } }
From source file:org.openconcerto.erp.graph.GraphFamilleArticlePanel.java
protected BigDecimal updateDataset(List<String> labels, List<Number> values) { final SQLTable tableVFElement = Configuration.getInstance().getDirectory() .getElement("SAISIE_VENTE_FACTURE_ELEMENT").getTable(); final SQLTable tableVF = tableVFElement.getTable("SAISIE_VENTE_FACTURE"); final SQLTable tableArticle = tableVFElement.getTable("ARTICLE"); final SQLSelect sel = new SQLSelect(); final String field = "ID_FAMILLE_ARTICLE"; sel.addSelect(tableArticle.getField(field)); sel.addSelect(tableVFElement.getField("T_PA_HT"), "SUM"); sel.addSelect(tableVFElement.getField("T_PV_HT"), "SUM"); sel.addSelect(tableVFElement.getField("QTE"), "SUM"); Where w = new Where(tableVF.getKey(), "=", tableVFElement.getField("ID_SAISIE_VENTE_FACTURE")); w = w.and(new Where(tableVF.getField("DATE"), this.d1, this.d2)); w = w.and(new Where(tableArticle.getKey(), "=", tableVFElement.getField("ID_ARTICLE"))); sel.setWhere(w);/*from w w w.j a v a 2 s. c o m*/ final List<Object[]> rowsArticle = (List<Object[]>) Configuration.getInstance().getBase().getDataSource() .execute(sel.asString() + " GROUP BY \"ARTICLE\".\"" + field + "\"", new ArrayListHandler()); Collections.sort(rowsArticle, new Comparator<Object[]>() { @Override public int compare(Object[] o1, Object[] o2) { BigDecimal pa1 = (BigDecimal) o1[1]; BigDecimal pv1 = (BigDecimal) o1[2]; BigDecimal qte1 = new BigDecimal(o1[3].toString()); BigDecimal pa2 = (BigDecimal) o2[1]; BigDecimal pv2 = (BigDecimal) o2[2]; BigDecimal qte2 = new BigDecimal(o2[3].toString()); BigDecimal marge1 = pv1.subtract(pa1).multiply(qte1, DecimalUtils.HIGH_PRECISION); BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION); return pv1.compareTo(pv2); } }); SQLTable tableFamille = tableVFElement.getTable("FAMILLE_ARTICLE"); BigDecimal total = BigDecimal.ZERO; for (int i = 0; i < rowsArticle.size(); i++) { Object[] o = rowsArticle.get(i); BigDecimal pv2 = (BigDecimal) o[2]; total = total.add(pv2); } if (total.signum() > 0) { for (int i = 0; i < 12 && i < rowsArticle.size(); i++) { Object[] o = rowsArticle.get(i); BigDecimal pa2 = (BigDecimal) o[1]; BigDecimal pv2 = (BigDecimal) o[2]; BigDecimal qte2 = new BigDecimal(o[3].toString()); BigDecimal marge2 = pv2.subtract(pa2).multiply(qte2, DecimalUtils.HIGH_PRECISION); String s = "Indfini"; if (o[0] != null) { int id = ((Number) o[0]).intValue(); s = tableFamille.getRow(id).getString("NOM"); } values.add(pv2); labels.add(s + "(" + decFormat.format(pv2.setScale(2, RoundingMode.HALF_UP).doubleValue()) + " soit " + pv2.divide(total, DecimalUtils.HIGH_PRECISION).movePointRight(2).setScale(2, RoundingMode.HALF_UP) + "%)"); } } return total; }
From source file:org.projectforge.fibu.OrderExport.java
private void addPosMapping(final PropertyMapping mapping, final AuftragDO order, final AuftragsPositionDO pos, final Object... params) { mapping.add(PosCol.NUMBER, order.getNummer()); mapping.add(PosCol.POS_NUMBER, "#" + pos.getNumber()); mapping.add(PosCol.DATE, order.getAngebotsDatum()); mapping.add(PosCol.PROJECT, order.getProjektAsString()); mapping.add(PosCol.ORDER_TITLE, order.getTitel()); mapping.add(PosCol.TITLE, pos.getTitel()); mapping.add(PosCol.TYPE,//from w w w. j a v a 2 s . c om pos.getArt() != null ? PFUserContext.getLocalizedString(pos.getArt().getI18nKey()) : ""); mapping.add(PosCol.STATUS, pos.getStatus() != null ? PFUserContext.getLocalizedString(pos.getStatus().getI18nKey()) : ""); mapping.add(PosCol.PERSON_DAYS, pos.getPersonDays()); final BigDecimal netSum = pos.getNettoSumme() != null ? pos.getNettoSumme() : BigDecimal.ZERO; final BigDecimal invoicedSum = pos.getFakturiertSum() != null ? pos.getFakturiertSum() : BigDecimal.ZERO; final BigDecimal toBeInvoicedSum = netSum.subtract(invoicedSum); mapping.add(PosCol.NETSUM, netSum); addCurrency(mapping, PosCol.INVOICED, invoicedSum); addCurrency(mapping, PosCol.TO_BE_INVOICED, toBeInvoicedSum); mapping.add(PosCol.COMPLETELY_INVOICED, pos.isVollstaendigFakturiert() == true ? "x" : ""); final Set<RechnungsPositionVO> invoicePositions = rechnungCache .getRechnungsPositionVOSetByAuftragsPositionId(pos.getId()); mapping.add(PosCol.INVOICES, getInvoices(invoicePositions)); mapping.add(PosCol.PERIOD_OF_PERFORMANCE_BEGIN, pos.getPeriodOfPerformanceBegin()); mapping.add(PosCol.PERIOD_OF_PERFORMANCE_END, pos.getPeriodOfPerformanceEnd()); final TaskNode node = taskTree.getTaskNodeById(pos.getTaskId()); mapping.add(PosCol.TASK, node != null ? node.getTask().getTitle() : ""); mapping.add(PosCol.COMMENT, pos.getBemerkung()); }
From source file:org.projectforge.fibu.datev.EmployeeSalaryExportDao.java
private void addEmployeeRow(final ExportSheet sheet, final EmployeeDO employee, final BigDecimal numberOfWorkingDays, final BigDecimal totalDuration) { final PFUserDO user = userGroupCache.getUser(employee.getUserId()); final ExportRow row = sheet.addRow(); row.addCell(0, user.getFullname());/*from ww w . jav a 2 s. c om*/ // Wochenstunden row.addCell(1, employee.getWochenstunden(), "STUNDEN"); // Sollstunden: Wochenstunden * Arbeitstage / 5 Arbeitstage pro Woche Integer wochenstunden = employee.getWochenstunden(); if (wochenstunden == null) { wochenstunden = 0; } final BigDecimal soll = new BigDecimal(wochenstunden).multiply(numberOfWorkingDays) .divide(new BigDecimal(5), 2, RoundingMode.HALF_UP); row.addCell(2, soll, "STUNDEN"); // Iststunden final BigDecimal total = totalDuration.divide(new BigDecimal(3600000), 2, RoundingMode.HALF_UP); row.addCell(3, total, "STUNDEN"); // Differenz final BigDecimal differenz = total.subtract(soll); row.addCell(4, differenz, "STUNDEN"); }
From source file:org.projectforge.business.fibu.datev.EmployeeSalaryExportDao.java
private void addEmployeeRow(final ExportSheet sheet, final EmployeeDO employee, final BigDecimal numberOfWorkingDays, final BigDecimal totalDuration) { final PFUserDO user = getUserGroupCache().getUser(employee.getUserId()); final ExportRow row = sheet.addRow(); row.addCell(0, user.getFullname());//from ww w . j av a2 s .co m // Wochenstunden row.addCell(1, employee.getWeeklyWorkingHours(), "STUNDEN"); // Sollstunden: Wochenstunden * Arbeitstage / 5 Arbeitstage pro Woche BigDecimal wochenstunden = employee.getWeeklyWorkingHours(); if (wochenstunden == null) { wochenstunden = BigDecimal.ZERO; } final BigDecimal soll = wochenstunden.multiply(numberOfWorkingDays).divide(new BigDecimal(5), 2, RoundingMode.HALF_UP); row.addCell(2, soll, "STUNDEN"); // Iststunden final BigDecimal total = totalDuration.divide(new BigDecimal(3600000), 2, RoundingMode.HALF_UP); row.addCell(3, total, "STUNDEN"); // Differenz final BigDecimal differenz = total.subtract(soll); row.addCell(4, differenz, "STUNDEN"); }
From source file:org.whispersystems.bithub.controllers.GithubController.java
private void sendPaymentsFor(Repository repository, List<Commit> commits, BigDecimal balance, BigDecimal exchangeRate) { for (Commit commit : commits) { try {/* w w w. j av a 2s . com*/ BigDecimal payout = balance.multiply(payoutRate); if (isViablePaymentAmount(payout)) { coinbaseClient.sendPayment(commit.getAuthor(), payout, commit.getUrl()); } balance = balance.subtract(payout); githubClient.addCommitComment(repository, commit, getCommitCommentStringForPayment(payout, exchangeRate)); } catch (TransferFailedException e) { logger.warn("Transfer failed", e); } } }
From source file:co.nubetech.apache.hadoop.TextSplitter.java
/** * Return the string encoded in a BigDecimal. Repeatedly multiply the input * value by 65536; the integer portion after such a multiplication * represents a single character in base 65536. Convert that back into a * char and create a string out of these until we have no data left. *///from w w w . j a va 2s .c o m String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }
From source file:org.apache.sqoop.mapreduce.db.TextSplitter.java
/** * Return the string encoded in a BigDecimal. * Repeatedly multiply the input value by 65536; the integer portion after * such a multiplication represents a single character in base 65536. * Convert that back into a char and create a string out of these until we * have no data left./*from ww w. j a v a2 s.c om*/ */ public String bigDecimalToString(BigDecimal bd) { BigDecimal cur = bd.stripTrailingZeros(); StringBuilder sb = new StringBuilder(); for (int numConverted = 0; numConverted < MAX_CHARS; numConverted++) { cur = cur.multiply(ONE_PLACE); int curCodePoint = cur.intValue(); if (0 == curCodePoint) { break; } cur = cur.subtract(new BigDecimal(curCodePoint)); sb.append(Character.toChars(curCodePoint)); } return sb.toString(); }