List of usage examples for java.math BigDecimal subtract
public BigDecimal subtract(BigDecimal subtrahend)
From source file:com.mg.merp.planning.support.MPSProcessorServiceBean.java
private RollUpMPSResult rollUpMPS(Mps mpsDst, MpsLine srcMpsLine, BigDecimal quan, Date countDay, int mpsSequence) { BigDecimal roundedQty = quan; if (srcMpsLine.getPlanningItem().getCatalog() != null) { Bom bom = bomService.findCurrentBOM(srcMpsLine.getPlanningItem().getCatalog().getId()); if (bom != null) { BigDecimal maxQty = bom.getMaxLotQty(); BigDecimal minQty = bom.getMinLotQty(); BigDecimal increment = bom.getLotIncrementQty(); if (!(MathUtils.compareToZeroOrNull(maxQty) == 0 || MathUtils.compareToZeroOrNull(minQty) == 0 || MathUtils.compareToZeroOrNull(increment) == 0)) { if (bom.getCatalog().getMeasure1().getId() != srcMpsLine.getPlanningItem().getMeasure() .getId()) {/*from w ww.j a v a 2 s.c o m*/ maxQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), maxQty); minQty = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), minQty); increment = getMeasureConversionService().conversion(bom.getCatalog().getMeasure1(), srcMpsLine.getPlanningItem().getMeasure(), bom.getCatalog(), srcMpsLine.getBucketOffsetDate(), increment); } long numOfMax = roundedQty.divide(maxQty).longValue(); roundedQty = maxQty.multiply(new BigDecimal(numOfMax)); BigDecimal remainder = roundedQty.add(roundedQty); if (MathUtils.compareToZero(remainder) != 0) { if (remainder.compareTo(minQty) < 0) { roundedQty = roundedQty.add(minQty); } else { long numOfInc = remainder.subtract(minQty).divide(increment).longValue(); BigDecimal remInc = remainder.subtract(minQty) .subtract(increment.multiply(new BigDecimal(numOfInc))); if (MathUtils.compareToZero(remInc) != 0) roundedQty = roundedQty.add(minQty) .add(increment.multiply(new BigDecimal(numOfInc))).add(increment); else roundedQty = roundedQty.add(remainder); } } } } } short bucket = MfUtils.determineBucketOffset(mpsDst.getPlanningLevel().getId(), countDay); MpsLine mpsLine = null; for (MpsLine line : generatedMPSLines) { if (MathUtils.compareToZero(line.getProductionDemandQty()) <= 0 && line.getPlanningItem().getId() == srcMpsLine.getPlanningItem().getId() && line.getBucketOffset() == bucket) { mpsLine = line; break; } } if (mpsLine == null) { mpsLine = mpsLineService.initialize(); mpsLine.setPlanningItem(srcMpsLine.getPlanningItem()); mpsLine.setLevelCode(srcMpsLine.getPlanningItem().getLowLevelCode()); mpsLine.setMps(mpsDst); mpsLine.setBucketOffset(bucket); BucketRange bucketRange = MfUtils.determineBucketRange(mpsDst.getPlanningLevel().getId(), bucket); mpsLine.setBucketOffsetDate(bucketRange.getBucketStart()); mpsLine.setDemandFenceDate(srcMpsLine.getDemandFenceDate()); mpsLine.setMpsSequence(mpsSequence); mpsLine.setOutputMpsSequence(null); mpsLine.setMeasure(srcMpsLine.getMeasure()); mpsLine.setPlannedQty(roundedQty); generatedMPSLines.add(mpsLine); // ? MPS return new RollUpMPSResult(roundedQty, mpsSequence + 1); } else { mpsLine.setPlannedQty(mpsLine.getPlannedQty().add(roundedQty)); return new RollUpMPSResult(roundedQty, mpsSequence); } }
From source file:org.egov.wtms.application.service.ConnectionDemandService.java
public BigDecimal getTotalAmountForBaseDemand(DemandDetail demanddetailBean, BigDecimal baseDemandAmount) { BigDecimal currentTotalAmount = ZERO; EgDemandDetails demandDetailsObj = waterConnectionDetailsRepository .findEgDemandDetailById(demanddetailBean.getId()); if (demanddetailBean.getId() == null) currentTotalAmount = baseDemandAmount.add(demanddetailBean.getActualAmount()); else if (demanddetailBean.getActualAmount().compareTo(demandDetailsObj.getAmount()) < 0) { BigDecimal diffExtraless = demandDetailsObj.getAmount().subtract(demanddetailBean.getActualAmount()); currentTotalAmount = baseDemandAmount.subtract(diffExtraless); } else if (demanddetailBean.getActualAmount().compareTo(demandDetailsObj.getAmount()) > 0) { BigDecimal diffExtra = demanddetailBean.getActualAmount().subtract(demandDetailsObj.getAmount()); currentTotalAmount = baseDemandAmount.add(diffExtra); } else if (demanddetailBean.getActualAmount().compareTo(demandDetailsObj.getAmount()) == 0) currentTotalAmount = baseDemandAmount; return currentTotalAmount; }
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()); }//from w w w.j a v a 2 s. co m return totCredit.subtract(totDebit); }
From source file:org.jpos.gl.GLSession.java
private BigDecimal applyEntries(BigDecimal balance, List entries) throws GLException { Iterator iter = entries.iterator(); while (iter.hasNext()) { GLEntry entry = (GLEntry) iter.next(); if (entry.isIncrease()) { balance = balance.add(entry.getAmount()); } else if (entry.isDecrease()) { balance = balance.subtract(entry.getAmount()); } else {/*from ww w . j a v a 2 s. c om*/ throw new GLException(entry.toString() + " has invalid account type"); } } return balance; }
From source file:com.xumpy.thuisadmin.services.implementations.BedragenSrvImpl.java
@Override @Transactional(value = "jpaTransactionManager") public BigDecimal getBedragAtDate(Date date, Rekeningen rekening) { BigDecimal rekeningStand; List<BedragenDaoPojo> lstBedragen; if (rekening != null) { lstBedragen = bedragenDao.getBedragenUntilDate(date, rekening.getPk_id(), userInfo.getPersoon().getPk_id()); rekeningStand = rekening.getWaarde(); } else {/*from w ww . ja va 2s . c o m*/ lstBedragen = bedragenDao.getBedragenUntilDate(date, null, userInfo.getPersoon().getPk_id()); rekeningStand = rekeningenDao.totalAllRekeningen(userInfo.getPersoon().getPk_id()); } for (BedragenDaoPojo bedrag : lstBedragen) { if (bedrag.getGroep().getNegatief().equals(1)) { rekeningStand = rekeningStand.add(bedrag.getBedrag()); } if (bedrag.getGroep().getNegatief().equals(0)) { rekeningStand = rekeningStand.subtract(bedrag.getBedrag()); } } return rekeningStand; }
From source file:org.egov.wtms.application.service.ConnectionDemandService.java
public BigDecimal getTotalCollectedAmountForDemand(final DemandDetail demanddetailBean, BigDecimal demandAmountCollected) { BigDecimal currentTotalAmount = ZERO; EgDemandDetails demandDetailsObj = waterConnectionDetailsRepository .findEgDemandDetailById(demanddetailBean.getId()); if (demanddetailBean.getId() == null) currentTotalAmount = demandAmountCollected.add(demanddetailBean.getActualCollection()); else if (demanddetailBean.getActualCollection().compareTo(demandDetailsObj.getAmtCollected()) < 0) { BigDecimal diffExtraless = demandDetailsObj.getAmtCollected() .subtract(demanddetailBean.getActualCollection()); currentTotalAmount = demandAmountCollected.subtract(diffExtraless); } else if (demanddetailBean.getActualCollection().compareTo(demandDetailsObj.getAmtCollected()) > 0) { BigDecimal diffExtra = demanddetailBean.getActualCollection() .subtract(demandDetailsObj.getAmtCollected()); currentTotalAmount = demandAmountCollected.add(diffExtra); } else if (demanddetailBean.getActualCollection().compareTo(demandDetailsObj.getAmtCollected()) == 0) currentTotalAmount = demandAmountCollected; return currentTotalAmount; }
From source file:org.openbravo.advpaymentmngt.process.FIN_PaymentProcess.java
/** * Method used to update the credit used when the user doing invoice processing or payment * processing//from w w w . j a v a 2 s.c om * * @param amount * Payment amount */ private void updateCustomerCredit(BusinessPartner businessPartner, BigDecimal amount, boolean add) { BigDecimal creditUsed = businessPartner.getCreditUsed(); if (add) { creditUsed = creditUsed.add(amount); } else { creditUsed = creditUsed.subtract(amount); } businessPartner.setCreditUsed(creditUsed); OBDal.getInstance().save(businessPartner); // OBDal.getInstance().flush(); }
From source file:com.axelor.apps.account.service.MoveLineExportService.java
@Transactional(rollbackOn = { AxelorException.class, Exception.class }) public MoveLineReport createMoveLineReport(Company company, int exportTypeSelect, LocalDate startDate, LocalDate endDate) throws AxelorException { MoveLineReport moveLineReport = new MoveLineReport(); moveLineReport.setCompany(company);/* w ww .j a va 2s. c om*/ moveLineReport.setTypeSelect(exportTypeSelect); moveLineReport.setDateFrom(startDate); moveLineReport.setDateTo(endDate); moveLineReport.setStatusSelect(MoveLineReportRepository.STATUS_DRAFT); moveLineReport.setDate(todayTime.toLocalDate()); moveLineReport.setRef(moveLineReportService.getSequence(moveLineReport)); moveLineReportService.buildQuery(moveLineReport); BigDecimal debitBalance = moveLineReportService.getDebitBalance(); BigDecimal creditBalance = moveLineReportService.getCreditBalance(); moveLineReport.setTotalDebit(debitBalance); moveLineReport.setTotalCredit(creditBalance); moveLineReport.setBalance(debitBalance.subtract(creditBalance)); moveLineReportRepo.save(moveLineReport); return moveLineReport; }
From source file:org.efaps.esjp.accounting.transaction.evaluation.DocumentInfo_Base.java
/** * Apply exchange gain loss.//from w w w . j av a 2 s. c o m * * @param _parameter Parameter as passed by the eFaps API * @throws EFapsException on error */ public void applyExchangeGainLoss(final Parameter _parameter) throws EFapsException { final AccountInfo gainAcc = AccountInfo.get4Config(_parameter, AccountingSettings.PERIOD_EXCHANGEGAIN); final AccountInfo lossAcc = AccountInfo.get4Config(_parameter, AccountingSettings.PERIOD_EXCHANGELOSS); if (gainAcc != null && lossAcc != null) { final QueryBuilder queryBldr = new QueryBuilder(CISales.Payment); queryBldr.addWhereAttrEqValue(CISales.Payment.TargetDocument, getInstance()); final MultiPrintQuery multi = queryBldr.getPrint(); final SelectBuilder selDocInst = new SelectBuilder().linkto(CISales.Payment.FromAbstractLink) .instance(); final SelectBuilder selCurInst = new SelectBuilder().linkto(CISales.Payment.CurrencyLink).instance(); multi.addSelect(selDocInst, selCurInst); multi.addAttribute(CISales.Payment.Amount, CISales.Payment.Date); multi.execute(); while (multi.next()) { final Instance docInst = multi.getSelect(selDocInst); final PrintQuery print = new PrintQuery(docInst); final SelectBuilder selDocCurInst = new SelectBuilder() .linkto(CISales.DocumentSumAbstract.RateCurrencyId).instance(); print.addSelect(selDocCurInst); print.addAttribute(CIERP.DocumentAbstract.Date); print.execute(); final Instance curInst = multi.getSelect(selCurInst); final Instance docCurInst = print.getSelect(selDocCurInst); final DateTime docDate = print.getAttribute(CIERP.DocumentAbstract.Date); final DateTime dateTmp = multi.getAttribute(CISales.Payment.Date); final BigDecimal amountTmp = multi.getAttribute(CISales.Payment.Amount); if (!curInst.equals(Currency.getBaseCurrency()) || !docCurInst.equals(Currency.getBaseCurrency())) { final Currency currency = new Currency(); final RateInfo[] rateInfos1 = currency.evaluateRateInfos(_parameter, dateTmp, curInst, docCurInst); final RateInfo[] rateInfos2 = currency.evaluateRateInfos(_parameter, docDate, curInst, docCurInst); final int idx; // payment in BaseCurreny ==> Document was not BaseCurrency therefore current against target if (curInst.equals(Currency.getBaseCurrency())) { idx = 2; // Document in BaseCurrency ==> payment was not BaseCurrency therefore current against base } else if (docCurInst.equals(Currency.getBaseCurrency())) { idx = 0; // neither Document nor payment are BaseCurrency but are the same } else if (curInst.equals(docCurInst)) { idx = 0; } else { idx = 0; } final BigDecimal rate1 = RateInfo.getRate(_parameter, rateInfos1[idx], docInst.getType().getName()); final BigDecimal rate2 = RateInfo.getRate(_parameter, rateInfos2[idx], docInst.getType().getName()); if (rate1.compareTo(rate2) != 0) { final BigDecimal amount1 = amountTmp.divide(rate1, BigDecimal.ROUND_HALF_UP); final BigDecimal amount2 = amountTmp.divide(rate2, BigDecimal.ROUND_HALF_UP); BigDecimal gainLoss = amount1.subtract(amount2); if (idx == 2) { gainLoss = gainLoss.multiply(rate1); } if (gainLoss.compareTo(BigDecimal.ZERO) != 0) { final boolean out = getInstance().getType() .isKindOf(CISales.PaymentDocumentOutAbstract); if (out) { final boolean gain = gainLoss.compareTo(BigDecimal.ZERO) > 0; for (final AccountInfo accinfo : getCreditAccounts()) { if (accinfo.getDocLink() != null && accinfo.getDocLink().equals(docInst)) { final BigDecimal accAmount; if (accinfo.getRateInfo().getCurrencyInstance() .equals(Currency.getBaseCurrency())) { accAmount = gainLoss; } else { accAmount = gainLoss.multiply(accinfo.getRate(_parameter)); } accinfo.addAmount(accAmount.negate()); } } if (gain) { gainAcc.setAmount(gainLoss.abs()).setRateInfo(RateInfo.getDummyRateInfo(), getInstance().getType().getName()); addCredit(gainAcc); } else { lossAcc.setAmount(gainLoss.abs()).setRateInfo(RateInfo.getDummyRateInfo(), getInstance().getType().getName()); addDebit(lossAcc); } } else { final boolean gain = gainLoss.compareTo(BigDecimal.ZERO) < 0; for (final AccountInfo accinfo : getDebitAccounts()) { if (accinfo.getDocLink() != null && accinfo.getDocLink().equals(docInst)) { final BigDecimal accAmount; if (!accinfo.getRateInfo().getCurrencyInstance() .equals(Currency.getBaseCurrency())) { accAmount = gainLoss; } else { accAmount = gainLoss.multiply(accinfo.getRate(_parameter)); } accinfo.addAmount(accAmount); } } if (gain) { gainAcc.setAmount(gainLoss.abs()).setRateInfo(RateInfo.getDummyRateInfo(), getInstance().getType().getName()); addDebit(gainAcc); } else { lossAcc.setAmount(gainLoss.abs()).setRateInfo(RateInfo.getDummyRateInfo(), getInstance().getType().getName()); addCredit(lossAcc); } } } } } } } }
From source file:org.openbravo.advpaymentmngt.actionHandler.ModifyPaymentPlanActionHandler.java
/** * Given a list of payment schedule element and a list of amounts associated to orders, creates * the payment schedule details for the given payment schedule element * // w ww . j a v a2s . c o m */ private HashMap<FIN_PaymentSchedule, BigDecimal> createPaymentScheduleDetail(FIN_PaymentSchedule invoicePS, HashMap<FIN_PaymentSchedule, BigDecimal> ordersProvided) { HashMap<FIN_PaymentSchedule, BigDecimal> orders = ordersProvided; Iterator<FIN_PaymentSchedule> ite = orders.keySet().iterator(); BigDecimal amount = getPendingPSAmounts(invoicePS); List<FIN_PaymentSchedule> lOrdersToRemove = new ArrayList<FIN_PaymentSchedule>(); FIN_PaymentSchedule orderPS = null; BigDecimal orderAmount = BigDecimal.ZERO; if (orders.containsKey(null)) { orderAmount = orders.get(null); } else { lOrdersToRemove.add(null); } while (amount.compareTo(BigDecimal.ZERO) != 0 && ite.hasNext()) { if (lOrdersToRemove.contains(orderPS) || orderAmount.compareTo(BigDecimal.ZERO) == 0) { orderPS = ite.next(); orderAmount = orders.get(orderPS); } if (amount.abs().compareTo(orderAmount.abs()) >= 0) { if (orderAmount.compareTo(BigDecimal.ZERO) != 0) { dao.getNewPaymentScheduleDetail(invoicePS, orderPS, orderAmount, BigDecimal.ZERO, null); } amount = amount.subtract(orderAmount); orderAmount = BigDecimal.ZERO; lOrdersToRemove.add(orderPS); } else { if (amount.compareTo(BigDecimal.ZERO) != 0) { dao.getNewPaymentScheduleDetail(invoicePS, orderPS, amount, BigDecimal.ZERO, null); } orderAmount = orderAmount.subtract(amount); amount = BigDecimal.ZERO; } orders.put(orderPS, orderAmount); } OBDal.getInstance().flush(); for (FIN_PaymentSchedule ps : lOrdersToRemove) { orders.remove(ps); } return orders; }