svn commit: r721986 [10/13] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/script/org/ofbiz/accounting/olap/ applications/order/entitydef/ applications/order/script/org/ofbiz/order/order/ applications/order/script/org/ofbiz/order/...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r721986 [10/13] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/script/org/ofbiz/accounting/olap/ applications/order/entitydef/ applications/order/script/org/ofbiz/order/order/ applications/order/script/org/ofbiz/order/...

lektran
Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryServices.java Sun Nov 30 22:51:11 2008
@@ -18,6 +18,8 @@
  *******************************************************************************/
 package org.ofbiz.product.inventory;
 
+import java.math.BigDecimal;
+import java.math.MathContext;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -55,10 +57,12 @@
     
     public final static String module = InventoryServices.class.getName();
     
+    public static final MathContext generalRounding = new MathContext(10);
+
     public static Map prepareInventoryTransfer(DispatchContext dctx, Map context) {
         GenericDelegator delegator = dctx.getDelegator();
         String inventoryItemId = (String) context.get("inventoryItemId");
-        Double xferQty = (Double) context.get("xferQty");  
+        BigDecimal xferQty = (BigDecimal) context.get("xferQty");  
         GenericValue inventoryItem = null;
         GenericValue newItem = null;        
         GenericValue userLogin = (GenericValue) context.get("userLogin");        
@@ -78,8 +82,8 @@
             
             String inventoryType = inventoryItem.getString("inventoryItemTypeId");
             if (inventoryType.equals("NON_SERIAL_INV_ITEM")) {
-                Double atp = inventoryItem.getDouble("availableToPromiseTotal");
-                Double qoh = inventoryItem.getDouble("quantityOnHandTotal");
+             BigDecimal atp = inventoryItem.getBigDecimal("availableToPromiseTotal");
+             BigDecimal qoh = inventoryItem.getBigDecimal("quantityOnHandTotal");
                 
                 if (atp == null) {
                     return ServiceUtil.returnError("The request transfer amount is not available, there is no available to promise on the Inventory Item with ID " + inventoryItem.getString("inventoryItemId"));
@@ -89,7 +93,7 @@
                 }
                 
                 // first make sure we have enough to cover the request transfer amount
-                if (xferQty.doubleValue() > atp.doubleValue()) {
+                if (xferQty.compareTo(atp) > 0) {
                     return ServiceUtil.returnError("The request transfer amount is not available, the available to promise [" + atp + "] is not sufficient for the desired transfer quantity [" + xferQty + "] on the Inventory Item with ID " + inventoryItem.getString("inventoryItemId"));
                 }
                             
@@ -102,16 +106,16 @@
                 // at this point we have already made sure that the xferQty is less than or equals to the atp, so if less that just create a new inventory record for the quantity to be moved
                 // NOTE: atp should always be <= qoh, so if xfer < atp, then xfer < qoh, so no need to check/handle that
                 // however, if atp < qoh && atp == xferQty, then we still need to split; oh, but no need to check atp == xferQty in the second part because if it isn't greater and isn't less, then it is equal
-                if (xferQty.doubleValue() < atp.doubleValue() || atp.doubleValue() < qoh.doubleValue()) {
-                    Double negXferQty = new Double(-xferQty.doubleValue());
+                if (xferQty.compareTo(atp) < 0 || atp.compareTo(qoh) < 0) {
+                 BigDecimal negXferQty = xferQty.negate();
                     // NOTE: new inventory items should always be created calling the
                     //       createInventoryItem service because in this way we are sure
                     //       that all the relevant fields are filled with default values.
                     //       However, the code here should work fine because all the values
                     //       for the new inventory item are inerited from the existing item.
                     newItem = GenericValue.create(inventoryItem);
-                    newItem.set("availableToPromiseTotal", new Double(0));
-                    newItem.set("quantityOnHandTotal", new Double(0));
+                    newItem.set("availableToPromiseTotal", BigDecimal.ZERO);
+                    newItem.set("quantityOnHandTotal", BigDecimal.ZERO);
                     
                     delegator.createSetNextSeqId(newItem);
                     
@@ -151,9 +155,9 @@
                 GenericValue inventoryItemToClear = newItem == null ? inventoryItem : newItem;
 
                 inventoryItemToClear.refresh();
-                double atp = inventoryItemToClear.get("availableToPromiseTotal") == null ? 0 : inventoryItemToClear.getDouble("availableToPromiseTotal").doubleValue();
-                if (atp != 0) {
-                    Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", new Double(-atp),
+                BigDecimal atp = inventoryItemToClear.get("availableToPromiseTotal") == null ? BigDecimal.ZERO : inventoryItemToClear.getBigDecimal("availableToPromiseTotal");
+                if (atp.compareTo(BigDecimal.ZERO) != 0) {
+                    Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", atp.negate(),
                             "inventoryItemId", inventoryItemToClear.get("inventoryItemId"), "userLogin", userLogin);
                     try {
                         Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap);
@@ -215,9 +219,9 @@
             
         if (inventoryType.equals("NON_SERIAL_INV_ITEM")) {
             // add an adjusting InventoryItemDetail so set ATP back to QOH: ATP = ATP + (QOH - ATP), diff = QOH - ATP
-            double atp = inventoryItem.get("availableToPromiseTotal") == null ? 0 : inventoryItem.getDouble("availableToPromiseTotal").doubleValue();
-            double qoh = inventoryItem.get("quantityOnHandTotal") == null ? 0 : inventoryItem.getDouble("quantityOnHandTotal").doubleValue();
-            Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", new Double(qoh - atp),
+         BigDecimal atp = inventoryItem.get("availableToPromiseTotal") == null ? BigDecimal.ZERO : inventoryItem.getBigDecimal("availableToPromiseTotal");
+         BigDecimal qoh = inventoryItem.get("quantityOnHandTotal") == null ? BigDecimal.ZERO : inventoryItem.getBigDecimal("quantityOnHandTotal");
+            Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", qoh.subtract(atp),
                     "inventoryItemId", inventoryItem.get("inventoryItemId"), "userLogin", userLogin);
             try {
                 Map result = dctx.getDispatcher().runSync("createInventoryItemDetail", createDetailMap);
@@ -305,9 +309,9 @@
         // re-set the fields on the item
         if (inventoryType.equals("NON_SERIAL_INV_ITEM")) {
             // add an adjusting InventoryItemDetail so set ATP back to QOH: ATP = ATP + (QOH - ATP), diff = QOH - ATP
-            double atp = inventoryItem.get("availableToPromiseTotal") == null ? 0 : inventoryItem.getDouble("availableToPromiseTotal").doubleValue();
-            double qoh = inventoryItem.get("quantityOnHandTotal") == null ? 0 : inventoryItem.getDouble("quantityOnHandTotal").doubleValue();
-            Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", new Double(qoh - atp),
+         BigDecimal atp = inventoryItem.get("availableToPromiseTotal") == null ? BigDecimal.ZERO : inventoryItem.getBigDecimal("availableToPromiseTotal");
+         BigDecimal qoh = inventoryItem.get("quantityOnHandTotal") == null ? BigDecimal.ZERO : inventoryItem.getBigDecimal("quantityOnHandTotal");
+            Map createDetailMap = UtilMisc.toMap("availableToPromiseDiff", qoh.subtract(atp),
                                                  "inventoryItemId", inventoryItem.get("inventoryItemId"),
                                                  "userLogin", userLogin);
             try {
@@ -361,7 +365,7 @@
         // find all inventory items w/ a negative ATP
         List inventoryItems = null;
         try {
-            EntityExpr ee = EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, new Double(0));
+            EntityExpr ee = EntityCondition.makeCondition("availableToPromiseTotal", EntityOperator.LESS_THAN, BigDecimal.ZERO);
             inventoryItems = delegator.findList("InventoryItem", ee, null, null, null, false);
         } catch (GenericEntityException e) {
             Debug.logError(e, "Trouble getting inventory items", module);
@@ -412,7 +416,7 @@
             Debug.log("Reservations for item: " + reservations.size(), module);
             
             // available at the time of order
-            double availableBeforeReserved = inventoryItem.getDouble("availableToPromiseTotal").doubleValue();
+            BigDecimal availableBeforeReserved = inventoryItem.getBigDecimal("availableToPromiseTotal");
             
             // go through all the reservations in order
             Iterator ri = reservations.iterator();
@@ -436,12 +440,12 @@
                                                               
                 // find the next possible ship date
                 Timestamp nextShipDate = null;
-                double availableAtTime = 0.00;
+                BigDecimal availableAtTime = BigDecimal.ZERO;
                 Iterator si = shipmentAndItems.iterator();
                 while (si.hasNext()) {
                     GenericValue shipmentItem = (GenericValue) si.next();
-                    availableAtTime += shipmentItem.getDouble("quantity").doubleValue();
-                    if (availableAtTime >= availableBeforeReserved) {
+                    availableAtTime = availableAtTime.add(shipmentItem.getBigDecimal("quantity"));
+                    if (availableAtTime.compareTo(availableBeforeReserved) >= 0) {
                         nextShipDate = shipmentItem.getTimestamp("estimatedArrivalDate");
                         break;
                     }
@@ -514,7 +518,7 @@
                 }
                                 
                 // subtract our qty from reserved to get the next value
-                availableBeforeReserved -= reservation.getDouble("quantity").doubleValue();
+                availableBeforeReserved = availableBeforeReserved.subtract(reservation.getBigDecimal("quantity"));
             }
         }
               
@@ -650,24 +654,24 @@
         String facilityId = (String)context.get("facilityId");
         String statusId = (String)context.get("statusId");
         
-        Double availableToPromiseTotal = new Double(0);
-        Double quantityOnHandTotal = new Double(0);
+        BigDecimal availableToPromiseTotal = BigDecimal.ZERO;
+        BigDecimal quantityOnHandTotal = BigDecimal.ZERO;
         
         if (UtilValidate.isNotEmpty(productAssocList)) {
-           // minimum QOH and ATP encountered
-           double minQuantityOnHandTotal = Double.MAX_VALUE;
-           double minAvailableToPromiseTotal = Double.MAX_VALUE;
+            // minimum QOH and ATP encountered
+         BigDecimal minQuantityOnHandTotal = null;
+         BigDecimal minAvailableToPromiseTotal = null;
           
            // loop through each associated product.  
            for (int i = 0; productAssocList.size() > i; i++) {
                GenericValue productAssoc = (GenericValue) productAssocList.get(i);
                String productIdTo = productAssoc.getString("productIdTo");
-               Double assocQuantity = productAssoc.getDouble("quantity");
+               BigDecimal assocQuantity = productAssoc.getBigDecimal("quantity");
               
                // if there is no quantity for the associated product in ProductAssoc entity, default it to 1.0
                if (assocQuantity == null) {
                    Debug.logWarning("ProductAssoc from [" + productAssoc.getString("productId") + "] to [" + productAssoc.getString("productIdTo") + "] has no quantity, assuming 1.0", module);
-                   assocQuantity = new Double(1.0);
+                   assocQuantity = BigDecimal.ONE;
                }
               
                // figure out the inventory available for this associated product
@@ -686,16 +690,16 @@
                }
               
                // Figure out what the QOH and ATP inventory would be with this associated product
-               Double currentQuantityOnHandTotal = (Double) resultOutput.get("quantityOnHandTotal");
-               Double currentAvailableToPromiseTotal = (Double) resultOutput.get("availableToPromiseTotal");
-               double tmpQuantityOnHandTotal = currentQuantityOnHandTotal.doubleValue()/assocQuantity.doubleValue();
-               double tmpAvailableToPromiseTotal = currentAvailableToPromiseTotal.doubleValue()/assocQuantity.doubleValue();
+               BigDecimal currentQuantityOnHandTotal = (BigDecimal) resultOutput.get("quantityOnHandTotal");
+               BigDecimal currentAvailableToPromiseTotal = (BigDecimal) resultOutput.get("availableToPromiseTotal");
+               BigDecimal tmpQuantityOnHandTotal = currentQuantityOnHandTotal.divide(assocQuantity, generalRounding);
+               BigDecimal tmpAvailableToPromiseTotal = currentAvailableToPromiseTotal.divide(assocQuantity, generalRounding);
 
                // reset the minimum QOH and ATP quantities if those quantities for this product are less
-               if (tmpQuantityOnHandTotal < minQuantityOnHandTotal) {
+               if (minQuantityOnHandTotal == null || tmpQuantityOnHandTotal.compareTo(minQuantityOnHandTotal) < 0) {
                    minQuantityOnHandTotal = tmpQuantityOnHandTotal;
                }
-               if (tmpAvailableToPromiseTotal < minAvailableToPromiseTotal) {
+               if (minAvailableToPromiseTotal == null || tmpAvailableToPromiseTotal.compareTo(minAvailableToPromiseTotal) < 0) {
                    minAvailableToPromiseTotal = tmpAvailableToPromiseTotal;
                }
             
@@ -705,8 +709,8 @@
                }
            }
           // the final QOH and ATP quantities are the minimum of all the products
-          quantityOnHandTotal = new Double(minQuantityOnHandTotal);
-          availableToPromiseTotal = new Double(minAvailableToPromiseTotal);
+          quantityOnHandTotal = minQuantityOnHandTotal;
+          availableToPromiseTotal = minAvailableToPromiseTotal;
         }
         
         Map result = ServiceUtil.returnSuccess();
@@ -755,10 +759,10 @@
                 return ServiceUtil.returnError("Unable to retrive product with id [" + productId + "]");
             }
 
-            double atp = 0.0;
-            double qoh = 0.0;
-            double mktgPkgAtp = 0.0;
-            double mktgPkgQoh = 0.0;
+            BigDecimal atp = BigDecimal.ZERO;
+            BigDecimal qoh = BigDecimal.ZERO;
+            BigDecimal mktgPkgAtp = BigDecimal.ZERO;
+            BigDecimal mktgPkgQoh = BigDecimal.ZERO;
             Iterator facilityIter = facilities.iterator();
 
             // loop through all the facilities
@@ -782,23 +786,23 @@
 
                 // add the results for this facility to the ATP/QOH counter for all facilities
                 if (!ServiceUtil.isError(invResult)) {
-                    Double fatp = (Double) invResult.get("availableToPromiseTotal");
-                    Double fqoh = (Double) invResult.get("quantityOnHandTotal");
-                    if (fatp != null) atp += fatp.doubleValue();
-                    if (fqoh != null) qoh += fqoh.doubleValue();
+                 BigDecimal fatp = (BigDecimal) invResult.get("availableToPromiseTotal");
+                 BigDecimal fqoh = (BigDecimal) invResult.get("quantityOnHandTotal");
+                    if (fatp != null) atp = atp.add(fatp);
+                    if (fqoh != null) qoh = qoh.add(fqoh);
                 }
                 if (("MARKETING_PKG_AUTO".equals(product.getString("productTypeId")) || "MARKETING_PKG_PICK".equals(product.getString("productTypeId"))) && (!ServiceUtil.isError(mktgPkgInvResult))) {
-                    Double fatp = (Double) mktgPkgInvResult.get("availableToPromiseTotal");
-                    Double fqoh = (Double) mktgPkgInvResult.get("quantityOnHandTotal");
-                    if (fatp != null) mktgPkgAtp += fatp.doubleValue();
-                    if (fqoh != null) mktgPkgQoh += fqoh.doubleValue();
+                 BigDecimal fatp = (BigDecimal) mktgPkgInvResult.get("availableToPromiseTotal");
+                 BigDecimal fqoh = (BigDecimal) mktgPkgInvResult.get("quantityOnHandTotal");
+                    if (fatp != null) mktgPkgAtp = mktgPkgAtp.add(fatp);
+                    if (fqoh != null) mktgPkgQoh = mktgPkgQoh.add(fqoh);
                 }
             }
 
-            atpMap.put(productId, new Double(atp));
-            qohMap.put(productId, new Double(qoh));
-            mktgPkgAtpMap.put(productId, new Double(mktgPkgAtp));
-            mktgPkgQohMap.put(productId, new Double(mktgPkgQoh));
+            atpMap.put(productId, atp);
+            qohMap.put(productId, qoh);
+            mktgPkgAtpMap.put(productId, mktgPkgAtp);
+            mktgPkgQohMap.put(productId, mktgPkgQoh);
         }
 
         results.put("availableToPromiseMap", atpMap);
@@ -815,7 +819,7 @@
         Timestamp checkTime = (Timestamp)context.get("checkTime");
         String facilityId = (String)context.get("facilityId");
         String productId = (String)context.get("productId");
-        String minimumStock = (String)context.get("minimumStock");
+        String minimumStockStr = (String)context.get("minimumStock");
         String statusId = (String)context.get("statusId");
 
         Map result = new HashMap();
@@ -846,30 +850,30 @@
             }
         }
         // filter for quantities
-        int minimumStockInt = 0;
-        if (minimumStock != null) {
-            minimumStockInt = new Double(minimumStock).intValue();
+        BigDecimal minimumStock = BigDecimal.ZERO;
+        if (minimumStockStr != null) {
+            minimumStock = new BigDecimal(minimumStockStr);
         }
 
-        int quantityOnHandTotalInt = 0;
+        BigDecimal quantityOnHandTotal = BigDecimal.ZERO;
         if (resultOutput.get("quantityOnHandTotal") != null) {
-            quantityOnHandTotalInt = ((Double)resultOutput.get("quantityOnHandTotal")).intValue();
+            quantityOnHandTotal = (BigDecimal)resultOutput.get("quantityOnHandTotal");
         }
-        int offsetQOHQtyAvailable = quantityOnHandTotalInt - minimumStockInt;
+        BigDecimal offsetQOHQtyAvailable = quantityOnHandTotal.subtract(minimumStock);
 
-        int availableToPromiseTotalInt = 0;
+        BigDecimal availableToPromiseTotal = BigDecimal.ZERO;
         if (resultOutput.get("availableToPromiseTotal") != null) {
-            availableToPromiseTotalInt = ((Double)resultOutput.get("availableToPromiseTotal")).intValue();
+            availableToPromiseTotal = (BigDecimal)resultOutput.get("availableToPromiseTotal");
         }
-        int offsetATPQtyAvailable = availableToPromiseTotalInt - minimumStockInt;
+        BigDecimal offsetATPQtyAvailable = availableToPromiseTotal.subtract(minimumStock);
     
-        double quantityOnOrder = InventoryWorker.getOutstandingPurchasedQuantity(productId, delegator);
+        BigDecimal quantityOnOrder = InventoryWorker.getOutstandingPurchasedQuantity(productId, delegator);
         result.put("totalQuantityOnHand", resultOutput.get("quantityOnHandTotal").toString());
         result.put("totalAvailableToPromise", resultOutput.get("availableToPromiseTotal").toString());
-        result.put("quantityOnOrder", new Double(quantityOnOrder));
+        result.put("quantityOnOrder", quantityOnOrder);
     
-        result.put("offsetQOHQtyAvailable", new Integer(offsetQOHQtyAvailable));
-        result.put("offsetATPQtyAvailable", new Integer(offsetATPQtyAvailable));
+        result.put("offsetQOHQtyAvailable", offsetQOHQtyAvailable);
+        result.put("offsetATPQtyAvailable", offsetATPQtyAvailable);
     
         List productPrices = null;
         try {
@@ -883,15 +887,15 @@
         while (pricesIt.hasNext()) {
             GenericValue onePrice = (GenericValue)pricesIt.next();
             if(onePrice.getString("productPriceTypeId").equals("DEFAULT_PRICE")){ //defaultPrice
-                result.put("defultPrice", onePrice.getDouble("price"));
+                result.put("defultPrice", onePrice.getBigDecimal("price"));
             }else if(onePrice.getString("productPriceTypeId").equals("WHOLESALE_PRICE")){//
-                result.put("wholeSalePrice", onePrice.getDouble("price"));
+                result.put("wholeSalePrice", onePrice.getBigDecimal("price"));
             }else if(onePrice.getString("productPriceTypeId").equals("LIST_PRICE")){//listPrice
-                result.put("listPrice", onePrice.getDouble("price"));
+                result.put("listPrice", onePrice.getBigDecimal("price"));
             }else{
-                result.put("defultPrice", onePrice.getDouble("price"));
-                result.put("listPrice", onePrice.getDouble("price"));
-                result.put("wholeSalePrice", onePrice.getDouble("price"));
+                result.put("defultPrice", onePrice.getBigDecimal("price"));
+                result.put("listPrice", onePrice.getBigDecimal("price"));
+                result.put("wholeSalePrice", onePrice.getBigDecimal("price"));
             }
         }
     
@@ -950,12 +954,12 @@
             }
     
             // Sum the sales usage quantities found
-            double salesUsageQuantity = 0;
+            BigDecimal salesUsageQuantity = BigDecimal.ZERO;
             GenericValue salesUsageItem = null;
             while((salesUsageItem = (GenericValue) salesUsageIt.next()) != null) {
                 if (salesUsageItem.get("quantity") != null) {
                     try {
-                        salesUsageQuantity += salesUsageItem.getDouble("quantity").doubleValue();
+                        salesUsageQuantity = salesUsageQuantity.add(salesUsageItem.getBigDecimal("quantity"));
                     } catch (Exception e) {
                         // Ignore
                     }
@@ -987,12 +991,12 @@
             }
     
             // Sum the production usage quantities found
-            double productionUsageQuantity = 0;
+            BigDecimal productionUsageQuantity = BigDecimal.ZERO;
             GenericValue productionUsageItem = null;
             while((productionUsageItem = (GenericValue) productionUsageIt.next()) != null) {
                 if (productionUsageItem.get("quantity") != null) {
                     try {
-                        productionUsageQuantity += productionUsageItem.getDouble("quantity").doubleValue();
+                        productionUsageQuantity = productionUsageQuantity.add(productionUsageItem.getBigDecimal("quantity"));
                     } catch (Exception e) {
                         // Ignore
                     }
@@ -1005,7 +1009,7 @@
                 e.printStackTrace();
             }
     
-            result.put("usageQuantity", new Double((salesUsageQuantity + productionUsageQuantity)));
+            result.put("usageQuantity", salesUsageQuantity.add(productionUsageQuantity));
 
         }
         return result;

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/inventory/InventoryWorker.java Sun Nov 30 22:51:11 2008
@@ -19,6 +19,7 @@
 
 package org.ofbiz.product.inventory;
 
+import java.math.BigDecimal;
 import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
@@ -72,8 +73,8 @@
      * @param delegator
      * @return
      */
-    public static double getOutstandingPurchasedQuantity(String productId, GenericDelegator delegator) {
-        double qty = 0.0;
+    public static BigDecimal getOutstandingPurchasedQuantity(String productId, GenericDelegator delegator) {
+     BigDecimal qty = BigDecimal.ZERO;
         List purchaseOrders = getOutstandingPurchaseOrders(productId, delegator);
         if (UtilValidate.isEmpty(purchaseOrders)) {
             return qty;
@@ -81,14 +82,14 @@
             for (Iterator pOi = purchaseOrders.iterator(); pOi.hasNext();) {
                 GenericValue nextOrder = (GenericValue) pOi.next();
                 if (nextOrder.get("quantity") != null) {
-                    double itemQuantity = nextOrder.getDouble("quantity").doubleValue();
-                    double cancelQuantity = 0.0;
+                 BigDecimal itemQuantity = nextOrder.getBigDecimal("quantity");
+                 BigDecimal cancelQuantity = BigDecimal.ZERO;
                     if (nextOrder.get("cancelQuantity") != null) {
-                        cancelQuantity = nextOrder.getDouble("cancelQuantity").doubleValue();
+                        cancelQuantity = nextOrder.getBigDecimal("cancelQuantity");
                     }
-                    itemQuantity -= cancelQuantity;
-                    if (itemQuantity >= 0.0) {
-                        qty += itemQuantity;
+                    itemQuantity = itemQuantity.subtract(cancelQuantity);
+                    if (itemQuantity.compareTo(BigDecimal.ZERO) >= 0) {
+                        qty = qty.add(itemQuantity);
                     }
                 }
             }
@@ -127,7 +128,7 @@
             List orderedProducts = delegator.findList("OrderItemQuantityReportGroupByProduct", conditions, fieldsToSelect, null, null, false);
             for (Iterator iter = orderedProducts.iterator(); iter.hasNext(); ) {
                 GenericValue value = (GenericValue) iter.next();
-                results.put(value.getString("productId"), value.getDouble("quantityOpen"));
+                results.put(value.getString("productId"), value.getBigDecimal("quantityOpen"));
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, module);

Modified: ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/price/PriceServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/price/PriceServices.java?rev=721986&r1=721985&r2=721986&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/price/PriceServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/product/src/org/ofbiz/product/price/PriceServices.java Sun Nov 30 22:51:11 2008
@@ -194,11 +194,10 @@
             partyId = userLogin.getString("partyId");
         }
 
-        Double quantityDbl = (Double) context.get("quantity");
-        if (quantityDbl == null) quantityDbl = new Double(1.0);
-        double quantity = quantityDbl.doubleValue();
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
+        if (quantity == null) quantity = BigDecimal.ONE;
 
-        Double amountDbl = (Double) context.get("amount");
+        BigDecimal amount = (BigDecimal) context.get("amount");
 
         List productPriceEcList = FastList.newInstance();
         productPriceEcList.add(EntityCondition.makeCondition("productId", EntityOperator.EQUALS, productId));
@@ -231,13 +230,13 @@
         List listPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE"));
         GenericValue listPriceValue = EntityUtil.getFirst(listPrices);
         if (listPrices != null && listPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module);
         }
 
         List defaultPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));
         GenericValue defaultPriceValue = EntityUtil.getFirst(defaultPrices);
         if (defaultPrices != null && defaultPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module);
         }
 
         // If there is an agreement between the company and the client, and there is
@@ -260,43 +259,43 @@
         List competitivePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE"));
         GenericValue competitivePriceValue = EntityUtil.getFirst(competitivePrices);
         if (competitivePrices != null && competitivePrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module);
         }
 
         List averageCosts = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST"));
         GenericValue averageCostValue = EntityUtil.getFirst(averageCosts);
         if (averageCosts != null && averageCosts.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module);
         }
 
         List promoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE"));
         GenericValue promoPriceValue = EntityUtil.getFirst(promoPrices);
         if (promoPrices != null && promoPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module);
         }
 
         List minimumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE"));
         GenericValue minimumPriceValue = EntityUtil.getFirst(minimumPrices);
         if (minimumPrices != null && minimumPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module);
         }
 
         List maximumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE"));
         GenericValue maximumPriceValue = EntityUtil.getFirst(maximumPrices);
         if (maximumPrices != null && maximumPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module);
         }
 
         List wholesalePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE"));
         GenericValue wholesalePriceValue = EntityUtil.getFirst(wholesalePrices);
         if (wholesalePrices != null && wholesalePrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module);
         }
 
         List specialPromoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE"));
         GenericValue specialPromoPriceValue = EntityUtil.getFirst(specialPromoPrices);
         if (specialPromoPrices != null && specialPromoPrices.size() > 1) {
-            if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module);
+            if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module);
         }
 
         // if any of these prices is missing and this product is a variant, default to the corresponding price on the virtual product
@@ -305,56 +304,56 @@
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE"));
                 listPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module);
                 }
             }
             if (defaultPriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));
                 defaultPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module);
                 }
             }
             if (averageCostValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST"));
                 averageCostValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module);
                 }
             }
             if (promoPriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE"));
                 promoPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module);
                 }
             }
             if (minimumPriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE"));
                 minimumPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module);
                 }
             }
             if (maximumPriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE"));
                 maximumPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module);
                 }
             }
             if (wholesalePriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE"));
                 wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module);
                 }
             }
             if (specialPromoPriceValue == null) {
                 List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE"));
                 specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices);
                 if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                    if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module);
+                    if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getBigDecimal("price"), module);
                 }
             }
         }
@@ -369,7 +368,7 @@
                 try {
                     List variantAssocList = EntityUtil.filterByDate(delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate")));
                     Iterator variantAssocIter = variantAssocList.iterator();
-                    double minDefaultPrice = Double.MAX_VALUE;
+                    BigDecimal minDefaultPrice = null;
                     List variantProductPrices = null;
                     String variantProductId = null;
                     while (variantAssocIter.hasNext()) {
@@ -379,14 +378,14 @@
                         List tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));
                         GenericValue curDefaultPriceValue = EntityUtil.getFirst(tempDefaultPriceList);
                         if (curDefaultPriceValue != null) {
-                            Double curDefaultPrice = curDefaultPriceValue.getDouble("price");
-                            if (curDefaultPrice.doubleValue() < minDefaultPrice) {
+                         BigDecimal curDefaultPrice = curDefaultPriceValue.getBigDecimal("price");
+                            if (minDefaultPrice == null || curDefaultPrice.compareTo(minDefaultPrice) < 0) {
                                 // check to see if the product is discontinued for sale before considering it the lowest price
                                 GenericValue curVariantProduct = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", curVariantProductId));
                                 if (curVariantProduct != null) {
                                     Timestamp salesDiscontinuationDate = curVariantProduct.getTimestamp("salesDiscontinuationDate");
                                     if (salesDiscontinuationDate == null || salesDiscontinuationDate.after(nowTimestamp)) {
-                                        minDefaultPrice = curDefaultPrice.doubleValue();
+                                        minDefaultPrice = curDefaultPrice;
                                         variantProductPrices = curVariantPriceList;
                                         variantProductId = curVariantProductId;
                                         // Debug.logInfo("Found new lowest price " + minDefaultPrice + " for variant with ID " + variantProductId, module);
@@ -402,63 +401,63 @@
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE"));
                             listPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + listPriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (defaultPriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));
                             defaultPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + defaultPriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (competitivePriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE"));
                             competitivePriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + competitivePriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + competitivePriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (averageCostValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST"));
                             averageCostValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + averageCostValue.getBigDecimal("price"), module);
                             }
                         }
                         if (promoPriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE"));
                             promoPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + promoPriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (minimumPriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE"));
                             minimumPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + minimumPriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (maximumPriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE"));
                             maximumPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + maximumPriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (wholesalePriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE"));
                             wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module);
                             }
                         }
                         if (specialPromoPriceValue == null) {
                             List virtualTempPrices = EntityUtil.filterByAnd(variantProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE"));
                             specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices);
                             if (virtualTempPrices != null && virtualTempPrices.size() > 1) {
-                                if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);
+                                if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + variantProductId + ", using the latest found with price: " + wholesalePriceValue.getBigDecimal("price"), module);
                             }
                         }
                     }
@@ -469,21 +468,21 @@
         }
 
         //boolean validPromoPriceFound = false;
-        double promoPrice = 0;
+        BigDecimal promoPrice = BigDecimal.ZERO;
         if (promoPriceValue != null && promoPriceValue.get("price") != null) {
-            promoPrice = promoPriceValue.getDouble("price").doubleValue();
+            promoPrice = promoPriceValue.getBigDecimal("price");
             //validPromoPriceFound = true;
         }
 
         //boolean validWholesalePriceFound = false;
-        double wholesalePrice = 0;
+        BigDecimal wholesalePrice = BigDecimal.ZERO;
         if (wholesalePriceValue != null && wholesalePriceValue.get("price") != null) {
-            wholesalePrice = wholesalePriceValue.getDouble("price").doubleValue();
+            wholesalePrice = wholesalePriceValue.getBigDecimal("price");
             //validWholesalePriceFound = true;
         }
 
         boolean validPriceFound = false;
-        double defaultPrice = 0;
+        BigDecimal defaultPrice = BigDecimal.ZERO;
         List orderItemPriceInfos = FastList.newInstance();
         if (defaultPriceValue != null) {
             // If a price calc formula (service) is specified, then use it to get the unit price
@@ -496,10 +495,10 @@
                 }
                 if (UtilValidate.isNotEmpty(customMethod) && UtilValidate.isNotEmpty(customMethod.getString("customMethodName"))) {
                     Map inMap = UtilMisc.toMap("userLogin", (GenericValue) context.get("userLogin"), "product", product);
-                    inMap.put("initialPrice", (Double)defaultPriceValue.get("price"));
+                    inMap.put("initialPrice", (BigDecimal)defaultPriceValue.get("price"));
                     inMap.put("currencyUomId", currencyUomId);
-                    inMap.put("quantity", quantityDbl);
-                    inMap.put("amount", amountDbl);
+                    inMap.put("quantity", quantity);
+                    inMap.put("amount", amount);
                     if (UtilValidate.isNotEmpty(surveyResponseId)) {
                         inMap.put("surveyResponseId", surveyResponseId);
                     }
@@ -509,10 +508,10 @@
                     try {
                         Map outMap = dispatcher.runSync(customMethod.getString("customMethodName"), inMap);
                         if (!ServiceUtil.isError(outMap)) {
-                            Double calculatedDefaultPrice = (Double)outMap.get("price");
+                         BigDecimal calculatedDefaultPrice = (BigDecimal)outMap.get("price");
                             orderItemPriceInfos = (List)outMap.get("orderItemPriceInfos");
                             if (UtilValidate.isNotEmpty(calculatedDefaultPrice)) {
-                                defaultPrice = calculatedDefaultPrice.doubleValue();
+                                defaultPrice = calculatedDefaultPrice;
                                 validPriceFound = true;
                             }
                         }
@@ -522,36 +521,36 @@
                 }
             }
             if (!validPriceFound && defaultPriceValue.get("price") != null) {
-                defaultPrice = defaultPriceValue.getDouble("price").doubleValue();
+                defaultPrice = defaultPriceValue.getBigDecimal("price");
                 validPriceFound = true;
             }
         }
 
-        Double listPriceDbl = listPriceValue != null ? listPriceValue.getDouble("price") : null;
+        BigDecimal listPrice = listPriceValue != null ? listPriceValue.getBigDecimal("price") : null;
 
-        if (listPriceDbl == null) {
+        if (listPrice == null) {
             // no list price, use defaultPrice for the final price
 
             // ========= ensure calculated price is not below minSalePrice or above maxSalePrice =========
-            Double maxSellPrice = maximumPriceValue != null ? maximumPriceValue.getDouble("price") : null;
-            if (maxSellPrice != null && defaultPrice > maxSellPrice.doubleValue()) {
-                defaultPrice = maxSellPrice.doubleValue();
+         BigDecimal maxSellPrice = maximumPriceValue != null ? maximumPriceValue.getBigDecimal("price") : null;
+            if (maxSellPrice != null && defaultPrice.compareTo(maxSellPrice) > 0) {
+                defaultPrice = maxSellPrice;
             }
             // min price second to override max price, safety net
-            Double minSellPrice = minimumPriceValue != null ? minimumPriceValue.getDouble("price") : null;
-            if (minSellPrice != null && defaultPrice < minSellPrice.doubleValue()) {
-                defaultPrice = minSellPrice.doubleValue();
+            BigDecimal minSellPrice = minimumPriceValue != null ? minimumPriceValue.getBigDecimal("price") : null;
+            if (minSellPrice != null && defaultPrice.compareTo(minSellPrice) < 0) {
+                defaultPrice = minSellPrice;
                 // since we have found a minimum price that has overriden a the defaultPrice, even if no valid one was found, we will consider it as if one had been...
                 validPriceFound = true;
             }
 
-            result.put("basePrice", new Double(defaultPrice));
-            result.put("price", new Double(defaultPrice));
-            result.put("defaultPrice", new Double(defaultPrice));
-            result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getDouble("price") : null);
-            result.put("averageCost", averageCostValue != null ? averageCostValue.getDouble("price") : null);
-            result.put("promoPrice", promoPriceValue != null ? promoPriceValue.getDouble("price") : null);
-            result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getDouble("price") : null);
+            result.put("basePrice", defaultPrice);
+            result.put("price", defaultPrice);
+            result.put("defaultPrice", defaultPrice);
+            result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getBigDecimal("price") : null);
+            result.put("averageCost", averageCostValue != null ? averageCostValue.getBigDecimal("price") : null);
+            result.put("promoPrice", promoPriceValue != null ? promoPriceValue.getBigDecimal("price") : null);
+            result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getBigDecimal("price") : null);
             result.put("validPriceFound", new Boolean(validPriceFound));
             result.put("isSale", Boolean.FALSE);
             result.put("orderItemPriceInfos", orderItemPriceInfos);
@@ -583,7 +582,7 @@
                             if ("PRIP_QUANTITY".equals(productPriceCond.getString("inputParamEnumId"))) {
                                 foundQuantityInputParam = true;
                             } else {
-                                if (!checkPriceCondition(productPriceCond, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, new Double(quantity), listPriceDbl.doubleValue(), currencyUomId, delegator, nowTimestamp)) {
+                                if (!checkPriceCondition(productPriceCond, productId, virtualProductId, prodCatalogId, productStoreGroupId, webSiteId, partyId, quantity, listPrice, currencyUomId, delegator, nowTimestamp)) {
                                     allExceptQuantTrue = false;
                                 }
                             }
@@ -610,7 +609,7 @@
                         ruleListToUse.add(quantityProductPriceRule);
                         ruleListToUse.addAll(nonQuantityProductPriceRules);
                     
-                        Map quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPriceDbl.doubleValue(), defaultPrice, promoPrice,
+                        Map quantCalcResults = calcPriceResultFromRules(ruleListToUse, listPrice, defaultPrice, promoPrice,
                             wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound,
                             averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId,
                             webSiteId, partyId, null, currencyUomId, delegator, nowTimestamp);
@@ -626,10 +625,10 @@
                     result.put("allQuantityPrices", allQuantityPrices);
 
                     // use a quantity 1 to get the main price, then fill in the quantity break prices
-                    Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice,
+                    Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice,
                         wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound,
                         averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId,
-                        webSiteId, partyId, new Double(1.0), currencyUomId, delegator, nowTimestamp);
+                        webSiteId, partyId, BigDecimal.ONE, currencyUomId, delegator, nowTimestamp);
                     result.putAll(calcResults);
                     // The orderItemPriceInfos out parameter requires a special treatment:
                     // the list of OrderItemPriceInfos generated by the price rule is appended to
@@ -644,10 +643,10 @@
                             checkIncludeVat, currencyUomId, productId, quantity, partyId, dispatcher);
                     if (errorResult != null) return errorResult;
                 } else {
-                    Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPriceDbl.doubleValue(), defaultPrice, promoPrice,
+                    Map calcResults = calcPriceResultFromRules(allProductPriceRules, listPrice, defaultPrice, promoPrice,
                         wholesalePrice, maximumPriceValue, minimumPriceValue, validPriceFound,
                         averageCostValue, productId, virtualProductId, prodCatalogId, productStoreGroupId,
-                        webSiteId, partyId, new Double(quantity), currencyUomId, delegator, nowTimestamp);
+                        webSiteId, partyId, quantity, currencyUomId, delegator, nowTimestamp);
                     result.putAll(calcResults);
                     // The orderItemPriceInfos out parameter requires a special treatment:
                     // the list of OrderItemPriceInfos generated by the price rule is appended to
@@ -673,16 +672,16 @@
     }
     
     public static Map addGeneralResults(Map result, GenericValue competitivePriceValue, GenericValue specialPromoPriceValue, GenericValue productStore,
-        String checkIncludeVat, String currencyUomId, String productId, double quantity, String partyId, LocalDispatcher dispatcher) {
-        result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getDouble("price") : null);
-        result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getDouble("price") : null);
+        String checkIncludeVat, String currencyUomId, String productId, BigDecimal quantity, String partyId, LocalDispatcher dispatcher) {
+        result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getBigDecimal("price") : null);
+        result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getBigDecimal("price") : null);
         result.put("currencyUsed", currencyUomId);
 
         // okay, now we have the calculated price, see if we should add in tax and if so do it
         if ("Y".equals(checkIncludeVat) && productStore != null && "Y".equals(productStore.getString("showPricesWithVatTax"))) {
             Map calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStore.get("productStoreId"),
-                    "productId", productId, "quantity", BigDecimal.valueOf(quantity),
-                    "basePrice", BigDecimal.valueOf(((Double) result.get("price")).doubleValue()));
+                    "productId", productId, "quantity", quantity,
+                    "basePrice", (BigDecimal) result.get("price"));
             if (UtilValidate.isNotEmpty(partyId)) {
                 calcTaxForDisplayContext.put("billToPartyId", partyId);
             }
@@ -693,25 +692,25 @@
                     return ServiceUtil.returnError("Error calculating VAT tax (with calcTaxForDisplay service)", null, null, calcTaxForDisplayResult);
                 }
                 // taxTotal, taxPercentage, priceWithTax
-                result.put("price", Double.valueOf(((BigDecimal) calcTaxForDisplayResult.get("priceWithTax")).doubleValue()));
+                result.put("price", (BigDecimal) calcTaxForDisplayResult.get("priceWithTax"));
 
                 // based on the taxPercentage calculate the other amounts, including: listPrice, defaultPrice, averageCost, promoPrice, competitivePrice
                 BigDecimal taxPercentage = (BigDecimal) calcTaxForDisplayResult.get("taxPercentage");
                 BigDecimal taxMultiplier = ONE_BASE.add(taxPercentage.divide(PERCENT_SCALE, taxCalcScale));
                 if (result.get("listPrice") != null) {
-                    result.put("listPrice", Double.valueOf( BigDecimal.valueOf(((Double) result.get("listPrice")).doubleValue()).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ).doubleValue()));
+                    result.put("listPrice", ((BigDecimal) result.get("listPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ));
                 }
                 if (result.get("defaultPrice") != null) {                    
-                    result.put("defaultPrice", Double.valueOf( BigDecimal.valueOf(((Double) result.get("defaultPrice")).doubleValue()).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ).doubleValue()));
+                    result.put("defaultPrice", ((BigDecimal) result.get("defaultPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ));
                 }
                 if (result.get("averageCost") != null) {
-                    result.put("averageCost", Double.valueOf( BigDecimal.valueOf(((Double) result.get("averageCost")).doubleValue()).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ).doubleValue()));
+                    result.put("averageCost", ((BigDecimal) result.get("averageCost")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ));
                 }              
                 if (result.get("promoPrice") != null) {
-                    result.put("promoPrice", Double.valueOf( BigDecimal.valueOf(((Double) result.get("promoPrice")).doubleValue()).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ).doubleValue()));
+                    result.put("promoPrice", ((BigDecimal) result.get("promoPrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ));
                 }
                 if (result.get("competitivePrice") != null) {
-                    result.put("competitivePrice", Double.valueOf( BigDecimal.valueOf(((Double) result.get("competitivePrice")).doubleValue()).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ).doubleValue()));
+                    result.put("competitivePrice", ((BigDecimal) result.get("competitivePrice")).multiply(taxMultiplier).setScale( taxFinalScale, taxRounding ));
                 }
             } catch (GenericServiceException e) {
                 String errMsg = "Error calculating VAT tax (with calcTaxForDisplay service): " + e.toString();
@@ -898,10 +897,10 @@
         return productPriceRules;
     }
     
-    public static Map calcPriceResultFromRules(List productPriceRules, double listPrice, double defaultPrice, double promoPrice,
-        double wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound,
+    public static Map calcPriceResultFromRules(List productPriceRules, BigDecimal listPrice, BigDecimal defaultPrice, BigDecimal promoPrice,
+        BigDecimal wholesalePrice, GenericValue maximumPriceValue, GenericValue minimumPriceValue, boolean validPriceFound,
         GenericValue averageCostValue, String productId, String virtualProductId, String prodCatalogId, String productStoreGroupId,
-        String webSiteId, String partyId, Double quantity, String currencyUomId, GenericDelegator delegator, Timestamp nowTimestamp) throws GenericEntityException {
+        String webSiteId, String partyId, BigDecimal quantity, String currencyUomId, GenericDelegator delegator, Timestamp nowTimestamp) throws GenericEntityException {
     
         Map calcResults = FastMap.newInstance();
 
@@ -915,11 +914,11 @@
         int totalRules = 0;
 
         // get some of the base values to calculate with
-        double averageCost = (averageCostValue != null && averageCostValue.get("price") != null) ? averageCostValue.getDouble("price").doubleValue() : listPrice;
-        double margin = listPrice - averageCost;
+        BigDecimal averageCost = (averageCostValue != null && averageCostValue.get("price") != null) ? averageCostValue.getBigDecimal("price") : listPrice;
+        BigDecimal margin = listPrice.subtract(averageCost);
 
         // calculate running sum based on listPrice and rules found
-        double price = listPrice;
+        BigDecimal price = listPrice;
         
         Iterator productPriceRulesIter = productPriceRules.iterator();
         while (productPriceRulesIter.hasNext()) {
@@ -996,33 +995,33 @@
                     totalActions++;
 
                     // yeah, finally here, perform the action, ie, modify the price
-                    double modifyAmount = 0;
+                    BigDecimal modifyAmount = BigDecimal.ZERO;
 
                     if ("PRICE_POD".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         if (productPriceAction.get("amount") != null) {
-                            modifyAmount = defaultPrice * (productPriceAction.getDouble("amount").doubleValue() / 100.0);
+                            modifyAmount = defaultPrice.multiply(productPriceAction.getBigDecimal("amount").movePointLeft(2));
                         }
                     } else if ("PRICE_POL".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         if (productPriceAction.get("amount") != null) {
-                            modifyAmount = listPrice * (productPriceAction.getDouble("amount").doubleValue() / 100.0);
+                            modifyAmount = listPrice.multiply(productPriceAction.getBigDecimal("amount").movePointLeft(2));
                         }
                     } else if ("PRICE_POAC".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         if (productPriceAction.get("amount") != null) {
-                            modifyAmount = averageCost * (productPriceAction.getDouble("amount").doubleValue() / 100.0);
+                            modifyAmount = averageCost.multiply(productPriceAction.getBigDecimal("amount").movePointLeft(2));
                         }
                     } else if ("PRICE_POM".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         if (productPriceAction.get("amount") != null) {
-                            modifyAmount = margin * (productPriceAction.getDouble("amount").doubleValue() / 100.0);
+                            modifyAmount = margin.multiply(productPriceAction.getBigDecimal("amount").movePointLeft(2));
                         }
                     } else if ("PRICE_FOL".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         if (productPriceAction.get("amount") != null) {
-                            modifyAmount = productPriceAction.getDouble("amount").doubleValue();
+                            modifyAmount = productPriceAction.getBigDecimal("amount");
                         }
                     } else if ("PRICE_FLAT".equals(productPriceAction.getString("productPriceActionTypeId"))) {
                         // this one is a bit different, break out of the loop because we now have our final price
                         foundFlatOverride = true;
                         if (productPriceAction.get("amount") != null) {
-                            price = productPriceAction.getDouble("amount").doubleValue();
+                            price = productPriceAction.getBigDecimal("amount");
                         } else {
                             Debug.logInfo("ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);
                             price = defaultPrice;
@@ -1033,18 +1032,18 @@
                         foundFlatOverride = true;
                         price = promoPrice;
                         if (productPriceAction.get("amount") != null) {
-                            price += productPriceAction.getDouble("amount").doubleValue();
+                            price = price.add(productPriceAction.getBigDecimal("amount"));
                         }
-                        if (price == 0.00) {
-                            if (defaultPrice != 0.00) {
+                        if (price.compareTo(BigDecimal.ZERO) == 0) {
+                            if (defaultPrice.compareTo(BigDecimal.ZERO) != 0) {
                                 Debug.logInfo("PromoPrice and ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);
                                 price = defaultPrice;
-                            } else if (listPrice != 0.00) {
+                            } else if (listPrice.compareTo(BigDecimal.ZERO) != 0) {
                                 Debug.logInfo("PromoPrice and ProductPriceAction had null amount and no default price was available, using list price: " + listPrice + " for product with id " + productId, module);
                                 price = listPrice;
                             } else {
                                 Debug.logError("PromoPrice and ProductPriceAction had null amount and no default or list price was available, so price is set to zero for product with id " + productId, module);
-                                price = 0.00;
+                                price = BigDecimal.ZERO;
                             }
                             isSale = false;                // reverse isSale flag, as this sale rule was actually not applied
                         }
@@ -1053,18 +1052,18 @@
                         foundFlatOverride = true;
                         price = wholesalePrice;
                         if (productPriceAction.get("amount") != null) {
-                            price += productPriceAction.getDouble("amount").doubleValue();
+                            price = price.add(productPriceAction.getBigDecimal("amount"));
                         }
-                        if (price == 0.00) {
-                            if (defaultPrice != 0.00) {
+                        if (price.compareTo(BigDecimal.ZERO) == 0) {
+                            if (defaultPrice.compareTo(BigDecimal.ZERO) != 0) {
                                 Debug.logInfo("WholesalePrice and ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);
                                 price = defaultPrice;
-                            } else if (listPrice != 0.00) {
+                            } else if (listPrice.compareTo(BigDecimal.ZERO) != 0) {
                                 Debug.logInfo("WholesalePrice and ProductPriceAction had null amount and no default price was available, using list price: " + listPrice + " for product with id " + productId, module);
                                 price = listPrice;
                             } else {
                                 Debug.logError("WholesalePrice and ProductPriceAction had null amount and no default or list price was available, so price is set to zero for product with id " + productId, module);
-                                price = 0.00;
+                                price = BigDecimal.ZERO;
                             }
                             isSale = false; // reverse isSale flag, as this sale rule was actually not applied
                         }
@@ -1082,7 +1081,7 @@
 
                     orderItemPriceInfo.set("productPriceRuleId", productPriceAction.get("productPriceRuleId"));
                     orderItemPriceInfo.set("productPriceActionSeqId", productPriceAction.get("productPriceActionSeqId"));
-                    orderItemPriceInfo.set("modifyAmount", new BigDecimal(modifyAmount));
+                    orderItemPriceInfo.set("modifyAmount", modifyAmount);
                     orderItemPriceInfo.set("rateCode", productPriceAction.get("rateCode"));
                     // make sure description is <= than 250 chars
                     String priceInfoDescriptionString = priceInfoDescription.toString();
@@ -1096,7 +1095,7 @@
                     if (foundFlatOverride) {
                         break;
                     } else {
-                        price += modifyAmount;
+                        price = price.add(modifyAmount);
                     }
                 }
             }
@@ -1129,25 +1128,25 @@
         }
 
         // ========= ensure calculated price is not below minSalePrice or above maxSalePrice =========
-        Double maxSellPrice = maximumPriceValue != null ? maximumPriceValue.getDouble("price") : null;
-        if (maxSellPrice != null && price > maxSellPrice.doubleValue()) {
-            price = maxSellPrice.doubleValue();
+        BigDecimal maxSellPrice = maximumPriceValue != null ? maximumPriceValue.getBigDecimal("price") : null;
+        if (maxSellPrice != null && price.compareTo(maxSellPrice) > 0) {
+            price = maxSellPrice;
         }
         // min price second to override max price, safety net
-        Double minSellPrice = minimumPriceValue != null ? minimumPriceValue.getDouble("price") : null;
-        if (minSellPrice != null && price < minSellPrice.doubleValue()) {
-            price = minSellPrice.doubleValue();
+        BigDecimal minSellPrice = minimumPriceValue != null ? minimumPriceValue.getBigDecimal("price") : null;
+        if (minSellPrice != null && price.compareTo(minSellPrice) < 0) {
+            price = minSellPrice;
             // since we have found a minimum price that has overriden a the defaultPrice, even if no valid one was found, we will consider it as if one had been...
             validPriceFound = true;
         }
 
         if (Debug.verboseOn()) Debug.logVerbose("Final Calculated price: " + price + ", rules: " + totalRules + ", conds: " + totalConds + ", actions: " + totalActions, module);
 
-        calcResults.put("basePrice", new Double(price));
-        calcResults.put("price", new Double(price));
-        calcResults.put("listPrice", new Double(listPrice));
-        calcResults.put("defaultPrice", new Double(defaultPrice));
-        calcResults.put("averageCost", new Double(averageCost));
+        calcResults.put("basePrice", price);
+        calcResults.put("price", price);
+        calcResults.put("listPrice", listPrice);
+        calcResults.put("defaultPrice", defaultPrice);
+        calcResults.put("averageCost", averageCost);
         calcResults.put("orderItemPriceInfos", orderItemPriceInfos);
         calcResults.put("isSale", new Boolean(isSale));
         calcResults.put("validPriceFound", new Boolean(validPriceFound));
@@ -1156,7 +1155,7 @@
     }
 
     public static boolean checkPriceCondition(GenericValue productPriceCond, String productId, String virtualProductId, String prodCatalogId,
-            String productStoreGroupId, String webSiteId, String partyId, Double quantity, double listPrice,
+            String productStoreGroupId, String webSiteId, String partyId, BigDecimal quantity, BigDecimal listPrice,
             String currencyUomId, GenericDelegator delegator, Timestamp nowTimestamp) throws GenericEntityException {
         if (Debug.verboseOn()) Debug.logVerbose("Checking price condition: " + productPriceCond, module);
         int compare = 0;
@@ -1230,7 +1229,7 @@
                 // NOTE: setting compare = 0 won't do the trick here because the condition won't always be or include and equal
                 return true;
             } else {
-                compare = quantity.compareTo(Double.valueOf(productPriceCond.getString("condValue")));
+                compare = quantity.compareTo(new BigDecimal(productPriceCond.getString("condValue")));
             }
         } else if ("PRIP_PARTY_ID".equals(productPriceCond.getString("inputParamEnumId"))) {
             if (UtilValidate.isNotEmpty(partyId)) {
@@ -1298,9 +1297,9 @@
                 compare = 1;
             }
         } else if ("PRIP_LIST_PRICE".equals(productPriceCond.getString("inputParamEnumId"))) {
-            Double listPriceValue = new Double(listPrice);
+            BigDecimal listPriceValue = listPrice;
 
-            compare = listPriceValue.compareTo(Double.valueOf(productPriceCond.getString("condValue")));
+            compare = listPriceValue.compareTo(new BigDecimal(productPriceCond.getString("condValue")));
         } else if ("PRIP_CURRENCY_UOMID".equals(productPriceCond.getString("inputParamEnumId"))) {
             compare = currencyUomId.compareTo(productPriceCond.getString("condValue"));
         } else {
@@ -1339,13 +1338,13 @@
 
         List orderItemPriceInfos = new LinkedList();
         boolean validPriceFound = false;
-        double price = 0.0;
+        BigDecimal price = BigDecimal.ZERO;
 
         GenericValue product = (GenericValue)context.get("product");
         String productId = product.getString("productId");
         String currencyUomId = (String)context.get("currencyUomId");
         String partyId = (String)context.get("partyId");
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         
         // a) Get the Price from the Agreement* data model
         // TODO: Implement this
@@ -1370,20 +1369,20 @@
                 for (int i = 0; i < productSuppliers.size(); i++) {
                     GenericValue productSupplier = (GenericValue) productSuppliers.get(i);
                     if (!validPriceFound) {
-                        price = ((Double)productSupplier.get("lastPrice")).doubleValue();
+                        price = ((BigDecimal)productSupplier.get("lastPrice"));
                         validPriceFound = true;
                     }
                     // add a orderItemPriceInfo element too, without orderId or orderItemId
                     StringBuffer priceInfoDescription = new StringBuffer();
                     priceInfoDescription.append("SupplierProduct ");
                     priceInfoDescription.append("[minimumOrderQuantity:");
-                    priceInfoDescription.append("" + productSupplier.getDouble("minimumOrderQuantity").doubleValue());
-                    priceInfoDescription.append(", lastPrice: " + productSupplier.getDouble("lastPrice").doubleValue());
+                    priceInfoDescription.append("" + productSupplier.getBigDecimal("minimumOrderQuantity"));
+                    priceInfoDescription.append(", lastPrice: " + productSupplier.getBigDecimal("lastPrice"));
                     priceInfoDescription.append("]");
                     GenericValue orderItemPriceInfo = delegator.makeValue("OrderItemPriceInfo");
                     //orderItemPriceInfo.set("productPriceRuleId", productPriceAction.get("productPriceRuleId"));
                     //orderItemPriceInfo.set("productPriceActionSeqId", productPriceAction.get("productPriceActionSeqId"));
-                    //orderItemPriceInfo.set("modifyAmount", new Double(modifyAmount));
+                    //orderItemPriceInfo.set("modifyAmount", modifyAmount);
                     // make sure description is <= than 250 chars
                     String priceInfoDescriptionString = priceInfoDescription.toString();
                     if (priceInfoDescriptionString.length() > 250) {
@@ -1433,12 +1432,12 @@
             // use the most current price
             GenericValue thisPrice = EntityUtil.getFirst(pricesToUse);
             if (thisPrice != null) {
-                price = thisPrice.getDouble("price").doubleValue();
+                price = thisPrice.getBigDecimal("price");
                 validPriceFound = true;
             }
         }
 
-        result.put("price", new Double(price));
+        result.put("price", price);
         result.put("validPriceFound", new Boolean(validPriceFound));
         result.put("orderItemPriceInfos", orderItemPriceInfos);
         return result;