svn commit: r541891 - in /ofbiz/trunk/applications: order/entitydef/ product/servicedef/ product/src/org/ofbiz/shipment/packing/ product/webapp/facility/WEB-INF/actions/shipment/ product/webapp/facility/shipment/

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

svn commit: r541891 - in /ofbiz/trunk/applications: order/entitydef/ product/servicedef/ product/src/org/ofbiz/shipment/packing/ product/webapp/facility/WEB-INF/actions/shipment/ product/webapp/facility/shipment/

jacopoc
Author: jacopoc
Date: Sat May 26 06:18:19 2007
New Revision: 541891

URL: http://svn.apache.org/viewvc?view=rev&rev=541891
Log:
Refactored code related to the Packing screen to support mkt pkg.
Thanks to Marco Risaliti for the initial patch (OFBIZ-1036) even if I have only partially applied it because I've choosen to follow a different approach for the packing screen.

Modified:
    ofbiz/trunk/applications/order/entitydef/entitygroup.xml
    ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml
    ofbiz/trunk/applications/product/servicedef/services_shipment.xml
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java
    ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java
    ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/shipment/PackOrder.bsh
    ofbiz/trunk/applications/product/webapp/facility/shipment/PackOrder.ftl

Modified: ofbiz/trunk/applications/order/entitydef/entitygroup.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitygroup.xml?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitygroup.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitygroup.xml Sat May 26 06:18:19 2007
@@ -58,6 +58,7 @@
     <entity-group group="org.ofbiz" entity="OrderItemAndProductContentInfo" />
     <entity-group group="org.ofbiz" entity="OrderItemAndShipGroupAssoc" />
     <entity-group group="org.ofbiz" entity="OrderItemAndShipGrpInvResAndItem" />
+    <entity-group group="org.ofbiz" entity="OrderItemAndShipGrpInvResAndItemSum" />
     <entity-group group="org.ofbiz" entity="OldOrderItemAssociation" />
     <entity-group group="org.ofbiz" entity="OrderItemAssoc" />
     <entity-group group="org.ofbiz" entity="OrderItemAssocType" />

Modified: ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml (original)
+++ ofbiz/trunk/applications/order/entitydef/entitymodel_view.xml Sat May 26 06:18:19 2007
@@ -1383,6 +1383,41 @@
         <key-map field-name="communicationEventId"/>
       </view-link>
     </view-entity>
+  
+    <view-entity entity-name="OrderItemAndShipGrpInvResAndItemSum"
+            package-name="org.ofbiz.order.order"
+            never-cache="true"
+            title="Order Item and Inventory Reservation View Entity">
+      <member-entity entity-alias="OI" entity-name="OrderItem"/>
+      <member-entity entity-alias="OISGIR" entity-name="OrderItemShipGrpInvRes"/>
+      <member-entity entity-alias="II" entity-name="InventoryItem"/>
+      <alias entity-alias="OI" name="orderId" group-by="true"/>
+      <alias entity-alias="OI" name="orderItemSeqId" group-by="true"/>
+      <alias entity-alias="OI" name="productId" group-by="true"/>
+      <alias entity-alias="II" name="inventoryProductId" field="productId" group-by="true"/>
+      <alias entity-alias="OISGIR" name="shipGroupSeqId" group-by="true"/>
+      <alias entity-alias="OI" name="quantityOrdered" function="sum">
+          <complex-alias operator="-">
+              <complex-alias-field entity-alias="OI" field="quantity" default-value="0"/>
+              <complex-alias-field entity-alias="OI" field="cancelQuantity" default-value="0"/>
+          </complex-alias>
+      </alias>
+      <alias entity-alias="OISGIR" name="totQuantityReserved" field="quantity" function="sum"/>
+      <alias entity-alias="OISGIR" name="totQuantityNotAvailable" field="quantityNotAvailable" function="sum"/>
+      <alias entity-alias="OISGIR" name="totQuantityAvailable" function="sum">
+          <complex-alias operator="-">
+              <complex-alias-field entity-alias="OISGIR" field="quantity" default-value="0"/>
+              <complex-alias-field entity-alias="OISGIR" field="quantityNotAvailable" default-value="0"/>
+          </complex-alias>
+      </alias>
+      <view-link entity-alias="OI" rel-entity-alias="OISGIR">
+        <key-map field-name="orderId"/>
+        <key-map field-name="orderItemSeqId"/>
+      </view-link>
+      <view-link entity-alias="OISGIR" rel-entity-alias="II">
+        <key-map field-name="inventoryItemId"/>
+      </view-link>
+    </view-entity>
 
 </entitymodel>
 

Modified: ofbiz/trunk/applications/product/servicedef/services_shipment.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_shipment.xml?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_shipment.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_shipment.xml Sat May 26 06:18:19 2007
@@ -406,6 +406,7 @@
         <attribute name="qtyInfo" type="Map" string-map-prefix="qty_" mode="IN" optional="true"/>
         <attribute name="pkgInfo" type="Map" string-map-prefix="pkg_" mode="IN" optional="true"/>
         <attribute name="selInfo" type="Map" string-map-prefix="sel_" mode="IN" optional="true"/>
+        <attribute name="iteInfo" type="Map" string-map-prefix="ite_" mode="IN" optional="true"/>
         <attribute name="wgtInfo" type="Map" string-map-prefix="wgt_" mode="IN" optional="true"/>
     </service>
 
@@ -448,6 +449,7 @@
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
         <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/>
         <attribute name="shipGroupSeqId" type="String" mode="IN" optional="false"/>
+        <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="inventoryItemId" type="String" mode="IN" optional="false"/>
         <attribute name="packageSeqId" type="Integer" mode="IN" optional="false"/>
     </service>

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingServices.java Sat May 26 06:18:19 2007
@@ -88,6 +88,7 @@
         session.setPickerPartyId(pickerPartyId);
 
         Map selInfo = (Map) context.get("selInfo");
+        Map iteInfo = (Map) context.get("iteInfo");
         Map prdInfo = (Map) context.get("prdInfo");
         Map qtyInfo = (Map) context.get("qtyInfo");
         Map pkgInfo = (Map) context.get("pkgInfo");
@@ -96,17 +97,18 @@
         if (selInfo != null) {
             Iterator i = selInfo.keySet().iterator();
             while (i.hasNext()) {
-                String orderItemSeqId = (String) i.next();
-                String prdStr = (String) prdInfo.get(orderItemSeqId);
+                String rowKey = (String) i.next();
+                String orderItemSeqId = (String) iteInfo.get(rowKey);
+                String prdStr = (String) prdInfo.get(rowKey);
                 if (UtilValidate.isEmpty(prdStr)) {
                     // set the productId to null if empty
                     prdStr = null;
                 }
 
                 // base package/quantity/weight strings
-                String pkgStr = (String) pkgInfo.get(orderItemSeqId);
-                String qtyStr = (String) qtyInfo.get(orderItemSeqId);
-                String wgtStr = (String) wgtInfo.get(orderItemSeqId);
+                String pkgStr = (String) pkgInfo.get(rowKey);
+                String qtyStr = (String) qtyInfo.get(rowKey);
+                String wgtStr = (String) wgtInfo.get(rowKey);
 
                 Debug.log("Item: " + orderItemSeqId + " / Product: " + prdStr + " / Quantity: " + qtyStr + " /  Package: " + pkgStr + " / Weight: " + wgtStr, module);
 
@@ -132,7 +134,7 @@
                 if (qtyStr == null) {
                     quantities = new String[packages.length];
                     for (int p = 0; p < packages.length; p++) {
-                        quantities[p] = (String) qtyInfo.get(orderItemSeqId + ":" + packages[p]);
+                        quantities[p] = (String) qtyInfo.get(rowKey + ":" + packages[p]);
                     }
                     if (quantities.length != packages.length) {
                         return ServiceUtil.returnError("Packages and quantities do not match.");
@@ -192,10 +194,11 @@
         String orderItemSeqId = (String) context.get("orderItemSeqId");
         String shipGroupSeqId = (String) context.get("shipGroupSeqId");
         String inventoryItemId = (String) context.get("inventoryItemId");
+        String productId = (String) context.get("productId");
         Integer packageSeqId = (Integer) context.get("packageSeqId");
 
         PackingSessionLine line = session.findLine(orderId, orderItemSeqId, shipGroupSeqId,
-                inventoryItemId, packageSeqId.intValue());
+                productId, inventoryItemId, packageSeqId.intValue());
 
         // remove the line
         if (line != null) {

Modified: ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java (original)
+++ ofbiz/trunk/applications/product/src/org/ofbiz/shipment/packing/PackingSession.java Sat May 26 06:18:19 2007
@@ -133,7 +133,7 @@
         // find the inventoryItemId to use
         if (reservations.size() == 1) {
             GenericValue res = EntityUtil.getFirst(reservations);
-            int checkCode = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, quantity, packageSeqId, update);
+            int checkCode = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity, packageSeqId, update);
             this.createPackLineItem(checkCode, res, orderId, orderItemSeqId, shipGroupSeqId, productId, quantity, weight, packageSeqId);
         } else {
             // more than one reservation found
@@ -143,15 +143,21 @@
 
             while (i.hasNext() && qtyRemain > 0) {
                 GenericValue res = (GenericValue) i.next();
+
+                // Check that the inventory item product match with the current product to pack
+                if (!productId.equals(res.getRelatedOne("InventoryItem").getString("productId"))) {
+                    continue;
+                }
+
                 double resQty = res.getDouble("quantity").doubleValue();
-                PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, res.getString("inventoryItemId"), packageSeqId);
+                PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, productId, res.getString("inventoryItemId"), packageSeqId);
                 if (UtilValidate.isNotEmpty(line) && !update) {
                     resQty -= line.getQuantity();
                 }
                 
                 double thisQty = resQty > qtyRemain ? qtyRemain : resQty;
 
-                int thisCheck = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, thisQty, packageSeqId, update);
+                int thisCheck = this.checkLineForAdd(res, orderId, orderItemSeqId, shipGroupSeqId, productId, thisQty, packageSeqId, update);
                 switch (thisCheck) {
                     case 2:
                         Debug.log("Packing check returned '2' - new pack line will be created!", module);
@@ -192,7 +198,7 @@
         this.addOrIncreaseLine(null, null, null, productId, quantity, packageSeqId, 0, false);
     }
 
-    public PackingSessionLine findLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String inventoryItemId, int packageSeq) {
+    public PackingSessionLine findLine(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, int packageSeq) {
         List lines = this.getLines();
         Iterator i = lines.iterator();
         while (i.hasNext()) {
@@ -200,6 +206,7 @@
             if (orderId.equals(line.getOrderId()) &&
                     orderItemSeqId.equals(line.getOrderItemSeqId()) &&
                     shipGroupSeqId.equals(line.getShipGroupSeqId()) &&
+                    productId.equals(line.getProductId()) &&
                     inventoryItemId.equals(line.getInventoryItemId()) &&
                     packageSeq == line.getPackageSeq()) {
                 return line;
@@ -274,13 +281,13 @@
         }
     }
 
-    protected int checkLineForAdd(GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, double quantity, int packageSeqId, boolean update) {
+    protected int checkLineForAdd(GenericValue res, String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, double quantity, int packageSeqId, boolean update) {
         // check to see if the reservation can hold the requested quantity amount
         String invItemId = res.getString("inventoryItemId");
         double resQty = res.getDouble("quantity").doubleValue();
 
-        PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, invItemId, packageSeqId);
-        double packedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId);
+        PackingSessionLine line = this.findLine(orderId, orderItemSeqId, shipGroupSeqId, productId, invItemId, packageSeqId);
+        double packedQty = this.getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, productId);
 
         Debug.log("Packed quantity [" + packedQty + "] + [" + quantity + "]", module);
 
@@ -342,22 +349,22 @@
         return packageSeq;
     }
 
-    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) {
-        return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, null, -1);
+    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) {
+        return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId,  productId, null, -1);
     }
 
-    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, int packageSeq) {
-        return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId, null, packageSeq);
+    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, int packageSeq) {
+        return getPackedQuantity(orderId, orderItemSeqId, shipGroupSeqId,  productId, null, packageSeq);
     }
 
-    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String inventoryItemId, int packageSeq) {
+    public double getPackedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId, String inventoryItemId, int packageSeq) {
         double total = 0.0;
         List lines = this.getLines();
         Iterator i = lines.iterator();
         while (i.hasNext()) {
             PackingSessionLine line = (PackingSessionLine) i.next();
             if (orderId.equals(line.getOrderId()) && orderItemSeqId.equals(line.getOrderItemSeqId()) &&
-                    shipGroupSeqId.equals(line.getShipGroupSeqId())) {
+                    shipGroupSeqId.equals(line.getShipGroupSeqId()) && productId.equals(line.getProductId())) {
                 if (inventoryItemId == null || inventoryItemId.equals(line.getInventoryItemId())) {
                     if (packageSeq == -1 || packageSeq == line.getPackageSeq()) {
                         total += line.getQuantity();
@@ -410,29 +417,19 @@
         return getPackedQuantity(productId, -1);
     }
 
-    public double getCurrentReservedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId) {
+    public double getCurrentReservedQuantity(String orderId, String orderItemSeqId, String shipGroupSeqId, String productId) {
         double reserved = -1;
-        List res = null;
         try {
-            res = this.getDelegator().findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", orderId,
-                    "orderItemSeqId", orderItemSeqId, "shipGroupSeqId", shipGroupSeqId));
+            GenericValue res = EntityUtil.getFirst(this.getDelegator().findByAnd("OrderItemAndShipGrpInvResAndItemSum", UtilMisc.toMap("orderId", orderId,
+                    "orderItemSeqId", orderItemSeqId, "shipGroupSeqId", shipGroupSeqId, "inventoryProductId", productId)));
+            Double reservedDbl = res.getDouble("totQuantityAvailable");
+            if (reservedDbl == null) {
+                reservedDbl = new Double(-1);
+            }
+            reserved = reservedDbl.doubleValue();
         } catch (GenericEntityException e) {
             Debug.logError(e, module);
         }
-
-        if (res != null) {
-            reserved = 0.0;
-            Iterator i = res.iterator();
-            while (i.hasNext()) {
-                GenericValue v = (GenericValue) i.next();
-                Double not = v.getDouble("quantityNotAvailable");
-                Double qty = v.getDouble("quantity");
-                if (not == null) not = new Double(0);
-                if (qty == null) qty = new Double(0);
-                reserved += (qty.doubleValue() - not.doubleValue());
-            }
-        }
-
         return reserved;
     }
 
@@ -626,8 +623,8 @@
         Iterator i = this.getLines().iterator();
         while (i.hasNext()) {
             PackingSessionLine line = (PackingSessionLine) i.next();
-            double reservedQty =  this.getCurrentReservedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId());
-            double packedQty = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId());
+            double reservedQty =  this.getCurrentReservedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId());
+            double packedQty = this.getPackedQuantity(line.getOrderId(), line.getOrderItemSeqId(), line.getShipGroupSeqId(), line.getProductId());
 
             if (packedQty != reservedQty) {
                 errors.add("Packed amount does not match reserved amount for item (" + line.getProductId() + ") [" + packedQty + " / " + reservedQty + "]");
@@ -717,7 +714,7 @@
             PackingSessionLine line = (PackingSessionLine) i.next();
             if (this.checkLine(processedLines, line)) {
                 double totalPacked = this.getPackedQuantity(line.getOrderId(),  line.getOrderItemSeqId(),
-                        line.getShipGroupSeqId(), line.getInventoryItemId(), -1);
+                        line.getShipGroupSeqId(), line.getProductId(), line.getInventoryItemId(), -1);
 
                 line.issueItemToShipment(shipmentId, picklistBinId, userLogin, new Double(totalPacked), getDispatcher());
                 processedLines.add(line);
@@ -955,15 +952,15 @@
                 quantity = v.getBigDecimal("quantity").setScale(2, BigDecimal.ROUND_HALF_UP);
                 try {
                     orderItem = v.getRelatedOne("OrderItem");
-                    productId = orderItem.getString("productId");
+                    productId = v.getRelatedOne("InventoryItem").getString("productId");
                 } catch (GenericEntityException e) {
                     Debug.logError(e, module);
                 }
             } else {
+                // this is an OrderItemAndShipGrpInvResAndItemSum
                 orderItem = v;
-                productId = v.getString("productId");
-                double reserved = getCurrentReservedQuantity(orderItem.getString("orderId"), orderItem.getString("orderItemSeqId"), primaryShipGrp);
-                quantity = new BigDecimal(reserved).setScale(2, BigDecimal.ROUND_HALF_UP);
+                productId = v.getString("inventoryProductId");
+                quantity = v.getBigDecimal("totQuantityAvailable").setScale(2, BigDecimal.ROUND_HALF_UP);
             }
             Debug.log("created item display object quanttiy: " + quantity + " (" + productId + ")", module);
         }
@@ -994,7 +991,13 @@
         public boolean equals(Object o) {
             if (o instanceof ItemDisplay) {
                 ItemDisplay d = (ItemDisplay) o;
-                return (d.productId.equals(productId));
+                boolean sameOrderItemProduct = true;
+                if (d.getOrderItem().getString("productId") != null && orderItem.getString("productId") != null) {
+                    sameOrderItemProduct = d.getOrderItem().getString("productId").equals(orderItem.getString("productId"));
+                } else if (d.getOrderItem().getString("productId") != null || orderItem.getString("productId") != null) {
+                    sameOrderItemProduct = false;
+                }
+                return (d.productId.equals(productId) && sameOrderItemProduct);
             } else {
                 return false;
             }            

Modified: ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/shipment/PackOrder.bsh
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/shipment/PackOrder.bsh?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/shipment/PackOrder.bsh (original)
+++ ofbiz/trunk/applications/product/webapp/facility/WEB-INF/actions/shipment/PackOrder.bsh Sat May 26 06:18:19 2007
@@ -132,15 +132,16 @@
                 // Generate the shipment cost estimate for the ship group
                 productStoreId = orh.getProductStoreId();
                 shippableItemInfo = orh.getOrderItemAndShipGroupAssoc(shipGroupSeqId);
+                shippableItems = delegator.findByAnd("OrderItemAndShipGrpInvResAndItemSum", UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", shipGroupSeqId));
                 shippableTotal = new Double(orh.getShippableTotalBd(shipGroupSeqId).doubleValue());
                 shippableWeight = new Double(orh.getShippableWeightBd(shipGroupSeqId).doubleValue());
                 shippableQuantity = new Double(orh.getShippableQuantityBd(shipGroupSeqId).doubleValue());
-                shipmentCostEstimate = packSession.getShipmentCostEstimate(orderItemShipGroup, productStoreId, shippableItemInfo, shippableTotal, shippableWeight, shippableQuantity);                
+                shipmentCostEstimate = packSession.getShipmentCostEstimate(orderItemShipGroup, productStoreId, shippableItemInfo, shippableTotal, shippableWeight, shippableQuantity);
                 context.put("shipmentCostEstimateForShipGroup", shipmentCostEstimate);
                 context.put("productStoreId", productStoreId);
 
                 if (picklistBinId == null) {
-                    packSession.addItemInfo(shippableItemInfo);
+                    packSession.addItemInfo(shippableItems);
                     //context.put("itemInfos", shippableItemInfo);
                 }
             } else {

Modified: ofbiz/trunk/applications/product/webapp/facility/shipment/PackOrder.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/webapp/facility/shipment/PackOrder.ftl?view=diff&rev=541891&r1=541890&r2=541891
==============================================================================
--- ofbiz/trunk/applications/product/webapp/facility/shipment/PackOrder.ftl (original)
+++ ofbiz/trunk/applications/product/webapp/facility/shipment/PackOrder.ftl Sat May 26 06:18:19 2007
@@ -239,6 +239,7 @@
             </tr>
                         
             <#if (itemInfos?has_content)>              
+              <#assign rowKey = 1>
               <#list itemInfos as itemInfo>                                            
               <#-- <#list itemInfos as orderItem>  -->
                 <#assign orderItem = itemInfo.orderItem/>
@@ -252,24 +253,24 @@
                 </#if>
                 -->
 
-                <#assign inputQty = (orderItemQuantity - shippedQuantity - packingSession.getPackedQuantity(orderId, orderItem.orderItemSeqId, shipGroupSeqId))>
+                <#assign inputQty = (orderItemQuantity - shippedQuantity - packingSession.getPackedQuantity(orderId, orderItem.orderItemSeqId, shipGroupSeqId, itemInfo.productId))>
                 <tr>
-                  <td><input type="checkbox" name="sel_${orderItem.orderItemSeqId}" value="Y" <#if (inputQty >0)>checked=""</#if>/></td>
+                  <td><input type="checkbox" name="sel_${rowKey}" value="Y" <#if (inputQty >0)>checked=""</#if>/></td>
                   <td><div class="tabletext">${orderItem.orderItemSeqId}</td>
-                  <td><div class="tabletext">${orderItem.productId?default("N/A")}</td>
+                  <td><div class="tabletext"><#if itemInfo.productId?exists && orderItem.productId?exists && orderItem.productId != itemInfo.productId>${orderItem.productId?default("N/A")}&nbsp;</#if>${itemInfo.productId?default("N/A")}</td>
                   <td><div class="tabletext">${orderItem.itemDescription?if_exists}</td>
                   <td align="right"><div class="tabletext">${orderItemQuantity}</td>
                   <td align="right"><div class="tabletext">${shippedQuantity?default(0)}</td>
-                  <td align="right"><div class="tabletext">${packingSession.getPackedQuantity(orderId, orderItem.orderItemSeqId, shipGroupSeqId)}</td>
+                  <td align="right"><div class="tabletext">${packingSession.getPackedQuantity(orderId, orderItem.orderItemSeqId, shipGroupSeqId, itemInfo.productId)}</td>
                   <td>&nbsp;&nbsp;</td>
                   <td align="center">
-                    <input type="text" class="inputBox" size="7" name="qty_${orderItem.orderItemSeqId}" value="${inputQty}">
+                    <input type="text" class="inputBox" size="7" name="qty_${rowKey}" value="${inputQty}">
                   </td>
                   <#--td align="center">
-                    <input type="text" class="inputBox" size="7" name="wgt_${orderItem.orderItemSeqId}" value="">
+                    <input type="text" class="inputBox" size="7" name="wgt_${rowKey}" value="">
                   </td-->
                   <td align="center">
-                    <select name="pkg_${orderItem.orderItemSeqId}">
+                    <select name="pkg_${rowKey}">
                       <option value="1">${uiLabelMap.ProductPackage} 1</option>
                       <option value="2">${uiLabelMap.ProductPackage} 2</option>
                       <option value="3">${uiLabelMap.ProductPackage} 3</option>
@@ -277,8 +278,10 @@
                       <option value="5">${uiLabelMap.ProductPackage} 5</option>
                     </select>
                   </td>
-                  <input type="hidden" name="prd_${orderItem.orderItemSeqId}" value="${orderItem.productId?if_exists}">
+                  <input type="hidden" name="prd_${rowKey}" value="${itemInfo.productId?if_exists}"/>
+                  <input type="hidden" name="ite_${rowKey}" value="${orderItem.orderItemSeqId}"/>
                 </tr>
+                <#assign rowKey = rowKey + 1>
               </#list>
             </#if>
             <tr><td colspan="10">&nbsp;</td></tr>
@@ -389,7 +392,7 @@
               <td align="right"><div class="tabletext">${line.getQuantity()}</td>
               <#--td align="right"><div class="tabletext">${line.getWeight()}</td-->
               <td align="right"><div class="tabletext">${line.getPackageSeq()}</td>
-              <td align="right"><a href="<@ofbizUrl>ClearPackLine?facilityId=${facilityId}&orderId=${line.getOrderId()}&orderItemSeqId=${line.getOrderItemSeqId()}&shipGroupSeqId=${line.getShipGroupSeqId()}&inventoryItemId=${line.getInventoryItemId()}&packageSeqId=${line.getPackageSeq()}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonClear}</a></td>
+              <td align="right"><a href="<@ofbizUrl>ClearPackLine?facilityId=${facilityId}&orderId=${line.getOrderId()}&orderItemSeqId=${line.getOrderItemSeqId()}&shipGroupSeqId=${line.getShipGroupSeqId()}&amp;productId=${line.getProductId()?default("")}&inventoryItemId=${line.getInventoryItemId()}&packageSeqId=${line.getPackageSeq()}</@ofbizUrl>" class="buttontext">${uiLabelMap.CommonClear}</a></td>
             </tr>
           </#list>
         </table>