📄 orderreadhelper.java
字号:
} public List getOrderItemAndShipGroupAssoc(String shipGroupSeqId) { List exprs = UtilMisc.toList(new EntityExpr("shipGroupSeqId", EntityOperator.EQUALS, shipGroupSeqId)); return EntityUtil.filterByAnd(getOrderItemAndShipGroupAssoc(), exprs); } public List getValidOrderItems() { List exprs = UtilMisc.toList( new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED"), new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED")); return EntityUtil.filterByAnd(getOrderItems(), exprs); } public List getValidOrderItems(String shipGroupSeqId) { if (shipGroupSeqId == null) return getValidOrderItems(); List exprs = UtilMisc.toList( new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ITEM_CANCELLED"), new EntityExpr("statusId", EntityOperator.NOT_EQUAL, "ITEM_REJECTED"), new EntityExpr("shipGroupSeqId", EntityOperator.EQUALS, shipGroupSeqId)); return EntityUtil.filterByAnd(getOrderItemAndShipGroupAssoc(), exprs); } public GenericValue getOrderItem(String orderItemSeqId) { List exprs = UtilMisc.toList(new EntityExpr("orderItemSeqId", EntityOperator.EQUALS, orderItemSeqId)); return EntityUtil.getFirst(EntityUtil.filterByAnd(getOrderItems(), exprs)); } public List getValidDigitalItems() { List digitalItems = new ArrayList(); // only approved or complete items apply List exprs = UtilMisc.toList( new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_APPROVED"), new EntityExpr("statusId", EntityOperator.EQUALS, "ITEM_COMPLETED")); List items = EntityUtil.filterByOr(getOrderItems(), exprs); Iterator i = items.iterator(); while (i.hasNext()) { GenericValue item = (GenericValue) i.next(); if (item.get("productId") != null) { GenericValue product = null; try { product = item.getRelatedOne("Product"); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get Product from OrderItem", module); } if (product != null) { GenericValue productType = null; try { productType = product.getRelatedOne("ProductType"); } catch (GenericEntityException e) { Debug.logError(e, "ERROR: Unable to get ProductType from Product", module); } if (productType != null) { String isDigital = productType.getString("isDigital"); if (isDigital != null && "Y".equalsIgnoreCase(isDigital)) { // make sure we have an OrderItemBilling record List orderItemBillings = null; try { orderItemBillings = item.getRelated("OrderItemBilling"); } catch (GenericEntityException e) { Debug.logError(e, "Unable to get OrderItemBilling from OrderItem"); } if (orderItemBillings != null && orderItemBillings.size() > 0) { // get the ProductContent records List productContents = null; try { productContents = product.getRelated("ProductContent"); } catch (GenericEntityException e) { Debug.logError("Unable to get ProductContent from Product", module); } List cExprs = UtilMisc.toList( new EntityExpr("productContentTypeId", EntityOperator.EQUALS, "DIGITAL_DOWNLOAD"), new EntityExpr("productContentTypeId", EntityOperator.EQUALS, "FULFILLMENT_EMAIL"), new EntityExpr("productContentTypeId", EntityOperator.EQUALS, "FULFILLMENT_EXTERNAL")); // add more as needed productContents = EntityUtil.filterByDate(productContents); productContents = EntityUtil.filterByOr(productContents, cExprs); if (productContents != null && productContents.size() > 0) { // make sure we are still within the allowed timeframe and use limits Iterator pci = productContents.iterator(); while (pci.hasNext()) { GenericValue productContent = (GenericValue) pci.next(); Timestamp fromDate = productContent.getTimestamp("purchaseFromDate"); Timestamp thruDate = productContent.getTimestamp("purchaseThruDate"); if (fromDate == null || item.getTimestamp("orderDate").after(fromDate)) { if (thruDate == null || item.getTimestamp("orderDate").before(thruDate)) { // TODO: Implement use count and days digitalItems.add(item); } } } } } } } } } } return digitalItems; } public List getOrderItemAdjustments(GenericValue orderItem) { return getOrderItemAdjustmentList(orderItem, getAdjustments()); } public String getCurrentOrderItemWorkEffort(GenericValue orderItem) { GenericValue workOrderItemFulFillment; try { workOrderItemFulFillment = orderItem.getRelatedOne("WorkOrderItemFulFillment"); } catch (GenericEntityException e) { return null; } GenericValue workEffort = null; try { workEffort = workOrderItemFulFillment.getRelatedOne("WorkEffort"); } catch (GenericEntityException e) { return null; } return workEffort.getString("workEffortId"); } public String getCurrentItemStatus(GenericValue orderItem) { GenericValue statusItem = null; try { statusItem = orderItem.getRelatedOne("StatusItem"); } catch (GenericEntityException e) { Debug.logError(e, "Trouble getting StatusItem : " + orderItem, module); } if (statusItem == null || statusItem.get("description") == null) { return "Not Available"; } else { return statusItem.getString("description"); } } public List getOrderItemPriceInfos(GenericValue orderItem) { if (orderItem == null) return null; if (this.orderItemPriceInfos == null) { GenericDelegator delegator = orderHeader.getDelegator(); try { orderItemPriceInfos = delegator.findByAnd("OrderItemPriceInfo", UtilMisc.toMap("orderId", orderHeader.get("orderId"))); } catch (GenericEntityException e) { Debug.logWarning(e, module); } } String orderItemSeqId = (String) orderItem.get("orderItemSeqId"); return EntityUtil.filterByAnd(this.orderItemPriceInfos, UtilMisc.toMap("orderItemSeqId", orderItemSeqId)); } public List getOrderItemShipGroupAssocs(GenericValue orderItem) { if (orderItem == null) return null; try { return orderHeader.getDelegator().findByAnd("OrderItemShipGroupAssoc", UtilMisc.toMap("orderId", orderItem.getString("orderId"), "orderItemSeqId", orderItem.getString("orderItemSeqId")), UtilMisc.toList("shipGroupSeqId")); } catch (GenericEntityException e) { Debug.logWarning(e, module); } return null; } public List getOrderItemShipGrpInvResList(GenericValue orderItem) { if (orderItem == null) return null; if (this.orderItemShipGrpInvResList == null) { GenericDelegator delegator = orderItem.getDelegator(); try { orderItemShipGrpInvResList = delegator.findByAnd("OrderItemShipGrpInvRes", UtilMisc.toMap("orderId", orderItem.get("orderId"))); } catch (GenericEntityException e) { Debug.logWarning(e, "Trouble getting OrderItemShipGrpInvRes List", module); } } return EntityUtil.filterByAnd(orderItemShipGrpInvResList, UtilMisc.toMap("orderItemSeqId", orderItem.getString("orderItemSeqId"))); } public List getOrderItemIssuances(GenericValue orderItem) { return this.getOrderItemIssuances(orderItem, null); } public List getOrderItemIssuances(GenericValue orderItem, String shipmentId) { if (orderItem == null) return null; if (this.orderItemIssuances == null) { GenericDelegator delegator = orderItem.getDelegator(); try { orderItemIssuances = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("orderId", orderItem.get("orderId"))); } catch (GenericEntityException e) { Debug.logWarning(e, "Trouble getting ItemIssuance(s)", module); } } // filter the issuances Map filter = UtilMisc.toMap("orderItemSeqId", orderItem.get("orderItemSeqId")); if (shipmentId != null) { filter.put("shipmentId", shipmentId); } return EntityUtil.filterByAnd(orderItemIssuances, filter); } public List getOrderReturnItems() { GenericDelegator delegator = orderHeader.getDelegator(); if (this.orderReturnItems == null) { try { this.orderReturnItems = delegator.findByAnd("ReturnItem", UtilMisc.toMap("orderId", orderHeader.getString("orderId"))); } catch (GenericEntityException e) { Debug.logError(e, "Problem getting ReturnItem from order", module); return null; } } return this.orderReturnItems; } /** * Get the quantity returned per order item. * In other words, this method will count the ReturnItems * related to each OrderItem. * * @return Map of returned quantities as Doubles keyed to the orderItemSeqId */ public Map getOrderItemReturnedQuantities() { List returnItems = getOrderReturnItems(); // since we don't have a handy grouped view entity, we'll have to group the return items by hand Map returnMap = new HashMap(); for (Iterator iter = this.getValidOrderItems().iterator(); iter.hasNext(); ) { GenericValue orderItem = (GenericValue) iter.next(); List group = EntityUtil.filterByAnd(returnItems, UtilMisc.toMap("orderId", orderItem.get("orderId"), "orderItemSeqId", orderItem.get("orderItemSeqId"))); // add up the returned quantities for this group TODO: received quantity should be used eventually double returned = 0; for (Iterator groupiter = group.iterator(); groupiter.hasNext(); ) { GenericValue returnItem = (GenericValue) groupiter.next(); if (returnItem.getDouble("returnQuantity") != null) { returned += ((Double) returnItem.getDouble("returnQuantity")).doubleValue(); } } // the quantity returned per order item returnMap.put(orderItem.get("orderItemSeqId"), new Double(returned)); } return returnMap; } /** * Get the total quantity of returned items for an order. This will count * only the ReturnItems that are directly correlated to an OrderItem. */ public BigDecimal getOrderReturnedQuantityBd() { List returnedItemsBase = getOrderReturnItems(); List returnedItems = new ArrayList(returnedItemsBase.size()); // filter just order items List orderItemExprs = UtilMisc.toList(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_PROD_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_FPROD_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_DPROD_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_FDPROD_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_PROD_FEATR_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_SPROD_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_WE_ITEM")); orderItemExprs.add(new EntityExpr("returnItemTypeId", EntityOperator.EQUALS, "RET_TE_ITEM")); returnedItemsBase = EntityUtil.filterByOr(returnedItemsBase, orderItemExprs); // get only the RETURN_RECEIVED and RETURN_COMPLETED statusIds returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_RECEIVED"))); returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED"))); BigDecimal returnedQuantity = ZERO; if (returnedItems != null) { Iterator i = returnedItems.iterator(); while (i.hasNext()) { GenericValue returnedItem = (GenericValue) i.next(); if (returnedItem.get("returnQuantity") != null) { returnedQuantity = returnedQuantity.add(returnedItem.getBigDecimal("returnQuantity")).setScale(scale, rounding); } } } return returnedQuantity.setScale(scale, rounding); } /** @deprecated */ public double getOrderReturnedQuantity() { return getOrderReturnedQuantityBd().doubleValue(); } public BigDecimal getOrderReturnedTotalBd() { return getOrderReturnedTotalBd(false); } /** @deprecated */ public double getOrderReturnedTotal() { return getOrderReturnedTotalBd().doubleValue(); } public BigDecimal getOrderReturnedTotalBd(boolean includeAll) { List returnedItemsBase = getOrderReturnItems(); List returnedItems = new ArrayList(returnedItemsBase.size()); // get only the RETURN_RECEIVED and RETURN_COMPLETED statusIds if (!includeAll) { returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_RECEIVED"))); returnedItems.addAll(EntityUtil.filterByAnd(returnedItemsBase, UtilMisc.toMap("statusId", "RETURN_COMPLETED")));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -