📄 orderreturnservices.java
字号:
Map sendResp = null; try { sendResp = dispatcher.runSync("sendMailFromScreen", sendMap); } catch (GenericServiceException e) { Debug.logError(e, "Problem sending mail", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderProblemSendingEmail", locale)); } // check for errors if (sendResp != null && !ServiceUtil.isError(sendResp)) { sendResp.put("emailType", emailType); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderProblemSendingEmail", locale), null, null, sendResp); } return sendResp; } } return ServiceUtil.returnFailure("No valid email setting for store"); } // return request notification public static Map sendReturnAcceptNotification(DispatchContext dctx, Map context) { return sendReturnNotificationScreen(dctx, context, "PRDS_RTN_ACCEPT"); } // return complete notification public static Map sendReturnCompleteNotification(DispatchContext dctx, Map context) { return sendReturnNotificationScreen(dctx, context, "PRDS_RTN_COMPLETE"); } // return cancel notification public static Map sendReturnCancelNotification(DispatchContext dctx, Map context) { return sendReturnNotificationScreen(dctx, context, "PRDS_RTN_CANCEL"); } // get the returnable quantiy for an order item public static Map getReturnableQuantity(DispatchContext dctx, Map context) { GenericDelegator delegator = dctx.getDelegator(); GenericValue orderItem = (GenericValue) context.get("orderItem"); GenericValue product = null; Locale locale = (Locale) context.get("locale"); if (orderItem.get("productId") != null) { try { product = orderItem.getRelatedOne("Product"); } catch (GenericEntityException e) { Debug.logError(e, "ERROR: Unable to get Product from OrderItem", module); } } // check returnable status boolean returnable = true; // first check returnable flag if (product != null && product.get("returnable") != null && "N".equalsIgnoreCase(product.getString("returnable"))) { // the product is not returnable at all returnable = false; } // next check support discontinuation if (product != null && product.get("supportDiscontinuationDate") != null && !UtilDateTime.nowTimestamp().before(product.getTimestamp("supportDiscontinuationDate"))) { // support discontinued either now or in the past returnable = false; } String itemStatus = orderItem.getString("statusId"); double orderQty = orderItem.getDouble("quantity").doubleValue(); if (orderItem.getDouble("cancelQuantity") != null) { orderQty -= orderItem.getDouble("cancelQuantity").doubleValue(); } // get the returnable quantity double returnableQuantity = 0.00; if (returnable && itemStatus.equals("ITEM_COMPLETED")) { List returnedItems = null; try { returnedItems = orderItem.getRelated("ReturnItem"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetReturnItemInformation", locale)); } if (returnedItems == null || returnedItems.size() == 0) { returnableQuantity = orderQty; } else { double returnedQty = 0.00; Iterator ri = returnedItems.iterator(); while (ri.hasNext()) { GenericValue returnItem = (GenericValue) ri.next(); GenericValue returnHeader = null; try { returnHeader = returnItem.getRelatedOne("ReturnHeader"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetReturnHeaderFromItem", locale)); } String returnStatus = returnHeader.getString("statusId"); if (!returnStatus.equals("RETURN_CANCELLED")) { returnedQty += returnItem.getDouble("returnQuantity").doubleValue(); } } if (returnedQty < orderQty) { returnableQuantity = orderQty - returnedQty; } } } // get the returnable price now equals to orderItem.unitPrice, since adjustments are booked separately Map result = ServiceUtil.returnSuccess(); result.put("returnableQuantity", new Double(returnableQuantity)); result.put("returnablePrice", orderItem.get("unitPrice")); return result; } // get a map of returnable items (items not already returned) and quantities public static Map getReturnableItems(DispatchContext dctx, Map context) { LocalDispatcher dispatcher = dctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); String orderId = (String) context.get("orderId"); Locale locale = (Locale) context.get("locale"); GenericValue orderHeader = null; try { orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId)); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetReturnItemInformation", locale)); } Map returnable = new HashMap(); if (orderHeader != null) { List orderItems = null; try { orderItems = orderHeader.getRelatedByAnd("OrderItem", UtilMisc.toMap("statusId", "ITEM_COMPLETED")); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetReturnHeaderFromItem", locale)); } if (orderItems != null) { Iterator i = orderItems.iterator(); while (i.hasNext()) { GenericValue item = (GenericValue) i.next(); Map serviceResult = null; try { serviceResult = dispatcher.runSync("getReturnableQuantity", UtilMisc.toMap("orderItem", item)); } catch (GenericServiceException e) { Debug.logError(e, module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToGetTheItemReturnableQuantity", locale)); } if (serviceResult.containsKey(ModelService.ERROR_MESSAGE)) { return ServiceUtil.returnError((String) serviceResult.get(ModelService.ERROR_MESSAGE)); } else { Map returnInfo = new HashMap(); // first the return info (quantity/price) returnInfo.put("returnableQuantity", serviceResult.get("returnableQuantity")); returnInfo.put("returnablePrice", serviceResult.get("returnablePrice")); // now the product type information String itemTypeKey = "FINISHED_GOOD"; // default item type (same as invoice) GenericValue product = null; if (item.get("productId") != null) { try { product = item.getRelatedOne("Product"); } catch (GenericEntityException e) { Debug.logError(e, module); return ServiceUtil.returnError("Unable to obtain order item information!"); } } if (product != null) { itemTypeKey = product.getString("productTypeId"); } else if (item != null) { itemTypeKey = item.getString("orderItemTypeId"); } returnInfo.put("itemTypeKey", itemTypeKey); returnable.put(item, returnInfo); } } } else { return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorNoOrderItemsFound", locale)); } } else { return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorUnableToFindOrderHeader", locale)); } Map result = ServiceUtil.returnSuccess(); result.put("returnableItems", returnable); return result; } // check return items status and update return header status public static Map checkReturnComplete(DispatchContext dctx, Map context) { //appears to not be used: LocalDispatcher dispatcher = ctx.getDispatcher(); GenericDelegator delegator = dctx.getDelegator(); String returnId = (String) context.get("returnId"); Locale locale = (Locale) context.get("locale"); GenericValue returnHeader = null; List returnItems = null; try { returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId)); if (returnHeader != null) { returnItems = returnHeader.getRelated("ReturnItem"); } } catch (GenericEntityException e) { Debug.logError(e, "Problems looking up return information", module); return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorGettingReturnHeaderItemInformation", locale)); } // if already completed just return if (returnHeader != null && returnHeader.get("statusId") != null) { String currentStatus = returnHeader.getString("statusId"); if ("RETURN_COMPLETED".equals(currentStatus) || "RETURN_CANCELLED".equals(currentStatus)) { return ServiceUtil.returnSuccess(); } } // now; to be used for all timestamps Timestamp now = UtilDateTime.nowTimestamp(); List completedItems = new ArrayList(); if (returnHeader != null && returnItems != null && returnItems.size() > 0) { Iterator itemsIter = returnItems.iterator(); while (itemsIter.hasNext()) { GenericValue item = (GenericValue) itemsIter.next(); String itemStatus = item != null ? item.getString("statusId") : null; if (itemStatus != null) { // both completed and cancelled items qualify for completed status change if ("RETURN_COMPLETED".equals(itemStatus) || "RETURN_CANCELLED".equals(itemStatus)) { completedItems.add(item); } } } // if all items are completed/cancelled these should match if (completedItems.size() == returnItems.size()) { List toStore = new LinkedList(); returnHeader.set("statusId", "RETURN_COMPLETED"); toStore.add(returnHeader); // create the status change history and set it to be stored String returnStatusId = delegator.getNextSeqId("ReturnStatus").toString();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -