diff --git a/applications/product/webapp/facility/WEB-INF/actions/shipment/PackingSlip.bsh b/applications/product/webapp/facility/WEB-INF/actions/shipment/PackingSlip.bsh new file mode 100644 index 0000000000..e9a3bb7499 --- /dev/null +++ b/applications/product/webapp/facility/WEB-INF/actions/shipment/PackingSlip.bsh @@ -0,0 +1,85 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +// This script gets shipment items grouped by package for use in the packing slip PDF or any screens that require by-package layout + +import javolution.util.FastList; +import javolution.util.FastMap; +import org.ofbiz.base.util.UtilMisc; + +// Since this script is run after ViewShipment, we will re-use the shipment in the context +shipment = context.get("shipment"); +if (shipment == null) return; + +// get the packages related to this shipment in order of packages +orderBy = UtilMisc.toList("shipmentPackageSeqId"); +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(); +shipmentItems = shipment.getRelated("ShipmentItem"); +for (iter = shipmentItems.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); +} + +// next scan the order items (via issuances) to count the quantity of each product requested +quantityRequestedByProduct = FastMap.newInstance(); +issuances = shipment.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); +} + +// for each package, we want to list the quantities and details of each product +packages = FastList.newInstance(); // note we assume that the package number is simply the index + 1 of this list +for (iter = shipmentPackages.iterator(); iter.hasNext(); ) { + shipmentPackage = iter.next(); + contents = shipmentPackage.getRelated("ShipmentPackageContent", UtilMisc.toList("shipmentItemSeqId")); + + // each line is one logical Product and the quantities associated with it + lines = FastList.newInstance(); + for (citer = contents.iterator(); citer.hasNext(); ) { + content = citer.next(); + shipmentItem = content.getRelatedOne("ShipmentItem"); + product = shipmentItem.getRelatedOne("Product"); + + line = FastMap.newInstance(); + line.put("product", product); + line.put("quantityInPackage", content.get("quantity")); + line.put("quantityShipped", quantityShippedByProduct.get(product.get("productId"))); + line.put("quantityRequested", quantityRequestedByProduct.get(product.get("productId"))); + lines.add(line); + } + packages.add(lines); +} +context.put("packages", packages); diff --git a/applications/product/webapp/facility/shipment/PackingSlip.fo.ftl b/applications/product/webapp/facility/shipment/PackingSlip.fo.ftl index d4eda89dcf..e52d9187b1 100644 --- a/applications/product/webapp/facility/shipment/PackingSlip.fo.ftl +++ b/applications/product/webapp/facility/shipment/PackingSlip.fo.ftl @@ -31,7 +31,6 @@ under the License. <#if hasPermission> - <#assign rowColor = "white"> <#assign shipGroup = shipment.getRelatedOne("PrimaryOrderItemShipGroup")?if_exists> <#assign carrier = (shipGroup.carrierPartyId)?default("N/A")> @@ -51,7 +50,10 @@ under the License. - ${uiLabelMap.ProductShipmentId} #${shipmentId} + + <#list packages as package> + + ${uiLabelMap.ProductShipmentId} #${shipmentId} / Package ${package_index + 1} ${uiLabelMap.ProductOrderId} #${shipment.primaryOrderId?default("N/A")} / ${shipment.primaryShipGroupSeqId?default("N/A")} @@ -110,47 +112,51 @@ under the License. - - + + + ${uiLabelMap.ProductProduct} - ${uiLabelMap.ProductQuantityRequested} - ${uiLabelMap.ProductQuantityShipped} + Requested + In this Package + Total Shipped - <#list shipmentItemDatas as shipmentItem> - <#assign itemIssuances = shipmentItem.itemIssuances> - <#list itemIssuances as issue> - <#assign orderItem = issue.getRelatedOne("OrderItem")> - <#assign product = shipmentItem.product> + <#list package as line> + <#if ((line_index % 2) == 0)> + <#assign rowColor = "white"> + <#else> + <#assign rowColor = "#CCCCCC"> + + - <#if product?has_content> - ${product.internalName?default("Internal Name Not Set!")} [${product.productId}] + <#if line.product?has_content> + ${line.product.internalName?default("Internal Name Not Set!")} [${line.product.productId}] <#else/> -   + ${line.getClass().getName()}  - ${orderItem.quantity} + ${line.quantityRequested?default(0)} - ${issue.quantity} + ${line.quantityInPackage?default(0)} + + + ${line.quantityShipped?default(0)} - <#-- toggle the row color --> - <#if rowColor == "white"> - <#assign rowColor = "#CCCCCC"> - <#else> - <#assign rowColor = "white"> - - + + <#if package_has_next> + <#-- packages --> + diff --git a/applications/product/widget/facility/ShipmentScreens.xml b/applications/product/widget/facility/ShipmentScreens.xml index 9753fe548b..752c89a9dd 100644 --- a/applications/product/widget/facility/ShipmentScreens.xml +++ b/applications/product/widget/facility/ShipmentScreens.xml @@ -275,7 +275,7 @@ under the License.