svn commit: r567789 - in /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis: OagisInventoryServices.java OagisServices.java OagisShipmentServices.java

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

svn commit: r567789 - in /ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis: OagisInventoryServices.java OagisServices.java OagisShipmentServices.java

jonesde
Author: jonesde
Date: Mon Aug 20 12:15:06 2007
New Revision: 567789

URL: http://svn.apache.org/viewvc?rev=567789&view=rev
Log:
Changed message handler to return Confirm BOD if the message has already been received; implemented stuff to only complete returns if all have been received, though there is a problem in receiveInventoryProduct service because it sets ReturnItems as received even for partial quantities (naughty, naughty); also a few other minor cleanups

Modified:
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java
    ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java

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?rev=567789&r1=567788&r2=567789&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisInventoryServices.java Mon Aug 20 12:15:06 2007
@@ -335,7 +335,7 @@
                 // run async because this will send a message back to the other server and may take some time, and/or fail
                 dispatcher.runAsync("oagisSendConfirmBod", sendConfirmBodCtx, null, true, 60, true);
             } catch (GenericServiceException e){
-                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                String errMsg = "Error sending Confirm BOD: " + e.toString();
                 Debug.logError(e, errMsg, module);
             }
             
@@ -580,7 +580,7 @@
                 // run async because this will send a message back to the other server and may take some time, and/or fail
                 dispatcher.runAsync("oagisSendConfirmBod", sendConfirmBodCtx, null, true, 60, true);
             } catch (GenericServiceException e){
-                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                String errMsg = "Error sending Confirm BOD: " + e.toString();
                 Debug.logError(e, errMsg, module);
             }
             
@@ -737,6 +737,8 @@
                         }
                     }
                     
+                    // TODOLATER: get the returnItem associated with the product received and update the receivedQuantity
+                    
                     String datetimeReceived = UtilXml.childElementValue(receiptLnElement, "os:DATETIMEISO");
                     Timestamp timestampItemReceived = OagisServices.parseIsoDateString(datetimeReceived, errorMapList);
                     ripCtx.put("datetimeReceived", timestampItemReceived);
@@ -863,6 +865,8 @@
                                         }
                                     }
                                     
+                                    // TODOLATER: another fun thing to check: see if the serial number matches a serial number attached to the original return (if possible!)
+                                    
                                     GenericValue inventoryItem = EntityUtil.getFirst(inventoryItemsBySerialNumber);
                                     if (inventoryItem != null) {
                                         Map updateInvItmMap = FastMap.newInstance();
@@ -950,12 +954,66 @@
                     String statusId = (String) processedStatusIdByReturnIdEntry.getValue();
 
                     if (UtilValidate.isNotEmpty(statusId) && statusId.equals("RETURN_ACCEPTED")) {
-                        // TODO (see note below): check to see if all return items have been received, if so then set to received then completed
-                        // NOTE DEJ20070815 because of the way the inventory is being received, ie not through the return; reviewing other code it looks like nothing
-                        //updates ReturnItem status or anything anyway, and there is no Return/Item stuff on the InventoryItemDetail to track it back;
-                        //so giving up on attempt to do this, will support multiple returns per message, but all must be complete a complete one at that, which is a BAD assumption
-                        dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", "RETURN_RECEIVED", "returnId", returnId, "userLogin", userLogin));
-                        dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", "RETURN_COMPLETED", "returnId", returnId, "userLogin", userLogin));
+                        // check to see if all return items have been received, if so then set to received then completed
+                        
+                        // NOTE: an alternative method would be to see if the total has been received for each
+                        //ReturnItem (receivedQuantity vs returnQuantity), but we may have a hard time matching
+                        //those up so that information is probably not as reliable
+                        
+                        // loop through ReturnItem records, get totals for each productId
+                        Map returnQuantityByProductIdMap = FastMap.newInstance();
+                        List returnItemList = delegator.findByAnd("ReturnItem", UtilMisc.toMap("returnId", returnId));
+                        Iterator returnItemIter = returnItemList.iterator();
+                        while (returnItemIter.hasNext()) {
+                            GenericValue returnItem = (GenericValue) returnItemIter.next();
+                            String productId = returnItem.getString("productId");
+                            Double returnQuantityDbl = returnItem.getDouble("returnQuantity");
+                            if (UtilValidate.isNotEmpty(productId) && returnQuantityDbl != null) {
+                                double newTotal = returnQuantityDbl.doubleValue();
+                                Double existingTotal = (Double) returnQuantityByProductIdMap.get(productId);
+                                if (existingTotal != null) newTotal += existingTotal.doubleValue();
+                                returnQuantityByProductIdMap.put(productId, new Double(newTotal));
+                            }
+                        }
+                        
+                        // set to true, if we find any that aren't fully received, will set to false
+                        boolean fullReturnReceived = true;
+                        
+                        // for each productId see if total received is equal to the total for that ID
+                        Iterator returnQuantityByProductIdEntryIter = returnQuantityByProductIdMap.entrySet().iterator();
+                        while (returnQuantityByProductIdEntryIter.hasNext()) {
+                            Map.Entry returnQuantityByProductIdEntry = (Map.Entry) returnQuantityByProductIdEntryIter.next();
+                            String productId = (String) returnQuantityByProductIdEntry.getKey();
+                            double returnQuantity = ((Double) returnQuantityByProductIdEntry.getValue()).doubleValue();
+                            
+                            double inventoryQuantity = 0;
+                            // note no facilityId because we don't really care where the return items were received
+                            List inventoryItemDetailList = delegator.findByAnd("InventoryItemAndDetail", UtilMisc.toMap("productId", productId, "returnId", returnId));
+                            // NOTE only consider those with a quantityOnHandDiff > 0 so we just look at how many have been received, not what was actually done with them
+                            Iterator inventoryItemDetailIter = inventoryItemDetailList.iterator();
+                            while (inventoryItemDetailIter.hasNext()) {
+                                GenericValue inventoryItemDetail = (GenericValue) inventoryItemDetailIter.next();
+                                Double quantityOnHandDiff = inventoryItemDetail.getDouble("quantityOnHandDiff");
+                                if (quantityOnHandDiff != null && quantityOnHandDiff.doubleValue() > 0) {
+                                    inventoryQuantity += quantityOnHandDiff.doubleValue();
+                                }
+                            }
+                            
+                            if (inventoryQuantity < returnQuantity) {
+                                fullReturnReceived = false;
+                                break;
+                            } else if (inventoryQuantity > returnQuantity) {
+                                // TODOLATER: we received MORE than expected... what to do about that?!?
+                                String warnMsg = "Received more [" + inventoryQuantity + "] than were expected on return [" + returnQuantity + "] for Return ID [" + returnId + "] and Product ID [" + productId + "]";
+                                Debug.logWarning(warnMsg, module);
+                                // even with that, allow it to go through and complete the return
+                            }
+                        }
+                        
+                        if (fullReturnReceived) {
+                            dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", "RETURN_RECEIVED", "returnId", returnId, "userLogin", userLogin));
+                            dispatcher.runSync("updateReturnHeader", UtilMisc.toMap("statusId", "RETURN_COMPLETED", "returnId", returnId, "userLogin", userLogin));
+                        }
                     }
                 }
             } catch (Throwable t) {
@@ -1007,7 +1065,7 @@
                 // run async because this will send a message back to the other server and may take some time, and/or fail
                 dispatcher.runAsync("oagisSendConfirmBod", sendConfirmBodCtx, null, true, 60, true);
             } catch (GenericServiceException e){
-                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                String errMsg = "Error sending Confirm BOD: " + e.toString();
                 Debug.logError(e, errMsg, module);
             }
             

Modified: ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java?rev=567789&r1=567788&r2=567789&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisServices.java Mon Aug 20 12:15:06 2007
@@ -510,9 +510,29 @@
                 // there was an error last time, tell the service this is a retry
                 messageProcessContext.put("isErrorRetry", Boolean.TRUE);
             } else {
-                String errMsg = "Message already received with ID: " + oagisMessageInfoKey;
-                Debug.logError(errMsg, module);
-                return ServiceUtil.returnError(errMsg);
+                String responseMsg = "Message already received with ID: " + oagisMessageInfoKey;
+                Debug.logError(responseMsg, module);
+
+                List errorMapList = UtilMisc.toList(UtilMisc.toMap("reasonCode", "MessageAlreadyReceive", "description", responseMsg));
+
+                Map sendConfirmBodCtx = FastMap.newInstance();
+                sendConfirmBodCtx.put("logicalId", logicalId);
+                sendConfirmBodCtx.put("component", component);
+                sendConfirmBodCtx.put("task", task);
+                sendConfirmBodCtx.put("referenceId", referenceId);
+                sendConfirmBodCtx.put("errorMapList", errorMapList);
+                sendConfirmBodCtx.put("userLogin", userLogin);
+
+                try {
+                    // run async because this will send a message back to the other server and may take some time, and/or fail
+                    dispatcher.runAsync("oagisSendConfirmBod", sendConfirmBodCtx, null, true, 60, true);
+                } catch (GenericServiceException e){
+                    String errMsg = "Error sending Confirm BOD: " + e.toString();
+                    Debug.logError(e, errMsg, module);
+                }
+                Map result = ServiceUtil.returnSuccess(responseMsg);
+                result.put("contentType", "text/plain");
+                return result;
             }
         }
         

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?rev=567789&r1=567788&r2=567789&view=diff
==============================================================================
--- ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java (original)
+++ ofbiz/trunk/specialpurpose/oagis/src/org/ofbiz/oagis/OagisShipmentServices.java Mon Aug 20 12:15:06 2007
@@ -448,7 +448,7 @@
                 // run async because this will send a message back to the other server and may take some time, and/or fail
                 dispatcher.runAsync("oagisSendConfirmBod", sendConfirmBodCtx, null, true, 60, true);
             } catch (GenericServiceException e){
-                String errMsg = "Error updating OagisMessageInfo for the Incoming Message: " + e.toString();
+                String errMsg = "Error sending Confirm BOD: " + e.toString();
                 Debug.logError(e, errMsg, module);
             }
             
@@ -882,7 +882,8 @@
                                     }
                                 } else {
                                     // TODO: again a quantity mismatch, whatever to do?
-                                    Debug.logWarning("Number of serial numbers [" + itemIssuanceAndInventoryItemList.size() + "] did not match quantity [" + itemQty + "] for return item: " + returnItem.getPrimaryKey(), module);
+                                    // just logging this as info because the product may not be serialized or have serialized inventory
+                                    Debug.logInfo("Number of serial numbers [" + itemIssuanceAndInventoryItemList.size() + "] did not match quantity [" + itemQty + "] for return item: " + returnItem.getPrimaryKey() + "; may not be a serialized inventory product", module);
                                 }
                             } else {
                                 // TODO: we don't know which serial numbers are returned, should we throw an error? probably not, just do what we can