Example usage for java.math RoundingMode FLOOR

List of usage examples for java.math RoundingMode FLOOR

Introduction

In this page you can find the example usage for java.math RoundingMode FLOOR.

Prototype

RoundingMode FLOOR

To view the source code for java.math RoundingMode FLOOR.

Click Source Link

Document

Rounding mode to round towards negative infinity.

Usage

From source file:controllers.Send.java

public static Result receiptBillPayment(String idToken) {
    try {// w ww.j a v a2s.c  o  m
        models.Transaction transaction = ApiHelper.getTransaction(idToken);
        transaction.senderAmount.setScale(6, RoundingMode.FLOOR);
        transaction.beneficiaryAmount.setScale(6, RoundingMode.FLOOR);
        return ok(receipt_bill_payment.render(null, transaction));
    } catch (ApiException e) {
        return ok(receipt_bill_payment.render(e.getMessage(), null));
    }
}

From source file:nl.strohalm.cyclos.entities.settings.LocalSettings.java

public BigDecimal truncate(final BigDecimal number) {
    if (number == null) {
        return null;
    } else {/*from  w  w w  . j  a v  a  2  s  .c o m*/
        return number.setScale(getPrecision().getValue(), RoundingMode.FLOOR);
    }
}

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

public static BigDecimal floor(BigDecimal b0) {
    return b0.setScale(0, RoundingMode.FLOOR);
}

From source file:org.bhave.sweeper.impl.DoubleSequenceSweep.java

@Override
public int size() {
    BigDecimal diff = to.subtract(from).abs();

    int size = diff.divide(step.abs(), RoundingMode.FLOOR).intValue();

    return (!(to.compareTo(BigDecimal.ZERO) < 0 && from.compareTo(BigDecimal.ZERO) > 0
            || to.compareTo(BigDecimal.ZERO) > 0 && from.compareTo(BigDecimal.ZERO) < 0)) ? (size + 1) : size;
}

From source file:org.broadleafcommerce.core.pricing.service.workflow.FulfillmentItemPricingActivity.java

/**
 * Distributes the order adjustments (if any) to the individual fulfillment group items.
 * @param order//  w  w w.ja  va 2  s  .c o  m
 * @param totalAllItems
 * @return
 */
protected Money distributeOrderSavingsToItems(Order order, BigDecimal totalAllItems) {
    Money returnAmount = new Money(order.getCurrency());

    BigDecimal orderAdjAmt = order.getOrderAdjustmentsValue().getAmount();

    for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
        for (FulfillmentGroupItem fgItem : fulfillmentGroup.getFulfillmentGroupItems()) {
            BigDecimal fgItemAmount = fgItem.getTotalItemAmount().getAmount();
            BigDecimal proratedAdjAmt = totalAllItems.compareTo(BigDecimal.ZERO) == 0 ? totalAllItems
                    : orderAdjAmt.multiply(fgItemAmount).divide(totalAllItems, RoundingMode.FLOOR);
            fgItem.setProratedOrderAdjustmentAmount(new Money(proratedAdjAmt, order.getCurrency()));
            returnAmount = returnAmount.add(fgItem.getProratedOrderAdjustmentAmount());
        }
    }
    return returnAmount;
}

From source file:org.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java

/**
 * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *//*ww w.ja v  a2s .  c  o m*/
@Override
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now
    PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;

    // index of item selected
    int itemIndex = getSelectedLine(request);
    PurApItem item = null;

    // if custom processing of an accounting line is not done then insert a line generically.
    if (processCustomInsertAccountingLine(purapForm, request) == false) {
        String errorPrefix = null;
        PurApAccountingLine line = null;

        boolean rulePassed = false;
        if (itemIndex >= 0) {
            item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex));
            //Calculating the dollar amount for the accounting Line.
            PurApAccountingLine lineItem = item.getNewSourceLine();
            if (lineItem.getAccountLinePercent() != null) {
                BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
                lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
            } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() == null) {
                KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
                BigDecimal dollarToPercent = dollar.bigDecimalValue()
                        .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
                lineItem.setAccountLinePercent(dollarToPercent);
            }
            line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem);
            //end
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "["
                    + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        } else if (itemIndex == -2) {
            //corrected: itemIndex == -2 is the only case for distribute account
            //This is the case when we're inserting an accounting line for distribute account.
            line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine();
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        }
        AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine();
        if (accountingLineBase != null) {
            String accountNumber = accountingLineBase.getAccountNumber();
            String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode();
            Map<String, String> criteria = new HashMap<String, String>();
            criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
            criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
            Account account = SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(Account.class,
                    criteria);
            rulePassed = checkForValidAccount(account);
        }
        if (rulePassed) {
            // add accountingLine
            SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);

            PurApAccountingLine newSourceLine = item.getNewSourceLine();
            List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines();

            BigDecimal initialValue = new BigDecimal(0);

            for (PurApAccountingLine accountLine : existingSourceLine) {
                initialValue = initialValue.add(accountLine.getAccountLinePercent());
            }
            if (itemIndex >= 0) {

                if ((newSourceLine.getAccountLinePercent()
                        .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED
                        && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT
                                .subtract(initialValue).intValue())
                        && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) {
                    if (OleSelectConstant.MAX_PERCENT.subtract(initialValue)
                            .intValue() != OleSelectConstant.ZERO) {
                        insertAccountingLine(purapForm, item, line);
                    }
                } else {
                    checkAccountingLinePercent(newSourceLine);

                }
                for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) {
                    if (oldSourceAccountingLine instanceof OlePurchaseOrderAccount) {
                        ((OlePurchaseOrderAccount) oldSourceAccountingLine)
                                .setExistingAmount(oldSourceAccountingLine.getAmount());
                    }
                }
                List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines();
                BigDecimal totalPercent = new BigDecimal(100);
                BigDecimal initialPercent = new BigDecimal(0);
                for (PurApAccountingLine purApAccountingLine : existingAccountingLine) {
                    initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());

                }
                initialPercent = totalPercent.subtract(initialPercent);
                BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT);
                if (maxPercent.intValue() == OleSelectConstant.ZERO) {
                    item.resetAccount(OleSelectConstant.ZERO_PERCENT);

                } else {
                    item.resetAccount(initialPercent);

                }
            } else if (itemIndex == -2) {
                //this is the case for distribute account
                ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line);
            }
        }
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:org.kuali.ole.module.purap.document.web.struts.OleRequisitionAction.java

/**
 * @see org.kuali.ole.sys.web.struts.KualiAccountingDocumentActionBase#insertSourceLine(org.apache.struts.action.ActionMapping,
 *      org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 *///from  ww  w  .  j  a v  a2s.c  om
@Override
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    // It would be preferable to find a way to genericize the KualiAccountingDocument methods but this will work for now
    PurchasingAccountsPayableFormBase purapForm = (PurchasingAccountsPayableFormBase) form;

    // index of item selected
    int itemIndex = getSelectedLine(request);
    PurApItem item = null;

    // if custom processing of an accounting line is not done then insert a line generically.
    if (processCustomInsertAccountingLine(purapForm, request) == false) {
        String errorPrefix = null;
        PurApAccountingLine line = null;

        boolean rulePassed = false;
        if (itemIndex >= 0) {
            item = ((PurchasingAccountsPayableDocument) purapForm.getDocument()).getItem((itemIndex));
            // calculating the dollar amount for the accounting Line.
            PurApAccountingLine lineItem = item.getNewSourceLine();
            if (item.getTotalAmount() != null && !item.getTotalAmount().equals(KualiDecimal.ZERO)) {
                if (lineItem.getAccountLinePercent() != null
                        && (lineItem.getAmount() == null || lineItem.getAmount().equals(KualiDecimal.ZERO))) {
                    BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
                    lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
                } else if (lineItem.getAmount() != null && lineItem.getAmount().isNonZero()
                        && lineItem.getAccountLinePercent() == null) {
                    KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
                    BigDecimal dollarToPercent = dollar.bigDecimalValue()
                            .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
                    lineItem.setAccountLinePercent(dollarToPercent);
                } else if (lineItem.getAmount() != null && lineItem.getAmount().isZero()
                        && lineItem.getAccountLinePercent() == null) {
                    lineItem.setAccountLinePercent(new BigDecimal(0));
                } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent().intValue() == 100) {
                    KualiDecimal dollar = lineItem.getAmount().multiply(new KualiDecimal(100));
                    BigDecimal dollarToPercent = dollar.bigDecimalValue()
                            .divide((item.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
                    lineItem.setAccountLinePercent(dollarToPercent);
                } else if (lineItem.getAmount() != null && lineItem.getAccountLinePercent() != null) {
                    BigDecimal percent = lineItem.getAccountLinePercent().divide(new BigDecimal(100));
                    lineItem.setAmount((item.getTotalAmount().multiply(new KualiDecimal(percent))));
                }
            } else {
                lineItem.setAmount(new KualiDecimal(0));
            }
            line = (PurApAccountingLine) ObjectUtils.deepCopy(lineItem);
            //end
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = OLEPropertyConstants.DOCUMENT + "." + PurapPropertyConstants.ITEM + "["
                    + Integer.toString(itemIndex) + "]." + OLEConstants.NEW_SOURCE_ACCT_LINE_PROPERTY_NAME;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        } else if (itemIndex == -2) {
            //corrected: itemIndex == -2 is the only case for distribute account
            //This is the case when we're inserting an accounting line for distribute account.
            line = ((PurchasingFormBase) purapForm).getAccountDistributionnewSourceLine();
            //SpringContext.getBean(AccountService.class).populateAccountingLineChartIfNeeded(line);
            errorPrefix = PurapPropertyConstants.ACCOUNT_DISTRIBUTION_NEW_SRC_LINE;
            rulePassed = SpringContext.getBean(KualiRuleService.class)
                    .applyRules(new AddAccountingLineEvent(errorPrefix, purapForm.getDocument(), line));
        }
        if (rulePassed) {
            AccountingLineBase accountingLineBase = (AccountingLineBase) item.getNewSourceLine();
            if (accountingLineBase != null) {
                String accountNumber = accountingLineBase.getAccountNumber();
                String chartOfAccountsCode = accountingLineBase.getChartOfAccountsCode();
                Map<String, String> criteria = new HashMap<String, String>();
                criteria.put(OleSelectConstant.ACCOUNT_NUMBER, accountNumber);
                criteria.put(OleSelectConstant.CHART_OF_ACCOUNTS_CODE, chartOfAccountsCode);
                Account account = SpringContext.getBean(BusinessObjectService.class)
                        .findByPrimaryKey(Account.class, criteria);
                rulePassed = checkForValidAccount(account);
            }
        }
        if (rulePassed) {
            // add accountingLine
            SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line);
            PurApAccountingLine newSourceLine = item.getNewSourceLine();
            List<PurApAccountingLine> existingSourceLine = item.getSourceAccountingLines();

            BigDecimal initialValue = OleSelectConstant.ZERO_PERCENT;

            for (PurApAccountingLine accountLine : existingSourceLine) {
                initialValue = initialValue.add(accountLine.getAccountLinePercent());

            }
            if (itemIndex >= 0) {

                if ((newSourceLine.getAccountLinePercent()
                        .intValue() <= OleSelectConstant.ACCOUNTINGLINE_PERCENT_HUNDRED
                        && newSourceLine.getAccountLinePercent().intValue() <= OleSelectConstant.MAX_PERCENT
                                .subtract(initialValue).intValue())
                        && newSourceLine.getAccountLinePercent().intValue() > OleSelectConstant.ZERO) {
                    if (OleSelectConstant.MAX_PERCENT.subtract(initialValue)
                            .intValue() != OleSelectConstant.ZERO) {
                        insertAccountingLine(purapForm, item, line);
                    }
                } else {
                    checkAccountingLinePercent(newSourceLine);

                }
                for (PurApAccountingLine oldSourceAccountingLine : item.getSourceAccountingLines()) {
                    if (oldSourceAccountingLine instanceof OleRequisitionAccount) {
                        ((OleRequisitionAccount) oldSourceAccountingLine)
                                .setExistingAmount(oldSourceAccountingLine.getAmount());
                    }
                }
                List<PurApAccountingLine> existingAccountingLine = item.getSourceAccountingLines();
                BigDecimal totalPercent = new BigDecimal(100);
                BigDecimal initialPercent = new BigDecimal(0);
                for (PurApAccountingLine purApAccountingLine : existingAccountingLine) {
                    initialPercent = initialPercent.add(purApAccountingLine.getAccountLinePercent());

                }
                initialPercent = totalPercent.subtract(initialPercent);
                BigDecimal maxPercent = initialPercent.max(OleSelectConstant.ZERO_PERCENT);
                if (maxPercent.intValue() == OleSelectConstant.ZERO) {
                    item.resetAccount(OleSelectConstant.ZERO_PERCENT);

                } else {
                    item.resetAccount(initialPercent);

                }
            } else if (itemIndex == -2) {
                //this is the case for distribute account
                ((PurchasingFormBase) purapForm).addAccountDistributionsourceAccountingLine(line);
            }
        }
    }

    return mapping.findForward(OLEConstants.MAPPING_BASIC);
}

From source file:org.kuali.ole.select.document.service.impl.OleInvoiceServiceImpl.java

/**
 * This method calculates the Amount and the Percent in Accounting Line if the Invoiced List Price changed
 *//*from   w ww  .  j av a2s. c o  m*/
public void calculateAccount(PurApItem purapItem) {
    purapItem.setExtendedPrice(purapItem.calculateExtendedPrice());
    List<PurApAccountingLine> purApAccountingLines = purapItem.getSourceAccountingLines();
    BigDecimal totalPercent = BigDecimal.ZERO;
    BigDecimal totalAmt = BigDecimal.ZERO;
    for (PurApAccountingLine account : purApAccountingLines) {
        if (purapItem.getTotalAmount() != null && !purapItem.getTotalAmount().equals(KualiDecimal.ZERO)) {
            if (account.getAccountLinePercent() != null
                    && (account.getAmount() == null || account.getAmount().equals(KualiDecimal.ZERO))) {
                BigDecimal percent = account.getAccountLinePercent().divide(new BigDecimal(100));
                account.setAmount((purapItem.getTotalAmount().multiply(new KualiDecimal(percent))));
            } else if (account.getAmount() != null && account.getAmount().isNonZero()
                    && account.getAccountLinePercent() == null) {
                KualiDecimal dollar = account.getAmount().multiply(new KualiDecimal(100));
                BigDecimal dollarToPercent = dollar.bigDecimalValue()
                        .divide((purapItem.getTotalAmount().bigDecimalValue()), 0, RoundingMode.FLOOR);
                account.setAccountLinePercent(dollarToPercent);
            } else if (account.getAmount() != null && account.getAmount().isZero()
                    && account.getAccountLinePercent() == null) {
                account.setAccountLinePercent(new BigDecimal(0));
            } else if ((account.getAmount() != null && account.getAccountLinePercent() != null)
                    || (account.getAmount() != null && account.getAccountLinePercent().intValue() == 100)) {
                BigDecimal percent = account.getAccountLinePercent().divide(new BigDecimal(100));
                account.setAmount((purapItem.getTotalAmount().multiply(new KualiDecimal(percent))));
            }
            totalPercent = totalPercent.add(account.getAccountLinePercent());
            totalAmt = totalAmt.add(account.getAmount().bigDecimalValue());
        } else {
            account.setAmount(KualiDecimal.ZERO);
        }
    }
    // If Total Percent or Total Amount mis matches,percentage is divided across accounting lines.
    if (totalPercent.intValue() != 100 || (purapItem.getTotalAmount() != null
            && totalAmt.compareTo(purapItem.getTotalAmount().bigDecimalValue()) != 0)) {
        for (PurApAccountingLine account : purApAccountingLines) {
            if (purapItem.getTotalAmount() != null && !purapItem.getTotalAmount().equals(KualiDecimal.ZERO)) {
                BigDecimal percent = BigDecimal.ONE.divide(new BigDecimal(purApAccountingLines.size()),
                        BigDecimal.ROUND_CEILING, BigDecimal.ROUND_HALF_UP);
                account.setAmount((purapItem.getTotalAmount().multiply(new KualiDecimal(percent))));
            } else {
                account.setAmount(KualiDecimal.ZERO);
            }
        }
    }

}

From source file:org.kuali.ole.select.document.web.struts.OleDisbursementVoucherAction.java

/**
 * This action executes an insert of a SourceAccountingLine into a document only after validating the accounting line and
 * checking any appropriate business rules.
 *
 * @param mapping// w  w  w  .  j av a2s  . c  o m
 * @param form
 * @param request
 * @param response
 * @return ActionForward
 * @throws Exception
 */
@Override
public ActionForward insertSourceLine(ActionMapping mapping, ActionForm form, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    OleDisbursementVoucherForm disbursementVoucherForm = (OleDisbursementVoucherForm) form;
    OleDisbursementVoucherDocument disbursementDocument = disbursementVoucherForm
            .getDisbursementVoucherDocument();
    OleDisbursementVoucherAccountingLine line = (OleDisbursementVoucherAccountingLine) disbursementVoucherForm
            .getNewSourceLine();
    KualiDecimal totalAmount = disbursementDocument.getDisbVchrCheckTotalAmount();
    if ((totalAmount != null) && KualiDecimal.ZERO.compareTo(totalAmount) != 0) {
        if (ObjectUtils.isNotNull(line.getAccountLinePercent())) {
            BigDecimal pct = new BigDecimal(line.getAccountLinePercent().toString())
                    .divide(new BigDecimal(100));
            line.setAmount(new KualiDecimal(pct.multiply(new BigDecimal(totalAmount.toString()))
                    .setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
        } else if (ObjectUtils.isNotNull(line.getAmount())
                && ObjectUtils.isNull(line.getAccountLinePercent())) {
            KualiDecimal dollar = line.getAmount().multiply(new KualiDecimal(100));
            BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((totalAmount.bigDecimalValue()), 0,
                    RoundingMode.FLOOR);
            line.setAccountLinePercent(dollarToPercent);
        }
    }
    return super.insertSourceLine(mapping, disbursementVoucherForm, request, response);
}

From source file:org.kuali.ole.select.document.web.struts.OleDisbursementVoucherAction.java

private void updateAccountAmountsWithTotal(List<OleDisbursementVoucherAccountingLine> sourceAccountingLines,
        KualiDecimal totalAmount) {/* www  .ja v  a2 s.co m*/
    if ((totalAmount != null) && KualiDecimal.ZERO.compareTo(totalAmount) != 0) {

        KualiDecimal accountTotal = KualiDecimal.ZERO;
        OleDisbursementVoucherAccountingLine lastAccount = null;

        for (OleDisbursementVoucherAccountingLine account : sourceAccountingLines) {
            if (ObjectUtils.isNotNull(account.getAccountLinePercent())) {
                BigDecimal pct = new BigDecimal(account.getAccountLinePercent().toString())
                        .divide(new BigDecimal(100));
                account.setAmount(new KualiDecimal(pct.multiply(new BigDecimal(totalAmount.toString()))
                        .setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)));
            } else if (ObjectUtils.isNotNull(account.getAmount())
                    && ObjectUtils.isNull(account.getAccountLinePercent())) {
                KualiDecimal dollar = account.getAmount().multiply(new KualiDecimal(100));
                BigDecimal dollarToPercent = dollar.bigDecimalValue().divide((totalAmount.bigDecimalValue()), 0,
                        RoundingMode.FLOOR);
                account.setAccountLinePercent(dollarToPercent);
            }
            accountTotal = accountTotal.add(account.getAmount());
            lastAccount = account;
        }
    }
}