svn commit: r558626 - in /ofbiz/trunk: applications/product/entitydef/ specialpurpose/oagis/config/ specialpurpose/oagis/src/org/ofbiz/oagis/ specialpurpose/oagis/templates/email/

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

svn commit: r558626 - in /ofbiz/trunk: applications/product/entitydef/ specialpurpose/oagis/config/ specialpurpose/oagis/src/org/ofbiz/oagis/ specialpurpose/oagis/templates/email/

apatel-2
Author: apatel
Date: Mon Jul 23 00:03:01 2007
New Revision: 558626

URL: http://svn.apache.org/viewvc?view=rev&rev=558626
Log:
Some fixes in syncInventory service and email template.

Modified:
    ofbiz/trunk/applications/product/entitydef/entitymodel.xml
    ofbiz/trunk/specialpurpose/oagis/config/OagisUiLabels.properties
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
    ofbiz/trunk/specialpurpose/oagis/templates/email/InventoryNoticeEmail.ftl

Modified: ofbiz/trunk/applications/product/entitydef/entitymodel.xml
URL: http://svn.apache.org/viewvc/ofbiz/trunk/applications/product/entitydef/entitymodel.xml?view=diff&rev=558626&r1=558625&r2=558626
==============================================================================
--- ofbiz/trunk/applications/product/entitydef/entitymodel.xml (original)
+++ ofbiz/trunk/applications/product/entitydef/entitymodel.xml Mon Jul 23 00:03:01 2007
@@ -1531,6 +1531,7 @@
       <member-entity entity-alias="IID" entity-name="InventoryItemDetail"/>
       <alias entity-alias="II" name="inventoryItemId"/>
       <alias entity-alias="II" name="productId"/>
+      <alias entity-alias="II" name="statusId"/>  
       <alias entity-alias="IID" name="inventoryItemDetailSeqId"/>  
       <alias entity-alias="IID" name="effectiveDate"/>  
       <alias entity-alias="IID" name="quantityOnHandDiff"/>

Modified: ofbiz/trunk/specialpurpose/oagis/config/OagisUiLabels.properties
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/config/OagisUiLabels.properties?view=diff&rev=558626&r1=558625&r2=558626
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/config/OagisUiLabels.properties (original)
+++ ofbiz/trunk/specialpurpose/oagis/config/OagisUiLabels.properties Mon Jul 23 00:03:01 2007
@@ -32,4 +32,6 @@
 OagisErrorInExportingMessageFromScreen = Error in exporting message from screen
 
 OagisInventoryDescription=Inventory Description
+OagisInventoryLevelDateTime=date/time
+OagisQuantityDiff=Qty Difference
 PageTitleOagisInventoryMismatchNotice=Inventory Mismatch Notice

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java?view=diff&rev=558626&r1=558625&r2=558626
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Mon Jul 23 00:03:01 2007
@@ -74,6 +74,7 @@
         LocalDispatcher dispatcher = ctx.getDispatcher();
         Locale locale = (Locale) context.get("locale");
         List errorMapList = FastList.newInstance();
+        List inventoryMapList = FastList.newInstance();
         
         if (userLogin == null) {
             try {
@@ -104,10 +105,9 @@
             return ServiceUtil.returnError("Unable to parse message: SyncInventory");
         }
         
-        Element receiveInventoryElement = doc.getDocumentElement();
-        receiveInventoryElement.normalize();
-                        
-        Element docCtrlAreaElement = UtilXml.firstChildElement(receiveInventoryElement, "N1:CNTROLAREA");
+        Element syncInventoryRootElement = doc.getDocumentElement();
+        syncInventoryRootElement.normalize();
+        Element docCtrlAreaElement = UtilXml.firstChildElement(syncInventoryRootElement, "N1:CNTROLAREA");
         Element docSenderElement = UtilXml.firstChildElement(docCtrlAreaElement, "N1:SENDER");
         Element docBsrElement = UtilXml.firstChildElement(docCtrlAreaElement, "N1:BSR");
             
@@ -121,55 +121,75 @@
         String referenceId = UtilXml.childElementValue(docSenderElement, "N2:REFERENCEID");
         String confirmation = UtilXml.childElementValue(docSenderElement, "N2:CONFIRMATION");
         String authId = UtilXml.childElementValue(docSenderElement, "N2:AUTHID");
-            
-        Element dataAreaElement = UtilXml.firstChildElement(receiveInventoryElement, "n:DATAAREA");
-        Element dataAreaSyncInventoryElement = UtilXml.firstChildElement(dataAreaElement, "n:SYNC_INVENTORY");
-        Element dataAreaInventoryElement = UtilXml.firstChildElement(dataAreaSyncInventoryElement, "n:INVENTORY");
-            
-        Element dataAreaQuantityElement = UtilXml.firstChildElement(dataAreaInventoryElement, "N1:QUANTITY");
-            
-        String itemQtyStr = UtilXml.childElementValue(dataAreaQuantityElement, "N2:VALUE");
-        double itemQty = Double.parseDouble(itemQtyStr);
-        // String sign = UtilXml.childElementValue(dataAreaQuantityElement, "N2:SIGN");
-        // String uom = UtilXml.childElementValue(dataAreaQuantityElement, "N2:UOM");
-        String productId = UtilXml.childElementValue(dataAreaQuantityElement, "N2:ITEM");
-        // String itemStatus = UtilXml.childElementValue(dataAreaQuantityElement, "N2:ITEMSTATUS");
         
-        String datetimeReceived = UtilXml.childElementValue(dataAreaInventoryElement, "N1:DATETIMEANY");
-        
-        // In BOD the timestamp come in the format "yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z"
-        // Parse this into a valid Timestamp Object
-        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z");
-        Timestamp timestamp = null;
-        try {        
-            timestamp = new Timestamp(sdf.parse(datetimeReceived).getTime());
-        } catch (ParseException e) {
-            String errMsg = "Error parsing Date: " + e.toString();
-            errorMapList.add(UtilMisc.toMap("reasonCode", "ParseException", "description", errMsg));
-            Debug.logError(e, errMsg, module);
-        }
-        // get quantity on hand diff  
-        double quantityOnHandDiff = 0.0;
-        List invItemAndDetails = null;
-        EntityCondition condition = new EntityConditionList(UtilMisc.toList(
-                new EntityExpr("effectiveDate", EntityOperator.LESS_THAN_EQUAL_TO, timestamp), new EntityExpr("productId", EntityOperator.EQUALS, productId)), EntityOperator.AND);
-        try {
-            invItemAndDetails = delegator.findByCondition("InventoryItemAndDetail", condition, null, UtilMisc.toList("inventoryItemId"));
-            Iterator invItemAndDetailIter = invItemAndDetails.iterator();
-            while (invItemAndDetailIter.hasNext()) {
-                GenericValue InventoryItemAndDetail = (GenericValue) invItemAndDetailIter.next();
-                quantityOnHandDiff = quantityOnHandDiff + Double.parseDouble(InventoryItemAndDetail.getString("quantityOnHandDiff"));
-            }
-        } catch (GenericEntityException e) {
-            String errMsg = "Error Getting Inventory Item And Detail: " + e.toString();
-            errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg));
-            Debug.logError(e, errMsg, module);
+        // data area elements
+        Element dataAreaElement = UtilXml.firstChildElement(syncInventoryRootElement, "n:DATAAREA");
+        Element syncInventoryElement = UtilXml.firstChildElement(dataAreaElement, "n:SYNC_INVENTORY");
+        
+        // get Inventory elements from message
+        List syncInventoryElementList = UtilXml.childElementList(syncInventoryElement, "n:INVENTORY");
+        if (UtilValidate.isNotEmpty(syncInventoryElementList)) {
+            Iterator syncInventoryElementIter = syncInventoryElementList.iterator();
+            while (syncInventoryElementIter.hasNext()) {
+                Element inventoryElement = (Element) syncInventoryElementIter.next();
+                Element quantityElement = UtilXml.firstChildElement(inventoryElement, "N1:QUANTITY");
+                
+                String itemQtyStr = UtilXml.childElementValue(quantityElement, "N2:VALUE");
+                double itemQty = Double.parseDouble(itemQtyStr);
+                // String sign = UtilXml.childElementValue(quantityElement, "N2:SIGN");
+                // String uom = UtilXml.childElementValue(quantityElement, "N2:UOM");
+                String productId = UtilXml.childElementValue(inventoryElement, "N2:ITEM");
+                String itemStatus = UtilXml.childElementValue(inventoryElement, "N2:ITEMSTATUS");
+                String statusId = null;
+                if (itemStatus.equals("AVAILABLE")) {
+                   statusId = "INV_AVAILABLE";
+                } else if (itemStatus.equals("NOTAVAILABLE")) {
+                    statusId = "INV_ON_HOLD";
+                }
+                String datetimeReceived = UtilXml.childElementValue(inventoryElement, "N1:DATETIMEANY");
+
+                // In BOD the timestamp come in the format "yyyy-MM-dd'T'HH:mm:ss.SSSS'Z'Z"
+                // Parse this into a valid Timestamp Object
+                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSS");
+                Timestamp timestamp = null;
+                try {        
+                    timestamp = new Timestamp(sdf.parse(datetimeReceived).getTime());
+                } catch (ParseException e) {
+                    String errMsg = "Error parsing Date: " + e.toString();
+                    errorMapList.add(UtilMisc.toMap("reasonCode", "ParseException", "description", errMsg));
+                    Debug.logError(e, errMsg, module);
+                }
+
+                // get quantity on hand diff  
+                double quantityOnHandDiff = 0.0;
+                List invItemAndDetails = null;
+                EntityCondition condition = new EntityConditionList(UtilMisc.toList(
+                        new EntityExpr("effectiveDate", EntityOperator.LESS_THAN_EQUAL_TO, timestamp), new EntityExpr("productId", EntityOperator.EQUALS, productId),
+                        new EntityExpr("statusId", EntityOperator.EQUALS, statusId)), EntityOperator.AND);
+                try {
+                    invItemAndDetails = delegator.findByCondition("InventoryItemAndDetail", condition, null, UtilMisc.toList("inventoryItemId"));
+                    if (invItemAndDetails != null) {
+                        Iterator invItemAndDetailIter = invItemAndDetails.iterator();
+                        while (invItemAndDetailIter.hasNext()) {
+                            GenericValue InventoryItemAndDetail = (GenericValue) invItemAndDetailIter.next();
+                            quantityOnHandDiff = quantityOnHandDiff + Double.parseDouble(InventoryItemAndDetail.getString("quantityOnHandDiff"));
+                        }
+                    }
+                } catch (GenericEntityException e) {
+                    String errMsg = "Error Getting Inventory Item And Detail: " + e.toString();
+                    errorMapList.add(UtilMisc.toMap("reasonCode", "GenericEntityException", "description", errMsg));
+                    Debug.logError(e, errMsg, module);
+                }
+
+                // check for mismatch in quantity
+                if (itemQty != quantityOnHandDiff) {
+                    double quantityDiff = Math.abs((itemQty - quantityOnHandDiff));
+                    inventoryMapList.add(UtilMisc.toMap("productId", productId, "statusId", statusId, "quantityOnHandDiff", String.valueOf(quantityOnHandDiff), "quantityFromMessage", itemQtyStr, "quantityDiff", String.valueOf(quantityDiff), "timestamp", timestamp));
+                }
+            }
         }
-        
-        // check for mismatch in quantity to send a mail to facility
-        if (itemQty != quantityOnHandDiff) {
-            double quantityDiff = Math.abs((itemQty - quantityOnHandDiff));
-            
+        // send mail if mismatch(s) found
+        if (inventoryMapList.size() > 0) {
             // prepare information to send mail
             Map sendMap = FastMap.newInstance();
     
@@ -226,7 +246,7 @@
             sendMap.put("sendBcc", productStoreEmail.getString("bccAddress"));
             sendMap.put("contentType", productStoreEmail.getString("contentType"));
             
-            Map bodyParameters = UtilMisc.toMap("quantityOnHandDiff", String.valueOf(quantityOnHandDiff), "quantityFromMessage", itemQtyStr, "quantityDiff", String.valueOf(quantityDiff), "productId", productId,  "locale", locale);
+            Map bodyParameters = UtilMisc.toMap("inventoryMapList", inventoryMapList, "locale", locale);
             sendMap.put("bodyParameters", bodyParameters);
             sendMap.put("userLogin", userLogin);
 

Modified: ofbiz/trunk/specialpurpose/oagis/templates/email/InventoryNoticeEmail.ftl
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/templates/email/InventoryNoticeEmail.ftl?view=diff&rev=558626&r1=558625&r2=558626
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/templates/email/InventoryNoticeEmail.ftl (original)
+++ ofbiz/trunk/specialpurpose/oagis/templates/email/InventoryNoticeEmail.ftl Mon Jul 23 00:03:01 2007
@@ -37,17 +37,23 @@
       <table width="100%" border="0" cellpadding="0">
         <tr align="left" valign="bottom">
           <td width="10%" align="left"><span class="tableheadtext"><b>${uiLabelMap.EcommerceProduct}</b></span></td>              
+          <td width="10%" align="center"><span class="tableheadtext"><b>${uiLabelMap.OagisInventoryLevelDateTime}</b></span></td>
+          <td width="10%" align="right"><span class="tableheadtext"><b>${uiLabelMap.OrderReturnItemInventoryStatus}</b></span></td>
           <td width="10%" align="right"><span class="tableheadtext"><b>${uiLabelMap.OrderQuantity} (Inventory)</b></span></td>
           <td width="10%" align="right"><span class="tableheadtext"><b>${uiLabelMap.OrderQuantity} (Message)</b></span></td>
-          <td width="10%" align="right"><span class="tableheadtext"><b>${uiLabelMap.CommonDiff}.</b></span></td>
+          <td width="10%" align="right"><span class="tableheadtext"><b>${uiLabelMap.OagisQuantityDiff}.</b></span></td>
         </tr>
         <tr><td colspan="10"><hr class="sepbar"/></td></tr>
-        <tr>
-          <td align="left" valign="top"> ${productId?if_exists}</td>  
-          <td align="right" valign="top"> ${quantityOnHandDiff?if_exists?if_exists}</td>  
-          <td align="right" valign="top"> ${quantityFromMessage?if_exists?if_exists}</td>  
-          <td align="right" valign="top"> ${quantityDiff?if_exists?if_exists}</td>  
-        </tr>
+        <#list inventoryMapList as inventoryMap>
+          <tr>
+            <td align="left" valign="top"> ${inventoryMap.productId?if_exists}</td>  
+            <td align="right" valign="top"> ${inventoryMap.timestamp?if_exists?if_exists}</td>
+            <td align="right" valign="top"> ${inventoryMap.statusId?if_exists?if_exists}</td>                        
+            <td align="center" valign="top"> ${inventoryMap.quantityOnHandDiff?if_exists?if_exists}</td>  
+            <td align="center" valign="top"> ${inventoryMap.quantityFromMessage?if_exists?if_exists}</td>  
+            <td align="right" valign="top"> ${inventoryMap.quantityDiff?if_exists?if_exists}</td>  
+          </tr>
+        </#list>  
         <tr><td colspan="10"><hr class="sepbar"/></td></tr>
       </table>
     </div>