Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/product/ProductWorker.java Mon Jan 5 23:13:36 2009 @@ -18,16 +18,26 @@ *******************************************************************************/ package org.ofbiz.product.product; +import java.math.BigDecimal; +import java.math.MathContext; +import java.sql.Timestamp; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; -import java.sql.Timestamp; + import javax.servlet.ServletRequest; import javax.servlet.jsp.PageContext; -import org.ofbiz.base.util.*; +import javolution.util.FastList; +import javolution.util.FastSet; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilDateTime; +import org.ofbiz.base.util.UtilFormatOut; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilValidate; import org.ofbiz.common.geo.GeoWorker; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericEntityException; @@ -38,9 +48,6 @@ import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ModelService; -import javolution.util.FastList; -import javolution.util.FastMap; -import javolution.util.FastSet; /** * Product Worker class to reduce code in JSPs. @@ -50,6 +57,8 @@ public static final String module = ProductWorker.class.getName(); public static final String resource = "ProductUiLabels"; + public static final MathContext generalRounding = new MathContext(10); + /** @deprecated */ public static void getProduct(PageContext pageContext, String attributeName) { getProduct(pageContext, attributeName, null); @@ -230,14 +239,14 @@ * invokes the getInventoryAvailableByFacility service, returns true if specified quantity is available, else false * this is only used in the related method that uses a ProductConfigWrapper, until that is refactored into a service as well... */ - private static boolean isProductInventoryAvailableByFacility(String productId, String inventoryFacilityId, double quantity, LocalDispatcher dispatcher) throws GenericServiceException { - Double availableToPromise = null; + private static boolean isProductInventoryAvailableByFacility(String productId, String inventoryFacilityId, BigDecimal quantity, LocalDispatcher dispatcher) throws GenericServiceException { + BigDecimal availableToPromise = null; try { Map<String, Object> result = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.toMap("productId", productId, "facilityId", inventoryFacilityId)); - availableToPromise = (Double) result.get("availableToPromiseTotal"); + availableToPromise = (BigDecimal) result.get("availableToPromiseTotal"); if (availableToPromise == null) { Debug.logWarning("The getInventoryAvailableByFacility service returned a null availableToPromise, the error message was:\n" + result.get(ModelService.ERROR_MESSAGE), module); @@ -249,7 +258,7 @@ } // check to see if we got enough back... - if (availableToPromise.doubleValue() >= quantity) { + if (availableToPromise.compareTo(quantity) >= 0) { if (Debug.infoOn()) Debug.logInfo("Inventory IS available in facility with id " + inventoryFacilityId + " for product id " + productId + "; desired quantity is " + quantity + ", available quantity is " + availableToPromise, module); return true; } else { @@ -262,17 +271,17 @@ * Invokes the getInventoryAvailableByFacility service, returns true if specified quantity is available for all the selected parts, else false. * Also, set the available flag for all the product configuration's options. **/ - public static boolean isProductInventoryAvailableByFacility(ProductConfigWrapper productConfig, String inventoryFacilityId, double quantity, LocalDispatcher dispatcher) throws GenericServiceException { + public static boolean isProductInventoryAvailableByFacility(ProductConfigWrapper productConfig, String inventoryFacilityId, BigDecimal quantity, LocalDispatcher dispatcher) throws GenericServiceException { boolean available = true; List<ConfigOption> options = productConfig.getSelectedOptions(); for (ConfigOption ci: options) { List<GenericValue> products = ci.getComponents(); for (GenericValue product: products) { String productId = product.getString("productId"); - Double cmpQuantity = product.getDouble("quantity"); - double neededQty = 1.0; + BigDecimal cmpQuantity = product.getBigDecimal("quantity"); + BigDecimal neededQty = BigDecimal.ZERO; if (cmpQuantity != null) { - neededQty = quantity * cmpQuantity.doubleValue(); + neededQty = quantity.multiply(cmpQuantity); } if (!isProductInventoryAvailableByFacility(productId, inventoryFacilityId, neededQty, dispatcher)) { ci.setAvailable(false); @@ -563,26 +572,26 @@ // product calc methods - public static double calcOrderAdjustments(List<GenericValue> orderHeaderAdjustments, double subTotal, boolean includeOther, boolean includeTax, boolean includeShipping) { - double adjTotal = 0.0; + public static BigDecimal calcOrderAdjustments(List<GenericValue> orderHeaderAdjustments, BigDecimal subTotal, boolean includeOther, boolean includeTax, boolean includeShipping) { + BigDecimal adjTotal = BigDecimal.ZERO; if (UtilValidate.isNotEmpty(orderHeaderAdjustments)) { List<GenericValue> filteredAdjs = filterOrderAdjustments(orderHeaderAdjustments, includeOther, includeTax, includeShipping, false, false); for (GenericValue orderAdjustment: filteredAdjs) { - adjTotal += calcOrderAdjustment(orderAdjustment, subTotal); + adjTotal = adjTotal.add(calcOrderAdjustment(orderAdjustment, subTotal)); } } return adjTotal; } - public static double calcOrderAdjustment(GenericValue orderAdjustment, double orderSubTotal) { - double adjustment = 0.0; + public static BigDecimal calcOrderAdjustment(GenericValue orderAdjustment, BigDecimal orderSubTotal) { + BigDecimal adjustment = BigDecimal.ZERO; if (orderAdjustment.get("amount") != null) { - adjustment += orderAdjustment.getDouble("amount").doubleValue(); + adjustment = adjustment.add(orderAdjustment.getBigDecimal("amount")); } else if (orderAdjustment.get("sourcePercentage") != null) { - adjustment += (orderAdjustment.getDouble("sourcePercentage").doubleValue() * orderSubTotal); + adjustment = adjustment.add(orderAdjustment.getBigDecimal("sourcePercentage").multiply(orderSubTotal)); } return adjustment; } @@ -620,11 +629,11 @@ return newOrderAdjustmentsList; } - public static double getAverageProductRating(GenericDelegator delegator, String productId) { + public static BigDecimal getAverageProductRating(GenericDelegator delegator, String productId) { return getAverageProductRating(delegator, productId, null); } - public static double getAverageProductRating(GenericDelegator delegator, String productId, String productStoreId) { + public static BigDecimal getAverageProductRating(GenericDelegator delegator, String productId, String productStoreId) { GenericValue product = null; try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); @@ -634,30 +643,30 @@ return ProductWorker.getAverageProductRating(product, productStoreId); } - public static double getAverageProductRating(GenericValue product, String productStoreId) { + public static BigDecimal getAverageProductRating(GenericValue product, String productStoreId) { return getAverageProductRating(product, null, productStoreId); } - public static double getAverageProductRating(GenericValue product, List<GenericValue> reviews, String productStoreId) { + public static BigDecimal getAverageProductRating(GenericValue product, List<GenericValue> reviews, String productStoreId) { if (product == null) { Debug.logWarning("Invalid product entity passed; unable to obtain valid product rating", module); - return 0.00; + return BigDecimal.ZERO; } - double productRating = 0.00; - Double productEntityRating = product.getDouble("productRating"); + BigDecimal productRating = BigDecimal.ZERO; + BigDecimal productEntityRating = product.getBigDecimal("productRating"); String entityFieldType = product.getString("ratingTypeEnum"); // null check if (productEntityRating == null) { - productEntityRating = Double.valueOf(0); + productEntityRating = BigDecimal.ZERO; } if (entityFieldType == null) { entityFieldType = ""; } if ("PRDR_FLAT".equals(entityFieldType)) { - productRating = productEntityRating.doubleValue(); + productRating = productEntityRating; } else { // get the product rating from the ProductReview entity; limit by product store if ID is passed Map<String, String> reviewByAnd = UtilMisc.toMap("statusId", "PRR_APPROVED"); @@ -675,30 +684,30 @@ } // tally the average - double ratingTally = 0; - double numRatings = 0; + BigDecimal ratingTally = BigDecimal.ZERO; + BigDecimal numRatings = BigDecimal.ZERO; if (reviews != null) { for (GenericValue productReview: reviews) { - Double rating = productReview.getDouble("productRating"); + BigDecimal rating = productReview.getBigDecimal("productRating"); if (rating != null) { - ratingTally += rating.doubleValue(); - numRatings++; + ratingTally = ratingTally.add(rating); + numRatings.add(BigDecimal.ONE); } } } - if (ratingTally > 0 && numRatings > 0) { - productRating = ratingTally / numRatings; + if (ratingTally.compareTo(BigDecimal.ZERO) > 0 && numRatings.compareTo(BigDecimal.ZERO) > 0) { + productRating = ratingTally.divide(numRatings, generalRounding); } if ("PRDR_MIN".equals(entityFieldType)) { // check for min - if (productEntityRating.doubleValue() > productRating) { - productRating = productEntityRating.doubleValue(); + if (productEntityRating.compareTo(productRating) > 0) { + productRating = productEntityRating; } } else if ("PRDR_MAX".equals(entityFieldType)) { // check for max - if (productRating > productEntityRating.doubleValue()) { - productRating = productEntityRating.doubleValue(); + if (productRating.compareTo(productEntityRating) > 0) { + productRating = productEntityRating; } } } @@ -990,8 +999,8 @@ String featurTo = incompatibilityVariant.getString("productFeatureIdTo"); for (String paramValueTo: selectedFeatures) { if(featurTo.equals(paramValueTo)){ - GenericValue featureFrom = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featur)); - GenericValue featureTo = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featurTo)); + //GenericValue featureFrom = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featur)); + //GenericValue featureTo = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featurTo)); //String message = UtilProperties.getMessage(resource, "cart.addToCart.incompatibilityVariantFeature", locale) + ":/" + featureFrom.getString("description") + "/ => /" + featureTo.getString("description") +"/"; //request.setAttribute("_ERROR_MESSAGE_", message); //return "incompatibilityVariantFeature"; @@ -1017,8 +1026,8 @@ } } if (!found) { - GenericValue featureFrom = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featur)); - GenericValue featureTo = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featurTo)); + //GenericValue featureFrom = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featur)); + //GenericValue featureTo = (GenericValue) delegator.findByPrimaryKey("ProductFeature", UtilMisc.toMap("productFeatureId", featurTo)); //String message = UtilProperties.getMessage(resource, "cart.addToCart.dependencyVariantFeature", locale) + ":/" + featureFrom.getString("description") + "/ => /" + featureTo.getString("description") +"/"; //request.setAttribute("_ERROR_MESSAGE_", message); Debug.logWarning("Dependancy features", module); @@ -1084,12 +1093,12 @@ if (UtilValidate.isNotEmpty(productFeaturePrices)) { GenericValue productFeaturePrice = productFeaturePrices.get(0); if (UtilValidate.isNotEmpty(productFeaturePrice)) { - productPrice.put("price", productPrice.getDouble("price").doubleValue() + productFeaturePrice.getDouble("price").doubleValue()); + productPrice.put("price", productPrice.getBigDecimal("price").add(productFeaturePrice.getBigDecimal("price"))); } } } if (productPrice.get("price") == null) { - productPrice.put("price", productPrice.getDouble("price").doubleValue()); + productPrice.put("price", productPrice.getBigDecimal("price")); } productPrice.put("productId", product.getString("productId")); productPrice.create(); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductHelper.java Mon Jan 5 23:13:36 2009 @@ -19,6 +19,7 @@ package org.ofbiz.product.spreadsheetimport; +import java.math.BigDecimal; import java.util.Map; import javolution.util.FastMap; @@ -46,15 +47,15 @@ // prepare the inventoryItem map public static Map<String, Object> prepareInventoryItem(String productId, - double quantityOnHand, String inventoryItemId) { + BigDecimal quantityOnHand, String inventoryItemId) { Map<String, Object> fields = FastMap.newInstance(); fields.put("inventoryItemId", inventoryItemId); fields.put("inventoryItemTypeId", "NON_SERIAL_INV_ITEM"); fields.put("productId", productId); fields.put("ownerPartyId", "Company"); fields.put("facilityId", "WebStoreWarehouse"); - fields.put("quantityOnHandTotal", Double.valueOf(quantityOnHand)); - fields.put("availableToPromiseTotal", Double.valueOf(quantityOnHand)); + fields.put("quantityOnHandTotal", quantityOnHand); + fields.put("availableToPromiseTotal", quantityOnHand); return fields; } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/spreadsheetimport/ImportProductServices.java Mon Jan 5 23:13:36 2009 @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.math.BigDecimal; import java.util.List; import java.util.Map; @@ -117,9 +118,9 @@ String productId = cell1.getStringCellValue(); // read QOH from ninth column HSSFCell cell8 = row.getCell((short) 8); - double quantityOnHand = 0.0; + BigDecimal quantityOnHand = BigDecimal.ZERO; if (cell8 != null && cell8.getCellType() == HSSFCell.CELL_TYPE_NUMERIC) - quantityOnHand = cell8.getNumericCellValue(); + quantityOnHand = new BigDecimal(cell8.getNumericCellValue()); // check productId if null then skip creating inventory item // too. @@ -128,11 +129,11 @@ if (productId != null && !productId.trim().equalsIgnoreCase("") && !productExists) { products.add(ImportProductHelper.prepareProduct(productId)); - if (quantityOnHand >= 0.0) + if (quantityOnHand.compareTo(BigDecimal.ZERO) >= 0) inventoryItems.add(ImportProductHelper.prepareInventoryItem(productId, quantityOnHand, delegator.getNextSeqId("InventoryItem"))); else - inventoryItems.add(ImportProductHelper.prepareInventoryItem(productId, 0.0, delegator + inventoryItems.add(ImportProductHelper.prepareInventoryItem(productId, BigDecimal.ZERO, delegator .getNextSeqId("InventoryItem"))); } int rowNum = row.getRowNum() + 1; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/store/ProductStoreWorker.java Mon Jan 5 23:13:36 2009 @@ -18,10 +18,12 @@ *******************************************************************************/ package org.ofbiz.product.store; +import java.math.BigDecimal; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Random; + import javax.servlet.ServletRequest; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; @@ -208,7 +210,7 @@ return EntityUtil.getFirst(getProductStoreShipmentMethods(delegator, productStoreId, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId)); } - public static List<GenericValue> getAvailableStoreShippingMethods(GenericDelegator delegator, String productStoreId, GenericValue shippingAddress, List<Double> itemSizes, Map<String, Double> featureIdMap, double weight, double orderTotal) { + public static List<GenericValue> getAvailableStoreShippingMethods(GenericDelegator delegator, String productStoreId, GenericValue shippingAddress, List<BigDecimal> itemSizes, Map<String, BigDecimal> featureIdMap, BigDecimal weight, BigDecimal orderTotal) { if (featureIdMap == null) { featureIdMap = FastMap.newInstance(); } @@ -227,42 +229,42 @@ for (GenericValue method: shippingMethods) { // test min/max weight first - Double minWeight = method.getDouble("minWeight"); - Double maxWeight = method.getDouble("maxWeight"); - if (minWeight != null && minWeight.doubleValue() > 0 && minWeight.doubleValue() > weight) { + BigDecimal minWeight = method.getBigDecimal("minWeight"); + BigDecimal maxWeight = method.getBigDecimal("maxWeight"); + if (minWeight != null && minWeight.compareTo(BigDecimal.ZERO) > 0 && minWeight.compareTo(weight) > 0) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to not enough weight", module); continue; } - if (maxWeight != null && maxWeight.doubleValue() > 0 && maxWeight.doubleValue() < weight) { + if (maxWeight != null && maxWeight.compareTo(BigDecimal.ZERO) > 0 && maxWeight.compareTo(weight) < 0) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to too much weight", module); continue; } // test order total - Double minTotal = method.getDouble("minTotal"); - Double maxTotal = method.getDouble("maxTotal"); - if (minTotal != null && minTotal.doubleValue() > 0 && minTotal.doubleValue() > orderTotal) { + BigDecimal minTotal = method.getBigDecimal("minTotal"); + BigDecimal maxTotal = method.getBigDecimal("maxTotal"); + if (minTotal != null && minTotal.compareTo(BigDecimal.ZERO) > 0 && minTotal.compareTo(orderTotal) > 0) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to not enough order total", module); continue; } - if (maxTotal != null && maxTotal.doubleValue() > 0 && maxTotal.doubleValue() < orderTotal) { + if (maxTotal != null && maxTotal.compareTo(BigDecimal.ZERO) > 0 && maxTotal.compareTo(orderTotal) < 0) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to too much shipping total", module); continue; } // test product sizes - Double minSize = method.getDouble("minSize"); - Double maxSize = method.getDouble("maxSize"); - if (minSize != null && minSize.doubleValue() > 0) { + BigDecimal minSize = method.getBigDecimal("minSize"); + BigDecimal maxSize = method.getBigDecimal("maxSize"); + if (minSize != null && minSize.compareTo(BigDecimal.ZERO) > 0) { boolean allMatch = false; if (itemSizes != null) { allMatch = true; - for (Double size: itemSizes) { - if (size.doubleValue() < minSize.doubleValue()) { + for (BigDecimal size: itemSizes) { + if (size.compareTo(minSize) < 0) { allMatch = false; } } @@ -273,12 +275,12 @@ continue; } } - if (maxSize != null && maxSize.doubleValue() > 0) { + if (maxSize != null && maxSize.compareTo(BigDecimal.ZERO) > 0) { boolean allMatch = false; if (itemSizes != null) { allMatch = true; - for (Double size: itemSizes) { - if (size.doubleValue() > maxSize.doubleValue()) { + for (BigDecimal size: itemSizes) { + if (size.compareTo(maxSize) > 0) { allMatch = false; } } @@ -324,7 +326,7 @@ // check the items excluded from shipping String includeFreeShipping = method.getString("includeNoChargeItems"); if (includeFreeShipping != null && "N".equalsIgnoreCase(includeFreeShipping)) { - if ((itemSizes == null || itemSizes.size() == 0) && orderTotal == 0) { + if ((itemSizes == null || itemSizes.size() == 0) && orderTotal.compareTo(BigDecimal.ZERO) == 0) { returnShippingMethods.remove(method); //Debug.logInfo("Removed shipping method due to all items being exempt from shipping", module); continue; @@ -562,7 +564,7 @@ return isStoreInventoryRequiredAndAvailable(request, product, null, Boolean.TRUE, null); } - public static boolean isStoreInventoryAvailable(ServletRequest request, GenericValue product, Double quantity) { + public static boolean isStoreInventoryAvailable(ServletRequest request, GenericValue product, BigDecimal quantity) { return isStoreInventoryRequiredAndAvailable(request, product, quantity, null, Boolean.TRUE); } @@ -576,7 +578,7 @@ * @param wantRequired If true then inventory required must be true for the result to be true, if false must be false; if null don't care * @param wantAvailable If true then inventory avilable must be true for the result to be true, if false must be false; if null don't care */ - public static boolean isStoreInventoryRequiredAndAvailable(ServletRequest request, GenericValue product, Double quantity, Boolean wantRequired, Boolean wantAvailable) { + public static boolean isStoreInventoryRequiredAndAvailable(ServletRequest request, GenericValue product, BigDecimal quantity, Boolean wantRequired, Boolean wantAvailable) { GenericValue productStore = getProductStore(request); if (productStore == null) { Debug.logWarning("No ProductStore found, return false for inventory check", module); @@ -587,7 +589,7 @@ return false; } - if (quantity == null) quantity = Double.valueOf(1); + if (quantity == null) quantity = BigDecimal.ONE; String productStoreId = productStore.getString("productStoreId"); LocalDispatcher dispatcher = (LocalDispatcher) request.getAttribute("dispatcher"); @@ -625,7 +627,7 @@ } } - public static boolean isStoreInventoryAvailable(ServletRequest request, ProductConfigWrapper productConfig, double quantity) { + public static boolean isStoreInventoryAvailable(ServletRequest request, ProductConfigWrapper productConfig, BigDecimal quantity) { GenericValue productStore = getProductStore(request); if (productStore == null) { @@ -640,7 +642,7 @@ } /** check inventory availability for the given catalog, product, quantity, etc */ - public static boolean isStoreInventoryAvailable(String productStoreId, ProductConfigWrapper productConfig, double quantity, GenericDelegator delegator, LocalDispatcher dispatcher) { + public static boolean isStoreInventoryAvailable(String productStoreId, ProductConfigWrapper productConfig, BigDecimal quantity, GenericDelegator delegator, LocalDispatcher dispatcher) { GenericValue productStore = getProductStore(productStoreId, delegator); if (productStore == null) { Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/subscription/SubscriptionServices.java Mon Jan 5 23:13:36 2009 @@ -18,6 +18,7 @@ *******************************************************************************/ package org.ofbiz.product.subscription; +import java.math.BigDecimal; import java.sql.Timestamp; import java.util.Calendar; import java.util.List; @@ -244,7 +245,7 @@ subContext.put("orderCreatedDate", orderCreatedDate); List<GenericValue> orderItemList = orderHeader.getRelated("OrderItem"); for (GenericValue orderItem: orderItemList) { - Double qty = orderItem.getDouble("quantity"); + BigDecimal qty = orderItem.getBigDecimal("quantity"); String productId = orderItem.getString("productId"); if (UtilValidate.isEmpty(productId)) { continue; Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/supplier/SupplierProductServices.java Mon Jan 5 23:13:36 2009 @@ -19,6 +19,7 @@ package org.ofbiz.product.supplier; +import java.math.BigDecimal; import java.util.Collection; import java.util.List; import java.util.Map; @@ -62,7 +63,7 @@ String productId = (String) context.get("productId"); String partyId = (String) context.get("partyId"); String currencyUomId = (String) context.get("currencyUomId"); - Double quantity =(Double) context.get("quantity"); + BigDecimal quantity =(BigDecimal) context.get("quantity"); String canDropShip = (String) context.get("canDropShip"); try { product = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", productId)); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/test/InventoryItemTransferTest.java Mon Jan 5 23:13:36 2009 @@ -28,6 +28,7 @@ import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilDateTime; +import java.math.BigDecimal; import java.util.Map; import javolution.util.FastMap; @@ -37,7 +38,7 @@ protected GenericDelegator delegator = null; protected GenericValue userLogin = null; protected static String inventoryTransferId = null; - protected double transferQty = 1; + protected BigDecimal transferQty = BigDecimal.ONE; public InventoryItemTransferTest(String name) { super(name); @@ -61,7 +62,7 @@ ctx.put("facilityId", "WebStoreWarehouse"); ctx.put("facilityIdTo", "WebStoreWarehouse"); ctx.put("receiveDate", UtilDateTime.nowTimestamp()); - ctx.put("xferQty", Double.valueOf(transferQty)); + ctx.put("xferQty", transferQty); ctx.put("userLogin", userLogin); Map<String, Object> resp = dispatcher.runSync("createInventoryTransfer", ctx); inventoryTransferId = (String) resp.get("inventoryTransferId"); Modified: ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/product/test/StockMovesTest.java Mon Jan 5 23:13:36 2009 @@ -19,18 +19,19 @@ package org.ofbiz.product.test; +import java.math.BigDecimal; +import java.util.List; +import java.util.Map; + +import javolution.util.FastList; +import javolution.util.FastMap; import junit.framework.TestCase; +import org.ofbiz.base.util.UtilMisc; import org.ofbiz.entity.GenericDelegator; import org.ofbiz.entity.GenericValue; import org.ofbiz.service.GenericDispatcher; import org.ofbiz.service.LocalDispatcher; -import org.ofbiz.base.util.UtilMisc; - -import java.util.Map; -import java.util.List; -import javolution.util.FastList; -import javolution.util.FastMap; /** * Facility Tests @@ -78,7 +79,7 @@ ppsmCtx.put("facilityId", "WebStoreWarehouse"); ppsmCtx.put("locationSeqId","TLTLTLUL01" ); ppsmCtx.put("targetLocationSeqId", "TLTLTLLL01"); - ppsmCtx.put("quantityMoved", Double.valueOf(5)); + ppsmCtx.put("quantityMoved", new BigDecimal("5")); ppsmCtx.put("userLogin", userLogin); Map<String, Object> respMap3 = dispatcher.runSync("processPhysicalStockMove", ppsmCtx); } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java Mon Jan 5 23:13:36 2009 @@ -18,13 +18,13 @@ *******************************************************************************/ package org.ofbiz.shipment.packing; +import java.math.BigDecimal; import java.util.Map; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilValidate; -import org.ofbiz.base.util.UtilMisc; import org.ofbiz.service.DispatchContext; import org.ofbiz.service.ServiceUtil; @@ -37,8 +37,8 @@ String shipGroupSeqId = (String) context.get("shipGroupSeqId"); String orderId = (String) context.get("orderId"); String productId = (String) context.get("productId"); - Double quantity = (Double) context.get("quantity"); - Double weight = (Double) context.get("weight"); + BigDecimal quantity = (BigDecimal) context.get("quantity"); + BigDecimal weight = (BigDecimal) context.get("weight"); Integer packageSeq = (Integer) context.get("packageSeq"); // set the instructions -- will clear out previous if now null @@ -50,18 +50,18 @@ session.setPickerPartyId(pickerPartyId); if (quantity == null) { - quantity = Double.valueOf(1); + quantity = BigDecimal.ONE; } Debug.log("OrderId [" + orderId + "] ship group [" + shipGroupSeqId + "] Pack input [" + productId + "] @ [" + quantity + "] packageSeq [" + packageSeq + "] weight [" + weight +"]", module); if (weight == null) { Debug.logWarning("OrderId [" + orderId + "] ship group [" + shipGroupSeqId + "] product [" + productId + "] being packed without a weight, assuming 0", module); - weight = Double.valueOf(0.0); + weight = BigDecimal.ZERO; } try { - session.addOrIncreaseLine(orderId, null, shipGroupSeqId, productId, quantity.doubleValue(), packageSeq.intValue(), weight.doubleValue(), false); + session.addOrIncreaseLine(orderId, null, shipGroupSeqId, productId, quantity, packageSeq.intValue(), weight, false); } catch (GeneralException e) { Debug.logError(e, module); return ServiceUtil.returnError(e.getMessage()); @@ -146,13 +146,13 @@ weights = new String[] { wgtStr }; for (int p = 0; p < packages.length; p++) { - double quantity; + BigDecimal quantity; int packageSeq; - double weightSeq; + BigDecimal weightSeq; try { - quantity = Double.parseDouble(quantities[p]); + quantity = new BigDecimal(quantities[p]); packageSeq = Integer.parseInt(packages[p]); - weightSeq = Double.parseDouble(weights[p]); + weightSeq = new BigDecimal(weights[p]); } catch (Exception e) { return ServiceUtil.returnError(e.getMessage()); } @@ -225,8 +225,8 @@ String carrierRoleTypeId = (String) context.get("carrierRoleTypeId"); String productStoreId = (String) context.get("productStoreId"); - double shippableWeight = setSessionPackageWeights(session, packageWeights); - Double estimatedShipCost = session.getShipmentCostEstimate(shippingContactMechId, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId, productStoreId, null, null, Double.valueOf(shippableWeight), null); + BigDecimal shippableWeight = setSessionPackageWeights(session, packageWeights); + BigDecimal estimatedShipCost = session.getShipmentCostEstimate(shippingContactMechId, shipmentMethodTypeId, carrierPartyId, carrierRoleTypeId, productStoreId, null, null, shippableWeight, null); session.setAdditionalShippingCharge(estimatedShipCost); session.setWeightUomId(weightUomId); @@ -242,7 +242,7 @@ // set the instructions -- will clear out previous if now null String instructions = (String) context.get("handlingInstructions"); String pickerPartyId = (String) context.get("pickerPartyId"); - Double additionalShippingCharge = (Double) context.get("additionalShippingCharge"); + BigDecimal additionalShippingCharge = (BigDecimal) context.get("additionalShippingCharge"); Map<String, String> packageWeights = UtilGenerics.checkMap(context.get("packageWeights")); String weightUomId = (String) context.get("weightUomId"); session.setHandlingInstructions(instructions); @@ -275,16 +275,16 @@ return resp; } - public static double setSessionPackageWeights(PackingSession session, Map<String, String> packageWeights) { - double shippableWeight = 0; + public static BigDecimal setSessionPackageWeights(PackingSession session, Map<String, String> packageWeights) { + BigDecimal shippableWeight = BigDecimal.ZERO; if (! UtilValidate.isEmpty(packageWeights)) { for (Map.Entry<String, String> entry: packageWeights.entrySet()) { String packageSeqId = entry.getKey(); String packageWeightStr = entry.getValue(); if (UtilValidate.isNotEmpty(packageWeightStr)) { - double packageWeight = UtilMisc.toDouble(packageWeights.get(packageSeqId)); - session.setPackageWeight(Integer.parseInt(packageSeqId), Double.valueOf(packageWeight)); - shippableWeight += packageWeight; + BigDecimal packageWeight = new BigDecimal((String)packageWeights.get(packageSeqId)); + session.setPackageWeight(Integer.parseInt(packageSeqId), packageWeight); + shippableWeight = shippableWeight.add(packageWeight); } else { session.setPackageWeight(Integer.parseInt(packageSeqId), null); } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java Mon Jan 5 23:13:36 2009 @@ -18,28 +18,32 @@ *******************************************************************************/ package org.ofbiz.shipment.packing; -import java.util.*; import java.math.BigDecimal; +import java.util.AbstractMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; -import javolution.util.FastMap; import javolution.util.FastList; +import javolution.util.FastMap; import javolution.util.FastSet; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.GeneralException; import org.ofbiz.base.util.UtilFormatOut; -import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilMisc; import org.ofbiz.base.util.UtilValidate; import org.ofbiz.entity.GenericDelegator; -import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.GenericEntityException; +import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.util.EntityUtil; +import org.ofbiz.product.product.ProductWorker; import org.ofbiz.service.GenericDispatcher; import org.ofbiz.service.GenericServiceException; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.service.ServiceUtil; -import org.ofbiz.product.product.ProductWorker; public class PackingSession implements java.io.Serializable { @@ -56,8 +60,8 @@ protected String shipmentId = null; protected String instructions = null; protected String weightUomId = null; - protected Double additionalShippingCharge = null; - protected Map<Integer, Double> packageWeights = null; + protected BigDecimal additionalShippingCharge = null; + protected Map<Integer, BigDecimal> packageWeights = null; protected List<PackingEvent> packEvents = null; protected List<PackingSessionLine> packLines = null; protected List<ItemDisplay> itemInfos = null; @@ -94,14 +98,14 @@ this(dispatcher, userLogin, null, null, null, null); } - public void addOrIncreaseLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, double quantity, int packageSeqId, double weight, boolean update) throws GeneralException { + public void addOrIncreaseLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, BigDecimal quantity, int packageSeqId, BigDecimal weight, boolean update) throws GeneralException { // reset the session if we just completed if (status == 0) { throw new GeneralException("Packing session has been completed; be sure to CLEAR before packing a new order! [000]"); } // do nothing if we are trying to add a quantity of 0 - if (!update && quantity == 0) { + if (!update && quantity.compareTo(BigDecimal.ZERO) == 0) { return; } @@ -138,11 +142,11 @@ this.createPackLineItem(checkCode, res, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity, weight, packageSeqId); } else { // more than one reservation found - Map<GenericValue, Double> toCreateMap = FastMap.newInstance(); + Map<GenericValue, BigDecimal> toCreateMap = FastMap.newInstance(); Iterator<GenericValue> i = reservations.iterator(); - double qtyRemain = quantity; + BigDecimal qtyRemain = quantity; - while (i.hasNext() && qtyRemain > 0) { + while (i.hasNext() && qtyRemain.compareTo(BigDecimal.ZERO) > 0) { GenericValue res = i.next(); // Check that the inventory item product match with the current product to pack @@ -150,26 +154,26 @@ continue; } - double resQty = res.getDouble("quantity").doubleValue(); - double resPackedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, res.getString("inventoryItemId"), -1); - if (resPackedQty >= resQty) { + BigDecimal resQty = res.getBigDecimal("quantity"); + BigDecimal resPackedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, res.getString("inventoryItemId"), -1); + if (resPackedQty.compareTo(resQty) >= 0) { continue; } else if (!update) { - resQty -= resPackedQty; + resQty = resQty.subtract(resPackedQty); } - double thisQty = resQty > qtyRemain ? qtyRemain : resQty; + BigDecimal thisQty = resQty.compareTo(qtyRemain) > 0 ? qtyRemain : resQty; int thisCheck = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, productId, thisQty, packageSeqId, update); switch (thisCheck) { case 2: Debug.log("Packing check returned '2' - new pack line will be created!", module); - toCreateMap.put(res, Double.valueOf(thisQty)); - qtyRemain -= thisQty; + toCreateMap.put(res, thisQty); + qtyRemain = qtyRemain.subtract(thisQty); break; case 1: Debug.log("Packing check returned '1' - existing pack line has been updated!", module); - qtyRemain -= thisQty; + qtyRemain = qtyRemain.subtract(thisQty); break; case 0: Debug.log("Packing check returned '0' - doing nothing.", module); @@ -177,11 +181,11 @@ } } - if (qtyRemain == 0) { - for (Map.Entry<GenericValue, Double> entry: toCreateMap.entrySet()) { + if (qtyRemain.compareTo(BigDecimal.ZERO) == 0) { + for (Map.Entry<GenericValue, BigDecimal> entry: toCreateMap.entrySet()) { GenericValue res = entry.getKey(); - Double qty = entry.getValue(); - this.createPackLineItem(2, res, orderId, orderItemSeqId, shipGroupSeqId, productId, qty.doubleValue(), weight, packageSeqId); + BigDecimal qty = entry.getValue(); + this.createPackLineItem(2, res, orderId, orderItemSeqId, shipGroupSeqId, productId, qty, weight, packageSeqId); } } else { throw new GeneralException("Not enough inventory reservation available; cannot pack the item! [103]"); @@ -192,12 +196,12 @@ this.runEvents(PackingEvent.EVENT_CODE_ADD); } - public void addOrIncreaseLine(String orderId, String orderItemSeqId, String shipGroupSeqId, double quantity, int packageSeqId) throws GeneralException { - this.addOrIncreaseLine(orderId, orderItemSeqId, shipGroupSeqId, null, quantity, packageSeqId, 0, false); + public void addOrIncreaseLine(String orderId, String orderItemSeqId, String shipGroupSeqId, BigDecimal quantity, int packageSeqId) throws GeneralException { + this.addOrIncreaseLine(orderId, orderItemSeqId, shipGroupSeqId, null, quantity, packageSeqId, BigDecimal.ZERO, false); } - public void addOrIncreaseLine(String productId, double quantity, int packageSeqId) throws GeneralException { - this.addOrIncreaseLine(null, null, null, productId, quantity, packageSeqId, 0, false); + public void addOrIncreaseLine(String productId, BigDecimal quantity, int packageSeqId) throws GeneralException { + this.addOrIncreaseLine(null, null, null, productId, quantity, packageSeqId, BigDecimal.ZERO, false); } public PackingSessionLine findLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, int packageSeq) { @@ -214,7 +218,7 @@ return null; } - protected void createPackLineItem(int checkCode, GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, double quantity, double weight, int packageSeqId) throws GeneralException { + protected void createPackLineItem(int checkCode, GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, BigDecimal quantity, BigDecimal weight, int packageSeqId) throws GeneralException { // process the result; add new item if necessary switch(checkCode) { case 0: @@ -231,7 +235,7 @@ } // Add the line weight to the package weight - if (weight > 0) this.addToPackageWeight(packageSeqId, Double.valueOf(weight)); + if (weight.compareTo(BigDecimal.ZERO) > 0) this.addToPackageWeight(packageSeqId, weight); // update the package sequence if (packageSeqId > packageSeq) { @@ -239,7 +243,7 @@ } } - protected String findOrderItemSeqId(String productId, String orderId, String shipGroupSeqId, double quantity) throws GeneralException { + protected String findOrderItemSeqId(String productId, String orderId, String shipGroupSeqId, BigDecimal quantity) throws GeneralException { Map<String, Object> lookupMap = FastMap.newInstance(); lookupMap.put("orderId", orderId); lookupMap.put("productId", productId); @@ -259,8 +263,8 @@ invLookup.put("shipGroupSeqId", shipGroupSeqId); List<GenericValue> reservations = this.getDelegator().findByAnd("OrderItemShipGrpInvRes", invLookup); for (GenericValue res: reservations) { - Double qty = res.getDouble("quantity"); - if (quantity <= qty.doubleValue()) { + BigDecimal qty = res.getBigDecimal("quantity"); + if (quantity.compareTo(qty) <= 0) { orderItemSeqId = item.getString("orderItemSeqId"); break; } @@ -275,27 +279,27 @@ } } - protected int checkLineForAdd(GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, double quantity, int packageSeqId, boolean update) { + protected int checkLineForAdd(GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, BigDecimal quantity, int packageSeqId, boolean update) { // check to see if the reservation can hold the requested quantity amount String invItemId = res.getString("inventoryItemId"); - double resQty = res.getDouble("quantity").doubleValue(); + BigDecimal resQty = res.getBigDecimal("quantity"); PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, productId, invItemId, packageSeqId); - double packedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId); + BigDecimal packedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId); Debug.log("Packed quantity [" + packedQty + "] + [" + quantity + "]", module); if (line == null) { Debug.log("No current line found testing [" + invItemId + "] R: " + resQty + " / Q: " + quantity, module); - if (resQty < quantity) { + if (resQty.compareTo(quantity) < 0) { return 0; } else { return 2; } } else { - double newQty = update ? quantity : (line.getQuantity() + quantity); + BigDecimal newQty = update ? quantity : (line.getQuantity().add(quantity)); Debug.log("Existing line found testing [" + invItemId + "] R: " + resQty + " / Q: " + newQty, module); - if (resQty < newQty) { + if (resQty.compareTo(newQty) < 0) { return 0; } else { line.setQuantity(newQty); @@ -341,22 +345,22 @@ return packageSeq; } - public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) { + public BigDecimal getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) { return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, null, -1); } - public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, int packageSeq) { + public BigDecimal getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, int packageSeq) { return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId, null, packageSeq); } - public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, int packageSeq) { - double total = 0.0; + public BigDecimal getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, int packageSeq) { + BigDecimal total = BigDecimal.ZERO; for (PackingSessionLine line: this.getLines()) { if (orderId.equals(line.getOrderId()) && orderItemSeqId.equals(line.getOrderItemSeqId()) && shipGroupSeqId.equals(line.getShipGroupSeqId()) && productId.equals(line.getProductId())) { if (inventoryItemId == null || inventoryItemId.equals(line.getInventoryItemId())) { if (packageSeq == -1 || packageSeq == line.getPackageSeq()) { - total += line.getQuantity(); + total = total.add(line.getQuantity()); } } } @@ -364,7 +368,7 @@ return total; } - public double getPackedQuantity(String productId, int packageSeq) { + public BigDecimal getPackedQuantity(String productId, int packageSeq) { if (productId != null) { try { productId = ProductWorker.findProductId(this.getDelegator(), productId); @@ -373,12 +377,12 @@ } } - double total = 0.0; + BigDecimal total = BigDecimal.ZERO; if (productId != null ) { for (PackingSessionLine line: this.getLines()) { if (productId.equals(line.getProductId())) { if (packageSeq == -1 || packageSeq == line.getPackageSeq()) { - total += line.getQuantity(); + total = total.add(line.getQuantity()); } } } @@ -386,44 +390,43 @@ return total; } - public double getPackedQuantity(int packageSeq) { - double total = 0.0; + public BigDecimal getPackedQuantity(int packageSeq) { + BigDecimal total = BigDecimal.ZERO; for (PackingSessionLine line: this.getLines()) { if (packageSeq == -1 || packageSeq == line.getPackageSeq()) { - total += line.getQuantity(); + total = total.add(line.getQuantity()); } } return total; } - public double getPackedQuantity(String productId) { + public BigDecimal getPackedQuantity(String productId) { return getPackedQuantity(productId, -1); } - public double getCurrentReservedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) { - double reserved = -1; + public BigDecimal getCurrentReservedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) { + BigDecimal reserved = BigDecimal.ONE.negate(); try { GenericValue res = EntityUtil.getFirst(this.getDelegator().findByAnd("OrderItemAndShipGrpInvResAndItemSum", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId, "shipGroupSeqId", shipGroupSeqId, "inventoryProductId", productId))); - Double reservedDbl = res.getDouble("totQuantityAvailable"); - if (reservedDbl == null) { - reservedDbl = Double.valueOf(-1); + reserved = res.getBigDecimal("totQuantityAvailable"); + if (reserved == null) { + reserved = BigDecimal.ONE.negate(); } - reserved = reservedDbl.doubleValue(); } catch (GenericEntityException e) { Debug.logError(e, module); } return reserved; } - public double getCurrentShippedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) { - double shipped = 0.0; + public BigDecimal getCurrentShippedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) { + BigDecimal shipped = BigDecimal.ZERO; List<GenericValue> issues = this.getItemIssuances(orderId, orderItemSeqId, shipGroupSeqId); if (issues != null) { for (GenericValue v: issues) { - Double qty = v.getDouble("quantity"); - if (qty == null) qty = Double.valueOf(0); - shipped += qty.doubleValue(); + BigDecimal qty = v.getBigDecimal("quantity"); + if (qty == null) qty = BigDecimal.ZERO; + shipped = shipped.add(qty); } } @@ -598,8 +601,8 @@ protected void checkReservations(boolean ignore) throws GeneralException { List<String> errors = FastList.newInstance(); for (PackingSessionLine line: this.getLines()) { - double reservedQty = this.getCurrentReservedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId()); - double packedQty = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId()); + BigDecimal reservedQty = this.getCurrentReservedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId()); + BigDecimal packedQty = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId()); if (packedQty != reservedQty) { errors.add("Packed amount does not match reserved amount for item (" + line.getProductId() + ") [" + packedQty + " / " + reservedQty + "]"); @@ -619,7 +622,7 @@ List<PackingSessionLine> lines = FastList.newInstance(); lines.addAll(this.getLines()); for (PackingSessionLine l: lines) { - if (l.getQuantity() == 0) { + if (l.getQuantity().compareTo(BigDecimal.ZERO) == 0) { this.packLines.remove(l); } } @@ -681,10 +684,10 @@ List<PackingSessionLine> processedLines = FastList.newInstance(); for (PackingSessionLine line: this.getLines()) { if (this.checkLine(processedLines, line)) { - double totalPacked = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), + BigDecimal totalPacked = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId(), line.getInventoryItemId(), -1); - line.issueItemToShipment(shipmentId, picklistBinId, userLogin, Double.valueOf(totalPacked), getDispatcher()); + line.issueItemToShipment(shipmentId, picklistBinId, userLogin, totalPacked, getDispatcher()); processedLines.add(line); } } @@ -727,8 +730,8 @@ } protected void updateShipmentRouteSegments() throws GeneralException { - Double shipmentWeight = Double.valueOf(getTotalWeight()); - if (shipmentWeight.doubleValue() <= 0) return; + BigDecimal shipmentWeight = getTotalWeight(); + if (shipmentWeight.compareTo(BigDecimal.ZERO) <= 0) return; List<GenericValue> shipmentRouteSegments = getDelegator().findByAnd("ShipmentRouteSegment", UtilMisc.toMap("shipmentId", this.getShipmentId())); if (! UtilValidate.isEmpty(shipmentRouteSegments)) { for (GenericValue shipmentRouteSegment: shipmentRouteSegments) { @@ -773,40 +776,40 @@ } } - public Double getAdditionalShippingCharge() { + public BigDecimal getAdditionalShippingCharge() { return additionalShippingCharge; } - public void setAdditionalShippingCharge(Double additionalShippingCharge) { + public void setAdditionalShippingCharge(BigDecimal additionalShippingCharge) { this.additionalShippingCharge = additionalShippingCharge; } - public double getTotalWeight() { - double total = 0.0; + public BigDecimal getTotalWeight() { + BigDecimal total = BigDecimal.ZERO; for (int i = 0; i < packageSeq; i++) { - Double packageWeight = getPackageWeight(i); + BigDecimal packageWeight = getPackageWeight(i); if (! UtilValidate.isEmpty(packageWeight)) { - total += packageWeight.doubleValue(); + total = total.add(packageWeight); } } return total; } - public Double getShipmentCostEstimate(GenericValue orderItemShipGroup, String productStoreId, List<GenericValue> shippableItemInfo, Double shippableTotal, Double shippableWeight, Double shippableQuantity) { + public BigDecimal getShipmentCostEstimate(GenericValue orderItemShipGroup, String productStoreId, List<GenericValue> shippableItemInfo, BigDecimal shippableTotal, BigDecimal shippableWeight, BigDecimal shippableQuantity) { return getShipmentCostEstimate(orderItemShipGroup.getString("contactMechId"), orderItemShipGroup.getString("shipmentMethodTypeId"), orderItemShipGroup.getString("carrierPartyId"), orderItemShipGroup.getString("carrierRoleTypeId"), productStoreId, shippableItemInfo, shippableTotal, shippableWeight, shippableQuantity); } - public Double getShipmentCostEstimate(GenericValue orderItemShipGroup, String productStoreId) { + public BigDecimal getShipmentCostEstimate(GenericValue orderItemShipGroup, String productStoreId) { return getShipmentCostEstimate(orderItemShipGroup.getString("contactMechId"), orderItemShipGroup.getString("shipmentMethodTypeId"), orderItemShipGroup.getString("carrierPartyId"), orderItemShipGroup.getString("carrierRoleTypeId"), productStoreId, null, null, null, null); } - public Double getShipmentCostEstimate(String shippingContactMechId, String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId, String productStoreId, List<GenericValue> shippableItemInfo, Double shippableTotal, Double shippableWeight, Double shippableQuantity) { + public BigDecimal getShipmentCostEstimate(String shippingContactMechId, String shipmentMethodTypeId, String carrierPartyId, String carrierRoleTypeId, String productStoreId, List<GenericValue> shippableItemInfo, BigDecimal shippableTotal, BigDecimal shippableWeight, BigDecimal shippableQuantity) { - Double shipmentCostEstimate = null; + BigDecimal shipmentCostEstimate = null; Map<String, Object> serviceResult = null; try { Map<String, Object> serviceContext = FastMap.newInstance(); @@ -826,17 +829,17 @@ serviceContext.put("shippableItemInfo", shippableItemInfo); if (UtilValidate.isEmpty(shippableWeight)) { - shippableWeight = Double.valueOf(getTotalWeight()); + shippableWeight = getTotalWeight(); } serviceContext.put("shippableWeight", shippableWeight); if (UtilValidate.isEmpty(shippableQuantity)) { - shippableQuantity = Double.valueOf(getPackedQuantity(-1)); + shippableQuantity = getPackedQuantity(-1); } serviceContext.put("shippableQuantity", shippableQuantity); if (UtilValidate.isEmpty(shippableTotal)) { - shippableTotal = Double.valueOf(0); + shippableTotal = BigDecimal.ZERO; } serviceContext.put("shippableTotal", shippableTotal); @@ -848,7 +851,7 @@ } if (! UtilValidate.isEmpty(serviceResult.get("shippingEstimateAmount"))) { - shipmentCostEstimate = (Double) serviceResult.get("shippingEstimateAmount"); + shipmentCostEstimate = (BigDecimal) serviceResult.get("shippingEstimateAmount"); } return shipmentCostEstimate; @@ -873,7 +876,7 @@ return UtilMisc.makeListWritable(packageSeqIds); } - public void setPackageWeight(int packageSeqId, Double packageWeight) { + public void setPackageWeight(int packageSeqId, BigDecimal packageWeight) { if (UtilValidate.isEmpty(packageWeight)) { packageWeights.remove(Integer.valueOf(packageSeqId)); } else { @@ -881,16 +884,20 @@ } } - public Double getPackageWeight(int packageSeqId) { + public BigDecimal getPackageWeight(int packageSeqId) { if (this.packageWeights == null) return null; - Double packageWeight = packageWeights.get(Integer.valueOf(packageSeqId)); + BigDecimal packageWeight = null; + Object p = packageWeights.get(new Integer(packageSeqId)); + if (p != null) { + packageWeight = (BigDecimal) p; + } return packageWeight; } - public void addToPackageWeight(int packageSeqId, Double weight) { + public void addToPackageWeight(int packageSeqId, BigDecimal weight) { if (UtilValidate.isEmpty(weight)) return; - Double packageWeight = getPackageWeight(packageSeqId); - Double newPackageWeight = UtilValidate.isEmpty(packageWeight) ? weight : Double.valueOf(weight.doubleValue() + packageWeight.doubleValue()); + BigDecimal packageWeight = getPackageWeight(packageSeqId); + BigDecimal newPackageWeight = UtilValidate.isEmpty(packageWeight) ? weight : weight.add(packageWeight); setPackageWeight(packageSeqId, newPackageWeight); } Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java?rev=731851&r1=731850&r2=731851&view=diff ============================================================================== --- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java (original) +++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSessionLine.java Mon Jan 5 23:13:36 2009 @@ -18,6 +18,7 @@ *******************************************************************************/ package org.ofbiz.shipment.packing; +import java.math.BigDecimal; import java.util.Map; import javolution.util.FastMap; @@ -40,11 +41,11 @@ protected String productId = null; protected String inventoryItemId = null; protected String shipmentItemSeqId = null; - protected double quantity = 0; - protected double weight = 0; + protected BigDecimal quantity = BigDecimal.ZERO; + protected BigDecimal weight = BigDecimal.ZERO; protected int packageSeq = 0; - public PackingSessionLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, double quantity, double weight, int packageSeq) { + public PackingSessionLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, BigDecimal quantity, BigDecimal weight, int packageSeq) { this.orderId = orderId; this.orderItemSeqId = orderItemSeqId; this.shipGroupSeqId = shipGroupSeqId; @@ -83,28 +84,28 @@ this.shipmentItemSeqId = shipmentItemSeqId; } - public double getQuantity() { + public BigDecimal getQuantity() { return this.quantity; } - public void setQuantity(double quantity) { + public void setQuantity(BigDecimal quantity) { this.quantity = quantity; } - public void addQuantity(double quantity) { - this.quantity += quantity; + public void addQuantity(BigDecimal quantity) { + this.quantity = this.quantity.add(quantity); } - public double getWeight() { + public BigDecimal getWeight() { return weight; } - public void setWeight(double weight) { + public void setWeight(BigDecimal weight) { this.weight = weight; } - public void addWeight(double weight) { - this.weight += weight; + public void addWeight(BigDecimal weight) { + this.weight = this.weight.add(weight); } public int getPackageSeq() { @@ -124,9 +125,9 @@ return false; } - protected void issueItemToShipment(String shipmentId, String picklistBinId, GenericValue userLogin, Double quantity, LocalDispatcher dispatcher) throws GeneralException { + protected void issueItemToShipment(String shipmentId, String picklistBinId, GenericValue userLogin, BigDecimal quantity, LocalDispatcher dispatcher) throws GeneralException { if (quantity == null) { - quantity = Double.valueOf(this.getQuantity()); + quantity = this.getQuantity(); } Map<String, Object> issueMap = FastMap.newInstance(); @@ -163,8 +164,8 @@ GenericValue plItem = delegator.findByPrimaryKey("PicklistItem", itemLookup); if (plItem != null) { Debug.log("Found picklist bin: " + plItem, module); - Double itemQty = plItem.getDouble("quantity"); - if (itemQty.doubleValue() == quantity.doubleValue()) { + BigDecimal itemQty = plItem.getBigDecimal("quantity"); + if (itemQty.compareTo(quantity) == 0) { // set to complete itemLookup.put("itemStatusId", "PICKITEM_COMPLETED"); } else { @@ -191,7 +192,7 @@ Map<String, Object> packageMap = FastMap.newInstance(); packageMap.put("shipmentId", shipmentId); packageMap.put("shipmentItemSeqId", this.getShipmentItemSeqId()); - packageMap.put("quantity", Double.valueOf(this.getQuantity())); + packageMap.put("quantity", this.getQuantity()); packageMap.put("shipmentPackageSeqId", shipmentPackageSeqId); packageMap.put("userLogin", userLogin); Map<String, Object> packageResp = dispatcher.runSync("addShipmentContentToPackage", packageMap); |
Free forum by Nabble | Edit this page |