You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ofbiz.apache.org by ap...@apache.org on 2007/07/03 03:15:12 UTC

svn commit: r552635 - in /ofbiz/trunk: applications/product/script/org/ofbiz/product/inventory/ applications/product/script/org/ofbiz/shipment/shipment/ applications/product/servicedef/ specialpurpose/oagis/src/org/ofbiz/oagis/

Author: apatel
Date: Mon Jul  2 18:15:06 2007
New Revision: 552635

URL: http://svn.apache.org/viewvc?view=rev&rev=552635
Log:
Minor fixes and clean up in inventory serialized reservation.

Modified:
    ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
    ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml
    ofbiz/trunk/applications/product/servicedef/services_facility.xml
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

Modified: ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml?view=diff&rev=552635&r1=552634&r2=552635
==============================================================================
--- ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml (original)
+++ ofbiz/trunk/applications/product/script/org/ofbiz/product/inventory/InventoryReserveServices.xml Mon Jul  2 18:15:06 2007
@@ -81,7 +81,7 @@
                 </else>
                 </if-compare>
                 <set field="orderByList[]" from-field="orderByString"/>
-
+                                                    
                 <set from-field="parameters.quantity" field="parameters.quantityNotReserved"/>
 
                 <!-- first reserve against InventoryItems in FLT_PICKLOC type locations, then FLT_BULK locations, then InventoryItems with no locations -->
@@ -257,31 +257,46 @@
         This way I'll get what I want and the other orderItem will also have a similar thing to issue.
         -->        
         <set field="inventoryItemLookUp.inventoryItemId" from-field="parameters.inventoryItemId"/>
-        <find-by-primary-key map-name="inventoryItemLookUp" entity-name="InventoryItem" value-name="inventoryItem"/>        
+        <find-by-primary-key map-name="inventoryItemLookUp" entity-name="InventoryItem" value-name="inventoryItem"/>                
         <set field="inventoryReservationLookUp.inventoryItemId" from-field="inventoryItem.inventoryItemId"/>
         <find-by-and map-name="inventoryReservationLookUp" list-name="invReservations" entity-name="OrderItemShipGrpInvRes"/>
         <first-from-list entry-name="inventoryItemReservation" list-name="invReservations"/>        
-        <set-service-fields map-name="inventoryItemReservation" to-map-name="cancelOrderItemShipGrpInvResMap" service-name="cancelOrderItemShipGrpInvRes"/>        
-        <set-service-fields map-name="inventoryItemReservation" to-map-name="reReserveOrderItemShipGrpInvResMap" service-name="reserveProductInventory"/>        
-        <!-- We'll get all except productId, facilityId, requireInventory fields in  inventoryItemReservation -->
+        <set-service-fields map-name="inventoryItemReservation" to-map-name="cancelOrderItemShipGrpInvResMap" service-name="cancelOrderItemShipGrpInvRes"/>
+        <!-- We'll get all except productId, facilityId, requireInventory fields in  inventoryItemReservation -->        
         <set field="reReserveOrderItemShipGrpInvResMap.facilityId" from-field="parameters.facilityId"/>
         <set field="reReserveOrderItemShipGrpInvResMap.productId" from-field="parameters.productId"/>
         <set field="reReserveOrderItemShipGrpInvResMap.requireInventory" from-field="parameters.requireInventory"/>                
         <!-- Step 1 call the cancel reservation service -->
         <call-service service-name="cancelOrderItemShipGrpInvRes" in-map-name="cancelOrderItemShipGrpInvResMap"/>
-        <!-- Step 2 call this method again and the reservation should go through -->
+        <!-- Step 2 call this method again and the reservation should go through -->        
+        <entity-and entity-name="InventoryItem" list-name="inventoryItems">
+            <field-map field-name="serialNumber" env-name="parameters.serialNumber"/>
+            <field-map field-name="productId" env-name="parameters.productId"/>
+        </entity-and>
         <set field="orderHeaderMap.orderId" from-field="parameters.orderId"/>
         <find-by-primary-key entity-name="OrderHeader" value-name="orderHeader" map-name="orderHeaderMap"/>
-        <call-simple-method method-name="reserveForInventoryItemInline"/>
+        <!-- Get the actual inventoryItem by the help of serialnumber and productId -->
+        <first-from-list list-name="inventoryItems" entry-name="inventoryItem"/>                
+        <entity-and entity-name="OrderItemShipGrpInvRes" list-name="inventoryItemReservations">
+            <field-map field-name="inventoryItemId" env-name="inventoryItem.inventoryItemId"/>            
+        </entity-and>
+        <first-from-list list-name="inventoryItemReservations" entry-name="inventoryItemReservation"/>
+        <if-not-empty field-name="inventoryItemReservation">
+            <set-service-fields map-name="inventoryItemReservation" to-map-name="reReserveOrderItemShipGrpInvResMap" service-name="reserveProductInventory"/>
+            <call-service service-name="reserveProductInventory" in-map-name="reReserveOrderItemShipGrpInvResMap">        
+                <result-to-field result-name="quantityNotReserved" field-name="paramaters.quantityNotReserved"/>
+            </call-service>
+            <set value="INV_AVAILABLE" field="inventoryItem.statusId"/>
+            <store-value value-name="inventoryItem"/>
+        </if-not-empty>
         <!-- Step 3 Now last thing, lets reReserve inventory for order form where we got our item. Be curtious -->
-        <call-service service-name="reserveProductInventory" in-map-name="reReserveOrderItemShipGrpInvResMap">        
-            <result-to-field result-name="quantityNotReserved" field-name="paramaters.quantityNotReserved"/>
-        </call-service>
+        <call-simple-method method-name="reserveForInventoryItemInline"/>
         <field-to-result field-name="quantityNotReserved" map-name="parameters"/>
+        <field-to-result field-name="inventoryItemId" map-name="inventoryItem"/>
     </simple-method>
     
     <simple-method method-name="reserveForInventoryItemInline" short-description="Does a reservation for one InventoryItem, meant to be called in-line">
-        <!-- only do something with this inventoryItem if there is more inventory to reserve -->
+        <!-- only do something with this inventoryItem if there is more inventory to reserve -->  
         <if-compare field-name="parameters.quantityNotReserved" operator="greater" value="0" type="Double">
             <!-- get the promiseDatetime -->
             <get-related-one value-name="inventoryItem" relation-name="ProductFacility" to-value-name="productFacility"/>

Modified: ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml?view=diff&rev=552635&r1=552634&r2=552635
==============================================================================
--- ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml (original)
+++ ofbiz/trunk/applications/product/script/org/ofbiz/shipment/shipment/ShipmentServices.xml Mon Jul  2 18:15:06 2007
@@ -853,19 +853,18 @@
         </check-permission>
         <set value="Create ShipmentPackageContent" field="operationName"/>
         <call-simple-method method-name="checkCanChangeShipmentStatusPacked"/>
-        <check-errors/>
-
+        <check-errors/>        
         <make-value value-name="newEntity" entity-name="ShipmentPackageContent"/>
         <set-pk-fields map-name="parameters" value-name="newEntity"/>
         <find-by-primary-key value-name="shipmentPackageContent" map-name="newEntity"/>
         <log level="verbose" message="In addShipmentContentToPackage trying values: ${newEntity}"/>
-        <if-empty field-name="shipmentPackageContent">
+        <if-empty field-name="shipmentPackageContent">            
             <set-service-fields service-name="createShipmentPackageContent" map-name="parameters" to-map-name="createSPCMap"/>
             <call-service service-name="createShipmentPackageContent" in-map-name="createSPCMap">
                 <result-to-field result-name="shipmentPackageSeqId" field-name="newEntity.shipmentPackageSeqId"/>
             </call-service>
         <else>
-            <!-- add the quantities and store it -->
+            <!-- add the quantities and store it -->            
             <calculate field-name="shipmentPackageContent.quantity" type="Double">
                 <calcop field-name="shipmentPackageContent.quantity" operator="add"><calcop field-name="parameters.quantity" operator="get"/></calcop>
             </calculate>
@@ -1394,12 +1393,14 @@
         <make-value entity-name="OrderItemShipGrpInvRes" value-name="orderItemShipGrpInvResLookupPk"/>                
         <set-pk-fields value-name="orderItemShipGrpInvResLookupPk" map-name="parameters"/>
         <find-by-primary-key entity-name="OrderItemShipGrpInvRes" map-name="orderItemShipGrpInvResLookupPk" value-name="orderItemShipGrpInvRes"/>       
-        <get-related-one to-value-name="inventoryItem" relation-name="InventoryItem" value-name="orderItemShipGrpInvRes"/>
+        <get-related-one to-value-name="inventoryItem" relation-name="InventoryItem" value-name="orderItemShipGrpInvRes"/>        
         <if-compare-field operator="not-equals" field-name="inventoryItem.serialNumber" to-field-name="parameters.serialNumber">            
             <!-- The inventory that we have reserved is not what we shipped. Lets reReserve, this time we'll get what we want -->
             <set-service-fields map-name="parameters" to-map-name="reserveAnInventoryItemCtx" service-name="reserveAnInventoryItem"/>
-            <call-service service-name="reserveAnInventoryItem" in-map-name="reserveAnInventoryItemCtx"/>
-        </if-compare-field>
+            <call-service service-name="reserveAnInventoryItem" in-map-name="reserveAnInventoryItemCtx">
+                <result-to-field result-name="inventoryItemId" field-name="parameters.inventoryItemId"/>
+            </call-service>
+        </if-compare-field>        
         <!-- get InventoryItem issued to shipment -->        
         <clear-field field-name="issueContext"/>
         <set from-field="parameters.shipmentId" field="issueContext.shipmentId"/>
@@ -1409,7 +1410,6 @@
         <set from-field="parameters.orderItemSeqId" field="issueContext.orderItemSeqId"/>
         <set from-field="parameters.inventoryItemId" field="issueContext.inventoryItemId"/>
         <set from-field="parameters.quantity" field="issueContext.quantity"/>
-        <log level="info" message="========issueContext===========${issueContext}====================="/>
         <call-service service-name="issueOrderItemShipGrpInvResToShipment" in-map-name="issueContext">
             <result-to-field result-name="itemIssuanceId" field-name="parameters.itemIssuanceId"/>
         </call-service>
@@ -1418,14 +1418,17 @@
         <entity-one entity-name="ItemIssuance" value-name="itemIssuance">
             <field-map field-name="itemIssuanceId" env-name="parameters.itemIssuanceId"/>
         </entity-one>
-
         <clear-field field-name="shipItemContext"/>
-        <set from-field="packageMap.${itemMap.trackingNum}" field="shipItemContext.shipmentPackageSeqId"/>
+        <set from-field="parameters.trackingNum" field="shipItemContext.shipmentPackageSeqId"/>
         <if-empty field-name="shipItemContext.shipmentPackageSeqId">
             <set value="New" field="shipItemContext.shipmentPackageSeqId"/>
         </if-empty>
         <log level="info" message="Package SeqID : ${shipItemContext.shipmentPackageSeqId}"/>
-
+        
+        <set from-field="itemIssuance.shipmentId" field="shipPackageContext.shipmentId"/>
+        <set from-field="shipItemContext.shipmentPackageSeqId" field="shipPackageContext.shipmentPackageSeqId"/>
+        <call-service service-name="createShipmentPackage" in-map-name="shipPackageContext"/>
+        
         <set from-field="itemIssuance.shipmentId" field="shipItemContext.shipmentId"/>
         <set from-field="itemIssuance.shipmentItemSeqId" field="shipItemContext.shipmentItemSeqId"/>
         <set from-field="itemIssuance.quantity" field="shipItemContext.quantity"/>
@@ -1433,7 +1436,7 @@
             <result-to-field result-name="shipmentPackageSeqId" field-name="packageMap.${parameters.trackingNum}"/>
             <result-to-field result-name="shipmentPackageSeqId" map-name="routeSegLookup"/>
         </call-service>
-
+        
         <if-not-empty field-name="shipmentPackageSeqId" map-name="routeSegLookup">
             <set from-field="itemIssuance.shipmentId" field="routeSegLookup.shipmentId"/>
             <!-- quick ship orders should only have one route segment -->

Modified: ofbiz/trunk/applications/product/servicedef/services_facility.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/servicedef/services_facility.xml?view=diff&rev=552635&r1=552634&r2=552635
==============================================================================
--- ofbiz/trunk/applications/product/servicedef/services_facility.xml (original)
+++ ofbiz/trunk/applications/product/servicedef/services_facility.xml Mon Jul  2 18:15:06 2007
@@ -233,7 +233,7 @@
     <service name="reserveAnInventoryItem" engine="simple"
             location="org/ofbiz/product/inventory/InventoryReserveServices.xml" invoke="reserveAnInventoryItem" auth="true">
         <description></description>
-        <attribute name="inventoryItemId" type="String" mode="IN" optional="false"/>
+        <attribute name="inventoryItemId" type="String" mode="INOUT" optional="false"/>
         <attribute name="productId" type="String" mode="IN" optional="false"/>
         <attribute name="orderId" type="String" mode="IN" optional="false"/>
         <attribute name="orderItemSeqId" type="String" mode="IN" optional="false"/>
@@ -242,6 +242,7 @@
         <attribute name="reservedDatetime" type="Timestamp" mode="IN" optional="true"/>
         <attribute name="requireInventory" type="String" mode="IN" optional="false"/>
         <attribute name="reserveOrderEnumId" type="String" mode="IN" optional="false"/>
+        <attribute name="serialNumber" type="String" mode="IN" optional="true"/>        
         <attribute name="sequenceId" type="Long" mode="IN" optional="true"/>
         <attribute name="quantityNotReserved" type="Double" mode="INOUT" optional="false"/>
     </service>

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java?view=diff&rev=552635&r1=552634&r2=552635
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Mon Jul  2 18:15:06 2007
@@ -1,450 +1,450 @@
-package org.ofbiz.oagis;
-
-/**
-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.
-**/
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.sql.Timestamp;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeSet;
-
-import javolution.util.FastList;
-
-import org.ofbiz.base.util.Debug;
-import org.ofbiz.base.util.UtilDateTime;
-import org.ofbiz.base.util.UtilMisc;
-import org.ofbiz.base.util.UtilProperties;
-import org.ofbiz.base.util.UtilXml;
-import org.ofbiz.base.util.collections.MapStack;
-import org.ofbiz.entity.GenericDelegator;
-import org.ofbiz.entity.GenericEntityException;
-import org.ofbiz.entity.GenericValue;
-import org.ofbiz.entity.condition.EntityCondition;
-import org.ofbiz.entity.condition.EntityConditionList;
-import org.ofbiz.entity.condition.EntityExpr;
-import org.ofbiz.entity.condition.EntityOperator;
-import org.ofbiz.entity.util.EntityUtil;
-import org.ofbiz.order.order.OrderReadHelper;
-import org.ofbiz.service.DispatchContext;
-import org.ofbiz.service.GenericServiceException;
-import org.ofbiz.service.LocalDispatcher;
-import org.ofbiz.service.ModelService;
-import org.ofbiz.service.ServiceUtil;
-import org.ofbiz.widget.fo.FoFormRenderer;
-import org.ofbiz.widget.html.HtmlScreenRenderer;
-import org.ofbiz.widget.screen.ScreenRenderer;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-
-public class OagisShipmentServices {
-    
-    public static final String module = OagisShipmentServices.class.getName();
-
-    protected static final HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer();
-    protected static final FoFormRenderer foFormRenderer = new FoFormRenderer();
-    
-    public static final String resource = "OagisUiLabels";
-    
-    public static Map showShipment(DispatchContext ctx, Map context) {
-        InputStream in = (InputStream) context.get("inputStream");
-        LocalDispatcher dispatcher = ctx.getDispatcher();
-        GenericDelegator delegator = ctx.getDelegator();
-        Map result = new HashMap();
-        List errorList = new LinkedList();
-        try {
-            Document doc = UtilXml.readXmlDocument(in, true, "ShowShipment");
-            GenericValue userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));            
-            Element showShipmentElement = doc.getDocumentElement();
-            showShipmentElement.normalize();
-            
-            Element controlAreaElement = UtilXml.firstChildElement(showShipmentElement, "N1:CNTROLAREA");
-            Element bsrElement = UtilXml.firstChildElement(controlAreaElement, "N1:BSR");
-            String bsrVerb = UtilXml.childElementValue(bsrElement, "N2:VERB");
-            String bsrNoun = UtilXml.childElementValue(bsrElement, "N2:NOUN");
-            String bsrRevision = UtilXml.childElementValue(bsrElement, "N2:REVISION");
-            
-            result.put("bsrVerb", bsrVerb);
-            result.put("bsrNoun", bsrNoun);
-            result.put("bsrRevision", bsrRevision);
-            
-            Element senderElement = UtilXml.firstChildElement(controlAreaElement, "N1:SENDER");
-            String logicalId = UtilXml.childElementValue(senderElement, "N2:LOGICALID");
-            String component = UtilXml.childElementValue(senderElement, "N2:COMPONENT");
-            String task = UtilXml.childElementValue(senderElement, "N2:TASK");
-            String referenceId = UtilXml.childElementValue(senderElement, "N2:REFERENCEID");
-            String confirmation = UtilXml.childElementValue(senderElement, "N2:CONFIRMATION");
-            String authId = UtilXml.childElementValue(senderElement, "N2:AUTHID");
-            
-            result.put("logicalId", logicalId);
-            result.put("component", component);
-            result.put("task", task);
-            result.put("referenceId", referenceId);
-            result.put("confirmation", confirmation);
-            result.put("authId", authId);
-            result.put("outgoingMessage", "N");
-            result.put("userLogin", userLogin);
-            
-            Element dataAreaElement = UtilXml.firstChildElement(showShipmentElement, "n:DATAAREA");
-            Element daShowShipmentElement = UtilXml.firstChildElement(dataAreaElement, "n:SHOW_SHIPMENT");
-            Element shipmentElement = UtilXml.firstChildElement(daShowShipmentElement, "n:SHIPMENT");                                  
-            String shipmentId = UtilXml.childElementValue(shipmentElement, "N2:DOCUMENTID");            
-           
-            Element shipUnitElement = UtilXml.firstChildElement(showShipmentElement, "n:SHIPUNIT");                                   
-            String trackingNum = UtilXml.childElementValue(shipUnitElement, "N2:TRACKINGID");            
-            
-            Element invItem = UtilXml.firstChildElement(shipUnitElement, "n:INVITEM");            
-            String productId = UtilXml.childElementValue(invItem, "N2:ITEM");
-            
-            Element invDetail = UtilXml.firstChildElement(invItem, "n:INVDETAIL");
-            String serialNumber = UtilXml.childElementValue(invDetail,"N1:SERIALNUM");
-            try {                
-                GenericValue shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
-                String shipGroupSeqId = shipment.getString("primaryShipGroupSeqId");                
-                String originFacilityId = shipment.getString("originFacilityId");                              
-                GenericValue shipmentItem = EntityUtil.getFirst(delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId, "productId",productId)));                
-                String shipmentItemSeqId = shipmentItem.getString("shipmentItemSeqId");                
-                GenericValue orderShipment = EntityUtil.getFirst(delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItemSeqId)));                
-                String orderId = orderShipment.getString("orderId");                
-                String orderItemSeqId = orderShipment.getString("orderItemSeqId");                
-                GenericValue product = delegator.findByPrimaryKey("Product",UtilMisc.toMap("productId",productId)); 
-                String requireInventory = product.getString("requireInventory");
-                if(requireInventory == null) {
-                    requireInventory = "N";
-                }                
-                GenericValue orderItemShipGrpInvReservation = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId,"shipGroupSeqId",shipGroupSeqId)));               
-                Map isitspastCtx = UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", shipGroupSeqId, "orderItemSeqId", orderItemSeqId, "quantity", shipmentItem.get("quantity"), "quantityNotReserved", shipmentItem.get("quantity"));                
-                isitspastCtx.put("productId", productId);
-                isitspastCtx.put("reservedDatetime", orderItemShipGrpInvReservation.get("reservedDatetime"));
-                isitspastCtx.put("requireInventory", requireInventory);
-                isitspastCtx.put("reserveOrderEnumId", orderItemShipGrpInvReservation.get("reserveOrderEnumId"));
-                isitspastCtx.put("sequenceId", orderItemShipGrpInvReservation.get("sequenceId"));
-                isitspastCtx.put("originFacilityId", originFacilityId);
-                isitspastCtx.put("userLogin", userLogin);
-                isitspastCtx.put("serialNumber", serialNumber);
-                isitspastCtx.put("trackingNum", trackingNum);
-                isitspastCtx.put("inventoryItemId", orderItemShipGrpInvReservation.get("inventoryItemId"));                
-                isitspastCtx.put("shipmentId", shipmentId);      
-                try {                    
-                    dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx);                                      
-                } catch(GenericServiceException e) {
-                    Debug.logInfo(e, module);
-                    errorList.add(e.getMessage());
-                }
-            } catch (GenericEntityException e) {
-                Debug.logInfo(e, module);
-                errorList.add(e.getMessage());
-            }
-        } catch (Exception e) {
-            Debug.logError(e, module);
-            errorList.add(e.getMessage());
-        }
-        result.put("contentType","text/plain");
-        if (errorList.size() > 0) {
-            // error message generation
-            result.put(ModelService.RESPONSE_MESSAGE,ModelService.RESPOND_ERROR); 
-            result.put(ModelService.ERROR_MESSAGE_LIST, errorList);
-            result.put("reasonCode", "1000"); 
-            result.put("description", "processing message failed");
-            return result;
-        }
-        return result;
-    }
-
-    public static Map processShipment(DispatchContext ctx, Map context) {
-        LocalDispatcher dispatcher = ctx.getDispatcher();
-        GenericDelegator delegator = ctx.getDelegator();
-        String orderId = (String) context.get("orderId");
-        String shipmentId = (String) context.get("shipmentId");
-        GenericValue userLogin = (GenericValue) context.get("userLogin");
-        Map result = ServiceUtil.returnSuccess();
-        MapStack bodyParameters =  MapStack.create();
-        if (userLogin == null) {
-            try {
-                userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));
-            } catch (GenericEntityException e) {
-                Debug.logError(e, "Error getting userLogin", module);
-            }
-        }
-        GenericValue orderHeader = null;
-        GenericValue orderItemShipGroup = null;
-        try {
-            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
-        } catch (GenericEntityException e) {
-            Debug.logError(e, module);
-            return ServiceUtil.returnError(e.getMessage());
-        }
-        GenericValue shipment =null;
-        if (orderHeader != null) {
-            String orderStatusId = orderHeader.getString("statusId");
-            if (orderStatusId.equals("ORDER_APPROVED")) {
-                try {
-                    Map  cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
-                    shipmentId = (String) cospResult.get("shipmentId");
-                } catch (GenericServiceException e) {
-                    Debug.logError(e, module);
-                    return ServiceUtil.returnError(e.getMessage());
-                }
-                try {
-                    shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
-                    bodyParameters.put("shipment", shipment);
-                    OrderReadHelper orderReadHelper = new OrderReadHelper(orderHeader);
-                    if(orderReadHelper.hasShippingAddress()) {
-                        GenericValue  address = EntityUtil.getFirst(orderReadHelper.getShippingLocations());
-                        bodyParameters.put("address", address);
-                    }
-                    String emailString = orderReadHelper.getOrderEmailString();
-                    bodyParameters.put("emailString", emailString);
-
-                    String contactMechId = shipment.getString("destinationTelecomNumberId");
-                    GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
-                    bodyParameters.put("telecomNumber", telecomNumber);
-
-                    List shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId));
-                    bodyParameters.put("shipmentItems", shipmentItems);
-                    
-                    orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)));
-                    bodyParameters.put("orderItemShipGroup", orderItemShipGroup);
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                Set correspondingPoIdSet = new TreeSet();
-                try {
-                    List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
-                    Iterator oiIter = orderItems.iterator();
-                    while (oiIter.hasNext()) {
-                        GenericValue orderItem = (GenericValue) oiIter.next();
-                        String correspondingPoId = orderItem.getString("correspondingPoId");
-                        correspondingPoIdSet.add(correspondingPoId);
-                        bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
-                    }
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                Set externalIdSet = new TreeSet();
-                try {
-                    GenericValue primaryOrderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
-                    externalIdSet.add(primaryOrderHeader.getString("externalId"));
-                    bodyParameters.put("externalIdSet", externalIdSet);
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                // if order was a return replacement order (associated with return)
-                List returnItemResponses =  null;
-                List returnItemRespExprs = UtilMisc.toList(new EntityExpr("replacementOrderId", EntityOperator.NOT_EQUAL, null));
-                EntityCondition returnItemRespCond = new EntityConditionList(returnItemRespExprs, EntityOperator.AND);
-                // list of fields to select (initial list)
-                List fieldsToSelect = FastList.newInstance();
-                fieldsToSelect.add("replacementOrderId");
-                try {
-                    returnItemResponses = delegator.findByCondition("ReturnItemResponse", returnItemRespCond, fieldsToSelect, null);
-                    Iterator rirIter = returnItemResponses.iterator();
-                    while (rirIter.hasNext()) {
-                        if (rirIter.next().equals(shipment.getString("primaryOrderId"))) {
-                            bodyParameters.put("shipnotes", "RETURNLABEL");
-                        }
-                    }
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
-                bodyParameters.put("logicalId", logicalId);
-                result.put("logicalId", logicalId);
-                
-                String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
-                bodyParameters.put("authId", authId);
-                result.put("authId", authId);
-
-                String referenceId = delegator.getNextSeqId("OagisMessageInfo");
-                bodyParameters.put("referenceId", referenceId);
-                result.put("referenceId", referenceId);
-                    
-                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
-                Timestamp timestamp = UtilDateTime.nowTimestamp();
-                String sentDate = dateFormat.format(timestamp);
-                bodyParameters.put("sentDate", sentDate);
-                result.put("sentDate", timestamp);
-               
-                // tracking shipper account
-                String partyId = shipment.getString("partyIdTo");
-                List partyCarrierAccounts = new ArrayList();
-                try {
-                    partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId));
-                    partyCarrierAccounts = EntityUtil.filterByDate(partyCarrierAccounts);
-                    if (partyCarrierAccounts != null) {
-                        Iterator pcaIter = partyCarrierAccounts.iterator();
-                        while (pcaIter.hasNext()) {
-                            GenericValue partyCarrierAccount = (GenericValue) pcaIter.next();
-                            String carrierPartyId = partyCarrierAccount.getString("carrierPartyId");
-                            if (carrierPartyId.equals(orderItemShipGroup.getString("carrierPartyId"))) {
-                                String accountNumber = partyCarrierAccount.getString("accountNumber");
-                                bodyParameters.put("shipperId", accountNumber);
-                            }
-                        }
-                    }
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                bodyParameters.put("shipmentId", shipmentId);
-                bodyParameters.put("orderId", orderId);
-                bodyParameters.put("userLogin", userLogin);
-                String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment");
-                OutputStream out = (OutputStream) context.get("outputStream");
-                Writer writer = new OutputStreamWriter(out);
-                ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
-                try {
-                    screens.render(bodyScreenUri);
-                } catch (Exception e) {
-                      Debug.logError(e, "Error rendering [text/xml]: ", module);
-                }
-                // prepare map to Create Oagis Message Info
-                result.put("component", "INVENTORY");
-                result.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char
-                result.put("outgoingMessage", "Y");
-                result.put("confirmation", "1");
-                result.put("bsrVerb", "PROCESS");
-                result.put("bsrNoun", "SHIPMENT");
-                result.put("bsrRevision", "001");
-                result.put("processingStatusId", orderStatusId);
-                result.put("orderId", orderId);
-                result.put("shipmentId", shipmentId);
-                result.put("userLogin", userLogin);
-            }
-        }
-        return result;
-    }
-    
-    public static Map receiveDelivery(DispatchContext dctx, Map context) {
-        GenericDelegator delegator = dctx.getDelegator();
-        String returnId = (String) context.get("returnId");
-        GenericValue userLogin = (GenericValue) context.get("userLogin");
-        Map result = ServiceUtil.returnSuccess();
-        MapStack bodyParameters =  MapStack.create();
-        if (userLogin == null) {
-            try {
-                userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));
-            } catch (GenericEntityException e) {
-                Debug.logError(e, "Error getting userLogin", module);
-            }
-        }
-        if (returnId != null) {
-            GenericValue returnHeader = null;
-            String statusId =null;
-            try {
-                returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId));
-                statusId = returnHeader.getString("statusId");
-            } catch (GenericEntityException e) {
-                Debug.logError(e, module);
-            }
-            if (statusId.equals("RETURN_ACCEPTED")) {
-                try {
-                    List returnItems = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnId", returnId));
-                    bodyParameters.put("returnItems", returnItems);
-                    
-                    String orderId = EntityUtil.getFirst(returnItems).getString("orderId");
-                    result.put("orderId", orderId);
-                    
-                    GenericValue postalAddress = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", returnHeader.getString("originContactMechId")));
-                    bodyParameters.put("postalAddress", postalAddress);
-       
-                    // calculate total qty of return items in a shipping unit received, order associated with return
-                    double itemQty = 0.0;
-                    double totalQty = 0.0;
-                    Iterator riIter = returnItems.iterator();
-                    while (riIter.hasNext()) {
-                        GenericValue returnItem = (GenericValue) riIter.next();
-                        itemQty = returnItem.getDouble("returnQuantity").doubleValue();
-                        totalQty = totalQty + itemQty;
-                    }
-                    bodyParameters.put("totalQty", new Double(totalQty));
-                    
-                    String partyId = returnHeader.getString("fromPartyId");
-                    List partyContactMechs = delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId));
-                    Iterator pcmIter = partyContactMechs.iterator();
-                    while (pcmIter.hasNext()) {
-                        GenericValue partyContactMech = (GenericValue) pcmIter.next();
-                        String contactMechId = partyContactMech.getString("contactMechId");
-                        GenericValue contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
-                        String contactMechTypeId = contactMech.getString("contactMechTypeId");
-                        if(contactMechTypeId.equals("EMAIL_ADDRESS")) {
-                           String emailString = contactMech.getString("infoString");
-                           bodyParameters.put("emailString", emailString);
-                        }
-                        if(contactMechTypeId.equals("TELECOM_NUMBER")) {
-                           GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
-                           bodyParameters.put("telecomNumber", telecomNumber);
-                        }
-                    }
-                } catch (GenericEntityException e) {
-                    Debug.logError(e, module);
-                }
-                String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
-                bodyParameters.put("logicalId", logicalId);
-                result.put("logicalId", logicalId);
-                
-                String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
-                bodyParameters.put("authId", authId);
-                result.put("authId", authId);
-                
-                String referenceId = delegator.getNextSeqId("OagisMessageInfo");
-                bodyParameters.put("referenceId", referenceId);
-                result.put("referenceId", referenceId);
-                
-                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
-                Timestamp timestamp = UtilDateTime.nowTimestamp();
-                String sentDate = dateFormat.format(timestamp);
-                bodyParameters.put("sentDate", sentDate);
-                result.put("sentDate", timestamp);
-                
-                bodyParameters.put("returnId", returnId);
-                String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ReceiveDelivery");
-                OutputStream out = (OutputStream) context.get("outputStream");
-                Writer writer = new OutputStreamWriter(out);
-                ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
-                try {
-                    screens.render(bodyScreenUri);
-                } catch (Exception e) {
-                      Debug.logError(e, "Error rendering [text/xml]: ", module);
-                }
-                // prepare map to store BOD information
-                result.put("component", "INVENTORY");
-                result.put("task", "RMA");  
-                result.put("outgoingMessage", "Y");
-                result.put("confirmation", "1");
-                result.put("bsrVerb", "RECEIVE");
-                result.put("bsrNoun", "DELIVERY");
-                result.put("bsrRevision", "001");
-                result.put("processingStatusId", statusId);        
-                result.put("returnId", returnId);
-                result.put("userLogin", userLogin);
-            }
-        }    
-        return result;
-    }
-}
+package org.ofbiz.oagis;
+
+/**
+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.
+**/
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.sql.Timestamp;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeSet;
+
+import javolution.util.FastList;
+
+import org.ofbiz.base.util.Debug;
+import org.ofbiz.base.util.UtilDateTime;
+import org.ofbiz.base.util.UtilMisc;
+import org.ofbiz.base.util.UtilProperties;
+import org.ofbiz.base.util.UtilXml;
+import org.ofbiz.base.util.collections.MapStack;
+import org.ofbiz.entity.GenericDelegator;
+import org.ofbiz.entity.GenericEntityException;
+import org.ofbiz.entity.GenericValue;
+import org.ofbiz.entity.condition.EntityCondition;
+import org.ofbiz.entity.condition.EntityConditionList;
+import org.ofbiz.entity.condition.EntityExpr;
+import org.ofbiz.entity.condition.EntityOperator;
+import org.ofbiz.entity.util.EntityUtil;
+import org.ofbiz.order.order.OrderReadHelper;
+import org.ofbiz.service.DispatchContext;
+import org.ofbiz.service.GenericServiceException;
+import org.ofbiz.service.LocalDispatcher;
+import org.ofbiz.service.ModelService;
+import org.ofbiz.service.ServiceUtil;
+import org.ofbiz.widget.fo.FoFormRenderer;
+import org.ofbiz.widget.html.HtmlScreenRenderer;
+import org.ofbiz.widget.screen.ScreenRenderer;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+
+public class OagisShipmentServices {
+    
+    public static final String module = OagisShipmentServices.class.getName();
+
+    protected static final HtmlScreenRenderer htmlScreenRenderer = new HtmlScreenRenderer();
+    protected static final FoFormRenderer foFormRenderer = new FoFormRenderer();
+    
+    public static final String resource = "OagisUiLabels";
+    
+    public static Map showShipment(DispatchContext ctx, Map context) {
+        InputStream in = (InputStream) context.get("inputStream");
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        GenericDelegator delegator = ctx.getDelegator();
+        Map result = new HashMap();
+        List errorList = new LinkedList();
+        try {
+            Document doc = UtilXml.readXmlDocument(in, true, "ShowShipment");
+            GenericValue userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));            
+            Element showShipmentElement = doc.getDocumentElement();
+            showShipmentElement.normalize();
+            
+            Element controlAreaElement = UtilXml.firstChildElement(showShipmentElement, "N1:CNTROLAREA");
+            Element bsrElement = UtilXml.firstChildElement(controlAreaElement, "N1:BSR");
+            String bsrVerb = UtilXml.childElementValue(bsrElement, "N2:VERB");
+            String bsrNoun = UtilXml.childElementValue(bsrElement, "N2:NOUN");
+            String bsrRevision = UtilXml.childElementValue(bsrElement, "N2:REVISION");
+            
+            result.put("bsrVerb", bsrVerb);
+            result.put("bsrNoun", bsrNoun);
+            result.put("bsrRevision", bsrRevision);
+            
+            Element senderElement = UtilXml.firstChildElement(controlAreaElement, "N1:SENDER");
+            String logicalId = UtilXml.childElementValue(senderElement, "N2:LOGICALID");
+            String component = UtilXml.childElementValue(senderElement, "N2:COMPONENT");
+            String task = UtilXml.childElementValue(senderElement, "N2:TASK");
+            String referenceId = UtilXml.childElementValue(senderElement, "N2:REFERENCEID");
+            String confirmation = UtilXml.childElementValue(senderElement, "N2:CONFIRMATION");
+            String authId = UtilXml.childElementValue(senderElement, "N2:AUTHID");
+            
+            result.put("logicalId", logicalId);
+            result.put("component", component);
+            result.put("task", task);
+            result.put("referenceId", referenceId);
+            result.put("confirmation", confirmation);
+            result.put("authId", authId);
+            result.put("outgoingMessage", "N");
+            result.put("userLogin", userLogin);
+            
+            Element dataAreaElement = UtilXml.firstChildElement(showShipmentElement, "n:DATAAREA");
+            Element daShowShipmentElement = UtilXml.firstChildElement(dataAreaElement, "n:SHOW_SHIPMENT");
+            Element shipmentElement = UtilXml.firstChildElement(daShowShipmentElement, "n:SHIPMENT");                                  
+            String shipmentId = UtilXml.childElementValue(shipmentElement, "N2:DOCUMENTID");            
+           
+            Element shipUnitElement = UtilXml.firstChildElement(daShowShipmentElement, "n:SHIPUNIT");
+            String trackingNum = UtilXml.childElementValue(shipUnitElement, "N2:TRACKINGID");            
+            
+            Element invItem = UtilXml.firstChildElement(shipUnitElement, "n:INVITEM");            
+            String productId = UtilXml.childElementValue(invItem, "N2:ITEM");
+            
+            Element invDetail = UtilXml.firstChildElement(invItem, "n:INVDETAIL");
+            String serialNumber = UtilXml.childElementValue(invDetail,"N1:SERIALNUM");
+            try {                
+                GenericValue shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
+                String shipGroupSeqId = shipment.getString("primaryShipGroupSeqId");                
+                String originFacilityId = shipment.getString("originFacilityId");                              
+                GenericValue shipmentItem = EntityUtil.getFirst(delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId, "productId",productId)));                
+                String shipmentItemSeqId = shipmentItem.getString("shipmentItemSeqId");                
+                GenericValue orderShipment = EntityUtil.getFirst(delegator.findByAnd("OrderShipment", UtilMisc.toMap("shipmentId", shipmentId, "shipmentItemSeqId", shipmentItemSeqId)));                
+                String orderId = orderShipment.getString("orderId");                
+                String orderItemSeqId = orderShipment.getString("orderItemSeqId");                
+                GenericValue product = delegator.findByPrimaryKey("Product",UtilMisc.toMap("productId",productId)); 
+                String requireInventory = product.getString("requireInventory");
+                if(requireInventory == null) {
+                    requireInventory = "N";
+                }                
+                GenericValue orderItemShipGrpInvReservation = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId,"shipGroupSeqId",shipGroupSeqId)));               
+                Map isitspastCtx = UtilMisc.toMap("orderId", orderId, "shipGroupSeqId", shipGroupSeqId, "orderItemSeqId", orderItemSeqId, "quantity", shipmentItem.get("quantity"), "quantityNotReserved", shipmentItem.get("quantity"));                
+                isitspastCtx.put("productId", productId);
+                isitspastCtx.put("reservedDatetime", orderItemShipGrpInvReservation.get("reservedDatetime"));
+                isitspastCtx.put("requireInventory", requireInventory);
+                isitspastCtx.put("reserveOrderEnumId", orderItemShipGrpInvReservation.get("reserveOrderEnumId"));
+                isitspastCtx.put("sequenceId", orderItemShipGrpInvReservation.get("sequenceId"));
+                isitspastCtx.put("originFacilityId", originFacilityId);
+                isitspastCtx.put("userLogin", userLogin);
+                isitspastCtx.put("serialNumber", serialNumber);
+                isitspastCtx.put("trackingNum", trackingNum);
+                isitspastCtx.put("inventoryItemId", orderItemShipGrpInvReservation.get("inventoryItemId"));                
+                isitspastCtx.put("shipmentId", shipmentId);      
+                try {                    
+                    dispatcher.runSync("issueSerializedInvToShipmentPackageAndSetTracking", isitspastCtx);                                      
+                } catch(GenericServiceException e) {
+                    Debug.logInfo(e, module);
+                    errorList.add(e.getMessage());
+                }
+            } catch (GenericEntityException e) {
+                Debug.logInfo(e, module);
+                errorList.add(e.getMessage());
+            }
+        } catch (Exception e) {
+            Debug.logError(e, module);
+            errorList.add(e.getMessage());
+        }
+        result.put("contentType","text/plain");
+        if (errorList.size() > 0) {
+            // error message generation
+            result.put(ModelService.RESPONSE_MESSAGE,ModelService.RESPOND_ERROR); 
+            result.put(ModelService.ERROR_MESSAGE_LIST, errorList);
+            result.put("reasonCode", "1000"); 
+            result.put("description", "processing message failed");
+            return result;
+        }
+        return result;
+    }
+
+    public static Map processShipment(DispatchContext ctx, Map context) {
+        LocalDispatcher dispatcher = ctx.getDispatcher();
+        GenericDelegator delegator = ctx.getDelegator();
+        String orderId = (String) context.get("orderId");
+        String shipmentId = (String) context.get("shipmentId");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Map result = ServiceUtil.returnSuccess();
+        MapStack bodyParameters =  MapStack.create();
+        if (userLogin == null) {
+            try {
+                userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "Error getting userLogin", module);
+            }
+        }
+        GenericValue orderHeader = null;
+        GenericValue orderItemShipGroup = null;
+        try {
+            orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));
+        } catch (GenericEntityException e) {
+            Debug.logError(e, module);
+            return ServiceUtil.returnError(e.getMessage());
+        }
+        GenericValue shipment =null;
+        if (orderHeader != null) {
+            String orderStatusId = orderHeader.getString("statusId");
+            if (orderStatusId.equals("ORDER_APPROVED")) {
+                try {
+                    Map  cospResult= dispatcher.runSync("createOrderShipmentPlan", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));
+                    shipmentId = (String) cospResult.get("shipmentId");
+                } catch (GenericServiceException e) {
+                    Debug.logError(e, module);
+                    return ServiceUtil.returnError(e.getMessage());
+                }
+                try {
+                    shipment = delegator.findByPrimaryKey("Shipment", UtilMisc.toMap("shipmentId", shipmentId));
+                    bodyParameters.put("shipment", shipment);
+                    OrderReadHelper orderReadHelper = new OrderReadHelper(orderHeader);
+                    if(orderReadHelper.hasShippingAddress()) {
+                        GenericValue  address = EntityUtil.getFirst(orderReadHelper.getShippingLocations());
+                        bodyParameters.put("address", address);
+                    }
+                    String emailString = orderReadHelper.getOrderEmailString();
+                    bodyParameters.put("emailString", emailString);
+
+                    String contactMechId = shipment.getString("destinationTelecomNumberId");
+                    GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
+                    bodyParameters.put("telecomNumber", telecomNumber);
+
+                    List shipmentItems = delegator.findByAnd("ShipmentItem", UtilMisc.toMap("shipmentId", shipmentId));
+                    bodyParameters.put("shipmentItems", shipmentItems);
+                    
+                    orderItemShipGroup = EntityUtil.getFirst(delegator.findByAnd("OrderItemShipGroup", UtilMisc.toMap("orderId", orderId)));
+                    bodyParameters.put("orderItemShipGroup", orderItemShipGroup);
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                Set correspondingPoIdSet = new TreeSet();
+                try {
+                    List orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
+                    Iterator oiIter = orderItems.iterator();
+                    while (oiIter.hasNext()) {
+                        GenericValue orderItem = (GenericValue) oiIter.next();
+                        String correspondingPoId = orderItem.getString("correspondingPoId");
+                        correspondingPoIdSet.add(correspondingPoId);
+                        bodyParameters.put("correspondingPoIdSet", correspondingPoIdSet);
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                Set externalIdSet = new TreeSet();
+                try {
+                    GenericValue primaryOrderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", shipment.getString("primaryOrderId")));
+                    externalIdSet.add(primaryOrderHeader.getString("externalId"));
+                    bodyParameters.put("externalIdSet", externalIdSet);
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                // if order was a return replacement order (associated with return)
+                List returnItemResponses =  null;
+                List returnItemRespExprs = UtilMisc.toList(new EntityExpr("replacementOrderId", EntityOperator.NOT_EQUAL, null));
+                EntityCondition returnItemRespCond = new EntityConditionList(returnItemRespExprs, EntityOperator.AND);
+                // list of fields to select (initial list)
+                List fieldsToSelect = FastList.newInstance();
+                fieldsToSelect.add("replacementOrderId");
+                try {
+                    returnItemResponses = delegator.findByCondition("ReturnItemResponse", returnItemRespCond, fieldsToSelect, null);
+                    Iterator rirIter = returnItemResponses.iterator();
+                    while (rirIter.hasNext()) {
+                        if (rirIter.next().equals(shipment.getString("primaryOrderId"))) {
+                            bodyParameters.put("shipnotes", "RETURNLABEL");
+                        }
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
+                bodyParameters.put("logicalId", logicalId);
+                result.put("logicalId", logicalId);
+                
+                String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
+                bodyParameters.put("authId", authId);
+                result.put("authId", authId);
+
+                String referenceId = delegator.getNextSeqId("OagisMessageInfo");
+                bodyParameters.put("referenceId", referenceId);
+                result.put("referenceId", referenceId);
+                    
+                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
+                Timestamp timestamp = UtilDateTime.nowTimestamp();
+                String sentDate = dateFormat.format(timestamp);
+                bodyParameters.put("sentDate", sentDate);
+                result.put("sentDate", timestamp);
+               
+                // tracking shipper account
+                String partyId = shipment.getString("partyIdTo");
+                List partyCarrierAccounts = new ArrayList();
+                try {
+                    partyCarrierAccounts = delegator.findByAnd("PartyCarrierAccount", UtilMisc.toMap("partyId", partyId));
+                    partyCarrierAccounts = EntityUtil.filterByDate(partyCarrierAccounts);
+                    if (partyCarrierAccounts != null) {
+                        Iterator pcaIter = partyCarrierAccounts.iterator();
+                        while (pcaIter.hasNext()) {
+                            GenericValue partyCarrierAccount = (GenericValue) pcaIter.next();
+                            String carrierPartyId = partyCarrierAccount.getString("carrierPartyId");
+                            if (carrierPartyId.equals(orderItemShipGroup.getString("carrierPartyId"))) {
+                                String accountNumber = partyCarrierAccount.getString("accountNumber");
+                                bodyParameters.put("shipperId", accountNumber);
+                            }
+                        }
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                bodyParameters.put("shipmentId", shipmentId);
+                bodyParameters.put("orderId", orderId);
+                bodyParameters.put("userLogin", userLogin);
+                String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ProcessShipment");
+                OutputStream out = (OutputStream) context.get("outputStream");
+                Writer writer = new OutputStreamWriter(out);
+                ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
+                try {
+                    screens.render(bodyScreenUri);
+                } catch (Exception e) {
+                      Debug.logError(e, "Error rendering [text/xml]: ", module);
+                }
+                // prepare map to Create Oagis Message Info
+                result.put("component", "INVENTORY");
+                result.put("task", "SHIPREQUES"); // Actual value of task is "SHIPREQUEST" which is more than 10 char
+                result.put("outgoingMessage", "Y");
+                result.put("confirmation", "1");
+                result.put("bsrVerb", "PROCESS");
+                result.put("bsrNoun", "SHIPMENT");
+                result.put("bsrRevision", "001");
+                result.put("processingStatusId", orderStatusId);
+                result.put("orderId", orderId);
+                result.put("shipmentId", shipmentId);
+                result.put("userLogin", userLogin);
+            }
+        }
+        return result;
+    }
+    
+    public static Map receiveDelivery(DispatchContext dctx, Map context) {
+        GenericDelegator delegator = dctx.getDelegator();
+        String returnId = (String) context.get("returnId");
+        GenericValue userLogin = (GenericValue) context.get("userLogin");
+        Map result = ServiceUtil.returnSuccess();
+        MapStack bodyParameters =  MapStack.create();
+        if (userLogin == null) {
+            try {
+                userLogin = delegator.findByPrimaryKey("UserLogin", UtilMisc.toMap("userLoginId", "admin"));
+            } catch (GenericEntityException e) {
+                Debug.logError(e, "Error getting userLogin", module);
+            }
+        }
+        if (returnId != null) {
+            GenericValue returnHeader = null;
+            String statusId =null;
+            try {
+                returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId));
+                statusId = returnHeader.getString("statusId");
+            } catch (GenericEntityException e) {
+                Debug.logError(e, module);
+            }
+            if (statusId.equals("RETURN_ACCEPTED")) {
+                try {
+                    List returnItems = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnId", returnId));
+                    bodyParameters.put("returnItems", returnItems);
+                    
+                    String orderId = EntityUtil.getFirst(returnItems).getString("orderId");
+                    result.put("orderId", orderId);
+                    
+                    GenericValue postalAddress = delegator.findByPrimaryKey("PostalAddress", UtilMisc.toMap("contactMechId", returnHeader.getString("originContactMechId")));
+                    bodyParameters.put("postalAddress", postalAddress);
+       
+                    // calculate total qty of return items in a shipping unit received, order associated with return
+                    double itemQty = 0.0;
+                    double totalQty = 0.0;
+                    Iterator riIter = returnItems.iterator();
+                    while (riIter.hasNext()) {
+                        GenericValue returnItem = (GenericValue) riIter.next();
+                        itemQty = returnItem.getDouble("returnQuantity").doubleValue();
+                        totalQty = totalQty + itemQty;
+                    }
+                    bodyParameters.put("totalQty", new Double(totalQty));
+                    
+                    String partyId = returnHeader.getString("fromPartyId");
+                    List partyContactMechs = delegator.findByAnd("PartyContactMech", UtilMisc.toMap("partyId", partyId));
+                    Iterator pcmIter = partyContactMechs.iterator();
+                    while (pcmIter.hasNext()) {
+                        GenericValue partyContactMech = (GenericValue) pcmIter.next();
+                        String contactMechId = partyContactMech.getString("contactMechId");
+                        GenericValue contactMech = delegator.findByPrimaryKey("ContactMech", UtilMisc.toMap("contactMechId", contactMechId));
+                        String contactMechTypeId = contactMech.getString("contactMechTypeId");
+                        if(contactMechTypeId.equals("EMAIL_ADDRESS")) {
+                           String emailString = contactMech.getString("infoString");
+                           bodyParameters.put("emailString", emailString);
+                        }
+                        if(contactMechTypeId.equals("TELECOM_NUMBER")) {
+                           GenericValue telecomNumber = delegator.findByPrimaryKey("TelecomNumber", UtilMisc.toMap("contactMechId", contactMechId));
+                           bodyParameters.put("telecomNumber", telecomNumber);
+                        }
+                    }
+                } catch (GenericEntityException e) {
+                    Debug.logError(e, module);
+                }
+                String logicalId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.LOGICALID");
+                bodyParameters.put("logicalId", logicalId);
+                result.put("logicalId", logicalId);
+                
+                String authId = UtilProperties.getPropertyValue("oagis.properties", "CNTROLAREA.SENDER.AUTHID");
+                bodyParameters.put("authId", authId);
+                result.put("authId", authId);
+                
+                String referenceId = delegator.getNextSeqId("OagisMessageInfo");
+                bodyParameters.put("referenceId", referenceId);
+                result.put("referenceId", referenceId);
+                
+                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
+                Timestamp timestamp = UtilDateTime.nowTimestamp();
+                String sentDate = dateFormat.format(timestamp);
+                bodyParameters.put("sentDate", sentDate);
+                result.put("sentDate", timestamp);
+                
+                bodyParameters.put("returnId", returnId);
+                String bodyScreenUri = UtilProperties.getPropertyValue("oagis.properties", "Oagis.Template.ReceiveDelivery");
+                OutputStream out = (OutputStream) context.get("outputStream");
+                Writer writer = new OutputStreamWriter(out);
+                ScreenRenderer screens = new ScreenRenderer(writer, bodyParameters, new HtmlScreenRenderer());
+                try {
+                    screens.render(bodyScreenUri);
+                } catch (Exception e) {
+                      Debug.logError(e, "Error rendering [text/xml]: ", module);
+                }
+                // prepare map to store BOD information
+                result.put("component", "INVENTORY");
+                result.put("task", "RMA");  
+                result.put("outgoingMessage", "Y");
+                result.put("confirmation", "1");
+                result.put("bsrVerb", "RECEIVE");
+                result.put("bsrNoun", "DELIVERY");
+                result.put("bsrRevision", "001");
+                result.put("processingStatusId", statusId);        
+                result.put("returnId", returnId);
+                result.put("userLogin", userLogin);
+            }
+        }    
+        return result;
+    }
+}