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

📄 orderreadhelper.java

📁 国外的一套开源CRM
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                            if (virtual != null) {
                                weight = virtual.getDouble("weight");
                            }
                        }

                        if (weight != null) {
                            shippableWeight += weight.doubleValue();
                        }
                    }
                }
            }
        }
        return shippableWeight;
    }

    public List getShippableSizes() {
        GenericDelegator delegator = orderHeader.getDelegator();
        List shippableSizes = new LinkedList();

        List validItems = getValidOrderItems();
        if (validItems != null) {
            Iterator i = validItems.iterator();
            while (i.hasNext()) {
                GenericValue item = (GenericValue) i.next();
                GenericValue product = null;
                try {
                    product = item.getRelatedOne("Product");
                } catch (GenericEntityException e) {
                    Debug.logError(e, "Problem getting Product from OrderItem", module);
                    return shippableSizes;
                }
                if (product != null) {
                    if (ProductWorker.shippingApplies(product)) {
                        Double height = product.getDouble("productHeight");
                        Double width = product.getDouble("productWidth");
                        Double depth = product.getDouble("productDepth");
                        String isVariant = product.getString("isVariant");
                        if (height == null && width == null && depth == null && isVariant != null && "Y".equals(isVariant)) {
                            // get the virtual product and check its values
                            GenericValue virtual = null;
                            try {
                                List virtuals = delegator.findByAnd("ProductAssoc", UtilMisc.toMap("productIdTo", product.getString("productId"), "productAssocTypeId", "PRODUCT_VARIENT"), UtilMisc.toList("-fromDate"));
                                if (virtuals != null) {
                                    virtuals = EntityUtil.filterByDate(virtuals);
                                }
                                virtual = EntityUtil.getFirst(virtuals);
                            } catch (GenericEntityException e) {
                                Debug.logError(e, "Problem getting virtual product");
                            }
                            if (virtual != null) {
                                height = virtual.getDouble("productHeight");
                                width = virtual.getDouble("productWidth");
                                depth = virtual.getDouble("productDepth");
                            }
                        }

                        if (height == null) height = new Double(0);
                        if (width == null) width = new Double(0);
                        if (depth == null) depth = new Double(0);
                        shippableSizes.add(new Double(height.doubleValue() * width.doubleValue() * depth.doubleValue()));
                    }
                }
            }
        }
        return shippableSizes;
    }

    public String getOrderEmailString() {
        GenericDelegator delegator = orderHeader.getDelegator();
        // get the email addresses from the order contact mech(s)
        List orderContactMechs = null;
        try {
            Map ocFields = UtilMisc.toMap("orderId", orderHeader.get("orderId"), "contactMechPurposeTypeId", "ORDER_EMAIL");
            orderContactMechs = delegator.findByAnd("OrderContactMech", ocFields);
        } catch (GenericEntityException e) {
            Debug.logWarning(e, "Problems getting order contact mechs", module);
        }

        StringBuffer emails = new StringBuffer();
        if (orderContactMechs != null) {
            Iterator oci = orderContactMechs.iterator();
            while (oci.hasNext()) {
                try {
                    GenericValue orderContactMech = (GenericValue) oci.next();
                    GenericValue contactMech = orderContactMech.getRelatedOne("ContactMech");
                    emails.append(emails.length() > 0 ? "," : "").append(contactMech.getString("infoString"));
                } catch (GenericEntityException e) {
                    Debug.logWarning(e, "Problems getting contact mech from order contact mech", module);
                }
            }
        }
        return emails.toString();
    }

    public double getOrderGrandTotal() {
        if (totalPrice == null) {
            totalPrice = new Double(getOrderGrandTotal(getValidOrderItems(), getAdjustments()));
        }// else already set
        return totalPrice.doubleValue();
    }

    public List getOrderHeaderAdjustments() {
        return getOrderHeaderAdjustments(getAdjustments());
    }

    public List getOrderHeaderAdjustmentsToShow() {
        return filterOrderAdjustments(getOrderHeaderAdjustments(), true, false, false, false, false);
    }

    public List getOrderHeaderStatuses() {
        return getOrderHeaderStatuses(getOrderStatuses());
    }

    public double getOrderAdjustmentsTotal() {
        return getOrderAdjustmentsTotal(getValidOrderItems(), getAdjustments());
    }

    public double getOrderAdjustmentTotal(GenericValue adjustment) {
        return calcOrderAdjustment(adjustment, getOrderItemsSubTotal());
    }

    // ========================================
    // ========== Order Item Methods ==========
    // ========================================

    public List getOrderItems() {
        if (orderItems == null) {
            try {
                orderItems = orderHeader.getRelated("OrderItem");
            } catch (GenericEntityException e) {
                Debug.logWarning(e, module);
            }
        }
        return (List) orderItems;
    }

    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 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) {
                    String productType = product.getString("productTypeId");
                    if ("DIGITAL_GOOD".equals(productType) || "FINDIG_GOOD".equals(productType)) {
                        // 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 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 getOrderItemInventoryReses(GenericValue orderItem) {
        if (orderItem == null) return null;
        if (this.orderItemInventoryReses == null) {
            GenericDelegator delegator = orderItem.getDelegator();

            try {
                orderItemInventoryReses = delegator.findByAnd("OrderItemInventoryRes", UtilMisc.toMap("orderId", orderItem.get("orderId")));
            } catch (GenericEntityException e) {
                Debug.logWarning(e, "Trouble getting OrderItemInventoryRes(s)", module);
            }
        }
        return EntityUtil.filterByAnd(orderItemInventoryReses, UtilMisc.toMap("orderItemSeqId", orderItem.getString("orderItemSeqId")));
    }

    public static List getOrderItemInventoryResFacilityIds(GenericValue orderHeader) {
        GenericDelegator delegator = orderHeader.getDelegator();
        List orderItems = null;
        List orderItemInventoryRes = new ArrayList();
        List result = new ArrayList();

        // filter for approved items only
        try {
            orderItems = delegator.findByAnd("OrderItem", UtilMisc.toMap("orderId", orderHeader.getString("orderId"), "statusId", "ITEM_APPROVED"));
        } catch (GenericEntityException e) {
            Debug.logError(e, "Cannot locate OrderItems from OrderHeader " + orderHeader.getString("orderId"), module);
        }
        if (UtilValidate.isNotEmpty(orderItems)) {
            Iterator oiIter = orderItems.iterator();
            GenericValue orderItem = null;
            List oiInventoryRes = null;

⌨️ 快捷键说明

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