List of usage examples for java.math RoundingMode FLOOR
RoundingMode FLOOR
To view the source code for java.math RoundingMode FLOOR.
Click Source Link
From source file:org.kuali.ole.select.document.web.struts.OleInvoiceAction.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 . ja va 2s . com*/ @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); if (itemIndex >= 0) { insertAccountingLine(purapForm, item, line); // clear the temp account item.resetAccount(); } 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.web.struts.OlePaymentRequestAction.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) *//* www .j ava 2 s .co 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); if (itemIndex >=0) { insertAccountingLine(purapForm, item, line); // clear the temp account item.resetAccount(); } else if (itemIndex == -2) { //this is the case for distribute account ((PurchasingFormBase)purapForm).addAccountDistributionsourceAccountingLine(line); } }*/ 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 PaymentRequestAccount) { ((PaymentRequestAccount) 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.web.struts.OleVendorCreditMemoAction.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) *//* w ww .j av a2 s.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)); } if (rulePassed) { // add accountingLine SpringContext.getBean(PersistenceService.class).retrieveNonKeyFields(line); if (itemIndex >= 0) { insertAccountingLine(purapForm, item, line); // clear the temp account item.resetAccount(); } 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.libreplan.business.reports.dtos.Util.java
public static BigDecimal getFractionalPart(BigDecimal value) { if (value == null) { return value; }/*from www .j av a2 s .c om*/ BigDecimal fractionalPart = value.subtract(value.setScale(0, RoundingMode.FLOOR)); return (fractionalPart.compareTo(BigDecimal.ZERO) != 0) ? fractionalPart : null; }
From source file:org.mifos.config.AccountingRules.java
private static RoundingMode getRoundingModeFromString(String modeStr, String type, RoundingMode defaultRoundingMode) { if (StringUtils.isBlank(modeStr)) { return defaultRoundingMode; }/*www .j av a 2 s . c om*/ RoundingMode mode = null; if (modeStr.equals("FLOOR")) { mode = RoundingMode.FLOOR; } else if (modeStr.equals("CEILING")) { mode = RoundingMode.CEILING; } else if (modeStr.equals("HALF_UP")) { mode = RoundingMode.HALF_UP; } else { throw new RuntimeException( type + " defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + modeStr); } return mode; }
From source file:org.mifos.config.AccountingRulesIntegrationTest.java
@Test public void testGetCurrencyRoundingMode() { RoundingMode configuredMode = AccountingRules.getCurrencyRoundingMode(); String roundingMode = "FLOOR"; RoundingMode configRoundingMode = RoundingMode.FLOOR; ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.setProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE, roundingMode); // return value from accounting rules class has to be the value defined // in the config file Assert.assertEquals(configRoundingMode, AccountingRules.getCurrencyRoundingMode()); // clear the RoundingRule property from the config file so should get // the default value configMgr.clearProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE); RoundingMode defaultValue = AccountingRules.getCurrencyRoundingMode(); Assert.assertEquals(defaultValue, RoundingMode.HALF_UP); // now set a wrong rounding mode in config roundingMode = "UP"; configMgr.addProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE, roundingMode); try {// ww w . j ava2 s . c om AccountingRules.getCurrencyRoundingMode(); } catch (RuntimeException e) { Assert.assertEquals(e.getMessage(), "CurrencyRoundingMode defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + roundingMode); } // save it back configMgr.setProperty(AccountingRulesConstants.CURRENCY_ROUNDING_MODE, configuredMode.toString()); }
From source file:org.mifos.config.AccountingRulesIntegrationTest.java
@Test public void testGetInitialRoundingMode() { RoundingMode configuredMode = AccountingRules.getInitialRoundingMode(); String roundingMode = "FLOOR"; RoundingMode configRoundingMode = RoundingMode.FLOOR; ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.setProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, roundingMode); // return value from accounting rules class has to be the value defined // in the config file Assert.assertEquals(configRoundingMode, AccountingRules.getInitialRoundingMode()); // clear the RoundingRule property from the config file configMgr.clearProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE); RoundingMode defaultValue = AccountingRules.getInitialRoundingMode(); Assert.assertEquals(defaultValue, RoundingMode.HALF_UP); // now set a wrong rounding mode in config roundingMode = "UP"; configMgr.addProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, roundingMode); try {// w w w .j ava 2 s . c o m AccountingRules.getInitialRoundingMode(); } catch (RuntimeException e) { Assert.assertEquals(e.getMessage(), "InitialRoundingMode defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + roundingMode); } // save it back configMgr.setProperty(AccountingRulesConstants.INITIAL_ROUNDING_MODE, configuredMode.toString()); }
From source file:org.mifos.config.AccountingRulesIntegrationTest.java
@Test public void testGetRoundingRule() { RoundingMode defaultValue = RoundingMode.CEILING; String roundingMode = "FLOOR"; RoundingMode configRoundingMode = RoundingMode.FLOOR; ConfigurationManager configMgr = ConfigurationManager.getInstance(); configMgr.addProperty(AccountingRulesConstants.ROUNDING_RULE, roundingMode); // return value from accounting rules class has to be the value defined // in the config file Assert.assertEquals(configRoundingMode, AccountingRules.getRoundingRule(defaultValue)); // clear the RoundingRule property from the config file configMgr.clearProperty(AccountingRulesConstants.ROUNDING_RULE); // now the return value from accounting rules class has to be the // default value (value from db) Assert.assertEquals(defaultValue, AccountingRules.getRoundingRule(defaultValue)); // now set a wrong rounding mode in config roundingMode = "UP"; configMgr.addProperty(AccountingRulesConstants.ROUNDING_RULE, roundingMode); try {//from ww w . java2s .c om AccountingRules.getRoundingRule(defaultValue); } catch (RuntimeException e) { Assert.assertEquals(e.getMessage(), "The rounding mode defined in the config file is not CEILING, FLOOR, HALF_UP. It is " + roundingMode); } configMgr.clearProperty(AccountingRulesConstants.ROUNDING_RULE); }
From source file:org.openlmis.rnr.repository.mapper.RequisitionMapperIT.java
@Test public void shouldGetRequisitionById() { Rnr requisition = new Rnr(new Facility(facility.getId()), new Program(program.getId()), processingPeriod1, false, MODIFIED_BY, 1L);/*w w w.j a va 2 s . c om*/ requisition.setAllocatedBudget(new BigDecimal(123.45)); requisition.setStatus(INITIATED); requisition.setId(1L); String submitterText = "submitter"; Signature submitterSignature = new Signature(Signature.Type.SUBMITTER, submitterText); String approverText = "approver"; Signature approverSignature = new Signature(Signature.Type.APPROVER, approverText); ArrayList<Signature> rnrSignatures = new ArrayList<>(); rnrSignatures.add(submitterSignature); rnrSignatures.add(approverSignature); requisition.setRnrSignatures(rnrSignatures); signatureMapper.insertSignature(submitterSignature); signatureMapper.insertSignature(approverSignature); mapper.insert(requisition); mapper.insertRnrSignature(requisition, submitterSignature); mapper.insertRnrSignature(requisition, approverSignature); Product product = insertProduct(true, "P1"); RnrLineItem fullSupplyLineItem = make( a(defaultRnrLineItem, with(fullSupply, true), with(productCode, product.getCode()))); RnrLineItem nonFullSupplyLineItem = make( a(defaultRnrLineItem, with(fullSupply, false), with(productCode, product.getCode()))); fullSupplyLineItem.setRnrId(requisition.getId()); nonFullSupplyLineItem.setRnrId(requisition.getId()); lineItemMapper.insert(fullSupplyLineItem, Collections.EMPTY_LIST.toString()); lineItemMapper.insert(nonFullSupplyLineItem, Collections.EMPTY_LIST.toString()); ProgramProduct programProduct = new ProgramProduct(program, product, 1, true); programProduct.setProductCategory(productCategory); programProductMapper.insert(programProduct); User author = new User(); author.setId(1L); Comment comment = new Comment(requisition.getId(), author, "A comment", null); commentMapper.insert(comment); updateSupplyingDepotForRequisition(requisition); Rnr fetchedRequisition = mapper.getById(requisition.getId()); assertThat(fetchedRequisition.getId(), is(requisition.getId())); assertThat(fetchedRequisition.getProgram().getId(), is(equalTo(program.getId()))); assertThat(fetchedRequisition.getFacility().getId(), is(equalTo(facility.getId()))); assertThat(fetchedRequisition.getPeriod().getId(), is(equalTo(processingPeriod1.getId()))); assertThat(fetchedRequisition.getModifiedBy(), is(equalTo(MODIFIED_BY))); assertThat(fetchedRequisition.getStatus(), is(equalTo(INITIATED))); assertThat(fetchedRequisition.getFullSupplyLineItems().size(), is(1)); assertThat(fetchedRequisition.getNonFullSupplyLineItems().size(), is(1)); assertThat(fetchedRequisition.getAllocatedBudget(), is(new BigDecimal(123.45).setScale(2, RoundingMode.FLOOR))); assertThat(fetchedRequisition.getRnrSignatures().size(), is(2)); assertThat(fetchedRequisition.getRnrSignatures().get(0).getType(), is(Signature.Type.SUBMITTER)); assertThat(fetchedRequisition.getRnrSignatures().get(0).getText(), is(submitterText)); assertThat(fetchedRequisition.getRnrSignatures().get(1).getType(), is(Signature.Type.APPROVER)); assertThat(fetchedRequisition.getRnrSignatures().get(1).getText(), is(approverText)); }
From source file:org.optaplanner.examples.common.persistence.AbstractSolutionImporter.java
public static String getFlooredPossibleSolutionSize(BigInteger possibleSolutionSize) { if (possibleSolutionSize.compareTo(BigInteger.valueOf(1000L)) < 0) { return possibleSolutionSize.toString(); }//from w w w. j av a 2s. c om return "10^" + (BigIntegerMath.log10(possibleSolutionSize, RoundingMode.FLOOR)); }