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

📄 priceservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
                                if (productPriceAction.get("amount") != null) {                                    modifyAmount = defaultPrice * (productPriceAction.getDouble("amount").doubleValue() / 100.0);                                }                            } else if ("PRICE_POL".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                if (productPriceAction.get("amount") != null) {                                    modifyAmount = listPrice * (productPriceAction.getDouble("amount").doubleValue() / 100.0);                                }                            } else if ("PRICE_POAC".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                if (productPriceAction.get("amount") != null) {                                    modifyAmount = averageCost * (productPriceAction.getDouble("amount").doubleValue() / 100.0);                                }                            } else if ("PRICE_POM".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                if (productPriceAction.get("amount") != null) {                                    modifyAmount = margin * (productPriceAction.getDouble("amount").doubleValue() / 100.0);                                }                            } else if ("PRICE_FOL".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                if (productPriceAction.get("amount") != null) {                                    modifyAmount = productPriceAction.getDouble("amount").doubleValue();                                }                            } else if ("PRICE_FLAT".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                // this one is a bit different, break out of the loop because we now have our final price                                foundFlatOverride = true;                                if (productPriceAction.get("amount") != null) {                                    price = productPriceAction.getDouble("amount").doubleValue();                                } else {                                    Debug.logInfo("ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);                                    price = defaultPrice;                                    isSale = false;                // reverse isSale flag, as this sale rule was actually not applied                                }                            } else if ("PRICE_PFLAT".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                // this one is a bit different too, break out of the loop because we now have our final price                                foundFlatOverride = true;                                price = promoPrice;                                if (productPriceAction.get("amount") != null) {                                    price += productPriceAction.getDouble("amount").doubleValue();                                }                                if (price == 0.00) {                                    if (defaultPrice != 0.00) {                                        Debug.logInfo("PromoPrice and ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);                                        price = defaultPrice;                                    } else if (listPrice != 0.00) {                                        Debug.logInfo("PromoPrice and ProductPriceAction had null amount and no default price was available, using list price: " + listPrice + " for product with id " + productId, module);                                        price = listPrice;                                    } else {                                        Debug.logError("PromoPrice and ProductPriceAction had null amount and no default or list price was available, so price is set to zero for product with id " + productId, module);                                        price = 0.00;                                    }                                    isSale = false;                // reverse isSale flag, as this sale rule was actually not applied                                }                            } else if ("PRICE_WFLAT".equals(productPriceAction.getString("productPriceActionTypeId"))) {                                // same as promo price but using the wholesale price instead                                foundFlatOverride = true;                                price = wholesalePrice;                                if (productPriceAction.get("amount") != null) {                                    price += productPriceAction.getDouble("amount").doubleValue();                                }                                if (price == 0.00) {                                    if (defaultPrice != 0.00) {                                        Debug.logInfo("WholesalePrice and ProductPriceAction had null amount, using default price: " + defaultPrice + " for product with id " + productId, module);                                        price = defaultPrice;                                    } else if (listPrice != 0.00) {                                        Debug.logInfo("WholesalePrice and ProductPriceAction had null amount and no default price was available, using list price: " + listPrice + " for product with id " + productId, module);                                        price = listPrice;                                    } else {                                        Debug.logError("WholesalePrice and ProductPriceAction had null amount and no default or list price was available, so price is set to zero for product with id " + productId, module);                                        price = 0.00;                                    }                                    isSale = false; // reverse isSale flag, as this sale rule was actually not applied                                }                            }                            // add a orderItemPriceInfo element too, without orderId or orderItemId                            StringBuffer priceInfoDescription = new StringBuffer();                            priceInfoDescription.append(condsDescription.toString());                            priceInfoDescription.append("[type:");                            priceInfoDescription.append(productPriceAction.getString("productPriceActionTypeId"));                            priceInfoDescription.append("]");                            GenericValue orderItemPriceInfo = delegator.makeValue("OrderItemPriceInfo", null);                            orderItemPriceInfo.set("productPriceRuleId", productPriceAction.get("productPriceRuleId"));                            orderItemPriceInfo.set("productPriceActionSeqId", productPriceAction.get("productPriceActionSeqId"));                            orderItemPriceInfo.set("modifyAmount", new Double(modifyAmount));                            // make sure description is <= than 250 chars                            String priceInfoDescriptionString = priceInfoDescription.toString();                            if (priceInfoDescriptionString.length() > 250) {                                priceInfoDescriptionString = priceInfoDescriptionString.substring(0, 250);                            }                            orderItemPriceInfo.set("description", priceInfoDescriptionString);                            orderItemPriceInfos.add(orderItemPriceInfo);                            if (foundFlatOverride) {                                break;                            } else {                                price += modifyAmount;                            }                        }                    }                    totalRules++;                    if (foundFlatOverride) {                        break;                    }                }                if (Debug.verboseOn()) {                    Debug.logVerbose("Unchecked Calculated price: " + price, module);                    Debug.logVerbose("PriceInfo:", module);                    Iterator orderItemPriceInfosIter = orderItemPriceInfos.iterator();                    while (orderItemPriceInfosIter.hasNext()) {                        GenericValue orderItemPriceInfo = (GenericValue) orderItemPriceInfosIter.next();                        Debug.logVerbose(" --- " + orderItemPriceInfo.toString(), module);                    }                }                // if no actions were run on the list price, then use the default price                if (totalActions == 0) {                    price = defaultPrice;                    // here we will leave validPriceFound as it was originally set for the defaultPrice since that is what we are setting the price to...                } else {                    // at least one price rule action was found, so we will consider it valid                    validPriceFound = true;                }                // ========= ensure calculated price is not below minSalePrice or above maxSalePrice =========                Double maxSellPrice = maximumPriceValue != null ? maximumPriceValue.getDouble("price") : null;                if (maxSellPrice != null && price > maxSellPrice.doubleValue()) {                    price = maxSellPrice.doubleValue();                }                // min price second to override max price, safety net                Double minSellPrice = minimumPriceValue != null ? minimumPriceValue.getDouble("price") : null;                if (minSellPrice != null && price < minSellPrice.doubleValue()) {                    price = minSellPrice.doubleValue();                    // since we have found a minimum price that has overriden a the defaultPrice, even if no valid one was found, we will consider it as if one had been...                    validPriceFound = true;                }                if (Debug.verboseOn()) Debug.logVerbose("Final Calculated price: " + price + ", rules: " + totalRules + ", conds: " + totalConds + ", actions: " + totalActions, module);                result.put("basePrice", new Double(price));                result.put("price", new Double(price));                result.put("listPrice", new Double(listPrice));                result.put("defaultPrice", new Double(defaultPrice));                result.put("averageCost", new Double(averageCost));            } catch (GenericEntityException e) {                Debug.logError(e, "Error getting rules from the database while calculating price", module);                return ServiceUtil.returnError("Error getting rules from the database while calculating price: " + e.toString());            }        }        result.put("competitivePrice", competitivePriceValue != null ? competitivePriceValue.getDouble("price") : null);        result.put("specialPromoPrice", specialPromoPriceValue != null ? specialPromoPriceValue.getDouble("price") : null);        result.put("orderItemPriceInfos", orderItemPriceInfos);        result.put("isSale", new Boolean(isSale));        result.put("validPriceFound", new Boolean(validPriceFound));        result.put("currencyUsed", currencyUomId);        // okay, now we have the calculated price, see if we should add in tax and if so do it        if ("Y".equals(checkIncludeVat) && productStore != null && "Y".equals(productStore.getString("showPricesWithVatTax"))) {            Map calcTaxForDisplayContext = UtilMisc.toMap("productStoreId", productStoreId,                     "productId", productId, "quantity", new BigDecimal(quantity),                     "basePrice", new BigDecimal(((Double) result.get("price")).doubleValue()));            if (UtilValidate.isNotEmpty(partyId)) {                calcTaxForDisplayContext.put("billToPartyId", partyId);            }                        try {                Map calcTaxForDisplayResult = dispatcher.runSync("calcTaxForDisplay", calcTaxForDisplayContext);                if (ServiceUtil.isError(calcTaxForDisplayResult)) {                    return ServiceUtil.returnError("Error calculating VAT tax (with calcTaxForDisplay service)", null, null, calcTaxForDisplayResult);                }                // taxTotal, taxPercentage, priceWithTax                result.put("price", new Double(((BigDecimal) calcTaxForDisplayResult.get("priceWithTax")).doubleValue()));                // based on the taxPercentage calculate the other amounts, including: listPrice, defaultPrice, averageCost, promoPrice, competitivePrice                BigDecimal taxPercentage = (BigDecimal) calcTaxForDisplayResult.get("taxPercentage");                BigDecimal taxMultiplier = ONE_BASE.add(taxPercentage.divide(PERCENT_SCALE, 3));                if (result.get("listPrice") != null) result.put("listPrice", new Double((new BigDecimal (((Double) result.get("listPrice")).doubleValue())).multiply(taxMultiplier).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));                if (result.get("defaultPrice") != null) result.put("defaultPrice", new Double((new BigDecimal (((Double) result.get("defaultPrice")).doubleValue())).multiply(taxMultiplier).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));                if (result.get("averageCost") != null) result.put("averageCost", new Double((new BigDecimal (((Double) result.get("averageCost")).doubleValue())).multiply(taxMultiplier).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));                                if (result.get("promoPrice") != null) result.put("promoPrice", new Double((new BigDecimal (((Double) result.get("promoPrice")).doubleValue())).multiply(taxMultiplier).setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue()));                if (result.get("competi

⌨️ 快捷键说明

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