List of usage examples for java.math RoundingMode HALF_UP
RoundingMode HALF_UP
To view the source code for java.math RoundingMode HALF_UP.
Click Source Link
From source file:org.kuali.ole.select.document.web.struts.OlePaymentRequestAction.java
/** * Add a new item to the document.// w ww. j a va2 s . c o m * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { OlePaymentRequestForm purchasingForm = (OlePaymentRequestForm) form; OlePaymentRequestItem item = (OlePaymentRequestItem) purchasingForm.getNewPurchasingItemLine(); item.getNewSourceLine().setAccountLinePercent(new BigDecimal(100)); // purchasingForm.getNewPurchasingItemLine().setItemDescription((item.getBibInfoBean().getTitle() != null ? // item.getBibInfoBean().getTitle() : "") + (item.getBibInfoBean().getAuthor() != null ? "," + // item.getBibInfoBean().getAuthor() : "") + (item.getBibInfoBean().getPublisher() != null ? "," + // item.getBibInfoBean().getPublisher() : "") + (item.getBibInfoBean().getIsbn() != null ? "," + // item.getBibInfoBean().getIsbn() : "")); OlePaymentRequestDocument document = (OlePaymentRequestDocument) purchasingForm.getDocument(); BibInfoWrapperService docStore = SpringContext.getBean(BibInfoWrapperServiceImpl.class); FileProcessingService fileProcessingService = SpringContext.getBean(FileProcessingService.class); String titleId = null; boolean isBibFileExist = false; Iterator itemIterator = document.getItems().iterator(); int itemCounter = 0; while (itemIterator.hasNext()) { OlePaymentRequestItem tempItem = (OlePaymentRequestItem) itemIterator.next(); if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) || tempItem .getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) { itemCounter++; } } String itemNo = String.valueOf(itemCounter); //String itemNo = String.valueOf(document.getItems().size() - 8); HashMap<String, String> dataMap = new HashMap<String, String>(); item.setBibInfoBean(new BibInfoBean()); if (item.getBibInfoBean().getDocStoreOperation() == null) { item.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF); } String tokenId = document.getDocumentNumber() + "_" + itemNo; setItemDescription(item, tokenId); /*dataMap.put(OleSelectConstant.FILEPATH, fileProcessingService.getMarcXMLFileDirLocation()); dataMap.put(OleSelectConstant.FILENAME, fileName); if (fileProcessingService.isCreateFileExist(dataMap)) { isBibFileExist = true; } if (isBibFileExist) { titleId = docStore.getTitleIdByMarcXMLFileProcessing(item.getBibInfoBean(), dataMap); item.setItemTitleId(titleId); BibInfoBean xmlBibInfoBean = new BibInfoBean(); dataMap.put(OleSelectConstant.TITLE_ID, titleId); dataMap.put(OleSelectConstant.DOC_CATEGORY_TYPE, OleSelectConstant.DOC_CATEGORY_TYPE_ITEMLINKS); xmlBibInfoBean = docStore.getBibInfo(dataMap); item.setBibInfoBean(xmlBibInfoBean); purchasingForm.getNewPurchasingItemLine().setItemDescription((item.getBibInfoBean().getTitle() != null ? item.getBibInfoBean().getTitle() : "") + (item.getBibInfoBean().getAuthor() != null ? "," + item.getBibInfoBean().getAuthor() : "") + (item.getBibInfoBean().getPublisher() != null ? "," + item.getBibInfoBean().getPublisher() : "") + (item.getBibInfoBean().getIsbn() != null ? "," + item.getBibInfoBean().getIsbn() : "")); HashMap<String,String> queryMap = new HashMap<String,String>(); queryMap.put(OleSelectConstant.DocStoreDetails.ITEMLINKS_KEY, item.getItemTitleId()); List<DocInfoBean> docStoreResult = docStore.searchBibInfo(queryMap); Iterator bibIdIterator = docStoreResult.iterator(); if(bibIdIterator.hasNext()){ DocInfoBean docInfoBean = (DocInfoBean)bibIdIterator.next(); item.setBibUUID(docInfoBean.getUniqueId()); } }*/ boolean ruleFlag = getKualiRuleService().applyRules(new OlePaymentRequestDescEvent(document, item)); if (ruleFlag) { if (document.getVendorDetail().getCurrencyType() != null) { if (document.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; } else { currencyTypeIndicator = false; } } if ((document.getVendorDetail() == null) || (document.getVendorDetail().getVendorName() != null && currencyTypeIndicator)) { boolean rulePassed = getKualiRuleService() .applyRules(new OleDiscountPaymentRequestEvent(document, item)); if (rulePassed) { purchasingForm.getNewPurchasingItemLine() .setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(item) .setScale(2, BigDecimal.ROUND_HALF_UP)); item = (OlePaymentRequestItem) purchasingForm.getAndResetNewPurchasingItemLine(); document.addItem(item); } } else { boolean rulePassed = getKualiRuleService() .applyRules(new OleForeignCurrencyPaymentRequestEvent(document, item)); if (rulePassed) { LOG.debug("###########Foreign Currency Field Calculation for Payment Request ###########"); SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(item); Long id = document.getVendorDetail().getCurrencyType().getCurrencyTypeId(); Map documentNumberMap = new HashMap(); documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id); org.kuali.rice.krad.service.BusinessObjectService businessObjectService = SpringContext .getBean(org.kuali.rice.krad.service.BusinessObjectService.class); List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy( OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); Iterator iterator = exchangeRateList.iterator(); if (iterator.hasNext()) { OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next(); item.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); } if (item.getItemExchangeRate() != null && item.getItemForeignUnitCost() != null) { item.setItemUnitCostUSD(new KualiDecimal(item.getItemForeignUnitCost().bigDecimalValue() .divide(item.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP))); item.setItemUnitPrice( item.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP)); item.setItemListPrice(item.getItemUnitCostUSD()); } item = (OlePaymentRequestItem) purchasingForm.getAndResetNewPurchasingItemLine(); document.addItem(item); } } } /*if(item.getDonorCode() == null){ GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectPropertyConstants.ERROR_DONOR_CODE,"donorCode"); }*/ return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.select.document.OlePaymentRequestDocument.java
@Override public void processAfterRetrieve() { super.processAfterRetrieve(); try {// w w w . j a v a 2s. c o m LOG.debug("###########inside OlePaymentRequestDocument processAfterRetrieve###########"); if (this.getVendorAliasName() == null) { populateVendorAliasName(); } if (this.getPaymentMethodId() != null) { OlePaymentMethod olePaymentMethod = SpringContext.getBean(BusinessObjectService.class) .findBySinglePrimaryKey(OlePaymentMethod.class, this.getPaymentMethodId()); this.setPaymentMethod(olePaymentMethod); } List<BigDecimal> newUnitPriceList = new ArrayList<BigDecimal>(); BigDecimal newUnitPrice = new BigDecimal(0); BigDecimal hundred = new BigDecimal(100); List<OlePaymentRequestItem> item = this.getItems(); for (int i = 0; item.size() > i; i++) { OlePaymentRequestItem items = (OlePaymentRequestItem) this.getItem(i); if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) { if (items.getItemDiscount() == null) { items.setItemDiscount(KualiDecimal.ZERO); } if (items.getItemListPrice() == null) { items.setItemListPrice(KualiDecimal.ZERO); } if (items.getItemDiscountType() != null && items.getItemDiscountType() .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) { newUnitPrice = (hundred.subtract(items.getItemDiscount().bigDecimalValue())).divide(hundred) .multiply(items.getItemListPrice().bigDecimalValue()); } else { newUnitPrice = items.getItemListPrice().bigDecimalValue() .subtract(items.getItemDiscount().bigDecimalValue()); } items.setItemSurcharge( items.getItemUnitPrice().subtract(newUnitPrice).setScale(4, RoundingMode.HALF_UP)); } } if (this.getVendorDetail().getCurrencyType() != null) { if (this.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; } else { currencyTypeIndicator = false; } } OleInvoiceDocument oleInvoiceDocument = SpringContext.getBean(BusinessObjectService.class) .findBySinglePrimaryKey(OleInvoiceDocument.class, this.getInvoiceIdentifier()); if (oleInvoiceDocument.getInvoiceCurrencyTypeId() != null && oleInvoiceDocument.getForeignVendorInvoiceAmount() != null && oleInvoiceDocument.getInvoiceCurrencyExchangeRate() != null) { this.setForeignVendorInvoiceAmount(this.getVendorInvoiceAmount().bigDecimalValue() .multiply(new BigDecimal(oleInvoiceDocument.getInvoiceCurrencyExchangeRate()))); } else { if (this.getVendorDetail() != null && (!currencyTypeIndicator)) { Long currencyTypeId = this.getVendorDetail().getCurrencyType().getCurrencyTypeId(); Map documentNumberMap = new HashMap(); documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, currencyTypeId); List<OleExchangeRate> exchangeRateList = (List) getBusinessObjectService().findMatchingOrderBy( OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); Iterator iterator = exchangeRateList.iterator(); for (OlePaymentRequestItem items : item) { iterator = exchangeRateList.iterator(); if (iterator.hasNext()) { OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next(); items.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); this.setForeignVendorInvoiceAmount(this.getVendorInvoiceAmount().bigDecimalValue() .multiply(tempOleExchangeRate.getExchangeRate())); } } } } String itemDescription = ""; for (OlePaymentRequestItem singleItem : item) { if (LOG.isDebugEnabled()) { LOG.debug("Title id while retriving ------>" + singleItem.getItemTitleId()); } if (singleItem.getItemTitleId() != null) { LOG.debug("###########inside processAfterRetrieve ole requisition item###########"); Bib bib = new BibMarc(); DocstoreClientLocator docstoreClientLocator = new DocstoreClientLocator(); if (singleItem.getItemTitleId() != null && singleItem.getItemTitleId() != "") { bib = docstoreClientLocator.getDocstoreClient().retrieveBib(singleItem.getItemTitleId()); singleItem.setBibUUID(bib.getId()); singleItem .setDocFormat(DocumentUniqueIDPrefix.getBibFormatType(singleItem.getItemTitleId())); } if (singleItem.getItemUnitPrice() != null) { singleItem.setItemUnitPrice( singleItem.getItemUnitPrice().setScale(2, BigDecimal.ROUND_HALF_UP)); } itemDescription = ((bib.getTitle() != null && !bib.getTitle().isEmpty()) ? bib.getTitle().trim() + ", " : "") + ((bib.getAuthor() != null && !bib.getAuthor().isEmpty()) ? bib.getAuthor().trim() + ", " : "") + ((bib.getPublisher() != null && !bib.getPublisher().isEmpty()) ? bib.getPublisher().trim() + ", " : "") + ((bib.getIsbn() != null && !bib.getIsbn().isEmpty()) ? bib.getIsbn().trim() + ", " : ""); if (itemDescription != null && !(itemDescription.equals(""))) { itemDescription = itemDescription.lastIndexOf(",") < 0 ? itemDescription : itemDescription.substring(0, itemDescription.lastIndexOf(",")); StringEscapeUtils stringEscapeUtils = new StringEscapeUtils(); itemDescription = stringEscapeUtils.unescapeXml(itemDescription); singleItem.setItemDescription(itemDescription); } HashMap<String, String> queryMap = new HashMap<String, String>(); if (singleItem.getPoItemIdentifier() != null) { queryMap.put(OLEConstants.PO_ITEM_ID, singleItem.getPoItemIdentifier().toString()); OleInvoiceItem oleInvoiceItem = getBusinessObjectService() .findByPrimaryKey(OleInvoiceItem.class, queryMap); if (oleInvoiceItem != null && oleInvoiceItem.getPoItemIdentifier() != null) { queryMap.clear(); queryMap.put(OLEConstants.OleCopy.PO_ITM_ID, oleInvoiceItem.getPoItemIdentifier().toString()); List<OLELinkPurapDonor> oleLinkPurapDonorList = (List<OLELinkPurapDonor>) getBusinessObjectService() .findMatching(OLELinkPurapDonor.class, queryMap); if (oleLinkPurapDonorList != null) { singleItem.setOleDonors(oleLinkPurapDonorList); } } } } for (OLEPaidCopy olePaidCopy : singleItem.getPaidCopies()) { if (olePaidCopy.getPaymentRequestItemId() == null && olePaidCopy.getPaymentRequestIdentifier() == null) { olePaidCopy.setPaymentRequestItemId(singleItem.getItemIdentifier()); olePaidCopy.setPaymentRequestIdentifier(this.getPurapDocumentIdentifier()); getBusinessObjectService().save(olePaidCopy); } } } if (this.getProrateBy() != null) { this.setProrateQty(this.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)); this.setProrateManual(this.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)); this.setProrateDollar(this.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)); this.setNoProrate(this.getProrateBy().equals(OLEConstants.NO_PRORATE)); } } catch (Exception e) { LOG.error("Exception during processAfterRetrieve() in OlePaymentRequestDocument", e); throw new RuntimeException(e); } }
From source file:org.kuali.kra.proposaldevelopment.printing.xmlstream.NIHResearchAndRelatedXmlStream.java
private ProposalPersonType getProposalPersonTypeWithValues(DevelopmentProposal developmentProposal, ProposalPerson proposalPerson, Budget budget) { ProposalPersonType proposalPersonType = ProposalPersonType.Factory.newInstance(); String degree = getDegree(proposalPerson); proposalPersonType.setDegree(degree); proposalPersonType.setEmail(proposalPerson.getEmailAddress()); proposalPersonType.setName(getProposalPersonFullNameType(proposalPerson)); proposalPersonType.setPhone(proposalPerson.getPhoneNumber()); if (PROJECT_ROLE_PI.equals(proposalPerson.getProposalPersonRoleId())) { proposalPersonType.setProjectRole(ProjectRoleType.PI_PD); } else if (PROJECT_ROLE_COI.equals(proposalPerson.getProposalPersonRoleId())) { proposalPersonType.setProjectRole(ProjectRoleType.CO_PI_PD); } else {/* www . j a va 2 s. c om*/ proposalPersonType.setProjectRole(ProjectRoleType.KEY_PERSON); } proposalPersonType.setSSN(proposalPerson.getSocialSecurityNumber()); if (proposalPerson.getDateOfBirth() != null) { proposalPersonType.setDOB(getDateTimeService().toDateString(proposalPerson.getDateOfBirth())); } BudgetDecimal calendarMonths = BudgetDecimal.ZERO; BudgetDecimal academicMonths = BudgetDecimal.ZERO; BudgetDecimal summerMonths = BudgetDecimal.ZERO; if (budget != null) for (BudgetPeriod budgetPeriod : budget.getBudgetPeriods()) { if (budgetPeriod.getBudgetPeriod().intValue() == 1) { for (BudgetLineItem lineItem : budgetPeriod.getBudgetLineItems()) { for (BudgetPersonnelDetails budgetPersonnelDetails : lineItem .getBudgetPersonnelDetailsList()) { if ((proposalPerson.getPersonId() != null && proposalPerson.getPersonId().equals(budgetPersonnelDetails.getPersonId())) || (proposalPerson.getRolodexId() != null && proposalPerson.getRolodexId() .toString().equals(budgetPersonnelDetails.getPersonId()))) { proposalPersonType.setPercentEffort( budgetPersonnelDetails.getPercentEffort().bigDecimalValue()); proposalPersonType.setRequestedCost( budgetPersonnelDetails.getSalaryRequested().bigDecimalValue()); if (ACADEMIC_PERIOD.equals(budgetPersonnelDetails.getPeriodTypeCode())) { academicMonths = academicMonths.add(budgetPersonnelDetails.getPercentEffort() .multiply(new BudgetDecimal("0.01")) .multiply(getNumberOfMonths(budgetPersonnelDetails.getStartDate(), budgetPersonnelDetails.getEndDate()))); } else if (CALENDAR_PERIOD.equals(budgetPersonnelDetails.getPeriodTypeCode())) { calendarMonths = calendarMonths.add(budgetPersonnelDetails.getPercentEffort() .multiply(new BudgetDecimal("0.01")) .multiply(getNumberOfMonths(budgetPersonnelDetails.getStartDate(), budgetPersonnelDetails.getEndDate()))); } else summerMonths = summerMonths.add(budgetPersonnelDetails.getPercentEffort() .multiply(new BudgetDecimal("0.01")) .multiply(getNumberOfMonths(budgetPersonnelDetails.getStartDate(), budgetPersonnelDetails.getEndDate()))); } } } } } proposalPersonType.setAcademicFundingMonths(academicMonths.bigDecimalValue().setScale(2)); proposalPersonType.setSummerFundingMonths(summerMonths.bigDecimalValue().setScale(2)); proposalPersonType.setFundingMonths(calendarMonths.bigDecimalValue().setScale(2, RoundingMode.HALF_UP)); return proposalPersonType; }
From source file:uk.org.openeyes.BiometryFunctions.java
/** * * @param number/*from w ww. j a v a2s.co m*/ * @return */ public double round2Decimals(BigDecimal number) { number = number.setScale(2, RoundingMode.HALF_UP); return number.doubleValue(); }
From source file:controllers.core.RoadmapController.java
/** * Return the HTML fragment of the KPIs for "scenario simulator". * //w ww.j a v a 2 s . com * @throws AccountManagementException */ @Restrict({ @Group(IMafConstants.ROADMAP_SIMULATOR_PERMISSION) }) public Result simulatorKpisFragment() throws AccountManagementException { List<String> ids = FilterConfig.getIdsFromRequest(request()); BigDecimal allocation = BigDecimal.ZERO; BigDecimal allocationConfirmed = BigDecimal.ZERO; BigDecimal allocationNotConfirmed = BigDecimal.ZERO; BigDecimal budget = BigDecimal.ZERO; BigDecimal budgetCapex = BigDecimal.ZERO; BigDecimal budgetOpex = BigDecimal.ZERO; BigDecimal forecast = BigDecimal.ZERO; BigDecimal forecastCapex = BigDecimal.ZERO; BigDecimal forecastOpex = BigDecimal.ZERO; BigDecimal engaged = BigDecimal.ZERO; BigDecimal engagedCapex = BigDecimal.ZERO; BigDecimal engagedOpex = BigDecimal.ZERO; for (String idString : ids) { Long id = Long.valueOf(idString); PortfolioEntry portfolioEntry = PortfolioEntryDao.getPEById(id); // allocation BigDecimal entryAllocatedActorDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEPlanAllocatedActorAsDaysByPEAndConfirmed(portfolioEntry, true); BigDecimal entryAllocatedActorDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEPlanAllocatedActorAsDaysByPEAndConfirmed(portfolioEntry, false); BigDecimal entryAllocatedOrgUnitDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedOrgUnitAsDaysByPE(portfolioEntry, true); BigDecimal entryAllocatedOrgUnitDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedOrgUnitAsDaysByPE(portfolioEntry, false); BigDecimal entryAllocatedCompetencyDaysConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedCompetencyAsDaysByPortfolioEntry(portfolioEntry, true); BigDecimal entryAllocatedCompetencyDaysNotConfirmed = PortfolioEntryResourcePlanDAO .getPEResourcePlanAllocatedCompetencyAsDaysByPortfolioEntry(portfolioEntry, false); BigDecimal entryAllocationDaysConfirmed = entryAllocatedActorDaysConfirmed .add(entryAllocatedOrgUnitDaysConfirmed).add(entryAllocatedCompetencyDaysConfirmed); BigDecimal entryAllocationDaysNotConfirmed = entryAllocatedActorDaysNotConfirmed .add(entryAllocatedOrgUnitDaysNotConfirmed).add(entryAllocatedCompetencyDaysNotConfirmed); allocation = allocation.add(entryAllocationDaysConfirmed).add(entryAllocationDaysNotConfirmed); allocationConfirmed = allocationConfirmed.add(entryAllocationDaysConfirmed); allocationNotConfirmed = allocationNotConfirmed.add(entryAllocationDaysNotConfirmed); if (getSecurityService().restrict(IMafConstants.PORTFOLIO_ENTRY_VIEW_FINANCIAL_INFO_ALL_PERMISSION)) { // budget Double entryBudgetCapex = PortfolioEntryDao.getPEAsBudgetAmountByOpex(id, false); Double entryBudgetOpex = PortfolioEntryDao.getPEAsBudgetAmountByOpex(id, true); budget = budget.add(new BigDecimal(entryBudgetCapex + entryBudgetOpex)); budgetCapex = budgetCapex.add(new BigDecimal(entryBudgetCapex)); budgetOpex = budgetOpex.add(new BigDecimal(entryBudgetOpex)); // forecast Double entryCostToCompleteCapex = PortfolioEntryDao .getPEAsCostToCompleteAmountByOpex(this.getPreferenceManagerPlugin(), id, false); Double entryCostToCompleteOpex = PortfolioEntryDao .getPEAsCostToCompleteAmountByOpex(this.getPreferenceManagerPlugin(), id, true); Double entryEngagedCapex = PortfolioEntryDao .getPEAsEngagedAmountByOpex(this.getPreferenceManagerPlugin(), id, false); Double entryEngagedOpex = PortfolioEntryDao .getPEAsEngagedAmountByOpex(this.getPreferenceManagerPlugin(), id, true); forecast = forecast.add(new BigDecimal( entryCostToCompleteCapex + entryCostToCompleteOpex + entryEngagedCapex + entryEngagedOpex)); forecastCapex = forecastCapex.add(new BigDecimal(entryCostToCompleteCapex + entryEngagedCapex)); forecastOpex = forecastOpex.add(new BigDecimal(entryCostToCompleteOpex + entryEngagedOpex)); // engaged engaged = engaged.add(new BigDecimal(entryEngagedCapex + entryEngagedOpex)); engagedCapex = engagedCapex.add(new BigDecimal(entryEngagedCapex)); engagedOpex = engagedOpex.add(new BigDecimal(entryEngagedOpex)); } } budget = budget.setScale(2, RoundingMode.HALF_UP); budgetCapex = budgetCapex.setScale(2, RoundingMode.HALF_UP); budgetOpex = budgetOpex.setScale(2, RoundingMode.HALF_UP); forecast = forecast.setScale(2, RoundingMode.HALF_UP); forecastCapex = forecastCapex.setScale(2, RoundingMode.HALF_UP); forecastOpex = forecastOpex.setScale(2, RoundingMode.HALF_UP); engaged = engaged.setScale(2, RoundingMode.HALF_UP); engagedCapex = engagedCapex.setScale(2, RoundingMode.HALF_UP); engagedOpex = engagedOpex.setScale(2, RoundingMode.HALF_UP); return ok(views.html.core.roadmap.roadmap_simulator_kpis_fragment.render(allocation, allocationConfirmed, allocationNotConfirmed, budget, budgetCapex, budgetOpex, forecast, forecastCapex, forecastOpex, engaged, engagedCapex, engagedOpex)); }
From source file:org.kuali.coeus.common.budget.impl.calculator.BudgetPeriodCalculator.java
public boolean syncToPeriodCostLimit(Budget budget, BudgetPeriod budgetPeriodBean, BudgetLineItem budgetDetailBean) { // If total_cost equals total_cost_limit, disp msg "Cost limit and total cost for this period is already in sync." ScaleTwoDecimal costLimit = budgetPeriodBean.getTotalCostLimit(); ScaleTwoDecimal periodTotal = budgetPeriodBean.getTotalCost(); // Set the Difference as TotalCostLimit minus TotalCost. BigDecimal difference = costLimit.subtract(periodTotal).bigDecimalValue(); ScaleTwoDecimal lineItemCost = budgetDetailBean.getLineItemCost(); BigDecimal multifactor;// w w w . j ava 2 s. c om // If line_item_cost is 0 then set the value of line_item_cost in line_items to 10000. if (lineItemCost.equals(ScaleTwoDecimal.ZERO)) { budgetDetailBean.setLineItemCost(new ScaleTwoDecimal(10000)); } calculate(budget, budgetPeriodBean); QueryList<BudgetLineItemCalculatedAmount> vecCalAmts = new QueryList<BudgetLineItemCalculatedAmount>( budgetDetailBean.getBudgetLineItemCalculatedAmounts()); resetRateClassTypeIfNeeded(vecCalAmts); ScaleTwoDecimal totalNOHCalcAmount = vecCalAmts.sumObjects("calculatedCost", new NotEquals("rateClassType", RateClassType.OVERHEAD.getRateClassType())); ScaleTwoDecimal totalOHCalcAmount = vecCalAmts.sumObjects("calculatedCost", new Equals("rateClassType", RateClassType.OVERHEAD.getRateClassType())); BigDecimal totalCost = budgetDetailBean.getLineItemCost().add(totalNOHCalcAmount).add(totalOHCalcAmount) .bigDecimalValue(); // If the lineItemCost <> 0, set multifactor to TotalCost divided by lineItemCost otherwise multifactor is TotalCost divided // by 10000 if (!lineItemCost.equals(ScaleTwoDecimal.ZERO)) { multifactor = totalCost.divide(lineItemCost.bigDecimalValue(), RoundingMode.HALF_UP); } else { multifactor = totalCost.divide(new ScaleTwoDecimal(10000).bigDecimalValue(), RoundingMode.HALF_UP); budgetDetailBean.setLineItemCost(ScaleTwoDecimal.ZERO); calculate(budget, budgetPeriodBean); totalCost = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); } if (isProposalBudget(budget) && new ScaleTwoDecimal(totalCost.add(difference)).isLessEqual(ScaleTwoDecimal.ZERO)) { return false; } // Set New Cost ScaleTwoDecimal newCost = lineItemCost .add(new ScaleTwoDecimal(difference.divide(multifactor, RoundingMode.HALF_UP))); budgetDetailBean.setLineItemCost(newCost); calculate(budget, budgetPeriodBean); return true; }
From source file:org.kuali.ole.module.purap.document.web.struts.OlePurchaseOrderAction.java
/** * @see org.kuali.ole.module.purap.document.web.struts.PurchaseOrderAction#addItem(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *//*from ww w .ja v a 2 s. c o m*/ @Override public ActionForward addItem(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LOG.debug("###########Inside AddItem in olePurchaseOrderAction ###########"); PurchasingFormBase purchasingForm = (PurchasingFormBase) form; OlePurchaseOrderItem purchaseOrderItem = (OlePurchaseOrderItem) purchasingForm.getNewPurchasingItemLine(); purchaseOrderItem.getNewSourceLine().setAccountLinePercent(new BigDecimal(100)); //purchasingForm.getNewPurchasingItemLine().setItemDescription((purchaseOrderItem.getBibInfoBean().getTitle() != null ? purchaseOrderItem.getBibInfoBean().getTitle() : "") + (purchaseOrderItem.getBibInfoBean().getAuthor() != null ? "," + purchaseOrderItem.getBibInfoBean().getAuthor() : "") + (purchaseOrderItem.getBibInfoBean().getPublisher() != null ? "," + purchaseOrderItem.getBibInfoBean().getPublisher() : "") + (purchaseOrderItem.getBibInfoBean().getIsbn() != null ? "," + purchaseOrderItem.getBibInfoBean().getIsbn() : "")); PurchaseOrderDocument document = (PurchaseOrderDocument) purchasingForm.getDocument(); // changes done for BibEditor starts OlePurchaseOrderForm oleForm = (OlePurchaseOrderForm) form; PurchaseOrderDocument doc = (PurchaseOrderDocument) oleForm.getDocument(); Iterator itemIterator = doc.getItems().iterator(); int itemCounter = 0; while (itemIterator.hasNext()) { OlePurchaseOrderItem tempItem = (OlePurchaseOrderItem) itemIterator.next(); if (tempItem.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_ITEM_CODE) || tempItem .getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_UNORDERED_ITEM_CODE)) { itemCounter++; } } String itemNo = String.valueOf(itemCounter); //String itemNo = String.valueOf(doc.getItems().size() - 4); HashMap<String, String> dataMap = new HashMap<String, String>(); BibInfoBean xmlBibInfoBean = new BibInfoBean(); if (purchaseOrderItem.getBibInfoBean() == null) { purchaseOrderItem.setBibInfoBean(xmlBibInfoBean); if (purchaseOrderItem.getBibInfoBean().getDocStoreOperation() == null) { purchaseOrderItem.getBibInfoBean().setDocStoreOperation(OleSelectConstant.DOCSTORE_OPERATION_STAFF); } } String fileName = document.getDocumentNumber() + "_" + itemNo; // Modified for jira OLE - 2437 starts setItemDescription(purchaseOrderItem, fileName); // purchaseOrderItem.setStartingCopyNumber(new KualiInteger(1)); // Modified for jira OLE - 2437 ends /* dataMap.put(OleSelectConstant.FILEPATH, fileProcessingService.getMarcXMLFileDirLocation()); dataMap.put(OleSelectConstant.FILENAME, fileName); if (fileProcessingService.isCreateFileExist(dataMap)) { isBibFileExist = true; } if (isBibFileExist) { titleId = docStore.getTitleIdByMarcXMLFileProcessing(purchaseOrderItem.getBibInfoBean(), dataMap); purchaseOrderItem.setItemTitleId(titleId); dataMap.put(OleSelectConstant.TITLE_ID, titleId); dataMap.put(OleSelectConstant.DOC_CATEGORY_TYPE, OleSelectConstant.DOC_CATEGORY_TYPE_ITEMLINKS); xmlBibInfoBean = docStore.getBibInfo(dataMap); purchaseOrderItem.setBibInfoBean(xmlBibInfoBean); purchasingForm.getNewPurchasingItemLine().setItemDescription((purchaseOrderItem.getBibInfoBean().getTitle() != null ? purchaseOrderItem.getBibInfoBean().getTitle() : "") + (purchaseOrderItem.getBibInfoBean().getAuthor() != null ? "," + purchaseOrderItem.getBibInfoBean().getAuthor() : "") + (purchaseOrderItem.getBibInfoBean().getPublisher() != null ? "," + purchaseOrderItem.getBibInfoBean().getPublisher() : "") + (purchaseOrderItem.getBibInfoBean().getIsbn() != null ? "," + purchaseOrderItem.getBibInfoBean().getIsbn() : "")); HashMap<String,String> queryMap = new HashMap<String,String>(); queryMap.put(OleSelectConstant.DocStoreDetails.ITEMLINKS_KEY, purchaseOrderItem.getItemTitleId()); List<DocInfoBean> docStoreResult = docStore.searchBibInfo(queryMap); Iterator bibIdIterator = docStoreResult.iterator(); if(bibIdIterator.hasNext()){ DocInfoBean docInfoBean = (DocInfoBean)bibIdIterator.next(); purchaseOrderItem.setBibUUID(docInfoBean.getUniqueId()); } }*/ // changes done for BibEditor ends if (document.getVendorDetail().getCurrencyType() != null) { if (document.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; } else { currencyTypeIndicator = false; } } boolean ruleFlag = getKualiRuleService() .applyRules(new OlePurchaseOrderDescEvent(document, purchaseOrderItem)); if (ruleFlag) { if ((document.getVendorDetail() == null) || (document.getVendorDetail().getVendorName() != null && currencyTypeIndicator)) { boolean rulePassed = getKualiRuleService() .applyRules(new DiscountPurchaseOrderEvent(document, purchaseOrderItem)); if (rulePassed) { purchasingForm.getNewPurchasingItemLine() .setItemUnitPrice(SpringContext.getBean(OlePurapService.class) .calculateDiscount(purchaseOrderItem).setScale(2, BigDecimal.ROUND_HALF_UP)); super.addItem(mapping, purchasingForm, request, response); } } else { boolean rulePassed = getKualiRuleService() .applyRules(new ForeignCurrencyPOEvent(document, purchaseOrderItem)); if (rulePassed) { LOG.debug("###########Foreign Currency Field additem for purchase Order ###########"); SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(purchaseOrderItem); Long id = document.getVendorDetail().getCurrencyType().getCurrencyTypeId(); Map documentNumberMap = new HashMap(); documentNumberMap.put(OleSelectConstant.CURRENCY_TYPE_ID, id); BusinessObjectService businessObjectService = SpringContext .getBean(BusinessObjectService.class); List<OleExchangeRate> exchangeRateList = (List) businessObjectService.findMatchingOrderBy( OleExchangeRate.class, documentNumberMap, OleSelectConstant.EXCHANGE_RATE_DATE, false); Iterator iterator = exchangeRateList.iterator(); if (iterator.hasNext()) { OleExchangeRate tempOleExchangeRate = (OleExchangeRate) iterator.next(); purchaseOrderItem .setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); } if (purchaseOrderItem.getItemExchangeRate() != null && purchaseOrderItem.getItemForeignUnitCost() != null) { purchaseOrderItem.setItemUnitCostUSD( new KualiDecimal(purchaseOrderItem.getItemForeignUnitCost().bigDecimalValue() .divide(purchaseOrderItem.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP))); purchaseOrderItem.setItemUnitPrice(purchaseOrderItem.getItemUnitCostUSD().bigDecimalValue() .setScale(2, BigDecimal.ROUND_HALF_UP)); purchaseOrderItem.setItemListPrice(purchaseOrderItem.getItemUnitCostUSD()); } super.addItem(mapping, purchasingForm, request, response); } } } if (purchaseOrderItem.getClaimDate() == null) { VendorDetail vendorDetail = document.getVendorDetail(); if (vendorDetail != null) { String claimInterval = vendorDetail.getClaimInterval(); if (StringUtils.isNotBlank(claimInterval)) { Integer actIntvl = Integer.parseInt(claimInterval); purchaseOrderItem.setClaimDate( new java.sql.Date(DateUtils.addDays(new java.util.Date(), actIntvl).getTime())); } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:nl.strohalm.cyclos.entities.settings.LocalSettings.java
public BigDecimal round(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.HALF_UP); } }
From source file:nl.strohalm.cyclos.entities.settings.LocalSettings.java
public BigDecimal roundHighPrecision(final BigDecimal number) { if (number == null) { return null; } else {// w w w. j a v a2 s . co m return number.setScale(getHighPrecision().getValue(), RoundingMode.HALF_UP); } }
From source file:org.kuali.ole.select.document.service.impl.OleInvoiceServiceImpl.java
/** * @see org.kuali.ole.select.document.service.OleInvoiceService#calculateProrateItemSurcharge(org.kuali.ole.select.document.OleInvoiceDocument) */// w ww .j a v a2 s . c o m @Override public void calculateProrateItemSurcharge(OleInvoiceDocument invoiceDocument) { LOG.debug("Inside Calculation for ProrateItemSurcharge"); // KualiDecimal addChargeItem = invoiceDocument.getGrandPreTaxTotalExcludingDiscount().subtract(invoiceDocument.getLineItemPreTaxTotal()); BigDecimal addChargeItem = BigDecimal.ZERO; List<OleInvoiceItem> item = invoiceDocument.getItems(); for (OleInvoiceItem items : item) { if (items.getItemType().isAdditionalChargeIndicator() && items.getExtendedPrice() != null) { addChargeItem = addChargeItem.add(items.getExtendedPrice().bigDecimalValue()); } } List<PurApItem> items = new ArrayList<>(); /*List<OlePurchaseOrderDocument> olePurchaseOrderDocuments = invoiceDocument.getPurchaseOrderDocuments(); for (OlePurchaseOrderDocument olePurchaseOrderDocument : olePurchaseOrderDocuments) { for (OlePurchaseOrderItem purItem : (List<OlePurchaseOrderItem>) olePurchaseOrderDocument.getItems()) { purItem.setItemListPrice(new KualiDecimal(purItem.getInvoiceItemListPrice())); if (purItem.isItemForInvoice() && purItem.getItemListPrice().compareTo(KualiDecimal.ZERO) >= 0) { items.add(purItem); } else { purItem.setItemSurcharge(BigDecimal.ZERO); } if (purItem.getItemListPrice().compareTo(KualiDecimal.ZERO) < 0) { purItem.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(purItem)); } } } if (items.size() == 0) {*/ for (OleInvoiceItem invoiceItem : (List<OleInvoiceItem>) invoiceDocument.getItems()) { /* if(invoiceItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && invoiceItem.getRelatedViews() != null) { invoiceItem.setRelatedViews(null); }*/ items.add(invoiceItem); } /* } else { for (OleInvoiceItem invoiceItem : (List<OleInvoiceItem>) invoiceDocument.getItems()) { if (!(invoiceItem.getItemType().isQuantityBasedGeneralLedgerIndicator())) { items.add(invoiceItem); } } }*/ List<BigDecimal> newUnitPriceList = new ArrayList<>(); BigDecimal totalExtPrice = new BigDecimal(0); BigDecimal newUnitPrice = new BigDecimal(0); BigDecimal extPrice = new BigDecimal(0); BigDecimal unitPricePercent = new BigDecimal(0); BigDecimal hundred = new BigDecimal(100); BigDecimal one = new BigDecimal(1); BigDecimal totalSurCharge = new BigDecimal(0); BigDecimal totalItemQuantity = new BigDecimal(0); BigDecimal itemSurchargeCons = new BigDecimal(0); for (PurApItem purItem : items) { if (purItem instanceof OlePurchaseOrderItem) { OlePurchaseOrderItem poItem = (OlePurchaseOrderItem) purItem; // purItem.setItemListPrice(new KualiDecimal(purItem.getInvoiceItemListPrice())); if ((poItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) && !ObjectUtils.isNull(poItem.getNoOfCopiesInvoiced()) && poItem.getItemListPrice().compareTo(KualiDecimal.ZERO) >= 0) { if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { totalItemQuantity = totalItemQuantity.add(poItem.getNoOfCopiesInvoiced().bigDecimalValue()); } if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR) || invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE) || invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { if (poItem.getItemDiscount() == null) { poItem.setItemDiscount(KualiDecimal.ZERO); } if (poItem.getItemDiscountType() != null && poItem.getItemDiscountType() .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) { newUnitPrice = (hundred.subtract(poItem.getItemDiscount().bigDecimalValue())) .divide(hundred).multiply(poItem.getItemListPrice().bigDecimalValue()); } else { newUnitPrice = poItem.getItemListPrice().bigDecimalValue() .subtract(poItem.getItemDiscount().bigDecimalValue()); } newUnitPriceList.add(newUnitPrice); extPrice = newUnitPrice.multiply(poItem.getNoOfCopiesInvoiced().bigDecimalValue()); totalExtPrice = totalExtPrice.add(extPrice); } if (invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) { if (poItem.getItemSurcharge() == null) { poItem.setItemSurcharge(BigDecimal.ZERO); } totalSurCharge = totalSurCharge.add(poItem.getNoOfCopiesInvoiced().bigDecimalValue() .multiply(poItem.getItemSurcharge())); } } } else if (purItem instanceof OleInvoiceItem) { OleInvoiceItem invItem = (OleInvoiceItem) purItem; if ((invItem.getItemType().isQuantityBasedGeneralLedgerIndicator()) && !ObjectUtils.isNull(invItem.getItemQuantity()) && invItem.getItemListPrice().compareTo(KualiDecimal.ZERO) >= 0) { if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { totalItemQuantity = totalItemQuantity.add(invItem.getItemQuantity().bigDecimalValue()); } if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR) || invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE) || invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { if (invItem.getItemDiscount() == null) { invItem.setItemDiscount(KualiDecimal.ZERO); } if (invItem.getItemDiscountType() != null && invItem.getItemDiscountType() .equalsIgnoreCase(OleSelectConstant.DISCOUNT_TYPE_PERCENTAGE)) { newUnitPrice = (hundred.subtract(invItem.getItemDiscount().bigDecimalValue())) .divide(hundred).multiply(invItem.getItemListPrice().bigDecimalValue()); } else { newUnitPrice = invItem.getItemListPrice().bigDecimalValue() .subtract(invItem.getItemDiscount().bigDecimalValue()); } newUnitPriceList.add(newUnitPrice); extPrice = newUnitPrice.multiply(invItem.getItemQuantity().bigDecimalValue()); totalExtPrice = totalExtPrice.add(extPrice); } if (invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) { if (invItem.getItemSurcharge() == null) { invItem.setItemSurcharge(BigDecimal.ZERO); } totalSurCharge = totalSurCharge.add( invItem.getItemQuantity().bigDecimalValue().multiply(invItem.getItemSurcharge())); } } } } if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { if (totalItemQuantity.compareTo(BigDecimal.ZERO) != 0) { itemSurchargeCons = one.divide(totalItemQuantity, 8, RoundingMode.HALF_UP); } } for (int i = 0, j = 0; items.size() > i; i++) { PurApItem purItem = items.get(i); if (purItem instanceof OlePurchaseOrderItem) { OlePurchaseOrderItem poItem = (OlePurchaseOrderItem) purItem; if (poItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && newUnitPriceList.size() > j && !ObjectUtils.isNull(poItem.getNoOfCopiesInvoiced())) { if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)) { if (totalExtPrice.compareTo(BigDecimal.ZERO) != 0) { unitPricePercent = newUnitPriceList.get(j).divide(totalExtPrice, 8, RoundingMode.HALF_UP); } poItem.setItemSurcharge( unitPricePercent.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP)); poItem.setItemUnitPrice(newUnitPriceList.get(j).add(poItem.getItemSurcharge())); } if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { poItem.setItemSurcharge( itemSurchargeCons.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP)); poItem.setItemUnitPrice(newUnitPriceList.get(j).add(poItem.getItemSurcharge())); } if (invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE) && poItem.getItemSurcharge() != null) { poItem.setItemUnitPrice(newUnitPriceList.get(j).add(poItem.getItemSurcharge())); } j++; } } else if (purItem instanceof OleInvoiceItem) { OleInvoiceItem invItem = (OleInvoiceItem) purItem; if (invItem.getItemType().isQuantityBasedGeneralLedgerIndicator() && newUnitPriceList.size() > j && !ObjectUtils.isNull(invItem.getItemQuantity())) { if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR)) { if (totalExtPrice.compareTo(BigDecimal.ZERO) != 0) { unitPricePercent = newUnitPriceList.get(j).divide(totalExtPrice, 8, RoundingMode.HALF_UP); } invItem.setItemSurcharge( unitPricePercent.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP)); invItem.setItemUnitPrice(newUnitPriceList.get(j).add(invItem.getItemSurcharge())); } if (invoiceDocument.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY)) { invItem.setItemSurcharge( itemSurchargeCons.multiply(addChargeItem).setScale(4, RoundingMode.HALF_UP)); invItem.setItemUnitPrice(newUnitPriceList.get(j).add(invItem.getItemSurcharge())); } if (invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE) && invItem.getItemSurcharge() != null) { invItem.setItemUnitPrice(newUnitPriceList.get(j).add(invItem.getItemSurcharge())); } j++; } } } if (invoiceDocument.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) { if (totalSurCharge.compareTo(addChargeItem) != 0) { GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OLEKeyConstants.ERROR_PAYMENT_REQUEST_TOTAL_MISMATCH); } } LOG.debug("Leaving Calculation for ProrateItemSurcharge"); }