⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inventoryservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                                                // subtract our qty from reserved to get the next value                availableBeforeReserved -= reservation.getDouble("quantity").doubleValue();            }        }                       // all items to cancel will also be in the notify list so start with that        List ordersToNotify = new ArrayList();        Set orderSet = ordersToUpdate.keySet();        Iterator orderIter = orderSet.iterator();        while (orderIter.hasNext()) {            String orderId = (String) orderIter.next();            Map backOrderedItems = (Map) ordersToUpdate.get(orderId);            Map cancelItems = (Map) ordersToCancel.get(orderId);            boolean cancelAll = false;            Timestamp cancelAllTime = null;                        List orderItemShipGroups = null;            try {                orderItemShipGroups= delegator.findByAnd("OrderItemShipGroup",                        UtilMisc.toMap("orderId", orderId));            } catch (GenericEntityException e) {                Debug.logError(e, "Cannot get OrderItemShipGroups from orderId" + orderId, module);            }                        Iterator orderItemShipGroupsIter = orderItemShipGroups.iterator();            while (orderItemShipGroupsIter.hasNext()) {                GenericValue orderItemShipGroup = (GenericValue)orderItemShipGroupsIter.next();                List orderItems = new java.util.Vector();                List orderItemShipGroupAssoc = null;                try {                                        orderItemShipGroupAssoc =                        delegator.findByAnd("OrderItemShipGroupAssoc",                                UtilMisc.toMap("shipGroupSeqId",                                        orderItemShipGroup.get("shipGroupSeqId"),                                        "orderId",                                        orderId));                                        Iterator assocIter = orderItemShipGroupAssoc.iterator();                    while (assocIter.hasNext()) {                        GenericValue assoc = (GenericValue)assocIter.next();                        GenericValue orderItem = assoc.getRelatedOne("OrderItem");                        if (orderItem != null) {                            orderItems.add(orderItem);                        }                    }                } catch (GenericEntityException e) {                     Debug.logError(e, "Problem fetching OrderItemShipGroupAssoc", module);                }                                    /* Check the split preference. */                boolean maySplit = false;                if (orderItemShipGroup != null && orderItemShipGroup.get("maySplit") != null) {                    maySplit = orderItemShipGroup.getBoolean("maySplit").booleanValue();                }                                /* Figure out if we must cancel all items. */                if (!maySplit && cancelItems != null) {                    cancelAll = true;                    Set cancelSet = cancelItems.keySet();                    cancelAllTime = (Timestamp) cancelItems.get(cancelSet.iterator().next());                }                                // if there are none to cancel just create an empty map                if (cancelItems == null) {                    cancelItems = new HashMap();                }                                if (orderItems != null) {                                List toBeStored = new ArrayList();                    Iterator orderItemsIter = orderItems.iterator();                    while (orderItemsIter.hasNext()) {                        GenericValue orderItem = (GenericValue) orderItemsIter.next();                        String orderItemSeqId = orderItem.getString("orderItemSeqId");                        Timestamp shipDate = (Timestamp) backOrderedItems.get(orderItemSeqId);                        Timestamp cancelDate = (Timestamp) cancelItems.get(orderItemSeqId);                        Timestamp currentCancelDate = (Timestamp) orderItem.getTimestamp("autoCancelDate");                                                Debug.logError("OI: " + orderId + " SEQID: "+ orderItemSeqId + " cancelAll: " + cancelAll + " cancelDate: " + cancelDate, module);                        if (backOrderedItems.containsKey(orderItemSeqId)) {                            orderItem.set("estimatedShipDate", shipDate);                                                        if (currentCancelDate == null) {                                                        if (cancelAll || cancelDate != null) {                                    if (orderItem.get("dontCancelSetUserLogin") == null && orderItem.get("dontCancelSetDate") == null) {                                                                    if (cancelAllTime != null) {                                            orderItem.set("autoCancelDate", cancelAllTime);                                        } else {                                            orderItem.set("autoCancelDate", cancelDate);                                        }                                    }                                }                                // only notify orders which have not already sent the final notice                                ordersToNotify.add(orderId);                                                    }                            toBeStored.add(orderItem);                                                }                    }                    if (toBeStored.size() > 0) {                        try {                            delegator.storeAll(toBeStored);                        } catch (GenericEntityException e) {                            Debug.logError(e, "Problem storing order items", module);                        }                    }                }                                            }                    }                // send off a notification for each order                Iterator orderNotifyIter = ordersToNotify.iterator();        while (orderNotifyIter.hasNext()) {                                   String orderId = (String) orderNotifyIter.next();                                                          try {                dispatcher.runAsync("sendOrderBackorderNotification", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));            } catch (GenericServiceException e) {                Debug.logError(e, "Problems sending off the notification", module);                continue;            }        }                        return ServiceUtil.returnSuccess();    }        /**     * Get Inventory Available for a Product based on the list of associated products.  The final ATP and QOH will     * be the minimum of all the associated products' inventory divided by their ProductAssoc.quantity      * */    public static Map getProductInventoryAvailablefromAssocProducts(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        List productAssocList = (List) context.get("assocProducts");                        Double availableToPromiseTotal = new Double(0);        Double quantityOnHandTotal = new Double(0);                if (productAssocList != null && productAssocList.size() > 0) {        	// minimum QOH and ATP encountered           double minQuantityOnHandTotal = Double.MAX_VALUE;           double minAvailableToPromiseTotal = Double.MAX_VALUE;                      // loop through each associated product.             for (int i = 0; productAssocList.size() > i; i++) {               GenericValue productAssoc = (GenericValue) productAssocList.get(i);               String productIdTo = productAssoc.getString("productIdTo");               Double assocQuantity = productAssoc.getDouble("quantity");                              // if there is no quantity for the associated product in ProductAssoc entity, default it to 1.0               if (assocQuantity == null) {                   Debug.logWarning("ProductAssoc from [" + productAssoc.getString("productId") + "] to [" + productAssoc.getString("productIdTo") + "] has no quantity, assuming 1.0", module);                   assocQuantity = new Double(1.0);               }                              // figure out the inventory available for this associated product               Map resultOutput = null;               try {                  resultOutput = dispatcher.runSync("getProductInventoryAvailable", UtilMisc.toMap("productId", productIdTo));               } catch (GenericServiceException e) {                  Debug.logError(e, "Problems getting inventory available by facility", module);                  return ServiceUtil.returnError(e.getMessage());               }                              // Figure out what the QOH and ATP inventory would be with this associated product               Double currentQuantityOnHandTotal = (Double) resultOutput.get("quantityOnHandTotal");               Double currentAvailableToPromiseTotal = (Double) resultOutput.get("availableToPromiseTotal");               double tmpQuantityOnHandTotal = currentQuantityOnHandTotal.doubleValue()/assocQuantity.doubleValue();               double tmpAvailableToPromiseTotal = currentAvailableToPromiseTotal.doubleValue()/assocQuantity.doubleValue();               // reset the minimum QOH and ATP quantities if those quantities for this product are less                if (tmpQuantityOnHandTotal < minQuantityOnHandTotal) {                   minQuantityOnHandTotal = tmpQuantityOnHandTotal;               }               if (tmpAvailableToPromiseTotal < minAvailableToPromiseTotal) {                   minAvailableToPromiseTotal = tmpAvailableToPromiseTotal;               }                            if (Debug.verboseOn()) {                   Debug.logVerbose("productIdTo = " + productIdTo + " assocQuantity = " + assocQuantity + "current QOH " + currentQuantityOnHandTotal +                 		"currentATP = " + currentAvailableToPromiseTotal + " minQOH = " + minQuantityOnHandTotal + " minATP = " + minAvailableToPromiseTotal, module);	               }           }          // the final QOH and ATP quantities are the minimum of all the products           quantityOnHandTotal = new Double(minQuantityOnHandTotal);          availableToPromiseTotal = new Double(minAvailableToPromiseTotal);        }                Map result = ServiceUtil.returnSuccess();        result.put("availableToPromiseTotal", availableToPromiseTotal);        result.put("quantityOnHandTotal", quantityOnHandTotal);        return result;    }        /**     * Given a set of order items, returns a hashmap with the ATP and QOH for each product. The default method is to sum     * inventories over all Facilities.     */    public static Map getProductInventorySummaryForItems(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();    	List orderItems = (List) context.get("orderItems");    	Map atpMap = new HashMap();    	Map qohMap = new HashMap();    	Map results = ServiceUtil.returnSuccess();    	results.put("availableToPromiseMap", atpMap);    	results.put("quantityOnHandMap", qohMap);    	    	List facilities = null;    	try {    	    facilities = delegator.findAll("Facility");    	} catch (GenericEntityException e) {    		Debug.logError(e, "Couldn't get list of facilities.", module);    		return ServiceUtil.returnError("Unable to locate facilities.");    	}    	    	    	Iterator iter = orderItems.iterator();    	while (iter.hasNext()) {    		GenericValue orderItem = (GenericValue) iter.next();    		String productId = orderItem.getString("productId");    		    		if ((productId == null) || productId.equals("")) continue;    		    		double atp = 0.0;    		double qoh = 0.0;    		Iterator facilityIter = facilities.iterator();    		while (facilityIter.hasNext()) {    			GenericValue facility = (GenericValue) facilityIter.next();    			Map params = UtilMisc.toMap("productId", productId, "facilityId", facility.getString("facilityId"));    			Map invResult = null;    			try {    				invResult = dispatcher.runSync("getInventoryAvailableByFacility", params);    			} catch (GenericServiceException e) {    				String msg = "Could not find inventory for facility [" + facility.getString("facilityId") + "]";    				Debug.logError(e, msg, module);    				return ServiceUtil.returnError(msg);    			}    			Double fatp = (Double) invResult.get("availableToPromiseTotal");    			Double fqoh = (Double) invResult.get("quantityOnHandTotal");    			if (fatp != null) atp += fatp.doubleValue();    			if (fqoh != null) qoh += fqoh.doubleValue();    		}    		atpMap.put(productId, new Double(atp));    		qohMap.put(productId, new Double(qoh));    	}    	return results;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -