svn commit: r667649 - in /ofbiz/trunk/applications: manufacturing/widget/manufacturing/ product/webapp/facility/WEB-INF/actions/facility/

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

svn commit: r667649 - in /ofbiz/trunk/applications: manufacturing/widget/manufacturing/ product/webapp/facility/WEB-INF/actions/facility/

mrisaliti
Author: mrisaliti
Date: Fri Jun 13 13:48:16 2008
New Revision: 667649

URL: http://svn.apache.org/viewvc?rev=667649&view=rev
Log:
Misc convertion of some bsh scripts to groovy (Part of issue OFBIZ-1801)

Added:
    ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.groovy
      - copied, changed from r667620, ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.bsh
Removed:
    ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.bsh
Modified:
    ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/facility/CountFacilityInventoryByProduct.groovy

Copied: ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.groovy (from r667620, ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.bsh)
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.groovy?p2=ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.groovy&p1=ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.bsh&r1=667620&r2=667649&rev=667649&view=diff
==============================================================================
--- ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.bsh (original)
+++ ofbiz/trunk/applications/manufacturing/widget/manufacturing/CuttingListReport.groovy Fri Jun 13 13:48:16 2008
@@ -17,23 +17,15 @@
  * under the License.
  */
 
-import java.util.*;
-import java.awt.Dimension;
-import org.ofbiz.entity.*;
-import org.ofbiz.base.util.*;
-import org.ofbiz.entity.util.*;
-import org.ofbiz.widget.html.*;
-import org.ofbiz.manufacturing.jobshopmgt.ProductionRun;
-import org.ofbiz.manufacturing.jobshopmgt.ProductionRunHelper;
-
-security = request.getAttribute("security");
-delegator = request.getAttribute("delegator");
-dispatcher = request.getAttribute("dispatcher");
+import java.awt.Dimension
+import org.ofbiz.entity.util.*
+import org.ofbiz.manufacturing.jobshopmgt.ProductionRun
+import org.ofbiz.manufacturing.jobshopmgt.ProductionRunHelper
 
-if(security.hasEntityPermission("MANUFACTURING", "_VIEW", session)) {
-    context.put("hasPermission", Boolean.TRUE);
+if (security.hasEntityPermission("MANUFACTURING", "_VIEW", session)) {
+    context.hasPermission = Boolean.TRUE;
 } else {
-    context.put("hasPermission", Boolean.FALSE);
+    context.hasPermission = Boolean.FALSE;
 }
 
 // -----------------------------
@@ -44,10 +36,10 @@
 // -----------------------------
 
 shipmentId = request.getParameter("shipmentId");
-context.put("shipmentId", shipmentId);
-shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
-context.put("shipment", shipment);
+context.shipmentId = shipmentId;
 
+shipment = delegator.findOne("Shipment", [shipmentId : shipmentId], false);
+context.shipment = shipment;
 
 // dimensionsByFeatureMap [key=feature; value=productsByShapeMap]
 // productsByShapeMap [key=dimension; value=quantityByProductsMap]
@@ -55,139 +47,85 @@
 // dimension={width*, height*, qty}
 // product={productId*,...}
 
-productIdToQuantity = new HashMap(); // key=productId, value=quantity
-productIdToProduct = new HashMap(); // key=productId, value=product
-dimensionToProducts = new HashMap(); // key=Dimension, value=list of products
-dimensionToQuantity = new HashMap(); // key=Dimension, value=tot qty (of products)
-
-shipmentPlans = delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId));
-
-if (shipmentPlans != null) {
-    shipmentPlansIt = shipmentPlans.iterator();
-    while (shipmentPlansIt.hasNext()) {
-        shipmentPlan = shipmentPlansIt.next();
+productIdToQuantity = [:]; // key=productId, value=quantity
+productIdToProduct = [:]; // key=productId, value=product
+dimensionToProducts = [:]; // key=Dimension, value=list of products
+dimensionToQuantity = [:]; // key=Dimension, value=tot qty (of products)
+
+shipmentPlans = delegator.findList("OrderShipment", EntityCondition.makeCondition([shipmentId : shipmentId]), null, null, null, false);
+
+if (shipmentPlans) {
+    shipmentPlans.each { shipmentPlan ->
         // Select the production run, if available
-        weIds = delegator.findByAnd("WorkOrderItemFulfillment", UtilMisc.toMap("orderId", shipmentPlan.getString("orderId"), "orderItemSeqId", shipmentPlan.getString("orderItemSeqId")), UtilMisc.toList("workEffortId")); // TODO: add shipmentId
+        weIds = delegator.findList("WorkOrderItemFulfillment", EntityCondition.makeCondition([orderId : shipmentPlan.orderId, orderItemSeqId : shipmentPlan.orderItemSeqId]), null, ['workEffortId'], null, false); // TODO: add shipmentId
         weId = EntityUtil.getFirst(weIds);
-        ArrayList productionRunTree = new ArrayList();
+        productionRunTree = [] as ArrayList;
         // TODO
-        if (weId != null) {
-            ProductionRunHelper.getLinkedProductionRuns(delegator, dispatcher, weId.getString("workEffortId"), productionRunTree);
+        if (weId) {
+            ProductionRunHelper.getLinkedProductionRuns(delegator, dispatcher, weId.workEffortId, productionRunTree);
             for (int i = 0; i < productionRunTree.size(); i++) {
-                ProductionRun oneProductionRun = (ProductionRun)productionRunTree.get(i);
-                if (ProductionRunHelper.hasTask(delegator, selectWorkEffortNameParameter, oneProductionRun.getGenericValue().getString("workEffortId"))) {
-                    GenericValue product = oneProductionRun.getProductProduced();
-                    String primaryCategory = product.getString("primaryProductCategoryId");
-                    if (primaryCategory != null && selectPrimaryCategoryIdParameter.equals(primaryCategory)) {
-                        String productId = product.getString("productId");
+                oneProductionRun = (ProductionRun)productionRunTree.get(i);
+                if (ProductionRunHelper.hasTask(delegator, selectWorkEffortNameParameter, oneProductionRun.getGenericValue().workEffortId)) {
+                    product = oneProductionRun.getProductProduced();
+                    primaryCategory = product.primaryProductCategoryId;
+                    if (primaryCategory && selectPrimaryCategoryIdParameter.equals(primaryCategory)) {
+                        productId = product.productId;
                         productIdToProduct.put(productId, product);
                         if (!productIdToQuantity.containsKey(productId)) {
                             productIdToQuantity.put(productId, new Double(0));
                         }
-                        Double qty = (Double)productIdToQuantity.get(productId);
+                        qty = (Double)productIdToQuantity.get(productId);
                         productIdToQuantity.put(productId, new Double(oneProductionRun.getGenericValue().getDouble("quantityToProduce").doubleValue() + qty.doubleValue()));
                     }
                 }
             }
         }
     }
-    Iterator productsIterator = productIdToProduct.values().iterator();
-    while (productsIterator.hasNext()) {
-        GenericValue product = (GenericValue)productsIterator.next();
-        Double heightD = product.getDouble("productHeight");
-        int height = 0;
-        if (heightD != null) height = (int)(heightD.doubleValue() * 1000);
-        Double widthD = product.getDouble("productWidth");
-        int width = 0;
-        if (widthD != null) width = (int)(widthD.doubleValue() * 1000);
+    productIdToProduct.values().each { product ->
+        heightD = product.getDouble("productHeight");
+        height = 0;        
+        if (heightD) {
+            height = (heightD.doubleValue() * 1000) as int;
+        }
+        
+        widthD = product.getDouble("productWidth");
+        width = 0;        
+        if (widthD) {
+            width = (widthD.doubleValue() * 1000) as int;
+        }
         Dimension dim = new Dimension(width, height);
         if (!dimensionToProducts.containsKey(dim)) {
             dimensionToProducts.put(dim, new ArrayList());
         }
-        List prodList = (List)dimensionToProducts.get(dim);
+        prodList = (List)dimensionToProducts.get(dim);
         prodList.add(product);
         // tot qty per dimension
         if (!dimensionToQuantity.containsKey(dim)) {
             dimensionToQuantity.put(dim, new Double(0));
         }
         Double qty = (Double)dimensionToQuantity.get(dim);
-        dimensionToQuantity.put(dim, new Double(((Double)productIdToQuantity.get(product.getString("productId"))).doubleValue() + qty.doubleValue()));
+        dimensionToQuantity.put(dim, new Double(((Double)productIdToQuantity.get(product.productId)).doubleValue() + qty.doubleValue()));
     }
     //
     //
     //
-    List list1 = new ArrayList();
-    Iterator dimIt = dimensionToProducts.keySet().iterator();
-    while (dimIt.hasNext()) {
-        Dimension dim = (Dimension)dimIt.next();
-        Map map1 = new HashMap();
+    list1 = [] as ArrayList;
+    dimensionToProducts.keySet().each { dim ->
+        map1 = [:];
         list1.add(map1);
-        map1.put("width", new Double(dim.getWidth() / 1000));
-        map1.put("height", new Double(dim.getHeight() / 1000));
-        map1.put("quantity", dimensionToQuantity.get(dim));
-        List list2 = new ArrayList();
-        map1.put("products", list2);
-        List products = (List)dimensionToProducts.get(dim);
+        map1.width = (dim.getWidth() / 1000) as Double;
+        map1.height = (dim.getHeight() / 1000) as Double;
+        map1.quantity = dimensionToQuantity.get(dim);
+        list2 = [] as ArrayList;
+        map1.products = list2;
+        products = (List)dimensionToProducts.get(dim);
         for (int i = 0; i < products.size(); i++) {
-            GenericValue product = (GenericValue)products.get(i);
-            Map map2 = new HashMap();
+            product = products.get(i);
+            Map map2 = [:];
             list2.add(map2);
-            map2.put("product", product);
-            map2.put("quantity", productIdToQuantity.get(product.getString("productId")));
+            map2.product = product;
+            map2.quantity = productIdToQuantity.get(product.productId);
         }
     }
-    context.put("cuttingList", list1);
-}
-
-/*
-// Data structure example
-Map map1, map2 = null;
-List list1, list2 = null;
-//
-GenericValue productA = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", "AR202"));
-GenericValue productB = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", "PENS45_001_BePoBi"));
-GenericValue productC = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", "ST_001_Bi"));
-GenericValue productD = delegator.findByPrimaryKey("Product", UtilMisc.toMap("productId", "25-00"));
-// products
-list2 = new ArrayList();
-map2 = new HashMap();
-map2.put("product", productA);
-map2.put("quantity", new Integer(12));
-list2.add(map2);
-map2 = new HashMap();
-map2.put("product", productB);
-map2.put("quantity", new Integer(4));
-list2.add(map2);
-// dimensions
-list1 = new ArrayList();
-map1 = new HashMap();
-map1.put("width", new Double(123.5));
-map1.put("length", new Double(243.8));
-map1.put("quantity", new Integer(16));
-map1.put("products", list2);
-list1.add(map1);
-// products
-list2 = new ArrayList();
-map2 = new HashMap();
-map2.put("product", productA);
-map2.put("quantity", new Integer(3));
-list2.add(map2);
-map2 = new HashMap();
-map2.put("product", productC);
-map2.put("quantity", new Integer(20));
-list2.add(map2);
-map2 = new HashMap();
-map2.put("product", productD);
-map2.put("quantity", new Integer(7));
-list2.add(map2);
-// dimensions
-map1 = new HashMap();
-map1.put("width", new Double(150.5));
-map1.put("length", new Double(145.3));
-map1.put("quantity", new Integer(30));
-map1.put("products", list2);
-list1.add(map1);
-
-context.put("cuttingList", list1);
-*/
-
+    context.cuttingList = list1;
+}
\ No newline at end of file

Modified: ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/facility/CountFacilityInventoryByProduct.groovy
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/facility/CountFacilityInventoryByProduct.groovy?rev=667649&r1=667648&r2=667649&view=diff
==============================================================================
--- ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/facility/CountFacilityInventoryByProduct.groovy (original)
+++ ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/facility/CountFacilityInventoryByProduct.groovy Fri Jun 13 13:48:16 2008
@@ -33,13 +33,12 @@
 import org.ofbiz.entity.*
 import org.ofbiz.entity.condition.*
 import org.ofbiz.entity.transaction.*
-import org.ofbiz.entity.util.EntityListIterator
+import org.ofbiz.entity.util.*
 import org.ofbiz.entity.model.DynamicViewEntity
 import org.ofbiz.entity.model.ModelKeyMap
 import org.ofbiz.entity.model.ModelViewEntity.ComplexAlias
 import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasField
 import org.ofbiz.entity.model.ModelViewEntity.ComplexAliasMember
-import org.ofbiz.entity.util.EntityFindOptions
 import org.ofbiz.product.inventory.*
 
 action = request.getParameter("action");