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

📄 priceservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        if (UtilValidate.isEmpty(partyId) && context.get("autoUserLogin") != null) {            GenericValue userLogin = (GenericValue) context.get("autoUserLogin");            partyId = userLogin.getString("partyId");        }        Double quantityDbl = (Double) context.get("quantity");        if (quantityDbl == null) quantityDbl = new Double(1.0);        double quantity = quantityDbl.doubleValue();                List productPriceEcList = FastList.newInstance();        productPriceEcList.add(new EntityExpr("productId", EntityOperator.EQUALS, productId));        // this funny statement is for backward compatibility purposes; the productPricePurposeId is a new pk field on the ProductPrice entity and in order databases may not be populated, until the pk is updated and such; this will ease the transition somewhat         if ("PURCHASE".equals(productPricePurposeId)) {            productPriceEcList.add(new EntityExpr(                    new EntityExpr("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId),                     EntityOperator.OR,                     new EntityExpr("productPricePurposeId", EntityOperator.EQUALS, null)));        } else {            productPriceEcList.add(new EntityExpr("productPricePurposeId", EntityOperator.EQUALS, productPricePurposeId));        }        productPriceEcList.add(new EntityExpr("currencyUomId", EntityOperator.EQUALS, currencyUomId));        productPriceEcList.add(new EntityExpr("productStoreGroupId", EntityOperator.EQUALS, productStoreGroupId));        if (UtilValidate.isNotEmpty(termUomId)) {            productPriceEcList.add(new EntityExpr("termUomId", EntityOperator.EQUALS, termUomId));        }        EntityCondition productPriceEc = new EntityConditionList(productPriceEcList, EntityOperator.AND);        // for prices, get all ProductPrice entities for this productId and currencyUomId        List productPrices = null;        try {            productPrices = delegator.findByConditionCache("ProductPrice", productPriceEc, null, UtilMisc.toList("-fromDate"));        } catch (GenericEntityException e) {            Debug.logError(e, "An error occurred while getting the product prices", module);        }        productPrices = EntityUtil.filterByDate(productPrices, true);        // ===== get the prices we need: list, default, average cost, promo, min, max =====        List listPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE"));        GenericValue listPriceValue = EntityUtil.getFirst(listPrices);        if (listPrices != null && listPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module);        }        List defaultPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));        GenericValue defaultPriceValue = EntityUtil.getFirst(defaultPrices);        if (defaultPrices != null && defaultPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module);        }        List competitivePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "COMPETITIVE_PRICE"));        GenericValue competitivePriceValue = EntityUtil.getFirst(competitivePrices);        if (competitivePrices != null && competitivePrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one COMPETITIVE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + competitivePriceValue.getDouble("price"), module);        }        List averageCosts = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST"));        GenericValue averageCostValue = EntityUtil.getFirst(averageCosts);        if (averageCosts != null && averageCosts.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module);        }        List promoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE"));        GenericValue promoPriceValue = EntityUtil.getFirst(promoPrices);        if (promoPrices != null && promoPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module);        }        List minimumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE"));        GenericValue minimumPriceValue = EntityUtil.getFirst(minimumPrices);        if (minimumPrices != null && minimumPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module);        }        List maximumPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE"));        GenericValue maximumPriceValue = EntityUtil.getFirst(maximumPrices);        if (maximumPrices != null && maximumPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module);        }        List wholesalePrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE"));        GenericValue wholesalePriceValue = EntityUtil.getFirst(wholesalePrices);        if (wholesalePrices != null && wholesalePrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);        }        List specialPromoPrices = EntityUtil.filterByAnd(productPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE"));        GenericValue specialPromoPriceValue = EntityUtil.getFirst(specialPromoPrices);        if (specialPromoPrices != null && specialPromoPrices.size() > 1) {            if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + productId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module);        }        // if any of these prices is missing and this product is a variant, default to the corresponding price on the virtual product        if (virtualProductPrices != null && virtualProductPrices.size() > 0) {            if (listPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "LIST_PRICE"));                listPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one LIST_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + listPriceValue.getDouble("price"), module);                }            }            if (defaultPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));                defaultPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one DEFAULT_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + defaultPriceValue.getDouble("price"), module);                }            }            if (averageCostValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "AVERAGE_COST"));                averageCostValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one AVERAGE_COST with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + averageCostValue.getDouble("price"), module);                }            }            if (promoPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "PROMO_PRICE"));                promoPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + promoPriceValue.getDouble("price"), module);                }            }            if (minimumPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MINIMUM_PRICE"));                minimumPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one MINIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + minimumPriceValue.getDouble("price"), module);                }            }            if (maximumPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "MAXIMUM_PRICE"));                maximumPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one MAXIMUM_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + maximumPriceValue.getDouble("price"), module);                }            }            if (wholesalePriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "WHOLESALE_PRICE"));                wholesalePriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one WHOLESALE_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + wholesalePriceValue.getDouble("price"), module);                }            }            if (specialPromoPriceValue == null) {                List virtualTempPrices = EntityUtil.filterByAnd(virtualProductPrices, UtilMisc.toMap("productPriceTypeId", "SPECIAL_PROMO_PRICE"));                specialPromoPriceValue = EntityUtil.getFirst(virtualTempPrices);                if (virtualTempPrices != null && virtualTempPrices.size() > 1) {                    if (Debug.infoOn()) Debug.logInfo("There is more than one SPECIAL_PROMO_PRICE with the currencyUomId " + currencyUomId + " and productId " + virtualProductId + ", using the latest found with price: " + specialPromoPriceValue.getDouble("price"), module);                }            }        }        // now if this is a virtual product check each price type, if doesn't exist get from variant with lowest DEFAULT_PRICE        if ("Y".equals(product.getString("isVirtual"))) {            // only do this if there is no default price, consider the others optional for performance reasons            if (defaultPriceValue == null) {                // Debug.logInfo("Product isVirtual and there is no default price for ID " + productId + ", trying variant prices", module);                //use the cache to find the variant with the lowest default price                try {                    List variantAssocList = EntityUtil.filterByDate(delegator.findByAndCache("ProductAssoc", UtilMisc.toMap("productId", product.get("productId"), "productAssocTypeId", "PRODUCT_VARIANT"), UtilMisc.toList("-fromDate")));                    Iterator variantAssocIter = variantAssocList.iterator();                    double minDefaultPrice = Double.MAX_VALUE;                    List variantProductPrices = null;                    String variantProductId = null;                    while (variantAssocIter.hasNext()) {                        GenericValue variantAssoc = (GenericValue) variantAssocIter.next();                        String curVariantProductId = variantAssoc.getString("productIdTo");                        List curVariantPriceList = EntityUtil.filterByDate(delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", curVariantProductId), UtilMisc.toList("-fromDate")), nowTimestamp);                        List tempDefaultPriceList = EntityUtil.filterByAnd(curVariantPriceList, UtilMisc.toMap("productPriceTypeId", "DEFAULT_PRICE"));                        GenericValue curDefaultPriceValue = EntityUtil.getFirst(tempDefaultPriceList);                        if (curDefaultPriceValue != null) {                            Double curDefaultPrice = curDefaultPriceValue.getDouble("price");                            if (curDefaultPrice.doubleValue() < minDefaultPrice) {                                // check to see if the product is discontinued for sale before considering it the lowest price                                GenericValue curVariantProduct = delegator.findByPrimaryKeyCache("Product", UtilMisc.toMap("productId", curVariantProductId));                                if (curVariantProduct != null) {                                    Timestamp salesDiscontinuationDate = curVariantProduct.getTimestamp("salesDiscontinuationDate");                                    if (salesDiscontinuationDate == null || salesDiscontinuationDate.after(nowTimestamp)) {                                        minDefaultPrice = curDefaultPrice.doubleValue();                                        variantProductPrices = curVariantPriceList;                                        variantProductId = curVariantProductId;                                        // Debug.logInfo("Found new lowest price " + minDefaultPrice + " for variant with ID " + variantProductId, module);                                    }                                }                            }                        }                    }                    if (variantProductPrices != null) {                        // we have some other options, give 'em a go...

⌨️ 快捷键说明

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