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.OleVendorCreditMemoAction.java
/** * Add a new item to the document./*w ww.ja v a2s . 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 { OleVendorCreditMemoForm purchasingForm = (OleVendorCreditMemoForm) form; OleCreditMemoItem item = (OleCreditMemoItem) purchasingForm.getNewPurchasingItemLine(); OleVendorCreditMemoDocument document = (OleVendorCreditMemoDocument) 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()) { OleCreditMemoItem tempItem = (OleCreditMemoItem) 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); 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 fileName = document.getDocumentNumber() + "_" + itemNo; setItemDescription(item, fileName); boolean ruleFlag = getKualiRuleService().applyRules(new OleCreditMemoDescEvent(document, item)); if (ruleFlag) { if (item.getItemDescription() == null || item.getItemDescription().isEmpty()) { GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_REQUIRED, new String[] { "Line Item" }); } else if (item.getPoUnitPrice() == null || item.getPoUnitPrice().equals(BigDecimal.ZERO)) { GlobalVariables.getMessageMap().putError(PurapConstants.ITEM_TAB_ERROR_PROPERTY, OleSelectConstant.ERROR_UNIT_PRICE_REQUIRED); } else { 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)) { item = (OleCreditMemoItem) purchasingForm.getAndResetNewPurchasingItemLine(); document.creditMemoCalculation(item); document.addItem(item); } else { boolean rulePassed = getKualiRuleService() .applyRules(new OleForeignCurrencyCreditMemoEvent(document, item)); if (rulePassed) { LOG.debug("###########Foreign Currency Field Calculation for Payment Request ###########"); 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(); 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()); } item = (OleCreditMemoItem) purchasingForm.getAndResetNewPurchasingItemLine(); document.addItem(item); } } } } return mapping.findForward(OLEConstants.MAPPING_BASIC); }
From source file:org.kuali.ole.module.purap.document.web.struts.OleRequisitionAction.java
/** * Calculate the whole document.// www. j a va2 s . com * * @param mapping An ActionMapping * @param form An ActionForm * @param request The HttpServletRequest * @param response The HttpServletResponse * @return An ActionForward * @throws Exception */ @Override public ActionForward calculate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { LOG.debug("Inside the OleRequisitionAction class Calculate"); PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form; List<PurApItem> purApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems(); for (PurApItem purApItem : purApItems) { List<KualiDecimal> existingAmount = new ArrayList<>(); for (PurApAccountingLine oldSourceAccountingLine : purApItem.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof OleRequisitionAccount) { if (((OleRequisitionAccount) oldSourceAccountingLine).getExistingAmount() != null) { existingAmount.add(((OleRequisitionAccount) oldSourceAccountingLine).getExistingAmount()); } } } int count = 0; for (PurApAccountingLine account : purApItem.getSourceAccountingLines()) { if (ObjectUtils.isNotNull(account.getAccountLinePercent()) || ObjectUtils.isNotNull(account.getAmount())) { if (account.getAmount() != null && count < existingAmount.size() && existingAmount.size() != 0 && !existingAmount.get(count).toString().equals(account.getAmount().toString())) { KualiDecimal calculatedPercent = new KualiDecimal(account.getAmount() .multiply(new KualiDecimal(100)).divide(purApItem.getTotalAmount()).toString()); account.setAccountLinePercent(calculatedPercent.bigDecimalValue() .setScale(OLEConstants.BIG_DECIMAL_SCALE, BigDecimal.ROUND_CEILING)); } else { if (account.getAccountLinePercent().intValue() == 100 && (account.getAmount() == null || account.getAccount() != null)) { KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent() .multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } else { KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent() .multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } } } count++; } for (PurApAccountingLine oldSourceAccountingLine : purApItem.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof OleRequisitionAccount) { ((OleRequisitionAccount) oldSourceAccountingLine) .setExistingAmount(oldSourceAccountingLine.getAmount()); } } } ActionForward forward = super.calculate(mapping, form, request, response); purchasingForm = (PurchasingAccountsPayableFormBase) form; PurchasingDocument purDoc = (PurchasingDocument) purchasingForm.getDocument(); PurchasingFormBase formBase = (PurchasingFormBase) form; OleRequisitionDocument reqDoc = (OleRequisitionDocument) formBase.getDocument(); boolean foreignCurrencyIndicator = false; List<OleRequisitionItem> item = reqDoc.getItems(); if (purDoc.getVendorDetail() != null) { foreignCurrencyIndicator = isForeignCurrency(purDoc.getVendorDetail().getCurrencyType()); } if (purDoc.getVendorDetail() == null || (purDoc.getVendorDetail() != null && (!foreignCurrencyIndicator))) { for (int i = 0; purDoc.getItems().size() > i; i++) { OleRequisitionItem items = (OleRequisitionItem) purDoc.getItem(i); if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) { boolean rulePassed = getKualiRuleService() .applyRules(new DiscountRequisitionEvent(reqDoc, items)); if (rulePassed) { items.setItemUnitPrice(SpringContext.getBean(OlePurapService.class).calculateDiscount(items) .setScale(2, BigDecimal.ROUND_HALF_UP)); } rulePassed = getKualiRuleService().applyRules(new CopiesRequisitionEvent(reqDoc, items)); } } } else { LOG.debug("###########Foreign Currency Field Calculation###########"); for (int i = 0; item.size() > i; i++) { OleRequisitionItem items = (OleRequisitionItem) reqDoc.getItem(i); if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) { boolean rulePassed = getKualiRuleService() .applyRules(new ForeignCurrencyRequisitionEvent(reqDoc, items)); if (rulePassed) { SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(items); Long id = reqDoc.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(); items.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); } if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null) { items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost() .bigDecimalValue().divide(items.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP))); items.setItemUnitPrice(items.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP)); items.setItemListPrice(items.getItemUnitCostUSD()); items.setTotalAmount(items.getTotalAmount()); } } } } } purchasingForm = (PurchasingAccountsPayableFormBase) form; List<PurApItem> newpurApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()) .getItems(); for (PurApItem purApItem : newpurApItems) { for (PurApAccountingLine account : purApItem.getSourceAccountingLines()) { KualiDecimal calculatedAmount = new KualiDecimal( account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } } forward = super.calculate(mapping, form, request, response); // formBase.setCalculated(true); // Added for jira OLE-964 OleRequisitionDocumentService oleRequisitionDocumentService = (OleRequisitionDocumentService) SpringContext .getBean("oleRequisitionDocumentService"); List<SourceAccountingLine> sourceAccountingLineList = reqDoc.getSourceAccountingLines(); for (SourceAccountingLine accLine : sourceAccountingLineList) { String notificationOption = null; boolean sufficientFundCheck; Map<String, Object> key = new HashMap<String, Object>(); String chartCode = accLine.getChartOfAccountsCode(); String accNo = accLine.getAccountNumber(); key.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, chartCode); key.put(OLEPropertyConstants.ACCOUNT_NUMBER, accNo); OleSufficientFundCheck account = SpringContext.getBean(BusinessObjectService.class) .findByPrimaryKey(OleSufficientFundCheck.class, key); if (account != null) { notificationOption = account.getNotificationOption(); } if (notificationOption != null && notificationOption.equals(OLEPropertyConstants.BLOCK_USE)) { sufficientFundCheck = oleRequisitionDocumentService.hasSufficientFundsOnRequisition(accLine); if (sufficientFundCheck) { GlobalVariables.getMessageMap().putError( OLEConstants.SufficientFundCheck.ERROR_MSG_FOR_INSUFF_FUND, RiceKeyConstants.ERROR_CUSTOM, OLEConstants.SufficientFundCheck.INSUFF_FUND_REQ + accLine.getAccountNumber()); } } } // End if (LOG.isDebugEnabled()) { LOG.debug("Inside the OleRequisitionAcrion class Calculate" + formBase.getNewPurchasingItemLine().getItemUnitPrice()); } return forward; }
From source file:ru.anr.base.BaseParent.java
/** * Short-cut for set a scale for {@link BigDecimal} using the standard * {@link RoundingMode#HALF_UP} mode (so called 'school' rounding). * //from ww w . j a va2 s . co m * @param d * A decimal value * @param scale * The scale * @return New {@link BigDecimal} in the specified scale */ public static final BigDecimal scale(BigDecimal d, int scale) { return d.setScale(scale, RoundingMode.HALF_UP); }
From source file:org.apache.carbondata.core.scan.executor.util.RestructureUtil.java
/** * Gets the default value based on the column data type. * * @param columnSchema//w w w .ja va2s .c o m * @param defaultValue * @return */ public static Object getMeasureDefaultValueByType(ColumnSchema columnSchema, byte[] defaultValue) { Object measureDefaultValue = null; if (!isDefaultValueNull(defaultValue)) { String value = null; switch (columnSchema.getDataType()) { case SHORT: value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Short.parseShort(value); break; case INT: value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Integer.parseInt(value); break; case LONG: value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); measureDefaultValue = Long.parseLong(value); break; case DECIMAL: BigDecimal decimal = DataTypeUtil.byteToBigDecimal(defaultValue); if (columnSchema.getScale() > decimal.scale()) { decimal = decimal.setScale(columnSchema.getScale(), RoundingMode.HALF_UP); } measureDefaultValue = Decimal.apply(decimal); break; default: value = new String(defaultValue, Charset.forName(CarbonCommonConstants.DEFAULT_CHARSET)); Double parsedValue = Double.valueOf(value); if (!Double.isInfinite(parsedValue) && !Double.isNaN(parsedValue)) { measureDefaultValue = parsedValue; } } } return measureDefaultValue; }
From source file:org.moe.gradle.utils.JUnitTestCollector.java
/** * Converts milliseconds to seconds.//from w ww. ja v a 2 s . c o m * * @param millis milliseconds * @return seconds */ private static double getAsSeconds(long millis) { final double t = ((double) millis) / (1000.0); return new BigDecimal(t).setScale(3, RoundingMode.HALF_UP).doubleValue(); }
From source file:com.orbar.pxdemo.Model.FiveZeroZeroImageBean.java
public void parseJSONObject(JSONObject imageObject) { userBean = new FiveZeroZeroUserBean(); try {// w w w . j a v a2s . c om if (imageObject.has("id") && !imageObject.isNull("id")) id = imageObject.getInt("id"); if (imageObject.has("user_id") && !imageObject.isNull("user_id")) userId = imageObject.getInt("user_id"); if (imageObject.has("name") && !imageObject.isNull("name")) name = imageObject.getString("name"); if (imageObject.has("description") && !imageObject.isNull("description")) description = imageObject.getString("description"); if (imageObject.has("camera") && !imageObject.isNull("camera")) camera = imageObject.getString("camera"); if (imageObject.has("lens") && !imageObject.isNull("lens")) lens = imageObject.getString("lens"); if (imageObject.has("focal_length") && !imageObject.isNull("focal_length")) focalLength = imageObject.getString("focal_length"); if (imageObject.has("iso") && !imageObject.isNull("iso")) iso = imageObject.getString("iso"); if (imageObject.has("shutter_speed") && !imageObject.isNull("shutter_speed")) shutterSpeed = imageObject.getString("shutter_speed"); if (imageObject.has("aperture") && !imageObject.isNull("aperture")) aperture = imageObject.getString("aperture"); if (imageObject.has("times_viewed") && !imageObject.isNull("times_viewed")) timesViewed = imageObject.getInt("times_viewed"); if (imageObject.has("rating") && !imageObject.isNull("rating")) { rating = (float) imageObject.getDouble("rating"); rating = Float.valueOf(new BigDecimal(rating).setScale(2, RoundingMode.HALF_UP).toString()); } if (imageObject.has("status") && !imageObject.isNull("status")) status = imageObject.getInt("status"); if (imageObject.has("created_at") && !imageObject.isNull("created_at")) createdAt = imageObject.getString("created_at"); if (imageObject.has("category") && !imageObject.isNull("category")) category = imageObject.getInt("category"); if (imageObject.has("category") && !imageObject.isNull("category")) category = imageObject.getInt("category"); if (imageObject.has("location") && !imageObject.isNull("location")) location = imageObject.getString("location"); //if (imageObject.has("privacy") && !imageObject.isNull("privacy")) // privacy = imageObject.getBoolean("privacy"); if (imageObject.has("latitude") && !imageObject.isNull("latitude")) { latitude = imageObject.getString("latitude"); String sLat = imageObject.getString("latitude"); double dLat = Double.valueOf(sLat); DecimalFormat df = new DecimalFormat("#.###"); latitude = df.format(dLat); } if (imageObject.has("longitude") && !imageObject.isNull("longitude")) { String sLong = imageObject.getString("longitude"); double dLong = Double.valueOf(sLong); DecimalFormat df = new DecimalFormat("#.##"); longitude = df.format(dLong); } if (imageObject.has("taken_at") && !imageObject.isNull("taken_at")) takenAt = imageObject.getString("taken_at"); if (imageObject.has("hi_res_uploaded") && !imageObject.isNull("hi_res_uploaded")) hiResUploaded = imageObject.getInt("hi_res_uploaded"); if (imageObject.has("for_sale") && !imageObject.isNull("for_sale")) forSale = imageObject.getBoolean("for_sale"); if (imageObject.has("width") && !imageObject.isNull("width")) width = imageObject.getInt("width"); if (imageObject.has("height") && !imageObject.isNull("height")) height = imageObject.getInt("height"); if (imageObject.has("votes_count") && !imageObject.isNull("votes_count")) votesCount = imageObject.getInt("votes_count"); if (imageObject.has("favorites_count") && !imageObject.isNull("favorites_count")) favoritesCount = imageObject.getInt("favorites_count"); if (imageObject.has("comments_count") && !imageObject.isNull("comments_count")) commentsCount = imageObject.getInt("comments_count"); if (imageObject.has("nsfw") && !imageObject.isNull("nsfw")) nsfw = imageObject.getBoolean("nsfw"); if (imageObject.has("sales_count") && !imageObject.isNull("sales_count")) salesCount = imageObject.getInt("sales_count"); if (imageObject.has("highest_rating") && !imageObject.isNull("highest_rating")) { highestRating = (float) imageObject.getDouble("highest_rating"); highestRating = Float .valueOf(new BigDecimal(highestRating).setScale(2, RoundingMode.HALF_UP).toString()); } if (imageObject.has("highest_rating_date") && !imageObject.isNull("highest_rating_date")) highestRatingDate = imageObject.getString("highest_rating_date"); if (imageObject.has("license_type") && !imageObject.isNull("license_type")) licenseType = imageObject.getInt("license_type"); if (imageObject.has("store_download") && !imageObject.isNull("store_download")) storeDownload = imageObject.getBoolean("store_download"); if (imageObject.has("store_print") && !imageObject.isNull("store_print")) storePrint = imageObject.getBoolean("store_print"); if (imageObject.has("voted") && !imageObject.isNull("voted")) { voted = imageObject.getBoolean("voted"); } else { voted = false; } if (imageObject.has("favorited") && !imageObject.isNull("favorited")) { favorited = imageObject.getBoolean("favorited"); } else { favorited = false; } if (imageObject.has("purchased") && !imageObject.isNull("purchased")) { purchased = imageObject.getBoolean("purchased"); } else { purchased = false; } if (imageObject.has("image_url") && !imageObject.isNull("image_url")) { imageUrl = imageObject.getString("image_url"); imageUrl = imageUrl.substring(0, imageUrl.lastIndexOf("/") + 1); } if (imageObject.has("user") && !imageObject.isNull("user")) userBean.parseJSONObject(imageObject.getJSONObject("user")); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.libreplan.importers.JiraOrderElementSynchronizer.java
/** * updates {@link DirectAdvanceAssignment} and {@link AdvanceMeasurement} if * they already exist, otherwise create new one * * @param orderElement//from www . j a v a 2s . co m * an existing orderElement * @param percentage * percentage for advanced measurement * @param latestWorkLogDate * date for advanced measurement */ private void updateOrCreateProgressAssignmentAndMeasurement(OrderElement orderElement, BigDecimal percentage, LocalDate latestWorkLogDate) { AdvanceType advanceType = PredefinedAdvancedTypes.PERCENTAGE.getType(); DirectAdvanceAssignment directAdvanceAssignment = orderElement .getDirectAdvanceAssignmentByType(advanceType); if (directAdvanceAssignment == null) { directAdvanceAssignment = DirectAdvanceAssignment.create(false, new BigDecimal(100).setScale(2)); directAdvanceAssignment.setAdvanceType(advanceType); try { orderElement.addAdvanceAssignment(directAdvanceAssignment); } catch (DuplicateValueTrueReportGlobalAdvanceException e) { // This couldn't happen as it has just created the // directAdvanceAssignment with false as reportGlobalAdvance throw new RuntimeException(e); } catch (DuplicateAdvanceAssignmentForOrderElementException e) { // This could happen if a parent or child of the current // OrderElement has an advance of type PERCENTAGE synchronizationInfo.addFailedReason(_( "Duplicate value AdvanceAssignment for order element of \"{0}\"", orderElement.getCode())); return; } } AdvanceMeasurement advanceMeasurement = directAdvanceAssignment .getAdvanceMeasurementAtExactDate(latestWorkLogDate); if (advanceMeasurement == null) { advanceMeasurement = AdvanceMeasurement.create(); advanceMeasurement.setDate(latestWorkLogDate); directAdvanceAssignment.addAdvanceMeasurements(advanceMeasurement); } advanceMeasurement.setValue(percentage.setScale(2, RoundingMode.HALF_UP)); DirectAdvanceAssignment spreadAdvanceAssignment = orderElement.getReportGlobalAdvanceAssignment(); if (spreadAdvanceAssignment != null) { spreadAdvanceAssignment.setReportGlobalAdvance(false); } directAdvanceAssignment.setReportGlobalAdvance(true); }
From source file:ru.anr.base.BaseParent.java
/** * Short-cut for division with specific//from ww w . ja va 2 s . c om * * @param a * A divided value * @param b * A divisor * * @param scale * The scale * @return New {@link BigDecimal} in the specified scale */ public static final BigDecimal div(BigDecimal a, BigDecimal b, int scale) { return a.divide(b, scale, RoundingMode.HALF_UP); }
From source file:org.kuali.ole.select.document.web.struts.OlePaymentRequestAction.java
/** * @see org.kuali.ole.module.purap.document.web.struts.AccountsPayableActionBase#calculate(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse) *///from w w w.j a va 2s . co m @Override public ActionForward calculate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { /*ActionForward forward = super.calculate(mapping, form, request, response);*/ /* calculateCurrency(mapping, form, request, response); */ PurchasingAccountsPayableFormBase purchasingForm = (PurchasingAccountsPayableFormBase) form; List<PurApItem> purApItems = ((PurchasingAccountsPayableDocument) purchasingForm.getDocument()).getItems(); for (PurApItem purApItem : purApItems) { List<KualiDecimal> existingAmount = new ArrayList<>(); for (PurApAccountingLine oldSourceAccountingLine : purApItem.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof PaymentRequestAccount) { if (((PaymentRequestAccount) oldSourceAccountingLine).getExistingAmount() != null) { existingAmount.add(((PaymentRequestAccount) oldSourceAccountingLine).getExistingAmount()); } } } int count = 0; for (PurApAccountingLine account : purApItem.getSourceAccountingLines()) { if (ObjectUtils.isNotNull(account.getAccountLinePercent()) || ObjectUtils.isNotNull(account.getAmount())) { if (account.getAmount() != null && count < existingAmount.size() && existingAmount.size() != 0 && !existingAmount.get(count).toString().equals(account.getAmount().toString())) { KualiDecimal calculatedPercent = new KualiDecimal(account.getAmount() .multiply(new KualiDecimal(100)).divide(purApItem.getTotalAmount()).toString()); account.setAccountLinePercent(calculatedPercent.bigDecimalValue() .setScale(OLEConstants.BIG_DECIMAL_SCALE, BigDecimal.ROUND_CEILING)); } else { if (account.getAccountLinePercent().intValue() == 100 && (account.getAmount() == null || account.getAccount() != null)) { KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent() .multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } else { KualiDecimal calculatedAmount = new KualiDecimal(account.getAccountLinePercent() .multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } } } count++; } for (PurApAccountingLine oldSourceAccountingLine : purApItem.getSourceAccountingLines()) { if (oldSourceAccountingLine instanceof PaymentRequestAccount) { ((PaymentRequestAccount) oldSourceAccountingLine) .setExistingAmount(oldSourceAccountingLine.getAmount()); } } } OlePaymentRequestForm paymentForm = (OlePaymentRequestForm) form; OlePaymentRequestDocument payDoc = (OlePaymentRequestDocument) paymentForm.getDocument(); Map invMap = new HashMap(); if (payDoc.getInvoiceIdentifier() != null) { invMap.put(PurapConstants.PRQSDocumentsStrings.INV_ID, payDoc.getInvoiceIdentifier()); payDoc.getInvoiceIdentifier(); OleInvoiceDocument oleInvoice = SpringContext .getBean(org.kuali.rice.krad.service.BusinessObjectService.class) .findByPrimaryKey(OleInvoiceDocument.class, invMap); payDoc.setProrateBy(oleInvoice.isProrateQty() ? OLEConstants.PRORATE_BY_QTY : oleInvoice.isProrateManual() ? OLEConstants.MANUAL_PRORATE : oleInvoice.isProrateDollar() ? OLEConstants.PRORATE_BY_DOLLAR : oleInvoice.isNoProrate() ? OLEConstants.NO_PRORATE : OLEConstants.DEFAULT_PRORATE_BY_INVOICE); List<OleInvoiceItem> item = oleInvoice.getItems(); for (int i = 0; item.size() > i; i++) { OleInvoiceItem items = (OleInvoiceItem) oleInvoice.getItem(i); if (items.getItemTypeCode().equals(PurapConstants.ItemTypeCodes.ITEM_TYPE_FREIGHT_CODE) && LOG.isDebugEnabled()) { LOG.debug("Item Type Code >>>>>>>>>>>" + items.getItemTypeCode()); LOG.debug("items.getItemUnitPrice() >>>>>>>>>" + items.getItemUnitPrice()); LOG.debug("items.getTotalAmount() >>>>>>>>" + items.getTotalAmount()); } } } else { payDoc.setProrateBy(payDoc.isProrateQty() ? OLEConstants.PRORATE_BY_QTY : payDoc.isProrateManual() ? OLEConstants.MANUAL_PRORATE : payDoc.isProrateDollar() ? OLEConstants.PRORATE_BY_DOLLAR : payDoc.isNoProrate() ? OLEConstants.NO_PRORATE : null); } boolean manualProrateValidFlag = true; if ((payDoc.getProrateBy() != null) && (payDoc.getProrateBy().equals(OLEConstants.PRORATE_BY_QTY) || payDoc.getProrateBy().equals(OLEConstants.PRORATE_BY_DOLLAR) || payDoc.getProrateBy().equals(OLEConstants.MANUAL_PRORATE))) { if (payDoc.getProrateBy() != null && payDoc.getProrateBy().equals(OLEConstants.MANUAL_PRORATE)) { // Validates the prorate surchanges if prorate by manual manualProrateValidFlag = getOlePaymentRequestService().validateProratedSurcharge(payDoc); } if (manualProrateValidFlag) { List<OlePaymentRequestItem> item = payDoc.getItems(); if (payDoc.getVendorDetail().getCurrencyType() != null) { if (payDoc.getVendorDetail().getCurrencyType().getCurrencyType() .equalsIgnoreCase(OleSelectConstant.CURRENCY_TYPE_NAME)) { currencyTypeIndicator = true; } else { currencyTypeIndicator = false; } } if (payDoc.getVendorDetail() == null || (payDoc.getVendorDetail() != null && currencyTypeIndicator)) { for (int i = 0; item.size() > i; i++) { OlePaymentRequestItem items = (OlePaymentRequestItem) payDoc.getItem(i); if (items.getItemType().isQuantityBasedGeneralLedgerIndicator()) { boolean rulePassed = getKualiRuleService() .applyRules(new OleDiscountPaymentRequestEvent(payDoc, items)); if (rulePassed) { items.setItemUnitPrice(SpringContext.getBean(OlePurapService.class) .calculateDiscount(items).setScale(2, BigDecimal.ROUND_HALF_UP)); } } } } else { LOG.debug("###########Foreign Currency Field Calculation###########"); for (int i = 0; item.size() > i; i++) { OlePaymentRequestItem items = (OlePaymentRequestItem) payDoc.getItem(i); Long id = payDoc.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(); items.setItemExchangeRate(new KualiDecimal(tempOleExchangeRate.getExchangeRate())); payDoc.setForeignVendorInvoiceAmount(payDoc.getVendorInvoiceAmount().bigDecimalValue() .multiply(tempOleExchangeRate.getExchangeRate())); } if ((items.getItemType().isQuantityBasedGeneralLedgerIndicator())) { boolean rulePassed = getKualiRuleService() .applyRules(new OleForeignCurrencyPaymentRequestEvent(payDoc, items)); if (rulePassed) { SpringContext.getBean(OlePurapService.class).calculateForeignCurrency(items); if (items.getItemExchangeRate() != null && items.getItemForeignUnitCost() != null) { items.setItemUnitCostUSD(new KualiDecimal(items.getItemForeignUnitCost() .bigDecimalValue().divide(items.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP))); items.setItemUnitPrice(items.getItemUnitCostUSD().bigDecimalValue().setScale(2, BigDecimal.ROUND_HALF_UP)); items.setItemListPrice(items.getItemUnitCostUSD()); //items.setPurchaseOrderItemUnitPrice(items.getItemUnitPrice()); } } } else { if (items.getItemExchangeRate() != null && items.getForeignCurrencyExtendedPrice() != null) { // added for jira - OLE-2203 if (items.isAdditionalChargeUsd()) { items.setItemUnitPrice(items.getForeignCurrencyExtendedPrice().bigDecimalValue() .setScale(2, BigDecimal.ROUND_HALF_UP)); } else { items.setItemUnitPrice( items.getForeignCurrencyExtendedPrice().bigDecimalValue() .divide(items.getItemExchangeRate().bigDecimalValue(), 4, RoundingMode.HALF_UP) .setScale(2, BigDecimal.ROUND_HALF_UP)); } } } } } getOlePaymentRequestService().calculateProrateItemSurcharge(payDoc); } } if (payDoc.getProrateBy() == null && manualProrateValidFlag) { getOlePaymentRequestService().calculateWithoutProrates(payDoc); } List<PurApItem> newpurApItems = ((PurchasingAccountsPayableDocument) paymentForm.getDocument()).getItems(); for (PurApItem purApItem : newpurApItems) { for (PurApAccountingLine account : purApItem.getSourceAccountingLines()) { KualiDecimal calculatedAmount = new KualiDecimal( account.getAccountLinePercent().multiply(purApItem.getTotalAmount().bigDecimalValue()) .divide(new BigDecimal(100)).toString()); account.setAmount(calculatedAmount); } } return super.calculate(mapping, form, request, response); }
From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java
protected void configureChart(final JFreeChart chart) { super.configureChart(chart); final CategoryPlot cpl = chart.getCategoryPlot(); final CategoryItemRenderer renderer = cpl.getRenderer(); if (StringUtils.isEmpty(getTooltipFormula()) == false) { renderer.setBaseToolTipGenerator( new FormulaCategoryTooltipGenerator(getRuntime(), getTooltipFormula())); }/* w w w .j av a 2 s . co m*/ if (StringUtils.isEmpty(getUrlFormula()) == false) { renderer.setBaseItemURLGenerator(new FormulaCategoryURLGenerator(getRuntime(), getUrlFormula())); } if (this.categoricalLabelFormat != null) { final StandardCategoryItemLabelGenerator scilg; if (categoricalLabelDecimalFormat != null) { final DecimalFormat numFormat = new DecimalFormat(categoricalLabelDecimalFormat, new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale())); numFormat.setRoundingMode(RoundingMode.HALF_UP); scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, numFormat); } else if (categoricalLabelDateFormat != null) { scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, new SimpleDateFormat( categoricalLabelDateFormat, getRuntime().getResourceBundleFactory().getLocale())); } else { final DecimalFormat formatter = new DecimalFormat(); formatter.setDecimalFormatSymbols( new DecimalFormatSymbols(getRuntime().getResourceBundleFactory().getLocale())); scilg = new StandardCategoryItemLabelGenerator(categoricalLabelFormat, formatter); } renderer.setBaseItemLabelGenerator(scilg); } renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible())); if (getItemLabelFont() != null) { renderer.setBaseItemLabelFont(getItemLabelFont()); } if (categoricalItemLabelRotation != null) { final ItemLabelPosition orgPosItemLabelPos = renderer.getBasePositiveItemLabelPosition(); if (orgPosItemLabelPos == null) { final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue()); renderer.setBasePositiveItemLabelPosition(pos2); } else { final ItemLabelPosition pos2 = new ItemLabelPosition(orgPosItemLabelPos.getItemLabelAnchor(), orgPosItemLabelPos.getTextAnchor(), orgPosItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue()); renderer.setBasePositiveItemLabelPosition(pos2); } final ItemLabelPosition orgNegItemLabelPos = renderer.getBaseNegativeItemLabelPosition(); if (orgNegItemLabelPos == null) { final ItemLabelPosition pos2 = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER, TextAnchor.CENTER, categoricalItemLabelRotation.doubleValue()); renderer.setBaseNegativeItemLabelPosition(pos2); } else { final ItemLabelPosition neg2 = new ItemLabelPosition(orgNegItemLabelPos.getItemLabelAnchor(), orgNegItemLabelPos.getTextAnchor(), orgNegItemLabelPos.getRotationAnchor(), categoricalItemLabelRotation.doubleValue()); renderer.setBaseNegativeItemLabelPosition(neg2); } } final Font labelFont = Font.decode(getLabelFont()); final CategoryAxis categoryAxis = cpl.getDomainAxis(); categoryAxis.setLabelFont(labelFont); categoryAxis.setTickLabelFont(labelFont); if (getCategoryTitleFont() != null) { categoryAxis.setLabelFont(getCategoryTitleFont()); } if (getCategoryTickFont() != null) { categoryAxis.setTickLabelFont(getCategoryTickFont()); } if (maxCategoryLabelWidthRatio != null) { categoryAxis.setMaximumCategoryLabelWidthRatio(maxCategoryLabelWidthRatio.floatValue()); } cpl.setDomainGridlinesVisible(showGridlines); if (labelRotation != null) { double angle = labelRotation.doubleValue(); CategoryLabelPosition top = createUpRotationCategoryLabelPosition(PlaneDirection.TOP, angle); CategoryLabelPosition bottom = createUpRotationCategoryLabelPosition(PlaneDirection.BOTTOM, angle); CategoryLabelPosition left = createUpRotationCategoryLabelPosition(PlaneDirection.LEFT, angle); CategoryLabelPosition right = createUpRotationCategoryLabelPosition(PlaneDirection.RIGHT, angle); CategoryLabelPositions rotationLabelPositions = new CategoryLabelPositions(top, bottom, left, right); categoryAxis.setCategoryLabelPositions(rotationLabelPositions); } final String[] colors = getSeriesColor(); for (int i = 0; i < colors.length; i++) { renderer.setSeriesPaint(i, parseColorFromString(colors[i])); } if (lowerMargin != null) { categoryAxis.setLowerMargin(lowerMargin.doubleValue()); } if (upperMargin != null) { categoryAxis.setUpperMargin(upperMargin.doubleValue()); } if (categoryMargin != null) { categoryAxis.setCategoryMargin(categoryMargin.doubleValue()); } configureRangeAxis(cpl, labelFont); }