List of usage examples for java.math BigDecimal setScale
@Deprecated(since = "9") public BigDecimal setScale(int newScale, int roundingMode)
From source file:com.salesmanager.core.util.ProductUtil.java
public static BigDecimal determinePriceWithAttributes(Product product, Collection attributes, Locale locale, String currency) {//from w ww.ja va 2s . com int decimalPlace = 2; Map currenciesmap = RefCache.getCurrenciesListWithCodes(); Currency c = (Currency) currenciesmap.get(currency); // prices BigDecimal bdprodprice = product.getProductPrice(); BigDecimal bddiscountprice = null; // discount price Special special = product.getSpecial(); Date dt = new Date(); java.util.Date spdate = null; java.util.Date spenddate = null; if (special != null) { spdate = special.getSpecialDateAvailable(); spenddate = special.getExpiresDate(); if (spdate.before(new Date(dt.getTime())) && spenddate.after(new Date(dt.getTime()))) { bddiscountprice = special.getSpecialNewProductPrice(); } } // all other prices Set prices = product.getPrices(); if (prices != null) { Iterator pit = prices.iterator(); while (pit.hasNext()) { ProductPrice pprice = (ProductPrice) pit.next(); pprice.setLocale(locale); if (pprice.isDefaultPrice()) {// overwrites default price bddiscountprice = null; spdate = null; spenddate = null; bdprodprice = pprice.getProductPriceAmount(); ProductPriceSpecial ppspecial = pprice.getSpecial(); if (ppspecial != null) { if (ppspecial.getProductPriceSpecialStartDate() != null && ppspecial.getProductPriceSpecialEndDate() != null && ppspecial.getProductPriceSpecialStartDate().before(new Date(dt.getTime())) && ppspecial.getProductPriceSpecialEndDate().after(new Date(dt.getTime()))) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } else if (ppspecial.getProductPriceSpecialDurationDays() > -1) { bddiscountprice = ppspecial.getProductPriceSpecialAmount(); } } break; } } } double fprodprice = 0; ; if (bdprodprice != null) { fprodprice = bdprodprice.setScale(decimalPlace, BigDecimal.ROUND_HALF_UP).doubleValue(); } // determine any properties prices BigDecimal attributesPrice = null; if (attributes != null) { Iterator i = attributes.iterator(); while (i.hasNext()) { ProductAttribute attr = (ProductAttribute) i.next(); if (!attr.isAttributeDisplayOnly() && attr.getOptionValuePrice().longValue() > 0) { if (attributesPrice == null) { attributesPrice = new BigDecimal(0); } attributesPrice = attributesPrice.add(attr.getOptionValuePrice()); } } } if (bddiscountprice != null) { if (attributesPrice != null) { bddiscountprice = bddiscountprice.add(attributesPrice); } return bddiscountprice; } else { if (attributesPrice != null) { bdprodprice = bdprodprice.add(attributesPrice); } return bdprodprice; } }
From source file:org.egov.adtax.service.AdvertisementDemandService.java
public Map<String, BigDecimal> checkPendingAmountByDemand(final AdvertisementPermitDetail advPermitDetail) { final Map<String, BigDecimal> demandFeeType = new LinkedHashMap<>(); BigDecimal totalDemand = BigDecimal.ZERO; BigDecimal totalCollection = BigDecimal.ZERO; BigDecimal totalPending = BigDecimal.ZERO; BigDecimal penaltyAmount = BigDecimal.ZERO; BigDecimal additionalTaxAmount = BigDecimal.ZERO; if (advPermitDetail != null && advPermitDetail.getAdvertisement() != null && advPermitDetail.getAdvertisement().getDemandId() != null) { for (final EgDemandDetails demandDtl : advPermitDetail.getAdvertisement().getDemandId() .getEgDemandDetails()) { totalDemand = totalDemand.add(demandDtl.getAmount()); totalCollection = totalCollection.add(demandDtl.getAmtCollected()); totalPending = totalPending.add(demandDtl.getAmount().subtract(demandDtl.getAmtCollected())); }//www.java2 s . c om penaltyAmount = advertisementPenaltyCalculator.calculatePenalty(advPermitDetail); additionalTaxAmount = advertisementAdditionalTaxCalculator .getTotalAdditionalTaxesByPassingAdvertisementPermit(advPermitDetail); } totalDemand = totalDemand.setScale(2, BigDecimal.ROUND_HALF_EVEN); totalCollection = totalCollection.setScale(2, BigDecimal.ROUND_HALF_EVEN); totalPending = totalPending.setScale(2, BigDecimal.ROUND_HALF_EVEN); penaltyAmount = penaltyAmount.setScale(2, BigDecimal.ROUND_HALF_EVEN); demandFeeType.put(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT, totalPending); demandFeeType.put(AdvertisementTaxConstants.TOTAL_DEMAND, totalDemand); demandFeeType.put(AdvertisementTaxConstants.TOTALCOLLECTION, totalCollection); demandFeeType.put(AdvertisementTaxConstants.PENALTYAMOUNT, penaltyAmount); demandFeeType.put(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT, additionalTaxAmount.setScale(0, BigDecimal.ROUND_HALF_UP)); return demandFeeType; }
From source file:org.apache.ofbiz.shipment.thirdparty.usps.UspsServices.java
public static Map<String, Object> uspsRateInquire(DispatchContext dctx, Map<String, ? extends Object> context) { Delegator delegator = dctx.getDelegator(); String shipmentGatewayConfigId = (String) context.get("shipmentGatewayConfigId"); String resource = (String) context.get("configProps"); Locale locale = (Locale) context.get("locale"); // check for 0 weight BigDecimal shippableWeight = (BigDecimal) context.get("shippableWeight"); if (shippableWeight.compareTo(BigDecimal.ZERO) == 0) { // TODO: should we return an error, or $0.00 ? return ServiceUtil.returnFailure(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsShippableWeightMustGreaterThanZero", locale)); }//from w w w. ja v a2s . com // get the origination ZIP String originationZip = null; GenericValue productStore = ProductStoreWorker.getProductStore(((String) context.get("productStoreId")), delegator); if (productStore != null && productStore.get("inventoryFacilityId") != null) { GenericValue facilityContactMech = ContactMechWorker.getFacilityContactMechByPurpose(delegator, productStore.getString("inventoryFacilityId"), UtilMisc.toList("SHIP_ORIG_LOCATION", "PRIMARY_LOCATION")); if (facilityContactMech != null) { try { GenericValue shipFromAddress = EntityQuery.use(delegator).from("PostalAddress") .where("contactMechId", facilityContactMech.getString("contactMechId")).queryOne(); if (shipFromAddress != null) { originationZip = shipFromAddress.getString("postalCode"); } } catch (GenericEntityException e) { Debug.logError(e, module); } } } if (UtilValidate.isEmpty(originationZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsUnableDetermineOriginationZip", locale)); } // get the destination ZIP String destinationZip = null; String shippingContactMechId = (String) context.get("shippingContactMechId"); if (UtilValidate.isNotEmpty(shippingContactMechId)) { try { GenericValue shipToAddress = EntityQuery.use(delegator).from("PostalAddress") .where("contactMechId", shippingContactMechId).queryOne(); if (shipToAddress != null) { if (!domesticCountries.contains(shipToAddress.getString("countryGeoId"))) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateInquiryOnlyInUsDestinations", locale)); } destinationZip = shipToAddress.getString("postalCode"); } } catch (GenericEntityException e) { Debug.logError(e, module); } } if (UtilValidate.isEmpty(destinationZip)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsUnableDetermineDestinationZip", locale)); } // get the service code String serviceCode = null; try { GenericValue carrierShipmentMethod = EntityQuery.use(delegator).from("CarrierShipmentMethod") .where("shipmentMethodTypeId", (String) context.get("shipmentMethodTypeId"), "partyId", (String) context.get("carrierPartyId"), "roleTypeId", (String) context.get("carrierRoleTypeId")) .queryOne(); if (carrierShipmentMethod != null) { serviceCode = carrierShipmentMethod.getString("carrierServiceCode").toUpperCase(); } } catch (GenericEntityException e) { Debug.logError(e, module); } if (UtilValidate.isEmpty(serviceCode)) { return ServiceUtil.returnError(UtilProperties.getMessage(resourceError, "FacilityShipmentUspsUnableDetermineServiceCode", locale)); } // create the request document Document requestDocument = createUspsRequestDocument("RateV2Request", true, delegator, shipmentGatewayConfigId, resource); // TODO: 70 lb max is valid for Express, Priority and Parcel only - handle other methods BigDecimal maxWeight = new BigDecimal("70"); String maxWeightStr = getShipmentGatewayConfigValue(delegator, shipmentGatewayConfigId, "maxEstimateWeight", resource, "shipment.usps.max.estimate.weight", "70"); try { maxWeight = new BigDecimal(maxWeightStr); } catch (NumberFormatException e) { Debug.logWarning( "Error parsing max estimate weight string [" + maxWeightStr + "], using default instead", module); maxWeight = new BigDecimal("70"); } List<Map<String, Object>> shippableItemInfo = UtilGenerics.checkList(context.get("shippableItemInfo")); List<Map<String, BigDecimal>> packages = ShipmentWorker.getPackageSplit(dctx, shippableItemInfo, maxWeight); boolean isOnePackage = packages.size() == 1; // use shippableWeight if there's only one package // TODO: Up to 25 packages can be included per request - handle more than 25 for (ListIterator<Map<String, BigDecimal>> li = packages.listIterator(); li.hasNext();) { Map<String, BigDecimal> packageMap = li.next(); BigDecimal packageWeight = isOnePackage ? shippableWeight : ShipmentWorker.calcPackageWeight(dctx, packageMap, shippableItemInfo, BigDecimal.ZERO); if (packageWeight.compareTo(BigDecimal.ZERO) == 0) { continue; } Element packageElement = UtilXml.addChildElement(requestDocument.getDocumentElement(), "Package", requestDocument); packageElement.setAttribute("ID", String.valueOf(li.nextIndex() - 1)); // use zero-based index (see examples) UtilXml.addChildElementValue(packageElement, "Service", serviceCode, requestDocument); UtilXml.addChildElementValue(packageElement, "ZipOrigination", StringUtils.substring(originationZip, 0, 5), requestDocument); UtilXml.addChildElementValue(packageElement, "ZipDestination", StringUtils.substring(destinationZip, 0, 5), requestDocument); BigDecimal weightPounds = packageWeight.setScale(0, BigDecimal.ROUND_FLOOR); // for Parcel post, the weight must be at least 1 lb if ("PARCEL".equals(serviceCode.toUpperCase()) && (weightPounds.compareTo(BigDecimal.ONE) < 0)) { weightPounds = BigDecimal.ONE; packageWeight = BigDecimal.ZERO; } // (packageWeight % 1) * 16 (Rounded up to 0 dp) BigDecimal weightOunces = packageWeight.remainder(BigDecimal.ONE).multiply(new BigDecimal("16")) .setScale(0, BigDecimal.ROUND_CEILING); UtilXml.addChildElementValue(packageElement, "Pounds", weightPounds.toPlainString(), requestDocument); UtilXml.addChildElementValue(packageElement, "Ounces", weightOunces.toPlainString(), requestDocument); // TODO: handle other container types, package sizes, and machinable packages // IMPORTANT: Express or Priority Mail will fail if you supply a Container tag: you will get a message like // Invalid container type. Valid container types for Priority Mail are Flat Rate Envelope and Flat Rate Box. /* This is an official response from the United States Postal Service: The <Container> tag is used to specify the flat rate mailing options, or the type of large or oversized package being mailed. If you are wanting to get regular Express Mail rates, leave the <Container> tag empty, or do not include it in the request at all. */ if ("Parcel".equalsIgnoreCase(serviceCode)) { UtilXml.addChildElementValue(packageElement, "Container", "None", requestDocument); } UtilXml.addChildElementValue(packageElement, "Size", "REGULAR", requestDocument); UtilXml.addChildElementValue(packageElement, "Machinable", "false", requestDocument); } // send the request Document responseDocument = null; try { responseDocument = sendUspsRequest("RateV2", requestDocument, delegator, shipmentGatewayConfigId, resource, locale); } catch (UspsRequestException e) { Debug.logInfo(e, module); return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentUspsRateDomesticSendingError", UtilMisc.toMap("errorString", e.getMessage()), locale)); } if (responseDocument == null) { return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentRateNotAvailable", locale)); } List<? extends Element> rates = UtilXml.childElementList(responseDocument.getDocumentElement(), "Package"); if (UtilValidate.isEmpty(rates)) { return ServiceUtil.returnError( UtilProperties.getMessage(resourceError, "FacilityShipmentRateNotAvailable", locale)); } BigDecimal estimateAmount = BigDecimal.ZERO; for (Element packageElement : rates) { try { Element postageElement = UtilXml.firstChildElement(packageElement, "Postage"); BigDecimal packageAmount = new BigDecimal(UtilXml.childElementValue(postageElement, "Rate")); estimateAmount = estimateAmount.add(packageAmount); } catch (NumberFormatException e) { Debug.logInfo(e, module); } } Map<String, Object> result = ServiceUtil.returnSuccess(); result.put("shippingEstimateAmount", estimateAmount); return result; }
From source file:org.egov.wtms.service.es.WaterChargeCollectionDocService.java
public List<WaterChargeConnectionTypeResponse> getFullCollectionIndexDtlsForCOnnectionType( final WaterChargeDashBoardRequest collectionDetailsRequest) { final List<WaterChargeConnectionTypeResponse> collectionIndexDetailsList = new ArrayList<>(); final WaterChargeConnectionTypeResponse collectionIndexDetails = new WaterChargeConnectionTypeResponse(); Date fromDate;//w w w . j av a2 s .c om Date toDate; BigDecimal todayColl;// need to test BigDecimal tillDateColl;// need to test final Long startTime = System.currentTimeMillis(); final CFinancialYear financialyear = cFinancialYearService.getCurrentFinancialYear(); /** * As per Elastic Search functionality, to get the total collections * between 2 dates, add a day to the endDate and fetch the results For * Current day's collection if dates are sent in the request, consider * the toDate, else take date range between current date +1 day */ if (StringUtils.isNotBlank(collectionDetailsRequest.getFromDate()) && StringUtils.isNotBlank(collectionDetailsRequest.getToDate())) { fromDate = DateUtils.getDate(collectionDetailsRequest.getFromDate(), DATE_FORMAT_YYYYMMDD); toDate = org.apache.commons.lang3.time.DateUtils .addDays(DateUtils.getDate(collectionDetailsRequest.getToDate(), DATE_FORMAT_YYYYMMDD), 1); } else { fromDate = new Date(); toDate = org.apache.commons.lang3.time.DateUtils.addDays(new Date(), 1); } // Todays collection todayColl = getCollectionBetweenDates(collectionDetailsRequest, fromDate, toDate, null); collectionIndexDetails.setTodayColl(todayColl); // Last year Todays day collection todayColl = getCollectionBetweenDates(collectionDetailsRequest, org.apache.commons.lang3.time.DateUtils.addYears(fromDate, -1), org.apache.commons.lang3.time.DateUtils.addYears(toDate, -1), null); collectionIndexDetails.setLastYearTodayColl(todayColl); /** * For collections between the date ranges if dates are sent in the * request, consider the same, else calculate from current year start * date till current date+1 day */ if (StringUtils.isNotBlank(collectionDetailsRequest.getFromDate()) && StringUtils.isNotBlank(collectionDetailsRequest.getToDate())) { fromDate = DateUtils.getDate(collectionDetailsRequest.getFromDate(), DATE_FORMAT_YYYYMMDD); toDate = org.apache.commons.lang3.time.DateUtils .addDays(DateUtils.getDate(collectionDetailsRequest.getToDate(), DATE_FORMAT_YYYYMMDD), 1); } else { fromDate = DateUtils.startOfDay(financialyear.getStartingDate()); toDate = org.apache.commons.lang3.time.DateUtils.addDays(new Date(), 1); } // Current Year till today collection tillDateColl = getCollectionBetweenDates(collectionDetailsRequest, fromDate, toDate, null); collectionIndexDetails.setCurrentYearTillDateColl(tillDateColl); // Last year till same date of todays date collection tillDateColl = getCollectionBetweenDates(collectionDetailsRequest, org.apache.commons.lang3.time.DateUtils.addYears(fromDate, -1), org.apache.commons.lang3.time.DateUtils.addYears(toDate, -1), null); collectionIndexDetails.setLastYearTillDateColl(tillDateColl); final Long timeTaken = System.currentTimeMillis() - startTime; if (LOGGER.isDebugEnabled()) LOGGER.debug("Time taken by getCompleteCollectionIndexDetails() is (millisecs) : " + timeTaken); /** * For fetching total demand between the date ranges if dates are sent * in the request, consider fromDate and toDate+1 , else calculate from * current year start date till current date+1 day */ if (StringUtils.isNotBlank(collectionDetailsRequest.getFromDate()) && StringUtils.isNotBlank(collectionDetailsRequest.getToDate())) { fromDate = DateUtils.getDate(collectionDetailsRequest.getFromDate(), "yyyy-MM-dd"); toDate = org.apache.commons.lang3.time.DateUtils .addDays(DateUtils.getDate(collectionDetailsRequest.getToDate(), "yyyy-MM-dd"), 1); } else { fromDate = DateUtils.startOfDay(financialyear.getStartingDate()); toDate = org.apache.commons.lang3.time.DateUtils.addDays(new Date(), 1); } // starts from final BigDecimal totalDemand = getTotalDemandBasedOnInputFilters(collectionDetailsRequest); if (LOGGER.isDebugEnabled()) LOGGER.debug("Time taken by getTotalDemandBasedOnInputFilters() is (millisecs): " + timeTaken); final int noOfMonths = DateUtils.noOfMonthsBetween(fromDate, toDate) + 1; collectionIndexDetails.setTotalDmd(totalDemand); // Proportional Demand = (totalDemand/12)*noOfmonths final BigDecimal proportionalDemand = totalDemand.divide(BigDecimal.valueOf(12), BigDecimal.ROUND_HALF_UP) .multiply(BigDecimal.valueOf(noOfMonths)); if (proportionalDemand.compareTo(BigDecimal.ZERO) > 0) collectionIndexDetails .setCurrentYearTillDateDmd(proportionalDemand.setScale(0, BigDecimal.ROUND_HALF_UP)); if (proportionalDemand.compareTo(BigDecimal.ZERO) > 0) collectionIndexDetails.setPerformance( collectionIndexDetails.getCurrentYearTillDateColl().multiply(WaterTaxConstants.BIGDECIMAL_100) .divide(proportionalDemand, 1, BigDecimal.ROUND_HALF_UP)); BigDecimal variation; if (collectionIndexDetails.getLastYearTillDateColl().compareTo(BigDecimal.ZERO) == 0) variation = WaterTaxConstants.BIGDECIMAL_100; else variation = collectionIndexDetails.getCurrentYearTillDateColl() .subtract(collectionIndexDetails.getLastYearTillDateColl()) .multiply(WaterTaxConstants.BIGDECIMAL_100) .divide(collectionIndexDetails.getLastYearTillDateColl(), 1, BigDecimal.ROUND_HALF_UP); collectionIndexDetails.setLastYearVar(variation); if (LOGGER.isDebugEnabled()) LOGGER.debug( "Time taken for setting values in getConsolidatedDemandInfo() is (millisecs): " + timeTaken); collectionIndexDetailsList.add(collectionIndexDetails); return collectionIndexDetailsList; }
From source file:org.egov.works.web.actions.measurementbook.MeasurementBookAction.java
private BigDecimal getAmountsForCurrentMB(final List<MBDetails> mbDetailsList, final double negoPerc, final String tenderType) { BigDecimal currentMBTenderedAmt = BigDecimal.ZERO; BigDecimal currMBAmount = BigDecimal.ZERO; BigDecimal tenderedMBAmount = BigDecimal.ZERO; BigDecimal currMBTotal = BigDecimal.ZERO; if (tenderType.equalsIgnoreCase(WorksConstants.PERC_TENDER)) { for (final MBDetails mbd : mbDetailsList) if (mbd.getWorkOrderActivity().getActivity().getRevisionType() == null) currentMBTenderedAmt = currentMBTenderedAmt.add(BigDecimal.valueOf(mbd.getAmount())); currMBAmount = mbHeader.getTotalMBAmount(); // applying percentage on tendered items if (currentMBTenderedAmt != null) tenderedMBAmount = currentMBTenderedAmt .add(currentMBTenderedAmt.multiply(BigDecimal.valueOf(negoPerc / 100))); // adding tendered amount with the non tendered items amount, to get // the total mb amount currMBTotal = tenderedMBAmount.add(currMBAmount.subtract(currentMBTenderedAmt)); } else/*from w w w . jav a2 s. co m*/ currMBTotal = mbHeader.getTotalMBAmount(); return currMBTotal.setScale(2, RoundingMode.HALF_UP); }
From source file:org.egov.adtax.service.AdvertisementDemandService.java
/** * @param demand//from w w w.j a va 2s . c o m * @param penaltyCalculationDate * @return Penalty Amount and PendingAmount */ public Map<String, BigDecimal> checkPedingAmountByDemand(final AdvertisementPermitDetail advPermitDetail) { final Map<String, BigDecimal> demandFeeType = new LinkedHashMap<>(); BigDecimal penaltyAmt = BigDecimal.ZERO; BigDecimal pendingAmount = BigDecimal.ZERO; BigDecimal additionalTaxAmount = BigDecimal.ZERO; /** * Assumption: We are calculating penalty for total pending amount. If penalty is part of demand, then also we are * considering that amount for penalty calculation. */ if (advPermitDetail != null && advPermitDetail.getAdvertisement() != null && advPermitDetail.getAdvertisement().getDemandId() != null) { for (final EgDemandDetails demandDtl : advPermitDetail.getAdvertisement().getDemandId() .getEgDemandDetails()) if (demandDtl.getAmount().subtract(demandDtl.getAmtCollected()).compareTo(BigDecimal.ZERO) > 0) pendingAmount = pendingAmount.add(demandDtl.getAmount().subtract(demandDtl.getAmtCollected())); penaltyAmt = advertisementPenaltyCalculator.calculatePenalty(advPermitDetail); additionalTaxAmount = advertisementAdditionalTaxCalculator .getTotalAdditionalTaxesByPassingAdvertisementPermit(advPermitDetail); } demandFeeType.put(AdvertisementTaxConstants.PENALTYAMOUNT, penaltyAmt.setScale(0, BigDecimal.ROUND_HALF_UP)); demandFeeType.put(AdvertisementTaxConstants.ADDITIONALTAXAMOUNT, additionalTaxAmount.setScale(0, BigDecimal.ROUND_HALF_UP)); demandFeeType.put(AdvertisementTaxConstants.PENDINGDEMANDAMOUNT, pendingAmount.setScale(0, BigDecimal.ROUND_HALF_UP)); return demandFeeType; }
From source file:org.libreplan.importers.JiraOrderElementSynchronizer.java
/** * updates {@link DirectAdvanceAssignment} and {@link AdvanceMeasurement} if * they already exist, otherwise create new one * * @param orderElement/*w w w .j av a 2 s . c o 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:org.kuali.kfs.module.purap.document.ElectronicInvoiceRejectDocument.java
public KualiDecimal getTotalAmount() { KualiDecimal returnValue = new KualiDecimal(zero); try {//from w w w .j av a 2s . com for (ElectronicInvoiceRejectItem eiri : this.invoiceRejectItems) { BigDecimal toAddAmount1 = eiri.getInvoiceItemSubTotalAmount(); KualiDecimal toAddAmount = KualiDecimal.ZERO; if (toAddAmount1 != null) { toAddAmount = new KualiDecimal( toAddAmount1.setScale(KualiDecimal.SCALE, KualiDecimal.ROUND_BEHAVIOR)); } if (LOG.isDebugEnabled()) { LOG.debug("getTotalAmount() setting returnValue with arithmatic => '" + returnValue.doubleValue() + "' + '" + toAddAmount.doubleValue() + "'"); } returnValue = returnValue.add(toAddAmount); } if (LOG.isDebugEnabled()) { LOG.debug("getTotalAmount() returning amount " + returnValue.doubleValue()); } return returnValue; } catch (NumberFormatException n) { // do nothing this is already rejected LOG.error("getTotalAmount() Error attempting to calculate total amount for invoice with filename " + this.invoiceFileName); return new KualiDecimal(zero); } }
From source file:org.egov.services.voucher.VoucherService.java
public Map<String, Object> getVoucherInfo(final Long voucherId) { if (LOGGER.isDebugEnabled()) LOGGER.debug("VoucherService | getVoucherDetails | Start"); final Map<String, Object> voucherMap = new HashMap<>(); final CVoucherHeader voucherHeader = (CVoucherHeader) persistenceService .find("from CVoucherHeader where id=?", voucherId); voucherMap.put(Constants.VOUCHERHEADER, voucherHeader); final List<CGeneralLedger> glList = voucherHibDAO.getGLInfo(voucherHeader.getId()); if (LOGGER.isDebugEnabled()) LOGGER.debug("total number of general ledger entry " + glList.size()); final List<VoucherDetails> billDetailslist = new ArrayList<>(); final List<VoucherDetails> subLedgerlist = new ArrayList<>(); VoucherDetails voucherDetail;/*from w ww . j a va 2s . c o m*/ VoucherDetails subLedgerDetail; BigDecimal crAmount; BigDecimal drAmount; try { for (final CGeneralLedger generalLedger : glList) { voucherDetail = new VoucherDetails(); if (null != generalLedger.getFunctionId()) { voucherDetail.setFunctionIdDetail(Long.valueOf(generalLedger.getFunctionId().toString())); voucherDetail.setFunctionDetail(functionDAO .getFunctionById(Long.valueOf(generalLedger.getFunctionId().toString())).getName()); } voucherDetail.setGlcodeIdDetail(generalLedger.getGlcodeId().getId()); voucherDetail.setGlcodeDetail(generalLedger.getGlcodeId().getGlcode()); voucherDetail.setAccounthead(coaDAO.findById(generalLedger.getGlcodeId().getId(), false).getName()); drAmount = new BigDecimal(generalLedger.getDebitAmount()); crAmount = new BigDecimal(generalLedger.getCreditAmount()); voucherDetail.setDebitAmountDetail(drAmount.setScale(2, BigDecimal.ROUND_HALF_UP)); voucherDetail.setCreditAmountDetail(crAmount.setScale(2, BigDecimal.ROUND_HALF_UP)); billDetailslist.add(voucherDetail); final List<CGeneralLedgerDetail> gledgerDetailList = voucherHibDAO .getGeneralledgerdetail(generalLedger.getId()); for (final CGeneralLedgerDetail gledgerDetail : gledgerDetailList) { if (chartOfAccountDetailService.getByGlcodeIdAndDetailTypeId( generalLedger.getGlcodeId().getId(), gledgerDetail.getDetailTypeId().getId().intValue()) != null) { subLedgerDetail = new VoucherDetails(); subLedgerDetail.setAmount(gledgerDetail.getAmount().setScale(2)); subLedgerDetail.setGlcode(coaDAO.findById(generalLedger.getGlcodeId().getId(), false)); subLedgerDetail.setSubledgerCode(generalLedger.getGlcodeId().getGlcode()); final Accountdetailtype accountdetailtype = voucherHibDAO .getAccountDetailById(gledgerDetail.getDetailTypeId().getId()); subLedgerDetail.setDetailType(accountdetailtype); subLedgerDetail.setDetailTypeName(accountdetailtype.getName()); final EntityType entity = voucherHibDAO.getEntityInfo(gledgerDetail.getDetailKeyId(), accountdetailtype.getId()); subLedgerDetail.setDetailCode(entity.getCode()); subLedgerDetail.setDetailKeyId(gledgerDetail.getDetailKeyId()); subLedgerDetail.setDetailKey(entity.getName()); subLedgerDetail.setFunctionDetail( generalLedger.getFunctionId() != null ? generalLedger.getFunctionId().toString() : "0"); subLedgerlist.add(subLedgerDetail); } } } } catch (final HibernateException e) { LOGGER.error("Exception occured in VoucherSerive |getVoucherInfo " + e); } catch (final Exception e) { LOGGER.error("Exception occured in VoucherSerive |getVoucherInfo " + e); } voucherMap.put(Constants.GLDEATILLIST, billDetailslist); /** * create empty sub ledger row */ if (subLedgerlist.isEmpty()) subLedgerlist.add(new VoucherDetails()); voucherMap.put("subLedgerDetail", subLedgerlist); return voucherMap; }
From source file:org.egov.works.web.actions.contractorBill.ContractorBillAction.java
private void validateMBAmountAndBillAmount(final List<MBHeader> mbHeaderList) { BigDecimal totalMBAmount = BigDecimal.ZERO; for (final MBHeader mbh : mbHeaderList) totalMBAmount = totalMBAmount.add(mbh.getTotalMBAmount()); if (!(billAmount.setScale(2, RoundingMode.HALF_UP) .compareTo(totalMBAmount.setScale(2, RoundingMode.HALF_UP)) == 0)) addFieldError("billAmount.compare.total.mbAmount", getText("billAmount.compare.total.mbAmount")); }