svn commit: r731346 [2/3] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/widget/ applications/content/script/org/ofbiz/content/content/ applications/ecommerce/script/org/ofbiz/ecommerce/customer/ applications/ecommerce/webapp/ecom...

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

svn commit: r731346 [2/3] - in /ofbiz/branches/typecheckcleanup200810: applications/accounting/widget/ applications/content/script/org/ofbiz/content/content/ applications/ecommerce/script/org/ofbiz/ecommerce/customer/ applications/ecommerce/webapp/ecom...

lektran
Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMNode.java Sun Jan  4 11:46:24 2009
@@ -19,6 +19,7 @@
 
 package org.ofbiz.manufacturing.bom;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Date;
@@ -59,11 +60,11 @@
     private GenericValue productAssoc; // the product assoc record (from ProductAssoc entity) in which the current product is in productIdTo
     private ArrayList children; // current node's children (ProductAssocs)
     private ArrayList childrenNodes; // current node's children nodes (BOMNode)
-    private double quantityMultiplier; // the necessary quantity as declared in the bom (from ProductAssocs or ProductManufacturingRule)
-    private double scrapFactor; // the scrap factor as declared in the bom (from ProductAssocs)
+    private BigDecimal quantityMultiplier; // the necessary quantity as declared in the bom (from ProductAssocs or ProductManufacturingRule)
+    private BigDecimal scrapFactor; // the scrap factor as declared in the bom (from ProductAssocs)
     // Runtime fields
     private int depth; // the depth of this node in the current tree
-    private double quantity; // the quantity of this node in the current tree
+    private BigDecimal quantity; // the quantity of this node in the current tree
     private String bomTypeId; // the type of the current tree
   
     public BOMNode(GenericValue product, LocalDispatcher dispatcher, GenericValue userLogin) {
@@ -76,11 +77,11 @@
         parentNode = null;
         productForRules = null;
         bomTypeId = null;
-        quantityMultiplier = 1;
-        scrapFactor = 1;
+        quantityMultiplier = BigDecimal.ONE;
+        scrapFactor = BigDecimal.ONE;
         // Now we initialize the fields used in breakdowns
         depth = 0;
-        quantity = 0;
+        quantity = BigDecimal.ZERO;
     }
 
     public BOMNode(String productId, GenericDelegator delegator, LocalDispatcher dispatcher, GenericValue userLogin) throws GenericEntityException {
@@ -145,11 +146,11 @@
                 String ruleCondition = (String)rule.get("productFeature");
                 String ruleOperator = (String)rule.get("ruleOperator");
                 String newPart = (String)rule.get("productIdInSubst");
-                double ruleQuantity = 0;
+                BigDecimal ruleQuantity = BigDecimal.ZERO;
                 try {
-                    ruleQuantity = rule.getDouble("quantity").doubleValue();
+                    ruleQuantity = rule.getBigDecimal("quantity");
                 } catch(Exception exc) {
-                    ruleQuantity = 0;
+                    ruleQuantity = BigDecimal.ZERO;
                 }
 
                 GenericValue feature = null;
@@ -179,7 +180,7 @@
                         oneChildNode.setRuleApplied(rule);
                         oneChildNode.setProductAssoc(origNode.getProductAssoc());
                         oneChildNode.setScrapFactor(origNode.getScrapFactor());
-                        if (ruleQuantity > 0) {
+                        if (ruleQuantity.compareTo(BigDecimal.ZERO) > 0) {
                             oneChildNode.setQuantityMultiplier(ruleQuantity);
                         } else {
                             oneChildNode.setQuantityMultiplier(origNode.getQuantityMultiplier());
@@ -199,23 +200,24 @@
         oneChildNode.setTree(tree);
         oneChildNode.setProductAssoc(node);
         try {
-            oneChildNode.setQuantityMultiplier(node.getDouble("quantity").doubleValue());
+            oneChildNode.setQuantityMultiplier(node.getBigDecimal("quantity"));
         } catch(Exception nfe) {
-            oneChildNode.setQuantityMultiplier(1);
+            oneChildNode.setQuantityMultiplier(BigDecimal.ONE);
         }
         try {
-            double percScrapFactor = node.getDouble("scrapFactor").doubleValue();
+            BigDecimal percScrapFactor = node.getBigDecimal("scrapFactor");
 
-            // A negative scrap factor is a salvage factor
-            if (percScrapFactor > -100 && percScrapFactor < 100) {
-                percScrapFactor = 1 + percScrapFactor / 100;
+            // A negative scrap factor is a salvage factor
+            BigDecimal bdHundred = new BigDecimal("100");
+            if (percScrapFactor.compareTo(bdHundred.negate()) > 0 && percScrapFactor.compareTo(bdHundred.negate()) < 0) {
+                percScrapFactor = BigDecimal.ONE.add(percScrapFactor.movePointLeft(2));
             } else {
                 Debug.logWarning("A scrap factor of [" + percScrapFactor + "] was ignored", module);
-                percScrapFactor = 1;
+                percScrapFactor = BigDecimal.ONE;
             }
             oneChildNode.setScrapFactor(percScrapFactor);
         } catch(Exception nfe) {
-            oneChildNode.setScrapFactor(1);
+            oneChildNode.setScrapFactor(BigDecimal.ONE);
         }
         BOMNode newNode = oneChildNode;
         // CONFIGURATOR
@@ -376,7 +378,7 @@
     }
     // ------------------------------------
     // Method used for TEST and DEBUG purposes
-    public void print(StringBuffer sb, double quantity, int depth) {
+    public void print(StringBuffer sb, BigDecimal quantity, int depth) {
         for (int i = 0; i < depth; i++) {
             sb.append("<b>&nbsp;*&nbsp;</b>");
         }
@@ -388,21 +390,21 @@
         depth++;
         for (int i = 0; i < children.size(); i++) {
             oneChild = (GenericValue)children.get(i);
-            double bomQuantity = 0;
+            BigDecimal bomQuantity = BigDecimal.ZERO;
             try {
-                bomQuantity = oneChild.getDouble("quantity").doubleValue();
+                bomQuantity = oneChild.getBigDecimal("quantity");
             } catch(Exception exc) {
-                bomQuantity = 1;
+                bomQuantity = BigDecimal.ONE;
             }
             oneChildNode = (BOMNode)childrenNodes.get(i);
             sb.append("<br/>");
             if (oneChildNode != null) {
-                oneChildNode.print(sb, (quantity * bomQuantity), depth);
+                oneChildNode.print(sb, quantity.multiply(bomQuantity), depth);
             }
         }
     }
 
-    public void print(ArrayList arr, double quantity, int depth, boolean excludeWIPs) {
+    public void print(ArrayList arr, BigDecimal quantity, int depth, boolean excludeWIPs) {
         // Now we set the depth and quantity of the current node
         // in this breakdown.
         this.depth = depth;
@@ -418,27 +420,27 @@
         }
         if (serviceName != null) {
             Map resultContext = null;
-            Map arguments = UtilMisc.toMap("neededQuantity", new Double(quantity * quantityMultiplier), "amount", new Double((tree!=null? tree.getRootAmount():0)));
-            Double width = null;
+            Map arguments = UtilMisc.toMap("neededQuantity", quantity.multiply(quantityMultiplier), "amount", tree != null ? tree.getRootAmount() : BigDecimal.ZERO);
+            BigDecimal width = null;
             if (getProduct().get("productWidth") != null) {
-                width = getProduct().getDouble("productWidth");
+                width = getProduct().getBigDecimal("productWidth");
             }
             if (width == null) {
-                width = new Double(0);
+                width = BigDecimal.ZERO;
             }
             arguments.put("width", width);
             Map inputContext = UtilMisc.toMap("arguments", arguments, "userLogin", userLogin);
             try {
                 resultContext = dispatcher.runSync(serviceName, inputContext);
-                Double calcQuantity = (Double)resultContext.get("quantity");
+                BigDecimal calcQuantity = (BigDecimal)resultContext.get("quantity");
                 if (calcQuantity != null) {
-                    this.quantity = calcQuantity.doubleValue();
+                    this.quantity = calcQuantity;
                 }
             } catch (GenericServiceException e) {
                 //Debug.logError(e, "Problem calling the getManufacturingComponents service", module);
             }
         } else {
-            this.quantity = quantity * quantityMultiplier * scrapFactor;
+            this.quantity = quantity.multiply(quantityMultiplier).multiply(scrapFactor);
         }
         // First of all we visit the current node.
         arr.add(this);
@@ -458,11 +460,11 @@
         }
     }
 
-    public void getProductsInPackages(ArrayList arr, double quantity, int depth, boolean excludeWIPs) {
+    public void getProductsInPackages(ArrayList arr, BigDecimal quantity, int depth, boolean excludeWIPs) {
         // Now we set the depth and quantity of the current node
         // in this breakdown.
         this.depth = depth;
-        this.quantity = quantity * quantityMultiplier * scrapFactor;
+        this.quantity = quantity.multiply(quantityMultiplier).multiply(scrapFactor);
         // First of all we visit the current node.
         if (this.getProduct().getString("shipmentBoxTypeId") != null) {
             arr.add(this);
@@ -492,7 +494,7 @@
             nodes.put(product.getString("productId"), sameNode);
         }
         // Now we add the current quantity to the node
-        sameNode.setQuantity(sameNode.getQuantity() + quantity);
+        sameNode.setQuantity(sameNode.getQuantity().add(quantity));
         // Now (recursively) we visit the children.
         BOMNode oneChildNode = null;
         for (int i = 0; i < childrenNodes.size(); i++) {
@@ -554,7 +556,7 @@
                 serviceContext.put("workEffortName", "SP_" + shipmentId + "_" + serviceContext.get("productId"));
             }
             
-            serviceContext.put("pRQuantity", new Double(getQuantity()));
+            serviceContext.put("pRQuantity", getQuantity());
             if (UtilValidate.isNotEmpty(maxEndDate)) {
                 serviceContext.put("startDate", maxEndDate);
             } else {
@@ -695,11 +697,11 @@
      * @return Value of property quantity.
      *
      */
-    public double getQuantity() {
+    public BigDecimal getQuantity() {
         return quantity;
     }
 
-    public void setQuantity(double quantity) {
+    public void setQuantity(BigDecimal quantity) {
         this.quantity = quantity;
     }
 
@@ -764,7 +766,7 @@
      * @return Value of property quantityMultiplier.
      *
      */
-    public double getQuantityMultiplier() {
+    public BigDecimal getQuantityMultiplier() {
         return quantityMultiplier;
     }    
     
@@ -772,7 +774,7 @@
      * @param quantityMultiplier New value of property quantityMultiplier.
      *
      */
-    public void setQuantityMultiplier(double quantityMultiplier) {
+    public void setQuantityMultiplier(BigDecimal quantityMultiplier) {
         this.quantityMultiplier = quantityMultiplier;
     }
     
@@ -796,7 +798,7 @@
      * @return Value of property scrapFactor.
      *
      */
-    public double getScrapFactor() {
+    public BigDecimal getScrapFactor() {
         return scrapFactor;
     }
     
@@ -804,7 +806,7 @@
      * @param scrapFactor New value of property scrapFactor.
      *
      */
-    public void setScrapFactor(double scrapFactor) {
+    public void setScrapFactor(BigDecimal scrapFactor) {
         this.scrapFactor = scrapFactor;
     }
     

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMServices.java Sun Jan  4 11:46:24 2009
@@ -19,6 +19,7 @@
 
 package org.ofbiz.manufacturing.bom;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.ArrayList;
 import java.util.Date;
@@ -290,8 +291,8 @@
         String fromDateStr = (String) context.get("fromDate");
         String bomType = (String) context.get("bomType");
         Integer type = (Integer) context.get("type");
-        Double quantity = (Double) context.get("quantity");
-        Double amount = (Double) context.get("amount");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
+        BigDecimal amount = (BigDecimal) context.get("amount");
         if (type == null) {
             type = new Integer(0);
         }
@@ -314,10 +315,10 @@
             return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage());
         }
         if (tree != null && quantity != null) {
-            tree.setRootQuantity(quantity.doubleValue());
+            tree.setRootQuantity(quantity);
         }
         if (tree != null && amount != null) {
-            tree.setRootAmount(amount.doubleValue());
+            tree.setRootAmount(amount);
         }
         result.put("tree", tree);
 
@@ -339,16 +340,16 @@
         GenericValue userLogin = (GenericValue)context.get("userLogin");
 
         String productId = (String) context.get("productId");
-        Double quantity = (Double) context.get("quantity");
-        Double amount = (Double) context.get("amount");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
+        BigDecimal amount = (BigDecimal) context.get("amount");
         String fromDateStr = (String) context.get("fromDate");
         Boolean excludeWIPs = (Boolean) context.get("excludeWIPs");
         
         if (quantity == null) {
-            quantity = new Double(1);
+            quantity = BigDecimal.ONE;
         }
         if (amount == null) {
-            amount = new Double(0);
+            amount = BigDecimal.ZERO;
         }
 
         Date fromDate = null;
@@ -372,8 +373,8 @@
         ArrayList components = new ArrayList();
         try {
             tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_SINGLE_LEVEL, delegator, dispatcher, userLogin);
-            tree.setRootQuantity(quantity.doubleValue());
-            tree.setRootAmount(amount.doubleValue());
+            tree.setRootQuantity(quantity);
+            tree.setRootAmount(amount);
             tree.print(components, excludeWIPs.booleanValue());
             if (components.size() > 0) components.remove(0);
         } catch(GenericEntityException gee) {
@@ -411,7 +412,7 @@
             Map componentMap = new HashMap();
             BOMNode node = (BOMNode)componentsIt.next();
             componentMap.put("product", node.getProduct());
-            componentMap.put("quantity", new Double(node.getQuantity()));
+            componentMap.put("quantity", node);
             componentsMap.add(componentMap);
         }
         result.put("componentsMap", componentsMap);
@@ -423,16 +424,16 @@
         GenericDelegator delegator = dctx.getDelegator();
         LocalDispatcher dispatcher = dctx.getDispatcher();
         String productId = (String) context.get("productId");
-        Double quantity = (Double) context.get("quantity");
-        Double amount = (Double) context.get("amount");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
+        BigDecimal amount = (BigDecimal) context.get("amount");
         String fromDateStr = (String) context.get("fromDate");
         GenericValue userLogin = (GenericValue)context.get("userLogin");
 
         if (quantity == null) {
-            quantity = new Double(1);
+            quantity = BigDecimal.ONE;
         }
         if (amount == null) {
-            amount = new Double(0);
+            amount = BigDecimal.ZERO;
         }
 
         Date fromDate = null;
@@ -451,8 +452,8 @@
         ArrayList notAssembledComponents = new ArrayList();
         try {
             tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);
-            tree.setRootQuantity(quantity.doubleValue());
-            tree.setRootAmount(amount.doubleValue());
+            tree.setRootQuantity(quantity);
+            tree.setRootAmount(amount);
             tree.print(components);
         } catch(GenericEntityException gee) {
             return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage());
@@ -539,7 +540,7 @@
                 // getProductsInPackages
                 Map serviceContext = new HashMap();
                 serviceContext.put("productId", orderItem.getString("productId"));
-                serviceContext.put("quantity", orderShipment.getDouble("quantity"));
+                serviceContext.put("quantity", orderShipment.getBigDecimal("quantity"));
                 Map resultService = null;
                 try {
                     resultService = dispatcher.runSync("getProductsInPackages", serviceContext);
@@ -640,11 +641,10 @@
                 String boxTypeId = (String)boxTypeContentEntry.getKey();
                 List contentList = (List)boxTypeContentEntry.getValue();
                 GenericValue boxType = (GenericValue)boxTypes.get(boxTypeId);
-                Double boxWidth = boxType.getDouble("boxLength");
-                double totalWidth = 0;
-                double boxWidthDbl = 0;
-                if (boxWidth != null) {
-                    boxWidthDbl = boxWidth.doubleValue();
+                BigDecimal boxWidth = boxType.getBigDecimal("boxLength");
+                BigDecimal totalWidth = BigDecimal.ZERO;
+                if (boxWidth == null) {
+                    boxWidth = BigDecimal.ZERO;
                 }
                 String shipmentPackageSeqId = null;
                 for (int i = 0; i < contentList.size(); i++) {
@@ -655,7 +655,7 @@
                     GenericValue orderShipment = (GenericValue)content.get("orderShipment");
 
                     GenericValue product = null;
-                    double quantity = 0;
+                    BigDecimal quantity = BigDecimal.ZERO;
                     boolean subProduct = contentMap.containsKey("componentIndex");
                     if (subProduct) {
                         // multi package
@@ -671,35 +671,34 @@
                         } catch (GenericEntityException e) {
                             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
                         }
-                        quantity = orderShipment.getDouble("quantity").doubleValue();
+                        quantity = orderShipment.getBigDecimal("quantity");
                     }
 
-                    Double productDepth = product.getDouble("shippingDepth");
+                    BigDecimal productDepth = product.getBigDecimal("shippingDepth");
                     if (productDepth == null) {
-                        productDepth = product.getDouble("productDepth");
+                        productDepth = product.getBigDecimal("productDepth");
                     }
-                    double productDepthDbl = 1;
-                    if (productDepth != null) {
-                        productDepthDbl = productDepth.doubleValue();
+                    if (productDepth == null) {
+                        productDepth = BigDecimal.ONE;
                     }
                     
-                    int firstMaxNumOfProducts = (int)((boxWidthDbl - totalWidth) / productDepthDbl);
-                    if (firstMaxNumOfProducts == 0) firstMaxNumOfProducts = 1;
+                    BigDecimal firstMaxNumOfProducts = boxWidth.subtract(totalWidth).divide(productDepth, 0, BigDecimal.ROUND_FLOOR);
+                    if (firstMaxNumOfProducts.compareTo(BigDecimal.ZERO) == 0) firstMaxNumOfProducts = BigDecimal.ONE;
                     //
-                    int maxNumOfProducts = (int)(boxWidthDbl / productDepthDbl);
-                    if (maxNumOfProducts == 0) maxNumOfProducts = 1;
+                    BigDecimal maxNumOfProducts = boxWidth.divide(productDepth, 0, BigDecimal.ROUND_FLOOR);
+                    if (maxNumOfProducts.compareTo(BigDecimal.ZERO) == 0) maxNumOfProducts = BigDecimal.ONE;
 
-                    double remQuantity = quantity;
+                    BigDecimal remQuantity = quantity;
                     boolean isFirst = true;
-                    while (remQuantity > 0) {
-                        int maxQuantity = 0;
+                    while (remQuantity.compareTo(BigDecimal.ZERO) > 0) {
+                        BigDecimal maxQuantity = BigDecimal.ZERO;
                         if (isFirst) {
                             maxQuantity = firstMaxNumOfProducts;
                             isFirst = false;
                         } else {
                             maxQuantity = maxNumOfProducts;
                         }
-                        double qty = (remQuantity < maxQuantity? remQuantity: maxQuantity);
+                        BigDecimal qty = (remQuantity.compareTo(maxQuantity) < 0 ? remQuantity : maxQuantity);
                         // If needed, create the package
                         if (shipmentPackageSeqId == null) {
                             try {
@@ -708,7 +707,7 @@
                             } catch (GenericServiceException e) {
                                 return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
                             }
-                            totalWidth = 0;
+                            totalWidth = BigDecimal.ZERO;
                         }
                         try {
                             Map inputMap = null;
@@ -718,21 +717,21 @@
                                 "shipmentItemSeqId", orderShipment.getString("shipmentItemSeqId"),
                                 "subProductId", product.getString("productId"),
                                 "userLogin", userLogin,
-                                "subProductQuantity", new Double(qty));
+                                "subProductQuantity", qty);
                             } else {
                                 inputMap = UtilMisc.toMap("shipmentId", orderShipment.getString("shipmentId"),
                                 "shipmentPackageSeqId", shipmentPackageSeqId,
                                 "shipmentItemSeqId", orderShipment.getString("shipmentItemSeqId"),
                                 "userLogin", userLogin,
-                                "quantity", new Double(qty));
+                                "quantity", qty);
                             }
                             Map resultService = dispatcher.runSync("createShipmentPackageContent", inputMap);
                         } catch (GenericServiceException e) {
                             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingPackageConfiguratorError", locale));
                         }
-                        totalWidth += qty * productDepthDbl;
-                        if (qty == maxQuantity) shipmentPackageSeqId = null;
-                        remQuantity = remQuantity - qty;
+                        totalWidth = totalWidth.add( qty.multiply(productDepth) );
+                        if (qty.compareTo(maxQuantity) == 0) shipmentPackageSeqId = null;
+                        remQuantity = remQuantity.subtract(qty);
                     }
                 }
             }
@@ -755,11 +754,11 @@
         GenericValue userLogin = (GenericValue)context.get("userLogin");
         
         String productId = (String) context.get("productId");
-        Double quantity = (Double) context.get("quantity");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
         String fromDateStr = (String) context.get("fromDate");
         
         if (quantity == null) {
-            quantity = new Double(1);
+            quantity = BigDecimal.ONE;
         }
         Date fromDate = null;
         if (UtilValidate.isNotEmpty(fromDateStr)) {
@@ -779,7 +778,7 @@
         ArrayList components = new ArrayList();
         try {
             tree = new BOMTree(productId, "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);
-            tree.setRootQuantity(quantity.doubleValue());
+            tree.setRootQuantity(quantity);
             tree.getProductsInPackages(components);
         } catch(GenericEntityException gee) {
             return ServiceUtil.returnError("Error creating bill of materials tree: " + gee.getMessage());

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/bom/BOMTree.java Sun Jan  4 11:46:24 2009
@@ -19,6 +19,7 @@
 
 package org.ofbiz.manufacturing.bom;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
@@ -50,8 +51,8 @@
     protected GenericDelegator delegator = null;
 
     BOMNode root;
-    double rootQuantity;
-    double rootAmount;
+    BigDecimal rootQuantity;
+    BigDecimal rootAmount;
     Date inDate;
     String bomTypeId;
     GenericValue inputProduct;
@@ -157,8 +158,8 @@
         }
         this.bomTypeId = bomTypeId;
         this.inDate = inDate;
-        rootQuantity = 1;
-        rootAmount = 0;
+        rootQuantity = BigDecimal.ONE;
+        rootAmount = BigDecimal.ZERO;
     }
 
     public GenericValue getInputProduct() {
@@ -199,7 +200,7 @@
      * @return Value of property rootQuantity.
      *
      */
-    public double getRootQuantity() {
+    public BigDecimal getRootQuantity() {
         return rootQuantity;
     }
     
@@ -207,7 +208,7 @@
      * @param rootQuantity New value of property rootQuantity.
      *
      */
-    public void setRootQuantity(double rootQuantity) {
+    public void setRootQuantity(BigDecimal rootQuantity) {
         this.rootQuantity = rootQuantity;
     }
 
@@ -215,7 +216,7 @@
      * @return Value of property rootAmount.
      *
      */
-    public double getRootAmount() {
+    public BigDecimal getRootAmount() {
         return rootAmount;
     }
     
@@ -223,7 +224,7 @@
      * @param rootAmount New value of property rootAmount.
      *
      */
-    public void setRootAmount(double rootAmount) {
+    public void setRootAmount(BigDecimal rootAmount) {
         this.rootAmount = rootAmount;
     }
     

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRun.java Sun Jan  4 11:46:24 2009
@@ -19,6 +19,7 @@
 
 package org.ofbiz.manufacturing.jobshopmgt;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -49,7 +50,7 @@
     protected GenericValue productionRun; // WorkEffort (PROD_ORDER_HEADER)
     protected GenericValue productionRunProduct; // WorkEffortGoodStandard (type: PRUN_PROD_DELIV)
     protected GenericValue productProduced; // Product (from WorkEffortGoodStandard of type: PRUN_PROD_DELIV)
-    protected Double quantity; // the estimatedQuantity
+    protected BigDecimal quantity; // the estimatedQuantity
     
     protected Timestamp estimatedStartDate;
     protected Timestamp estimatedCompletionDate;
@@ -165,7 +166,7 @@
                 try {
                     List productionRunProducts = productionRun.getRelated("WorkEffortGoodStandard", UtilMisc.toMap("workEffortGoodStdTypeId", "PRUN_PROD_DELIV"),null);
                     this.productionRunProduct = EntityUtil.getFirst(productionRunProducts);
-                    quantity = productionRunProduct.getDouble("estimatedQuantity");
+                    quantity = productionRunProduct.getBigDecimal("estimatedQuantity");
                     productProduced = productionRunProduct.getRelatedOneCache("Product");
                 } catch (GenericEntityException e) {
                     Debug.logWarning(e.getMessage(), module);
@@ -180,7 +181,7 @@
      * get the quantity property.
      * @return the quantity property
      **/
-    public Double getQuantity(){
+    public BigDecimal getQuantity(){
         if (exist()) {
             if (quantity == null)  getProductProduced();
             return quantity;
@@ -191,17 +192,17 @@
      * set the quantity property and recalculated the productComponent quantity.
      * @return
      **/
-    public void setQuantity(Double newQuantity) {
+    public void setQuantity(BigDecimal newQuantity) {
         if (quantity == null) getProductProduced();
-        double previousQuantity = quantity.doubleValue(), componentQuantity;
+        BigDecimal previousQuantity = quantity, componentQuantity;
         this.quantity = newQuantity;
         this.quantityIsUpdated = true;
         this.updateCompletionDate = true;
         if (productionRunComponents == null) getProductionRunComponents();
         for (Iterator iter = productionRunComponents.iterator(); iter.hasNext();){
             GenericValue component = (GenericValue) iter.next();
-            componentQuantity = component.getDouble("estimatedQuantity").doubleValue();
-            component.set("estimatedQuantity", new Double(componentQuantity / previousQuantity * newQuantity.doubleValue()));
+            componentQuantity = component.getBigDecimal("estimatedQuantity");
+            component.set("estimatedQuantity", componentQuantity.divide(previousQuantity, 10, BigDecimal.ROUND_HALF_UP).multiply(newQuantity));
         }
     }
     /**
@@ -387,18 +388,15 @@
     }
     
     /*
-     * FIXME: the three getEstimatedTaskTime(...) methods will be removed and
+     * FIXME: the two getEstimatedTaskTime(...) methods will be removed and
      * implemented in the "getEstimatedTaskTime" service.
      */
-    public static long getEstimatedTaskTime(GenericValue task, double quantity, LocalDispatcher dispatcher) {
-        return getEstimatedTaskTime(task, new Double(quantity), dispatcher);
-    }
-    public static long getEstimatedTaskTime(GenericValue task, Double quantity, LocalDispatcher dispatcher) {
+    public static long getEstimatedTaskTime(GenericValue task, BigDecimal quantity, LocalDispatcher dispatcher) {
         return getEstimatedTaskTime(task, quantity, null, null, dispatcher);
     }
-    public static long getEstimatedTaskTime(GenericValue task, Double quantity, String productId, String routingId, LocalDispatcher dispatcher) {
+    public static long getEstimatedTaskTime(GenericValue task, BigDecimal quantity, String productId, String routingId, LocalDispatcher dispatcher) {
         if (quantity == null) {
-            quantity = new Double(1);
+            quantity = BigDecimal.ONE;
         }
         if (task == null) return 0;
         double setupTime = 0;

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunEvents.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunEvents.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunEvents.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunEvents.java Sun Jan  4 11:46:24 2009
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.manufacturing.jobshopmgt;
 
+import java.math.BigDecimal;
 import java.sql.Timestamp;
 import java.util.Collection;
 import java.util.List;
@@ -52,9 +53,9 @@
         
         Map parameters = UtilHttp.getParameterMap(request);
 
-        Double quantity = null;
+        BigDecimal quantity = null;
         try {
-            quantity = Double.valueOf((String)parameters.get("quantity"));
+            quantity = new BigDecimal((String)parameters.get("quantity"));
         } catch(NumberFormatException nfe) {
             String errMsg = "Invalid format for quantity field: " + nfe.toString();
             Debug.logError(nfe, errMsg, module);

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/jobshopmgt/ProductionRunServices.java Sun Jan  4 11:46:24 2009
@@ -193,7 +193,7 @@
         // Mandatory input fields
         String productId = (String) context.get("productId");
         Timestamp  startDate =  (Timestamp) context.get("startDate");
-        Double pRQuantity = (Double) context.get("pRQuantity");
+        BigDecimal pRQuantity = (BigDecimal) context.get("pRQuantity");
         String facilityId = (String) context.get("facilityId");
         // Optional input fields
         String workEffortId = (String) context.get("routingId");
@@ -405,7 +405,7 @@
                         serviceContext.put("fromDate", productBom.get("fromDate"));
                         // Here we use the getQuantity method to get the quantity already
                         // computed by the getManufacturingComponents service
-                        serviceContext.put("estimatedQuantity", new Double(node.getQuantity()));
+                        serviceContext.put("estimatedQuantity", node.getQuantity());
                         serviceContext.put("userLogin", userLogin);
                         resultService = null;
                         try {
@@ -465,7 +465,7 @@
                     return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunPrinted", locale));
                 }
 
-                Double quantity = (Double) context.get("quantity");
+                BigDecimal quantity = (BigDecimal) context.get("quantity");
                 if (quantity != null &&  ! quantity.equals(productionRun.getQuantity())) {
                     productionRun.setQuantity(quantity);
                 }
@@ -809,22 +809,22 @@
             serviceContext.put("workEffortId", taskId);
             serviceContext.put("currentStatusId", "PRUN_COMPLETED");
             serviceContext.put("actualCompletionDate", UtilDateTime.nowTimestamp());
-            Double quantityToProduce = theTask.getDouble("quantityToProduce");
+            BigDecimal quantityToProduce = theTask.getBigDecimal("quantityToProduce");
             if (quantityToProduce == null) {
-                quantityToProduce = new Double(0);
+                quantityToProduce = BigDecimal.ZERO;
             }
-            Double quantityProduced = theTask.getDouble("quantityProduced");
+            BigDecimal quantityProduced = theTask.getBigDecimal("quantityProduced");
             if (quantityProduced == null) {
-                quantityProduced = new Double(0);
+                quantityProduced = BigDecimal.ZERO;
             }
-            Double quantityRejected = theTask.getDouble("quantityRejected");
+            BigDecimal quantityRejected = theTask.getBigDecimal("quantityRejected");
             if (quantityRejected == null) {
-                quantityRejected = new Double(0);
+                quantityRejected = BigDecimal.ZERO;
             }
-            double totalQuantity = quantityProduced.doubleValue() + quantityRejected.doubleValue();
-            double diffQuantity = quantityToProduce.doubleValue() - totalQuantity;
-            if (diffQuantity > 0) {
-                quantityProduced = new Double(quantityProduced.doubleValue() + diffQuantity);
+            BigDecimal totalQuantity = quantityProduced.add(quantityRejected);
+            BigDecimal diffQuantity = quantityToProduce.subtract(totalQuantity);
+            if (diffQuantity.compareTo(BigDecimal.ZERO) > 0) {
+                quantityProduced = quantityProduced.add(diffQuantity);
             }
             serviceContext.put("quantityProduced", quantityProduced);
             if (theTask.get("actualSetupMillis") == null) {
@@ -833,7 +833,7 @@
             if (theTask.get("actualMilliSeconds") == null) {
                 Double autoMillis = null;
                 if (theTask.get("estimatedMilliSeconds") != null) {
-                    autoMillis = new Double(quantityProduced.doubleValue() * theTask.getDouble("estimatedMilliSeconds").doubleValue());
+                    autoMillis = new Double(quantityProduced.doubleValue() * theTask.getDouble("estimatedMilliSeconds"));
                 }
                 serviceContext.put("actualMilliSeconds", autoMillis);
             }
@@ -1002,7 +1002,7 @@
                     inMap.put("costComponentTypeId", "ACTUAL_" + workEffortCostCalc.getString("costComponentTypeId"));
                     inMap.put("costComponentCalcId", costComponentCalc.getString("costComponentCalcId"));
                     inMap.put("costUomId", costComponentCalc.getString("currencyUomId"));
-                    inMap.put("cost", new Double(totalCost.doubleValue()));
+                    inMap.put("cost", totalCost);
                     dispatcher.runSync("createCostComponent", inMap);
                 } else {
                     // use the custom method (aka formula) to compute the costs
@@ -1041,7 +1041,7 @@
                 Map inMap = UtilMisc.toMap("userLogin", userLogin, "workEffortId", productionRunTaskId);
                 inMap.put("costComponentTypeId", "ACTUAL_MAT_COST");
                 inMap.put("costUomId", currencyUomId);
-                inMap.put("cost", new Double(materialsCost.doubleValue()));
+                inMap.put("cost", materialsCost);
                 dispatcher.runSync("createCostComponent", inMap);
             }
         } catch(Exception e) {
@@ -1143,7 +1143,7 @@
         // Mandatory input fields
         String productionRunId = (String)context.get("productionRunId");
         String productId = (String)context.get("productId");
-        Double quantity = (Double) context.get("estimatedQuantity");
+        BigDecimal quantity = (BigDecimal) context.get("estimatedQuantity");
         // Optional input fields
         String workEffortId = (String)context.get("workEffortId");
         
@@ -1215,7 +1215,7 @@
         String productId = (String)context.get("productId");
         // Optional input fields
         String workEffortId = (String)context.get("workEffortId"); // the production run task
-        Double quantity = (Double) context.get("estimatedQuantity");
+        BigDecimal quantity = (BigDecimal) context.get("estimatedQuantity");
         
         ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher);
         List components = productionRun.getProductionRunComponents();
@@ -1300,7 +1300,7 @@
         
         // The production run is loaded
         ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher);
-        Double pRQuantity = productionRun.getQuantity();
+        BigDecimal pRQuantity = productionRun.getQuantity();
         if (pRQuantity == null) {
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunTaskNotExists", locale));
         }
@@ -1427,7 +1427,7 @@
         String productionRunId = (String)context.get("workEffortId");
         
         // Optional input fields
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
         String inventoryItemTypeId = (String)context.get("inventoryItemTypeId");
         String lotId = (String)context.get("lotId");
         Boolean createLotIfNeeded = (Boolean)context.get("createLotIfNeeded");
@@ -1457,29 +1457,29 @@
         if ("WIP".equals(productionRun.getProductProduced().getString("productTypeId"))) {
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductIsWIP", locale));
         }
-        Double quantityProduced = productionRun.getGenericValue().getDouble("quantityProduced");
+        BigDecimal quantityProduced = productionRun.getGenericValue().getBigDecimal("quantityProduced");
 
         if (quantityProduced == null) {
-            quantityProduced = new Double(0);
+            quantityProduced = BigDecimal.ZERO;
         }
-        Double quantityDeclared = lastTask.getDouble("quantityProduced");
+        BigDecimal quantityDeclared = lastTask.getBigDecimal("quantityProduced");
 
         if (quantityDeclared == null) {
-            quantityDeclared = new Double(0);
+            quantityDeclared = BigDecimal.ZERO;
         }
         // If the quantity already produced is not lower than the quantity declared, no inventory is created.
-        double maxQuantity = quantityDeclared.doubleValue() - quantityProduced.doubleValue();
+        BigDecimal maxQuantity = quantityDeclared.subtract(quantityProduced);
 
-        if (maxQuantity <= 0) {
+        if (maxQuantity.compareTo(BigDecimal.ZERO) <= 0) {
             return result;
         }
 
         // If quantity was not passed, the max quantity is used
         if (quantity == null) {
-            quantity = new Double(maxQuantity);
+            quantity = maxQuantity;
         }
         //
-        if (quantity.doubleValue() > maxQuantity) {
+        if (quantity.compareTo(maxQuantity) > 0) {
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionRunProductProducedNotStillAvailable", locale));
         }
         
@@ -1520,7 +1520,7 @@
             Map outputMap = dispatcher.runSync("getProductionRunCost", UtilMisc.<String, Object>toMap("userLogin", userLogin, "workEffortId", productionRunId));
             BigDecimal totalCost = (BigDecimal)outputMap.get("totalCost");
             // FIXME
-            unitCost = totalCost.divide(BigDecimal.valueOf(quantity.doubleValue()), decimals, rounding);
+            unitCost = totalCost.divide(quantity, decimals, rounding);
         } catch (GenericServiceException e) {
             Debug.logWarning(e.getMessage(), module);
             return ServiceUtil.returnError(e.getMessage());
@@ -1537,7 +1537,7 @@
                     serviceContext.put("datetimeReceived", UtilDateTime.nowTimestamp());
                     serviceContext.put("comments", "Created by production run " + productionRunId);
                     if (unitCost.compareTo(ZERO) != 0) {
-                        serviceContext.put("unitCost", new Double(unitCost.doubleValue()));
+                        serviceContext.put("unitCost", unitCost);
                     }
                     //serviceContext.put("serialNumber", productionRunId);
                     serviceContext.put("lotId", lotId);
@@ -1548,8 +1548,8 @@
                     serviceContext.clear();
                     serviceContext.put("inventoryItemId", inventoryItemId);
                     serviceContext.put("workEffortId", productionRunId);
-                    serviceContext.put("availableToPromiseDiff", new Double(1));
-                    serviceContext.put("quantityOnHandDiff", new Double(1));
+                    serviceContext.put("availableToPromiseDiff", BigDecimal.ONE);
+                    serviceContext.put("quantityOnHandDiff", BigDecimal.ONE);
                     serviceContext.put("userLogin", userLogin);
                     resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext);
                     serviceContext.clear();
@@ -1575,7 +1575,7 @@
                 serviceContext.put("comments", "Created by production run " + productionRunId);
                 serviceContext.put("lotId", lotId);
                 if (unitCost.compareTo(ZERO) != 0) {
-                    serviceContext.put("unitCost", new Double(unitCost.doubleValue()));
+                    serviceContext.put("unitCost", unitCost);
                 }
                 serviceContext.put("userLogin", userLogin);
                 Map resultService = dispatcher.runSync("createInventoryItem", serviceContext);
@@ -1609,7 +1609,7 @@
         }
         // Now the production run's quantityProduced is updated
         Map serviceContext = UtilMisc.toMap("workEffortId", productionRunId);
-        serviceContext.put("quantityProduced", new Double(quantityProduced.doubleValue() + quantity.doubleValue()));
+        serviceContext.put("quantityProduced", quantityProduced.add(quantity));
         serviceContext.put("actualCompletionDate", UtilDateTime.nowTimestamp());
         serviceContext.put("userLogin", userLogin);
         try {
@@ -1633,22 +1633,22 @@
         String productionRunId = (String)context.get("workEffortId");
         
         // Optional input fields
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         Map componentsLocationMap = (Map)context.get("componentsLocationMap");
       
         // The production run is loaded
         ProductionRun productionRun = new ProductionRun(productionRunId, delegator, dispatcher);
 
-        Double quantityProduced = productionRun.getGenericValue().getDouble("quantityProduced");
-        Double quantityToProduce = productionRun.getGenericValue().getDouble("quantityToProduce");
+        BigDecimal quantityProduced = productionRun.getGenericValue().getBigDecimal("quantityProduced");
+        BigDecimal quantityToProduce = productionRun.getGenericValue().getBigDecimal("quantityToProduce");
         if (quantityProduced == null) {
-            quantityProduced = new Double(0);
+            quantityProduced = BigDecimal.ZERO;
         }
         if (quantityToProduce == null) {
-            quantityToProduce = new Double(0);
+            quantityToProduce = BigDecimal.ZERO;
         }
-        double minimumQuantityProducedByTask = quantityProduced.doubleValue() + quantity.doubleValue();
-        if (minimumQuantityProducedByTask > quantityToProduce.doubleValue()) {
+        BigDecimal minimumQuantityProducedByTask = quantityProduced.add(quantity);
+        if (minimumQuantityProducedByTask.compareTo(quantityToProduce) > 0) {
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingQuantityProducedIsHigherThanQuantityDeclared", locale));
         }
 
@@ -1657,14 +1657,14 @@
             GenericValue oneTask = (GenericValue)tasks.get(i);
             String taskId = oneTask.getString("workEffortId");
             if ("PRUN_RUNNING".equals(oneTask.getString("currentStatusId"))) {
-                Double quantityDeclared = oneTask.getDouble("quantityProduced");
+                BigDecimal quantityDeclared = oneTask.getBigDecimal("quantityProduced");
                 if (quantityDeclared == null) {
-                    quantityDeclared = new Double(0);
+                    quantityDeclared = BigDecimal.ZERO;
                 }
-                if (minimumQuantityProducedByTask > quantityDeclared.doubleValue()) {
+                if (minimumQuantityProducedByTask.compareTo(quantityDeclared) > 0) {
                     try {
                         Map serviceContext = UtilMisc.toMap("productionRunId", productionRunId, "productionRunTaskId", taskId);
-                        serviceContext.put("addQuantityProduced", new Double(minimumQuantityProducedByTask - quantityDeclared.doubleValue()));
+                        serviceContext.put("addQuantityProduced", minimumQuantityProducedByTask.subtract(quantityDeclared));
                         serviceContext.put("issueRequiredComponents", Boolean.TRUE);
                         serviceContext.put("componentsLocationMap", componentsLocationMap);
                         serviceContext.put("userLogin", userLogin);
@@ -1696,12 +1696,12 @@
         // Mandatory input fields
         String productionRunTaskId = (String)context.get("workEffortId");
         String productId = (String)context.get("productId");
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         
         // Optional input fields
         String facilityId = (String)context.get("facilityId");
         String currencyUomId = (String)context.get("currencyUomId");
-        Double unitCost = (Double)context.get("unitCost");
+        BigDecimal unitCost = (BigDecimal)context.get("unitCost");
         String inventoryItemTypeId = (String)context.get("inventoryItemTypeId");
         
         // The default is non-serialized inventory item
@@ -1735,8 +1735,8 @@
                     serviceContext.clear();
                     serviceContext.put("inventoryItemId", inventoryItemId);
                     serviceContext.put("workEffortId", productionRunTaskId);
-                    serviceContext.put("availableToPromiseDiff", new Double(1));
-                    serviceContext.put("quantityOnHandDiff", new Double(1));
+                    serviceContext.put("availableToPromiseDiff", BigDecimal.ONE);
+                    serviceContext.put("quantityOnHandDiff", BigDecimal.ONE);
                     serviceContext.put("userLogin", userLogin);
                     resultService = dispatcher.runSync("createInventoryItemDetail", serviceContext);
                     serviceContext.clear();
@@ -1803,8 +1803,8 @@
         String productionRunTaskId = (String)context.get("workEffortId");
         String productId = (String)context.get("productId");
         // Optional input fields
-        Double quantity = (Double)context.get("quantity");
-        if (quantity == null || quantity.doubleValue() == 0) {
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
+        if (quantity == null || quantity.compareTo(ZERO) == 0) {
             return ServiceUtil.returnSuccess();
         }
         // Verify how many items of the given productId
@@ -1812,28 +1812,28 @@
         // If less than passed quantity then return an error message.
         try {
             Iterator issuances = (delegator.findByAnd("WorkEffortAndInventoryAssign", UtilMisc.toMap("workEffortId", productionRunTaskId, "productId", productId))).iterator();
-            double totalIssued = 0.0;
+            BigDecimal totalIssued = BigDecimal.ZERO;
             while (issuances.hasNext()) {
                 GenericValue issuance = (GenericValue)issuances.next();
-                Double issued = issuance.getDouble("quantity");
+                BigDecimal issued = issuance.getBigDecimal("quantity");
                 if (issued != null) {
-                    totalIssued += issued.doubleValue();
+                    totalIssued = totalIssued.add(issued);
                 }
             }
             Iterator returns = (delegator.findByAnd("WorkEffortAndInventoryProduced", UtilMisc.toMap("workEffortId", productionRunTaskId, "productId", productId))).iterator();
-            double totalReturned = 0.0;
+            BigDecimal totalReturned = BigDecimal.ZERO;
             while (returns.hasNext()) {
                 GenericValue returned = (GenericValue)returns.next();
                 GenericValue returnDetail = EntityUtil.getFirst(delegator.findByAnd("InventoryItemDetail", UtilMisc.toMap("inventoryItemId", returned.getString("inventoryItemId")), UtilMisc.toList("inventoryItemDetailSeqId")));
                 if (returnDetail != null) {
-                    Double qtyReturned = returnDetail.getDouble("quantityOnHandDiff");
+                    BigDecimal qtyReturned = returnDetail.getBigDecimal("quantityOnHandDiff");
                     if (qtyReturned != null) {
-                        totalReturned += qtyReturned.doubleValue();
+                        totalReturned = totalReturned.add(qtyReturned);
                     }
                 }
             }
-            if (quantity.doubleValue() > totalIssued - totalReturned) {
-                return ServiceUtil.returnError("Production Run Task with id [" + productionRunTaskId + "] cannot return more items [" + quantity + "] than the ones currently allocated [" + (totalIssued - totalReturned) + "]");
+            if (quantity.compareTo(totalIssued.subtract(totalReturned)) > 0) {
+                return ServiceUtil.returnError("Production Run Task with id [" + productionRunTaskId + "] cannot return more items [" + quantity + "] than the ones currently allocated [" + (totalIssued.subtract(totalReturned)) + "]");
             }
         } catch(GenericEntityException gee) {
             return ServiceUtil.returnError(gee.getMessage());
@@ -1874,8 +1874,8 @@
         // Optional input fields
         Timestamp fromDate = (Timestamp)context.get("fromDate");
         Timestamp toDate = (Timestamp)context.get("toDate");
-        Double addQuantityProduced = (Double)context.get("addQuantityProduced");
-        Double addQuantityRejected = (Double)context.get("addQuantityRejected");
+        BigDecimal addQuantityProduced = (BigDecimal)context.get("addQuantityProduced");
+        BigDecimal addQuantityRejected = (BigDecimal)context.get("addQuantityRejected");
         Double addSetupTime = (Double)context.get("addSetupTime");
         Double addTaskTime = (Double)context.get("addTaskTime");
         String comments = (String)context.get("comments");
@@ -1892,10 +1892,10 @@
             toDate = UtilDateTime.nowTimestamp();
         }
         if (addQuantityProduced == null) {
-            addQuantityProduced = new Double(0);
+            addQuantityProduced = BigDecimal.ZERO;
         }
         if (addQuantityRejected == null) {
-            addQuantityRejected = new Double(0);
+            addQuantityRejected = BigDecimal.ZERO;
         }
         if (addSetupTime == null) {
             addSetupTime = new Double(0);
@@ -1940,47 +1940,47 @@
             actualSetupMillis = new Double(0);
         }
 
-        Double quantityProduced = theTask.getDouble("quantityProduced");
+        BigDecimal quantityProduced = theTask.getBigDecimal("quantityProduced");
         if (quantityProduced == null) {
-            quantityProduced = new Double(0);
+            quantityProduced = BigDecimal.ZERO;
         }
-        Double quantityRejected = theTask.getDouble("quantityRejected");
+        BigDecimal quantityRejected = theTask.getBigDecimal("quantityRejected");
         if (quantityRejected == null) {
-            quantityRejected = new Double(0);
+            quantityRejected = BigDecimal.ZERO;
         }
         double totalMillis = actualMilliSeconds.doubleValue() + addTaskTime.doubleValue();
         double totalSetupMillis = actualSetupMillis.doubleValue() + addSetupTime.doubleValue();
-        double totalQuantityProduced = quantityProduced.doubleValue() + addQuantityProduced.doubleValue();
-        double totalQuantityRejected = quantityRejected.doubleValue() + addQuantityRejected.doubleValue();
+        BigDecimal totalQuantityProduced = quantityProduced.add(addQuantityProduced);
+        BigDecimal totalQuantityRejected = quantityRejected.add(addQuantityRejected);
         
-        if (issueRequiredComponents.booleanValue() && addQuantityProduced.doubleValue() > 0) {
-            Double quantityToProduce = theTask.getDouble("quantityToProduce");
+        if (issueRequiredComponents.booleanValue() && addQuantityProduced.compareTo(ZERO) > 0) {
+            BigDecimal quantityToProduce = theTask.getBigDecimal("quantityToProduce");
             if (quantityToProduce == null) {
-                quantityToProduce = new Double(0);
+                quantityToProduce = BigDecimal.ZERO;
             }
-            if (quantityToProduce.doubleValue() > 0) {
+            if (quantityToProduce.compareTo(ZERO) > 0) {
                 try {
                     List<GenericValue> components = theTask.getRelated("WorkEffortGoodStandard");
                     for (GenericValue component : components) {
-                        double totalRequiredMaterialQuantity = component.getDouble("estimatedQuantity").doubleValue() * totalQuantityProduced / quantityToProduce.doubleValue();
+                        BigDecimal totalRequiredMaterialQuantity = component.getBigDecimal("estimatedQuantity").multiply(totalQuantityProduced).divide(quantityToProduce, rounding);
                         // now get the units that have been already issued and subtract them
                         List<GenericValue> issuances = delegator.findByAnd("WorkEffortAndInventoryAssign", UtilMisc.toMap("workEffortId", workEffortId, "productId", component.getString("productId")));
-                        double totalIssued = 0.0;
+                        BigDecimal totalIssued = BigDecimal.ZERO;
                         for (GenericValue issuance : issuances) {
-                            Double issued = issuance.getDouble("quantity");
+                            BigDecimal issued = issuance.getBigDecimal("quantity");
                             if (issued != null) {
-                                totalIssued += issued.doubleValue();
+                                totalIssued = totalIssued.add(issued);
                             }
                         }
-                        double requiredQuantity = totalRequiredMaterialQuantity - totalIssued;
-                        if (requiredQuantity > 0) {
+                        BigDecimal requiredQuantity = totalRequiredMaterialQuantity.subtract(totalIssued);
+                        if (requiredQuantity.compareTo(ZERO) > 0) {
                             GenericPK key = component.getPrimaryKey();
                             Map componentsLocation = null;
                             if (componentsLocationMap != null) {
                                 componentsLocation = (Map)componentsLocationMap.get(key);
                             }
                             Map serviceContext = UtilMisc.toMap("workEffortId", workEffortId, "productId", component.getString("productId"), "fromDate", component.getTimestamp("fromDate"));
-                            serviceContext.put("quantity", new Double(requiredQuantity));
+                            serviceContext.put("quantity", requiredQuantity);
                             if (componentsLocation != null) {
                                 serviceContext.put("locationSeqId", (String)componentsLocation.get("locationSeqId"));
                                 serviceContext.put("secondaryLocationSeqId", (String)componentsLocation.get("secondaryLocationSeqId"));
@@ -2020,8 +2020,8 @@
             serviceContext.put("workEffortId", workEffortId);
             serviceContext.put("actualMilliSeconds", new Double(totalMillis));
             serviceContext.put("actualSetupMillis", new Double(totalSetupMillis));
-            serviceContext.put("quantityProduced", new Double(totalQuantityProduced));
-            serviceContext.put("quantityRejected", new Double(totalQuantityRejected));
+            serviceContext.put("quantityProduced", totalQuantityProduced);
+            serviceContext.put("quantityRejected", totalQuantityRejected);
             serviceContext.put("userLogin", userLogin);
             Map resultService = dispatcher.runSync("updateWorkEffort", serviceContext);
         } catch(Exception exc) {
@@ -2065,7 +2065,7 @@
         // Mandatory input fields
         String requirementId = (String)context.get("requirementId");
         // Optional input fields
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         
         GenericValue requirement = null;
         try {
@@ -2080,7 +2080,7 @@
         }
         
         if (quantity == null) {
-            quantity = requirement.getDouble("quantity");
+            quantity = requirement.getBigDecimal("quantity");
         }
         Map serviceContext = new HashMap();
         serviceContext.clear();
@@ -2127,7 +2127,7 @@
         // Optional input fields
         String configId = (String)context.get("configId");
         ProductConfigWrapper config = (ProductConfigWrapper)context.get("config");
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         String orderId = (String)context.get("orderId");
         String orderItemSeqId = (String)context.get("orderItemSeqId");
         
@@ -2142,7 +2142,7 @@
             return ServiceUtil.returnError("ProductConfigurationNotValid");
         }
         if (quantity == null) {
-            quantity = new Double(1);
+            quantity = BigDecimal.ONE;
         }
         String instanceProductId = null;
         try {
@@ -2175,13 +2175,13 @@
             //components.addAll(co.getComponents());
             Iterator selComponents = co.getComponents().iterator();
             while (selComponents.hasNext()) {
-                Double componentQuantity = null;
+                BigDecimal componentQuantity = null;
                 GenericValue selComponent = (GenericValue)selComponents.next();
                 if (selComponent.get("quantity") != null) {
-                    componentQuantity = selComponent.getDouble("quantity");
+                    componentQuantity = selComponent.getBigDecimal("quantity");
                 }
                 if (componentQuantity == null) {
-                    componentQuantity = new Double(1);
+                    componentQuantity = BigDecimal.ONE;
                 }
                 String componentProductId = selComponent.getString("productId");
                 if (co.isVirtualComponent(selComponent)) {      
@@ -2190,10 +2190,10 @@
                         componentProductId = (String)componentOptions.get(componentProductId);
                     }
                 }
-                componentQuantity = new Double(quantity.doubleValue() * componentQuantity.doubleValue());
+                componentQuantity = quantity.multiply(componentQuantity);
                 if (components.containsKey(componentProductId)) {
-                    Double totalQuantity = (Double)components.get(componentProductId);
-                    componentQuantity = new Double(totalQuantity.doubleValue() + componentQuantity.doubleValue());
+                    BigDecimal totalQuantity = (BigDecimal)components.get(componentProductId);
+                    componentQuantity = totalQuantity.add(componentQuantity);
                 }
                 components.put(componentProductId, componentQuantity);
                 
@@ -2222,9 +2222,9 @@
         while (componentsIt.hasNext()) {
             Map.Entry component = (Map.Entry)componentsIt.next();
             String productId = (String)component.getKey();
-            Double componentQuantity = (Double)component.getValue();
+            BigDecimal componentQuantity = (BigDecimal)component.getValue();
             if (componentQuantity == null) {
-                componentQuantity = new Double(1);
+                componentQuantity = BigDecimal.ONE;
             }
             resultService = null;
             serviceContext = new HashMap();
@@ -2288,35 +2288,35 @@
 
         try {
             // first figure out how much of this product we already have in stock (ATP)
-            double existingAtp = 0.0;
+            BigDecimal existingAtp = BigDecimal.ZERO;
             Map tmpResults = dispatcher.runSync("getInventoryAvailableByFacility", UtilMisc.<String, Object>toMap("productId", orderItem.getString("productId"), "facilityId", facilityId, "userLogin", userLogin));
             if (tmpResults.get("availableToPromiseTotal") != null) {
-                existingAtp = ((Double) tmpResults.get("availableToPromiseTotal")).doubleValue();
+                existingAtp = (BigDecimal) tmpResults.get("availableToPromiseTotal");
             }
             // if the order is immediately fulfilled, adjust the atp to compensate for it not reserved
             if (isImmediatelyFulfilled) {
-                existingAtp -= orderItem.getDouble("quantity");
+                existingAtp = existingAtp.subtract(orderItem.getBigDecimal("quantity"));
             }
             
             if (Debug.verboseOn()) { Debug.logVerbose("Order item [" + orderItem + "] Existing ATP = [" + existingAtp + "]", module); }
             // we only need to produce more marketing packages if there isn't enough in stock.
-            if (existingAtp < 0.0) {
+            if (existingAtp.compareTo(ZERO) < 0) {
                 // how many should we produce?  If there already is some inventory, then just produce enough to bring ATP back up to zero.
-                double qtyRequired = 0 - existingAtp;
+                BigDecimal qtyRequired = BigDecimal.ZERO.subtract(existingAtp);
                 // ok so that's how many we WANT to produce, but let's check how many we can actually produce based on the available components
                 Map serviceContext = new HashMap();
                 serviceContext.put("productId", orderItem.getString("productId"));
                 serviceContext.put("facilityId", facilityId);
                 serviceContext.put("userLogin", userLogin);
                 Map resultService = dispatcher.runSync("getMktgPackagesAvailable", serviceContext);
-                double mktgPackagesAvailable = ((Double) resultService.get("availableToPromiseTotal")).doubleValue();
+                BigDecimal mktgPackagesAvailable = (BigDecimal) resultService.get("availableToPromiseTotal");
 
-                double qtyToProduce = Math.min(qtyRequired, mktgPackagesAvailable);
+                BigDecimal qtyToProduce = qtyRequired.min(mktgPackagesAvailable);
 
-                if (qtyToProduce > 0) {
+                if (qtyToProduce.compareTo(ZERO) > 0) {
                     if (Debug.verboseOn()) { Debug.logVerbose("Required quantity (all orders) = [" + qtyRequired + "] quantity to produce = [" + qtyToProduce + "]", module); }
 
-                    serviceContext.put("pRQuantity", new Double(qtyToProduce));
+                    serviceContext.put("pRQuantity", qtyToProduce);
                     serviceContext.put("startDate", UtilDateTime.nowTimestamp());
                     //serviceContext.put("workEffortName", "");
 
@@ -2365,10 +2365,10 @@
 
         String shipmentId = (String) context.get("shipmentId");
         String orderItemSeqId = (String) context.get("orderItemSeqId");
-        Double quantity = (Double) context.get("quantity");
+        BigDecimal quantity = (BigDecimal) context.get("quantity");
         String fromDateStr = (String) context.get("fromDate");
         
-        Double amount = null;
+        BigDecimal amount = null;
         Date fromDate = null;
         if (UtilValidate.isNotEmpty(fromDateStr)) {
             try {
@@ -2411,7 +2411,7 @@
                 continue;
             }
             if (orderItem.get("quantity") != null) {
-                quantity = orderItem.getDouble("quantity");
+                quantity = orderItem.getBigDecimal("quantity");
             } else {
                 continue;
             }
@@ -2425,16 +2425,16 @@
                 return ServiceUtil.returnError("Error reading the WorkOrderItemFulfillment: " + gee.getMessage());
             }
             if (orderItem.get("selectedAmount") != null) {
-                amount = orderItem.getDouble("selectedAmount");
+                amount = orderItem.getBigDecimal("selectedAmount");
             }
             if (amount == null) {
-                amount = new Double(0);
+                amount = BigDecimal.ZERO;
             }
             try {
                 ArrayList components = new ArrayList();
                 BOMTree tree = new BOMTree(orderItem.getString("productId"), "MANUF_COMPONENT", fromDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);
-                tree.setRootQuantity(quantity.doubleValue());
-                tree.setRootAmount(amount.doubleValue());
+                tree.setRootQuantity(quantity);
+                tree.setRootAmount(amount);
                 tree.print(components);
                 tree.createManufacturingOrders(null, fromDate, null, null, null, orderId, orderItem.getString("orderItemSeqId"), shipmentId, userLogin);
             } catch(GenericEntityException gee) {
@@ -2454,20 +2454,20 @@
 
         String productId = (String)context.get("productId");
         Timestamp startDate = (Timestamp)context.get("startDate");
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         String facilityId = (String)context.get("facilityId");
         String workEffortName = (String)context.get("workEffortName");
         String description = (String)context.get("description");
         String routingId = (String)context.get("routingId");
         String workEffortId = null;
         if (quantity == null) {
-            quantity = new Double(1.0);
+            quantity = BigDecimal.ONE;
         }
         try {
             ArrayList components = new ArrayList();
             BOMTree tree = new BOMTree(productId, "MANUF_COMPONENT", startDate, BOMTree.EXPLOSION_MANUFACTURING, delegator, dispatcher, userLogin);
-            tree.setRootQuantity(quantity.doubleValue());
-            tree.setRootAmount(0.0);
+            tree.setRootQuantity(quantity);
+            tree.setRootAmount(BigDecimal.ZERO);
             tree.print(components);
             workEffortId = tree.createManufacturingOrders(facilityId, startDate, workEffortName, description, routingId, null, null, null, userLogin);
         } catch(GenericEntityException gee) {
@@ -2688,7 +2688,7 @@
         if (startDate == null) {
             startDate = UtilDateTime.nowTimestamp();
         }
-        double totQty = 0.0;
+        BigDecimal totQty = BigDecimal.ZERO;
         try {
             List findOutgoingProductionRunsConds = new LinkedList();
 
@@ -2707,16 +2707,16 @@
             if (outgoingProductionRuns != null) {
                 for (int i = 0; i < outgoingProductionRuns.size(); i++) {
                     GenericValue outgoingProductionRun = (GenericValue)outgoingProductionRuns.get(i);
-                    Double dblQty = outgoingProductionRun.getDouble("estimatedQuantity");
-                    double qty = (dblQty != null? dblQty.doubleValue(): 0.0);
-                    totQty += qty;
+                    BigDecimal qty = outgoingProductionRun.getBigDecimal("estimatedQuantity");
+                    qty = qty != null ? qty : BigDecimal.ZERO;
+                    totQty = totQty.add(qty);
                 }
             }
         } catch (GenericEntityException e) {
             Debug.logError(e, "Problem calling the getProductionRunTotResQty service", module);
             return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ManufacturingProductionResQtyCalc", locale));
         }
-        result.put("reservedQuantity", new Double(totQty));
+        result.put("reservedQuantity", totQty);
         return result;
     }
 
@@ -2727,8 +2727,8 @@
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         String inventoryItemId = (String)context.get("inventoryItemId");
         /*
-        Double quantity = (Double)context.get("quantityAccepted");
-        if (quantity != null && quantity.doubleValue() == 0) {
+        BigDecimal quantity = (BigDecimal)context.get("quantityAccepted");
+        if (quantity != null && quantity.BigDecimalValue() == 0) {
             return ServiceUtil.returnSuccess();
         }
          */
@@ -2737,7 +2737,7 @@
             if (inventoryItem == null) {
                 return ServiceUtil.returnError("Error: inventory item with id [" + inventoryItemId + "] not found.");
             }
-            if (inventoryItem.get("availableToPromiseTotal") != null && inventoryItem.getDouble("availableToPromiseTotal").doubleValue() <= 0) {
+            if (inventoryItem.get("availableToPromiseTotal") != null && inventoryItem.getBigDecimal("availableToPromiseTotal").compareTo(ZERO) <= 0) {
                 return ServiceUtil.returnSuccess();
             }
             GenericValue product = inventoryItem.getRelatedOne("Product");
@@ -2769,7 +2769,7 @@
         GenericValue userLogin = (GenericValue) context.get("userLogin");
         // Mandatory input fields
         String inventoryItemId = (String)context.get("inventoryItemId");
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         List inventoryItemIds = new ArrayList();
         try {
             GenericValue inventoryItem = delegator.findByPrimaryKey("InventoryItem", UtilMisc.toMap("inventoryItemId", inventoryItemId));
@@ -2795,8 +2795,8 @@
                 serviceContext.put("quantity", quantity);
             }
             resultService = dispatcher.runSync("issueInventoryItemToWorkEffort", serviceContext);
-            Double issuedQuantity = (Double)resultService.get("quantityIssued");
-            if (issuedQuantity.doubleValue() == 0) {
+            BigDecimal issuedQuantity = (BigDecimal)resultService.get("quantityIssued");
+            if (issuedQuantity.compareTo(ZERO) == 0) {
                 return ServiceUtil.returnError("Error decomposing inventory item: no marketing packages found in inventory item [" + inventoryItem.getString("inventoryItemId") + "].");
             }
             // get the package's unit cost to compute a cost coefficient ratio which is the marketing package's actual unit cost divided by its standard cost
@@ -2807,18 +2807,18 @@
                                  "costComponentTypePrefix", "EST_STD",
                                  "userLogin", userLogin);
             resultService = dispatcher.runSync("getProductCost", serviceContext);
-            Double packageCost = (Double)resultService.get("productCost");
-            Double inventoryItemCost = inventoryItem.getDouble("unitCost");
-            Double costCoefficient = null;
-            if (packageCost == null || packageCost.doubleValue() == 0 || inventoryItemCost == null) {
+            BigDecimal packageCost = (BigDecimal)resultService.get("productCost");
+            BigDecimal inventoryItemCost = inventoryItem.getBigDecimal("unitCost");
+            BigDecimal costCoefficient = null;
+            if (packageCost == null || packageCost.compareTo(ZERO) == 0 || inventoryItemCost == null) {
                 // if the actual cost of the item (marketing package) that we are decomposing is not available, or
                 // if the standard cost of the marketing package is not available then
                 // the cost coefficient ratio is set to 1.0:
                 // this means that the unit costs of the inventory items of the components
                 // will be equal to the components' standard costs
-                costCoefficient = new Double(1.0);
+                costCoefficient = BigDecimal.ONE;
             } else {
-                costCoefficient = new Double(inventoryItemCost.doubleValue() / packageCost.doubleValue());
+                costCoefficient = inventoryItemCost.divide(packageCost, 10, rounding);
             }
             
             // the components are retrieved
@@ -2841,10 +2841,10 @@
                                      "costComponentTypePrefix", "EST_STD",
                                      "userLogin", userLogin);
                 resultService = dispatcher.runSync("getProductCost", serviceContext);
-                Double componentCost = (Double)resultService.get("productCost");
+                BigDecimal componentCost = (BigDecimal)resultService.get("productCost");
                 
                 // return the component to inventory at its standard cost multiplied by the cost coefficient from above
-                Double componentInventoryItemCost = new Double(costCoefficient.doubleValue() * componentCost.doubleValue());
+                BigDecimal componentInventoryItemCost = costCoefficient.multiply(componentCost);
                 serviceContext.clear();
                 serviceContext = UtilMisc.toMap("productId", ((GenericValue)component.get("product")).getString("productId"),
                                      "quantity", component.get("quantity"),
@@ -2886,18 +2886,18 @@
                     "PRUN_CREATED".equals(genericResult.getString("currentStatusId"))) {
                     continue;
                 }
-                Double qtyToProduce = genericResult.getDouble("quantityToProduce");
+                BigDecimal qtyToProduce = genericResult.getBigDecimal("quantityToProduce");
                 if (qtyToProduce == null) {
-                    qtyToProduce = new Double(0);
+                    qtyToProduce = BigDecimal.ZERO;
                 }
-                Double qtyProduced = genericResult.getDouble("quantityProduced");
+                BigDecimal qtyProduced = genericResult.getBigDecimal("quantityProduced");
                 if (qtyProduced == null) {
-                    qtyProduced = new Double(0);
+                    qtyProduced = BigDecimal.ZERO;
                 }
                 if (qtyProduced.compareTo(qtyToProduce) >= 0) {
                     continue;
                 }
-                double qtyDiff = qtyToProduce.doubleValue() - qtyProduced.doubleValue();
+                BigDecimal qtyDiff = qtyToProduce.subtract(qtyProduced);
                 String productId =  genericResult.getString("productId");
                 Timestamp estimatedShipDate = genericResult.getTimestamp("estimatedCompletionDate");
                 if (estimatedShipDate == null) {
@@ -2908,12 +2908,12 @@
                 }
                 TreeMap productMap = (TreeMap)products.get(productId);
                 if (!productMap.containsKey(estimatedShipDate)) {
-                    productMap.put(estimatedShipDate, UtilMisc.toMap("remainingQty", new Double(0.0), "reservations", FastList.newInstance()));
+                    productMap.put(estimatedShipDate, UtilMisc.toMap("remainingQty", BigDecimal.ZERO, "reservations", FastList.newInstance()));
                 }
                 Map dateMap = (Map)productMap.get(estimatedShipDate);
-                Double remainingQty = (Double)dateMap.get("remainingQty");
+                BigDecimal remainingQty = (BigDecimal)dateMap.get("remainingQty");
                 //List reservations = (List)dateMap.get("reservations");
-                remainingQty = new Double(remainingQty.doubleValue() + qtyDiff);
+                remainingQty = remainingQty.add(qtyDiff);
                 dateMap.put("remainingQty", remainingQty);
             }
 
@@ -2935,7 +2935,7 @@
                     }
                 }
                 String productId =  genericResult.getString("productId");
-                double orderQuantity = genericResult.getDouble("quantity").doubleValue();
+                BigDecimal orderQuantity = genericResult.getBigDecimal("quantity");
                 GenericValue orderItemDeliverySchedule = null;
                 try {
                     orderItemDeliverySchedule = delegator.findByPrimaryKey("OrderDeliverySchedule", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", genericResult.getString("orderItemSeqId")));
@@ -2957,19 +2957,19 @@
                 }
                 TreeMap productMap = (TreeMap)products.get(productId);
                 if (!productMap.containsKey(estimatedShipDate)) {
-                    productMap.put(estimatedShipDate, UtilMisc.toMap("remainingQty", new Double(0.0), "reservations", FastList.newInstance()));
+                    productMap.put(estimatedShipDate, UtilMisc.toMap("remainingQty", BigDecimal.ZERO, "reservations", FastList.newInstance()));
                 }
                 Map dateMap = (Map)productMap.get(estimatedShipDate);
-                Double remainingQty = (Double)dateMap.get("remainingQty");
+                BigDecimal remainingQty = (BigDecimal)dateMap.get("remainingQty");
                 //List reservations = (List)dateMap.get("reservations");
-                remainingQty = new Double(remainingQty.doubleValue() + orderQuantity);
+                remainingQty = remainingQty.add(orderQuantity);
                 dateMap.put("remainingQty", remainingQty);
             }
 
             // backorders
             List backordersCondList = FastList.newInstance();
             backordersCondList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.NOT_EQUAL, null));
-            backordersCondList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, new Double(0.0)));
+            backordersCondList.add(EntityCondition.makeCondition("quantityNotAvailable", EntityOperator.GREATER_THAN, BigDecimal.ZERO));
             //backordersCondList.add(EntityCondition.makeCondition(EntityCondition.makeCondition("statusId", EntityOperator.EQUALS, "ITEM_CREATED"), EntityOperator.OR, EntityCondition.makeCondition("statusId", EntityOperator.LESS_THAN, "ITEM_APPROVED")));
 
             List backorders = delegator.findList("OrderItemAndShipGrpInvResAndItem", EntityCondition.makeCondition(backordersCondList, EntityOperator.AND), null, UtilMisc.toList("shipBeforeDate"), null, false);
@@ -2981,8 +2981,8 @@
                                                                                                                   "shipGroupSeqId", genericResult.get("shipGroupSeqId")));
                 Timestamp requiredByDate = orderItemShipGroup.getTimestamp("shipByDate");
 
-                Double quantityNotAvailable = genericResult.getDouble("quantityNotAvailable");
-                double quantityNotAvailableRem = quantityNotAvailable.doubleValue();
+                BigDecimal quantityNotAvailable = genericResult.getBigDecimal("quantityNotAvailable");
+                BigDecimal quantityNotAvailableRem = quantityNotAvailable;
                 if (requiredByDate == null) {
                     // If shipByDate is not set, 'now' is assumed.
                     requiredByDate = now;
@@ -2998,12 +2998,12 @@
                     Timestamp currentDate = (Timestamp)subsetMapKeysIt.next();
                     Map currentDateMap = (Map) subsetMap.get(currentDate);
                     //List reservations = (List)currentDateMap.get("reservations");
-                    Double remainingQty = (Double)currentDateMap.get("remainingQty");
-                    if (remainingQty.doubleValue() == 0) {
+                    BigDecimal remainingQty = (BigDecimal)currentDateMap.get("remainingQty");
+                    if (remainingQty.compareTo(ZERO) == 0) {
                         continue;
                     }
-                    if (remainingQty.doubleValue() >= quantityNotAvailableRem) {
-                        remainingQty = new Double(remainingQty.doubleValue() - quantityNotAvailableRem);
+                    if (remainingQty.compareTo(quantityNotAvailableRem) >= 0) {
+                        remainingQty = remainingQty.subtract(quantityNotAvailableRem);
                         currentDateMap.put("remainingQty", remainingQty);
                         GenericValue orderItemShipGrpInvRes = delegator.findByPrimaryKey("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", genericResult.getString("orderId"),
                                                                                                                                   "shipGroupSeqId", genericResult.getString("shipGroupSeqId"),
@@ -3011,11 +3011,11 @@
                                                                                                                                   "inventoryItemId", genericResult.getString("inventoryItemId")));
                         orderItemShipGrpInvRes.set("promisedDatetime", currentDate);
                         orderItemShipGrpInvRes.store();
-                        // Todo: set the reservation
+                        // TODO: set the reservation
                         break;
                     } else {
-                        quantityNotAvailableRem = quantityNotAvailableRem - remainingQty.doubleValue();
-                        remainingQty = new Double(0.0);
+                        quantityNotAvailableRem = quantityNotAvailableRem.subtract(remainingQty);
+                        remainingQty = BigDecimal.ZERO;
                         currentDateMap.put("remainingQty", remainingQty);
                     }
                 }

Modified: ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java?rev=731346&r1=731345&r2=731346&view=diff
==============================================================================
--- ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java (original)
+++ ofbiz/branches/typecheckcleanup200810/applications/manufacturing/src/org/ofbiz/manufacturing/mrp/InventoryEventPlannedServices.java Sun Jan  4 11:46:24 2009
@@ -18,6 +18,7 @@
  *******************************************************************************/
 package org.ofbiz.manufacturing.mrp;
 
+import java.math.BigDecimal;
 import java.util.Map;
 
 import org.ofbiz.base.util.Debug;
@@ -49,7 +50,7 @@
                                         "productId", context.get("productId"),
                                         "eventDate", context.get("eventDate"),
                                         "mrpEventTypeId", context.get("mrpEventTypeId"));
-        Double quantity = (Double)context.get("quantity");
+        BigDecimal quantity = (BigDecimal)context.get("quantity");
         GenericValue mrpEvent = null;
         try {
             createOrUpdateMrpEvent(parameters, quantity, (String)context.get("facilityId"), (String)context.get("eventName"), false, delegator);
@@ -60,7 +61,7 @@
         return ServiceUtil.returnSuccess();
     }
 
-    public static void createOrUpdateMrpEvent(Map mrpEventKeyMap, Double newQuantity, String facilityId, String eventName, boolean isLate, GenericDelegator delegator) throws GenericEntityException {
+    public static void createOrUpdateMrpEvent(Map mrpEventKeyMap, BigDecimal newQuantity, String facilityId, String eventName, boolean isLate, GenericDelegator delegator) throws GenericEntityException {
         GenericValue mrpEvent = null;
         mrpEvent = delegator.findByPrimaryKey("MrpEvent", mrpEventKeyMap);
         if (mrpEvent == null) {
@@ -71,8 +72,8 @@
             mrpEvent.put("isLate", (isLate? "Y": "N"));
             mrpEvent.create();
         } else {
-            double qties = newQuantity.doubleValue() + ((Double)mrpEvent.get("quantity")).doubleValue();
-            mrpEvent.put("quantity", new Double(qties));
+            BigDecimal qties = newQuantity.add((BigDecimal)mrpEvent.get("quantity"));
+            mrpEvent.put("quantity", qties);
             if (!UtilValidate.isEmpty(eventName)) {
                 String existingEventName = mrpEvent.getString("eventName");
                 mrpEvent.put("eventName", (UtilValidate.isEmpty(existingEventName)? eventName: existingEventName + ", " + eventName));