Bug fix to ensure the packing PDF calculates correct values for the requested count when handling multiple issuances. OFBIZ-1070
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@552809 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
import javolution.util.FastList;
|
||||
import javolution.util.FastMap;
|
||||
import org.ofbiz.base.util.UtilMisc;
|
||||
import org.ofbiz.base.util.*;
|
||||
import org.ofbiz.entity.condition.*;
|
||||
|
||||
// Since this script is run after ViewShipment, we will re-use the shipment in the context
|
||||
shipment = context.get("shipment");
|
||||
@@ -33,6 +35,7 @@ shipmentPackages = shipment.getRelated("ShipmentPackage", orderBy);
|
||||
|
||||
// first we scan the shipment items and count the quantity of each product that is being shipped
|
||||
quantityShippedByProduct = FastMap.newInstance();
|
||||
quantityInShipmentByProduct = FastMap.newInstance();
|
||||
shipmentItems = shipment.getRelated("ShipmentItem");
|
||||
for (iter = shipmentItems.iterator(); iter.hasNext(); ) {
|
||||
shipmentItem = iter.next();
|
||||
@@ -42,22 +45,54 @@ for (iter = shipmentItems.iterator(); iter.hasNext(); ) {
|
||||
if (shipped == null) shipped = new Double(0);
|
||||
shipped += shipmentItem.getDouble("quantity").doubleValue();
|
||||
quantityShippedByProduct.put(productId, shipped);
|
||||
quantityInShipmentByProduct.put(productId, shipped);
|
||||
}
|
||||
|
||||
// Add in the total of all previously shipped items
|
||||
previousShipmentIter = delegator.findListIteratorByCondition("Shipment",
|
||||
new EntityConditionList(
|
||||
UtilMisc.toList(
|
||||
new EntityExpr("primaryOrderId", EntityOperator.EQUALS, shipment.getString("primaryOrderId")),
|
||||
new EntityExpr("shipmentTypeId", EntityOperator.EQUALS, "SALES_SHIPMENT"),
|
||||
new EntityExpr("createdDate", EntityOperator.LESS_THAN_EQUAL_TO, shipment.getString("createdDate"))
|
||||
),
|
||||
EntityOperator.AND),
|
||||
null, null, null, null);
|
||||
|
||||
while ((previousShipmentItem = previousShipmentIter.next()) != null) {
|
||||
if (previousShipmentItem.getString("shipmentId").equals(shipment.getString("shipmentId")) == false) {
|
||||
previousShipmentItems = previousShipmentItem.getRelated("ShipmentItem");
|
||||
for (iter = previousShipmentItems.iterator(); iter.hasNext(); ) {
|
||||
shipmentItem = iter.next();
|
||||
productId = shipmentItem.get("productId");
|
||||
|
||||
shipped = quantityShippedByProduct.get(productId);
|
||||
if (shipped == null) shipped = new Double(0);
|
||||
shipped += shipmentItem.getDouble("quantity").doubleValue();
|
||||
quantityShippedByProduct.put(productId, shipped);
|
||||
}
|
||||
}
|
||||
}
|
||||
previousShipmentIter.close();
|
||||
|
||||
// next scan the order items (via issuances) to count the quantity of each product requested
|
||||
quantityRequestedByProduct = FastMap.newInstance();
|
||||
issuances = shipment.getRelated("ItemIssuance");
|
||||
countedOrderItems = FastMap.newInstance(); // this map is only used to keep track of the order items already counted
|
||||
order = shipment.getRelatedOne("PrimaryOrderHeader");
|
||||
issuances = order.getRelated("ItemIssuance");
|
||||
for (iter = issuances.iterator(); iter.hasNext(); ) {
|
||||
issuance = iter.next();
|
||||
orderItem = issuance.getRelatedOne("OrderItem");
|
||||
productId = orderItem.get("productId");
|
||||
|
||||
requested = quantityRequestedByProduct.get(productId);
|
||||
if (requested == null) requested = new Double(0);
|
||||
cancelQuantity = orderItem.getDouble("cancelQuantity");
|
||||
quantity = orderItem.getDouble("quantity");
|
||||
requested += quantity.doubleValue() - (cancelQuantity != null ? cancelQuantity.doubleValue() : 0);
|
||||
quantityRequestedByProduct.put(productId, requested);
|
||||
if (!countedOrderItems.containsKey(orderItem.getString("orderId") + orderItem.getString("orderItemSeqId"))) {
|
||||
countedOrderItems.put(orderItem.getString("orderId") + orderItem.getString("orderItemSeqId"), null);
|
||||
requested = quantityRequestedByProduct.get(productId);
|
||||
if (requested == null) requested = new Double(0);
|
||||
cancelQuantity = orderItem.getDouble("cancelQuantity");
|
||||
quantity = orderItem.getDouble("quantity");
|
||||
requested += quantity.doubleValue() - (cancelQuantity != null ? cancelQuantity.doubleValue() : 0);
|
||||
quantityRequestedByProduct.put(productId, requested);
|
||||
}
|
||||
}
|
||||
|
||||
// for each package, we want to list the quantities and details of each product
|
||||
@@ -76,6 +111,7 @@ for (iter = shipmentPackages.iterator(); iter.hasNext(); ) {
|
||||
line = FastMap.newInstance();
|
||||
line.put("product", product);
|
||||
line.put("quantityInPackage", content.get("quantity"));
|
||||
line.put("quantityInShipment", quantityInShipmentByProduct.get(product.get("productId")));
|
||||
line.put("quantityShipped", quantityShippedByProduct.get(product.get("productId")));
|
||||
line.put("quantityRequested", quantityRequestedByProduct.get(product.get("productId")));
|
||||
lines.add(line);
|
||||
|
||||
@@ -53,7 +53,7 @@ under the License.
|
||||
</fo:block>
|
||||
<fo:block><fo:leader/></fo:block>
|
||||
|
||||
<fo:block font-size="14pt">${uiLabelMap.ProductShipmentId} #${shipmentId} / Package ${package_index + 1}</fo:block>
|
||||
<fo:block font-size="14pt">${uiLabelMap.ProductShipmentId} #${shipmentId} / Package ${package_index + 1}<#if (packages?size > 1)> of ${packages?size}</#if></fo:block>
|
||||
<fo:block font-size="12pt">${uiLabelMap.ProductOrderId} #${shipment.primaryOrderId?default("N/A")} / ${shipment.primaryShipGroupSeqId?default("N/A")}</fo:block>
|
||||
<fo:block><fo:leader/></fo:block>
|
||||
|
||||
@@ -112,14 +112,22 @@ under the License.
|
||||
<fo:block space-after.optimum="10pt" font-size="10pt">
|
||||
<fo:table>
|
||||
<fo:table-column column-width="250pt"/>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
<#if (packages?size > 1)>
|
||||
<fo:table-column column-width="58pt"/>
|
||||
<fo:table-column column-width="45pt"/>
|
||||
<fo:table-column column-width="50pt"/>
|
||||
<fo:table-column column-width="47pt"/>
|
||||
<#else>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
<fo:table-column column-width="67pt"/>
|
||||
</#if>
|
||||
<fo:table-header>
|
||||
<fo:table-row font-weight="bold">
|
||||
<fo:table-cell padding="2pt" background-color="#D4D0C8"><fo:block>${uiLabelMap.ProductProduct}</fo:block></fo:table-cell>
|
||||
<fo:table-cell padding="2pt" background-color="#D4D0C8"><fo:block>Requested</fo:block></fo:table-cell>
|
||||
<fo:table-cell padding="2pt" background-color="#D4D0C8"><fo:block>In this Package</fo:block></fo:table-cell>
|
||||
<#if (packages?size > 1)><fo:table-cell padding="2pt" background-color="#D4D0C8"><fo:block>In this Shipment</fo:block></fo:table-cell></#if>
|
||||
<fo:table-cell padding="2pt" background-color="#D4D0C8"><fo:block>Total Shipped</fo:block></fo:table-cell>
|
||||
</fo:table-row>
|
||||
</fo:table-header>
|
||||
@@ -145,6 +153,11 @@ under the License.
|
||||
<fo:table-cell padding="2pt" background-color="${rowColor}">
|
||||
<fo:block>${line.quantityInPackage?default(0)}</fo:block>
|
||||
</fo:table-cell>
|
||||
<#if (packages?size > 1)>
|
||||
<fo:table-cell padding="2pt" background-color="${rowColor}">
|
||||
<fo:block>${line.quantityInShipment?default(0)}</fo:block>
|
||||
</fo:table-cell>
|
||||
</#if>
|
||||
<fo:table-cell padding="2pt" background-color="${rowColor}">
|
||||
<fo:block>${line.quantityShipped?default(0)}</fo:block>
|
||||
</fo:table-cell>
|
||||
|
||||
Reference in New Issue
Block a user