Example usage for java.math BigDecimal subtract

List of usage examples for java.math BigDecimal subtract

Introduction

In this page you can find the example usage for java.math BigDecimal subtract.

Prototype

public BigDecimal subtract(BigDecimal subtrahend) 

Source Link

Document

Returns a BigDecimal whose value is (this - subtrahend) , and whose scale is max(this.scale(), subtrahend.scale()) .

Usage

From source file:org.apache.calcite.runtime.SqlFunctions.java

public static BigDecimal ceil(BigDecimal b0, BigDecimal b1) {
    final BigDecimal[] bigDecimals = b0.divideAndRemainder(b1);
    BigDecimal r = bigDecimals[1];
    if (r.signum() > 0) {
        r = r.subtract(b1);
    }//w w w  .  ja v a  2s . c om
    return b0.subtract(r);
}

From source file:org.apache.calcite.runtime.SqlFunctions.java

/** SQL <code>-</code> operator applied to BigDecimal values. */
public static BigDecimal minus(BigDecimal b0, BigDecimal b1) {
    return (b0 == null || b1 == null) ? null : b0.subtract(b1);
}

From source file:org.openbravo.costing.AverageCostAdjustment.java

@Override
protected BigDecimal getOutgoingBackdatedTrxAdjAmt(CostAdjustmentLine costAdjLine) {
    // Calculate the average cost on the transaction's movement date and adjust the cost if needed.
    MaterialTransaction trx = costAdjLine.getInventoryTransaction();
    Costing costing = getAvgCostOnMovementDate(trx, getCostDimensions(), getCostOrg(), areBackdatedTrxFixed);

    if (costing == null) {
        // In case the backdated transaction is on a date where the stock was not initialized there
        // isn't any costing entry related to an inventory transaction which results in a null
        // costing.
        // Try again with average algorithm getProductCost method using the movement date as
        // parameter.
        costing = AverageAlgorithm.getProductCost(trx.getMovementDate(), trx.getProduct(), getCostDimensions(),
                getCostOrg());//  w ww.j  a va  2  s  . c  o  m
    }

    if (costing == null) {
        String errorMessage = OBMessageUtils.parseTranslation("@NoAvgCostDefined@ @Organization@: "
                + getCostOrg().getName() + ", @Product@: " + trx.getProduct().getName() + ", @Date@: "
                + OBDateUtils.formatDate(trx.getMovementDate()));
        throw new OBException(errorMessage);
    }
    BigDecimal cost = costing.getCost();
    Currency costCurrency = getCostCurrency();
    if (costing.getCurrency() != costCurrency) {
        cost = FinancialUtils.getConvertedAmount(costing.getCost(), costing.getCurrency(), costCurrency,
                trx.getTransactionProcessDate(), getCostOrg(), FinancialUtils.PRECISION_COSTING);
    }
    BigDecimal expectedCostAmt = trx.getMovementQuantity().abs().multiply(cost).setScale(stdCurPrecission,
            RoundingMode.HALF_UP);
    BigDecimal currentCost = trx.getTransactionCost();
    return expectedCostAmt.subtract(currentCost);
}

From source file:org.egov.ptis.domain.service.property.VacancyRemissionService.java

private BigDecimal adjustExcessToCollection(BigDecimal excess, final EgDemandDetails dmdDet) {
    if (excess.compareTo((dmdDet.getAmount().subtract(dmdDet.getAmtCollected()))) > 0) {
        excess = excess.subtract(dmdDet.getAmount().subtract(dmdDet.getAmtCollected()));
        dmdDet.setAmtCollected(dmdDet.getAmount());
    } else {//from   w  w w. ja  v  a2s.  c o m
        dmdDet.setAmtCollected(dmdDet.getAmtCollected().add(excess));
        excess = BigDecimal.ZERO;
    }
    return excess;
}

From source file:org.egov.wtms.application.service.collection.ConnectionBillService.java

/**
 * Creates the advance bill details/*from  w  w w  .  j  a v a  2s .c o  m*/
 *
 * @param billDetails
 * @param orderMap
 * @param currentInstallmentDemand
 * @param demandDetail
 * @param reason
 * @param installment
 */
private void createAdvanceBillDetails(List<EgBillDetails> billDetails, BigDecimal currentInstallmentDemand,
        EgDemand demand, Billable billable, List<Installment> advanceInstallments,
        Installment dmdDetInstallment) {

    /*
     * Advance will be created with current year second half installment. While fetching advance collection, we will pass
     * current year second half installment
     */
    BigDecimal advanceCollection = demandGenericDAO.getBalanceByDmdMasterCodeInst(demand,
            DEMANDRSN_CODE_ADVANCE, moduleService.getModuleByName(MODULE_NAME), dmdDetInstallment);
    CFinancialYear finYear = financialYearDAO.getFinancialYearByDate(new Date());

    if (advanceCollection.signum() < 0)
        advanceCollection = advanceCollection.abs();
    BigDecimal partiallyCollectedAmount = ZERO;
    if (currentInstallmentDemand.signum() > 0)
        partiallyCollectedAmount = advanceCollection.remainder(currentInstallmentDemand);
    if (currentInstallmentDemand.signum() > 0) {
        Integer noOfAdvancesPaid = advanceCollection.subtract(partiallyCollectedAmount)
                .divide(currentInstallmentDemand).intValue();
        if (LOG.isDebugEnabled())
            LOG.debug("getBilldetails - advanceCollection = {}, noOfAdvancesPaid={}", advanceCollection,
                    noOfAdvancesPaid);

        Installment installment;
        int j;
        if (noOfAdvancesPaid < MAX_ADVANCES_ALLOWED)
            for (int i = noOfAdvancesPaid; i < advanceInstallments.size(); i++) {
                installment = advanceInstallments.get(i);
                EgDemandReason reasonmaster = connectionDemandService
                        .getDemandReasonByCodeAndInstallment(DEMANDRSN_CODE_ADVANCE, installment);
                if (reasonmaster != null) {
                    EgBillDetails billdetail = new EgBillDetails();
                    billdetail.setDrAmount(ZERO);
                    billdetail.setCrAmount(currentInstallmentDemand);

                    billdetail.setGlcode(GLCODE_FOR_ADVANCE);
                    billdetail.setEgDemandReason(reasonmaster);
                    billdetail.setCreateDate(new Date());
                    billdetail.setModifiedDate(new Date());
                    j = billDetails.size() + 1;
                    billdetail.setOrderNo(j);
                    billdetail.setDescription(reasonmaster.getEgDemandReasonMaster().getReasonMaster() + " - "
                            + installment.getDescription());
                    if (billdetail.getDescription().contains(DEMANDRSN_REASON_ADVANCE))
                        billdetail.setPurpose(PURPOSE.ADVANCE_AMOUNT.toString());
                    else if (billdetail.getEgDemandReason().getEgInstallmentMaster().getToDate()
                            .compareTo(finYear.getStartingDate()) < 0)
                        billdetail.setPurpose(PURPOSE.ARREAR_AMOUNT.toString());
                    else if (billdetail.getEgDemandReason().getEgInstallmentMaster().getFromDate()
                            .compareTo(finYear.getStartingDate()) >= 0
                            && billdetail.getEgDemandReason().getEgInstallmentMaster().getToDate()
                                    .compareTo(finYear.getEndingDate()) >= 0)
                        billdetail.setPurpose(PURPOSE.CURRENT_AMOUNT.toString());
                    else
                        billdetail.setPurpose(PURPOSE.OTHERS.toString());
                    billdetail.setFunctionCode(STRING_WCMS_FUCNTION_CODE);
                    billdetail.setAdditionalFlag(0);
                    billDetails.add(billdetail);
                }
            }
    } else if (LOG.isDebugEnabled())
        LOG.debug("getBillDetails - All advances are paid...");
}

From source file:org.efaps.esjp.accounting.transaction.Recalculate_Base.java

/**
 * Creates the gain loss4 document account.
 *
 * @param _parameter Parameter as passed by the eFaps API
 * @return the return// w ww.  j a  v a2 s . co  m
 * @throws EFapsException on error
 */
public Return createGainLoss4DocumentAccount(final Parameter _parameter) throws EFapsException {
    final Set<String> setAccounts = getAccounts4DocumentConfig(_parameter);

    final String[] oidsDoc = (String[]) Context.getThreadContext().getSessionAttribute(
            CIFormAccounting.Accounting_GainLoss4DocumentAccountForm.selectedDocuments.name);
    final DateTime dateTo = new DateTime(_parameter
            .getParameterValue(CIFormAccounting.Accounting_GainLoss4DocumentAccountForm.transactionDate.name));
    for (final String oid : oidsDoc) {
        final Instance instDoc = Instance.get(oid);

        final QueryBuilder attrQuerBldr = new QueryBuilder(CIAccounting.Transaction2SalesDocument);
        attrQuerBldr.addWhereAttrEqValue(CIAccounting.Transaction2SalesDocument.ToLink, instDoc);
        final AttributeQuery attrQuery = attrQuerBldr
                .getAttributeQuery(CIAccounting.Transaction2SalesDocument.FromLink);

        // filter classification Document
        final QueryBuilder attrQueryBldr2 = new QueryBuilder(CIAccounting.Transaction);
        attrQueryBldr2.addWhereAttrEqValue(CIAccounting.Transaction.PeriodLink,
                _parameter.getInstance().getId());
        attrQueryBldr2.addWhereAttrInQuery(CIAccounting.Transaction.ID, attrQuery);
        final AttributeQuery attrQuery2 = attrQuerBldr.getAttributeQuery(CIAccounting.Transaction.ID);

        final QueryBuilder queryBldr = new QueryBuilder(CIAccounting.TransactionPositionAbstract);
        queryBldr.addWhereAttrInQuery(CIAccounting.TransactionPositionAbstract.TransactionLink, attrQuery2);
        final MultiPrintQuery multi = queryBldr.getPrint();
        multi.addAttribute(CIAccounting.TransactionPositionAbstract.Amount,
                CIAccounting.TransactionPositionAbstract.RateAmount,
                CIAccounting.TransactionPositionAbstract.CurrencyLink,
                CIAccounting.TransactionPositionAbstract.RateCurrencyLink);
        final SelectBuilder selAcc = new SelectBuilder()
                .linkto(CIAccounting.TransactionPositionAbstract.AccountLink).oid();
        multi.addSelect(selAcc);
        multi.execute();
        final Map<String, AccountInfo> map = new HashMap<>();
        while (multi.next()) {
            final Instance accountInst = Instance.get(multi.<String>getSelect(selAcc));
            if (setAccounts.contains(accountInst.getOid())) {
                final BigDecimal oldRateAmount = multi
                        .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.RateAmount);
                final BigDecimal oldAmount = multi
                        .<BigDecimal>getAttribute(CIAccounting.TransactionPositionAbstract.Amount);
                final Instance targetCurrInst = Instance.get(CIERP.Currency.getType(),
                        multi.<Long>getAttribute(CIAccounting.TransactionPositionAbstract.RateCurrencyLink));
                final Instance currentInst = Instance.get(CIERP.Currency.getType(),
                        multi.<Long>getAttribute(CIAccounting.TransactionPositionAbstract.CurrencyLink));

                final PriceUtil priceUtil = new PriceUtil();
                final BigDecimal[] rates = priceUtil.getRates(_parameter, targetCurrInst, currentInst);
                final BigDecimal rate = rates[2];
                final BigDecimal newAmount = oldRateAmount.divide(rate, BigDecimal.ROUND_HALF_UP);

                BigDecimal gainloss = BigDecimal.ZERO;
                if (!currentInst.equals(targetCurrInst)) {
                    gainloss = newAmount.subtract(oldAmount);
                } else {
                    gainloss = newAmount;
                }
                if (map.containsKey(accountInst.getOid())) {
                    final AccountInfo tarAcc = map.get(accountInst.getOid());
                    tarAcc.addAmount(gainloss);
                } else {
                    final AccountInfo tarAcc = new AccountInfo(accountInst, gainloss);
                    tarAcc.setAmountRate(gainloss);
                    tarAcc.setCurrInstance(currentInst);
                    map.put(accountInst.getOid(), tarAcc);
                }
            }
        }

        if (!map.isEmpty()) {
            Insert insert = null;
            CurrencyInst curr = null;
            BigDecimal gainlossSum = BigDecimal.ZERO;
            for (final Entry<String, AccountInfo> entry : map.entrySet()) {
                final AccountInfo tarAcc = entry.getValue();
                final Instance instAcc = Instance.get(entry.getKey());
                final BigDecimal gainloss = tarAcc.getAmount();
                gainlossSum = gainlossSum.add(gainloss);
                final Instance currInstance = tarAcc.getCurrInstance();
                curr = new CurrencyInst(currInstance);
                final Map<String, String[]> mapVal = validateInfo(_parameter, gainloss);
                final String[] accs = mapVal.get("accs");
                final String[] check = mapVal.get("check");

                if (checkAccounts(accs, 0, check).length() > 0) {
                    if (gainloss.compareTo(BigDecimal.ZERO) != 0) {
                        final String[] accOids = mapVal.get("accountOids");
                        if (insert == null) {
                            final DateTimeFormatter formater = DateTimeFormat.mediumDate();
                            final String dateStr = dateTo
                                    .withChronology(Context.getThreadContext().getChronology())
                                    .toString(formater.withLocale(Context.getThreadContext().getLocale()));
                            final StringBuilder description = new StringBuilder();
                            description
                                    .append(DBProperties
                                            .getProperty("Accounting_DocumentAccountForm.TxnRecalculate.Label"))
                                    .append(" ").append(dateStr);
                            insert = new Insert(CIAccounting.Transaction);
                            insert.add(CIAccounting.Transaction.Description, description.toString());
                            insert.add(CIAccounting.Transaction.Date, dateTo);
                            insert.add(CIAccounting.Transaction.PeriodLink, _parameter.getInstance().getId());
                            insert.add(CIAccounting.Transaction.Status,
                                    Status.find(CIAccounting.TransactionStatus.uuid, "Open").getId());
                            insert.execute();
                        }

                        Insert insertPos = new Insert(CIAccounting.TransactionPositionCredit);
                        insertPos.add(CIAccounting.TransactionPositionCredit.TransactionLink, insert.getId());
                        if (gainloss.signum() < 0) {
                            insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink, instAcc.getId());
                        } else {
                            insertPos.add(CIAccounting.TransactionPositionCredit.AccountLink,
                                    Instance.get(accOids[0]).getId());
                        }
                        insertPos.add(CIAccounting.TransactionPositionCredit.Amount, gainloss.abs());
                        insertPos.add(CIAccounting.TransactionPositionCredit.RateAmount, gainloss.abs());
                        insertPos.add(CIAccounting.TransactionPositionCredit.CurrencyLink,
                                currInstance.getId());
                        insertPos.add(CIAccounting.TransactionPositionCredit.RateCurrencyLink,
                                currInstance.getId());
                        insertPos.add(CIAccounting.TransactionPositionCredit.Rate,
                                new Object[] { BigDecimal.ONE, BigDecimal.ONE });
                        insertPos.execute();

                        insertPos = new Insert(CIAccounting.TransactionPositionDebit);
                        insertPos.add(CIAccounting.TransactionPositionDebit.TransactionLink, insert.getId());
                        if (gainloss.signum() < 0) {
                            insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink,
                                    Instance.get(accOids[0]).getId());
                        } else {
                            insertPos.add(CIAccounting.TransactionPositionDebit.AccountLink, instAcc.getId());
                        }
                        insertPos.add(CIAccounting.TransactionPositionDebit.Amount, gainloss.abs().negate());
                        insertPos.add(CIAccounting.TransactionPositionDebit.RateAmount,
                                gainloss.abs().negate());
                        insertPos.add(CIAccounting.TransactionPositionDebit.CurrencyLink, currInstance.getId());
                        insertPos.add(CIAccounting.TransactionPositionDebit.RateCurrencyLink,
                                currInstance.getId());
                        insertPos.add(CIAccounting.TransactionPositionDebit.Rate,
                                new Object[] { BigDecimal.ONE, BigDecimal.ONE });
                        insertPos.execute();
                    }
                }
            }
            if (insert != null) {
                final Instance instance = insert.getInstance();
                // create classifications
                final Classification classification1 = (Classification) CIAccounting.TransactionClass.getType();
                final Insert relInsert1 = new Insert(classification1.getClassifyRelationType());
                relInsert1.add(classification1.getRelLinkAttributeName(), instance.getId());
                relInsert1.add(classification1.getRelTypeAttributeName(), classification1.getId());
                relInsert1.execute();

                final Insert classInsert1 = new Insert(classification1);
                classInsert1.add(classification1.getLinkAttributeName(), instance.getId());
                classInsert1.execute();

                final Classification classification = (Classification) CIAccounting.TransactionClassGainLoss
                        .getType();
                final Insert relInsert = new Insert(classification.getClassifyRelationType());
                relInsert.add(classification.getRelLinkAttributeName(), instance.getId());
                relInsert.add(classification.getRelTypeAttributeName(), classification.getId());
                relInsert.execute();

                final Insert classInsert = new Insert(classification);
                classInsert.add(classification.getLinkAttributeName(), instance.getId());
                classInsert.add(CIAccounting.TransactionClassGainLoss.Amount, gainlossSum);
                classInsert.add(CIAccounting.TransactionClassGainLoss.RateAmount, gainlossSum);
                classInsert.add(CIAccounting.TransactionClassGainLoss.CurrencyLink, curr.getInstance().getId());
                classInsert.add(CIAccounting.TransactionClassGainLoss.RateCurrencyLink,
                        curr.getInstance().getId());
                classInsert.add(CIAccounting.TransactionClassGainLoss.Rate,
                        new Object[] { BigDecimal.ONE, BigDecimal.ONE });
                classInsert.execute();

                new Create().connectDocs2Transaction(_parameter, instance, instDoc);
            }
        }
    }

    return new Return();
}

From source file:com.nkapps.billing.dao.PaymentDaoImpl.java

@Override
public void savePaymentManual(String bankStatementId, List<Payment> paymentList, Long issuerSerialNumber,
        String issuerIp) throws Exception {
    Session session = getSession();//from www .  j a  va  2s. co m
    Transaction transaction = session.beginTransaction();
    BankStatement bs = (BankStatement) session.get(BankStatement.class, bankStatementId);
    if (bs == null) {
        throw new Exception(messageSource.getMessage("bank_statement.editable.bs_not_found", null,
                LocaleContextHolder.getLocale()));
    }

    String q = "SELECT COALESCE(bs.paymentSum,0) - COALESCE(bs.returnSum,0) - (SELECT COALESCE(SUM(kp.paidSum),0) FROM bs.bankStatementPayments bsp JOIN bsp.id.payment p JOIN p.keyPayments kp WHERE p.claim = 0) AS overpaymentSum"
            + " FROM BankStatement bs" + " WHERE bs = :bs";
    Query query = session.createQuery(q);
    query.setParameter("bs", bs);
    BigDecimal overpaymentSum = (BigDecimal) query.uniqueResult();

    if (overpaymentSum.compareTo(BigDecimal.ZERO) > 0) {
        LocalDateTime dateTime = LocalDateTime.now();

        overpaymentDao.returnStateCommit(session, bs, overpaymentSum, issuerSerialNumber, issuerIp, dateTime); // if bankstatement already converted to payment, then them must revert

        for (Payment payment : paymentList) {
            BigDecimal paymentSum = payment.getPaymentSum();
            if (paymentSum.compareTo(overpaymentSum) > 0) {
                paymentSum = overpaymentSum;
                overpaymentSum = BigDecimal.ZERO;
            } else {
                overpaymentSum = overpaymentSum.subtract(paymentSum);
            }
            payment.setPaymentSum(paymentSum);
            payment.setIssuerSerialNumber(issuerSerialNumber);
            payment.setIssuerIp(issuerIp);
            payment.setDateCreated(dateTime);
            payment.setDateUpdated(dateTime);

            session.save(payment);

            BankStatementPayment bsp = new BankStatementPayment();
            BankStatementPaymentId bspId = new BankStatementPaymentId();
            bspId.setBankStatement(bs);
            bspId.setPayment(payment);
            bsp.setId(bspId);

            session.save(bsp);

            if (overpaymentSum.compareTo(BigDecimal.ZERO) <= 0) {
                break;
            }
        }
    }

    transaction.commit();
    session.close();
}

From source file:org.openvpms.archetype.rules.finance.till.TillRulesTestCase.java

private BigDecimal checkBalance(BigDecimal initialCashFloat, BigDecimal newCashFloat, FinancialAct balance,
        String status) {// w w  w. j ava  2s  . c o m
    // make sure the balance is updated
    assertEquals(status, balance.getStatus());
    // end time should be > startTime < now
    Date startTime = balance.getActivityStartTime();
    Date endTime = balance.getActivityEndTime();
    if (TillBalanceStatus.CLEARED.equals(status)) {
        // CLEARED balances have an end time
        assertEquals(1, endTime.compareTo(startTime));
        assertEquals(-1, endTime.compareTo(new Date()));
    } else {
        // IN_PROGRESS balances do not
        assertNull(endTime);
    }

    BigDecimal total = newCashFloat.subtract(initialCashFloat);

    if (initialCashFloat.compareTo(newCashFloat) != 0) {
        // expect a till balance adjustment to have been made
        Set<ActRelationship> rels = balance.getSourceActRelationships();
        assertEquals(1, rels.size());
        ActRelationship r = rels.toArray(new ActRelationship[rels.size()])[0];
        Act target = (Act) get(r.getTarget());
        assertTrue(TypeHelper.isA(target, "act.tillBalanceAdjustment"));
        ActBean adjBean = new ActBean(target);
        BigDecimal amount = adjBean.getBigDecimal("amount");

        boolean credit = (newCashFloat.compareTo(initialCashFloat) < 0);
        BigDecimal adjustmentTotal = total.abs();
        assertTrue(adjustmentTotal.compareTo(amount) == 0);
        assertEquals(credit, adjBean.getBoolean("credit"));
    } else {
        // no till balance adjustment should have been generated
        assertTrue(balance.getSourceActRelationships().isEmpty());
    }

    // check the till balance.
    BigDecimal expectedBalance = total.negate();
    assertTrue(expectedBalance.compareTo(balance.getTotal()) == 0);

    // make sure the till is updated
    Party till = (Party) get(this.till.getObjectReference());
    IMObjectBean bean = new IMObjectBean(till);
    BigDecimal currentFloat = bean.getBigDecimal("tillFloat");
    Date lastCleared = bean.getDate("lastCleared");
    Date now = new Date();

    assertTrue(currentFloat.compareTo(newCashFloat) == 0);
    assertTrue(now.compareTo(lastCleared) == 1); // expect now > lastCleared
    return expectedBalance;
}

From source file:uk.co.onehp.trickle.services.betfair.BetfairServiceImpl.java

@Override
@Transactional// w ww. ja  v a2 s  .co m
public void placeBet(Bet bet) {
    PlaceBetsReq placeBetsReq = new PlaceBetsReq();
    placeBetsReq.setBets(new ArrayOfPlaceBets());
    //if price falls within range
    //if chasing
    //place entire amount at chased price, market on close
    //else
    //place as much as possible at highest price, market on close
    //place remainder at SP limit on close
    //else
    //place at SP limit on close
    Strategy strategy = bet.getStrategy();
    BigDecimal liability = strategy.getLiability().divide(new BigDecimal(bet.getNumberOfSplits()),
            BigDecimal.ROUND_HALF_UP);
    Pricing bestPricing = BettingUtil.bestPrice(bet.getHorse().getPrices(), strategy.getAspect());
    if (bestPricing.getPrice().compareTo(strategy.getMaxOdds()) <= 0
            && bestPricing.getPrice().compareTo(strategy.getMinOdds()) >= 0) {
        if (strategy.getChasePriceByTick() == 0) {
            if (bestPricing.getAmountAvailable().compareTo(liability) >= 0) {
                placeBetsReq.getBets().getPlaceBets()
                        .add(createMOCExchangeBet(bet, liability, bestPricing.getPrice()));
            } else {
                placeBetsReq.getBets().getPlaceBets().add(
                        createMOCExchangeBet(bet, bestPricing.getAmountAvailable(), bestPricing.getPrice()));
                placeBetsReq.getBets().getPlaceBets()
                        .add(createLimitedSPBet(bet, liability.subtract(bestPricing.getAmountAvailable())));
            }
        } else {
            placeBetsReq.getBets().getPlaceBets()
                    .add(createMOCExchangeBet(bet, liability, BettingUtil.findChasePrice(bestPricing.getPrice(),
                            strategy.getChasePriceByTick(), strategy.getAspect())));
        }
    } else {
        placeBetsReq.getBets().getPlaceBets().add(createLimitedSPBet(bet, liability));
    }
    sendRequest(placeBetsReq);
}

From source file:org.apache.fineract.portfolio.servicecharge.service.ServiceChargeJournalDetailsReadPlatformServiceImpl.java

private Map<GLExpenseTagsForServiceCharge, BigDecimal> apportionMobilization(
        Map<GLExpenseTagsForServiceCharge, BigDecimal> dataMap) {
    Map<GLExpenseTagsForServiceCharge, BigDecimal> resultMap = new HashMap<>();
    BigDecimal mobilizationAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.MOBILIZATION).toPlainString());
    BigDecimal servicingAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.SERVICING).toPlainString());
    BigDecimal investmentAmount = new BigDecimal(
            dataMap.get(GLExpenseTagsForServiceCharge.INVESTMENT).toPlainString());
    BigDecimal dlAmount = BigDecimal.ONE;
    BigDecimal outstandingLoanAmount = BigDecimal.ONE;

    BigDecimal multiplicand = BigDecimal.ONE.multiply(dlAmount);
    multiplicand = ServiceChargeOperationUtils.divideNonZeroValues(multiplicand, outstandingLoanAmount);

    servicingAmount = mobilizationAmount.multiply(multiplicand);
    investmentAmount = mobilizationAmount.subtract(servicingAmount);

    resultMap.put(GLExpenseTagsForServiceCharge.SERVICING, servicingAmount);
    resultMap.put(GLExpenseTagsForServiceCharge.INVESTMENT, investmentAmount);

    return resultMap;
}