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

📄 priceservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: PriceServices.java 7275 2006-04-11 08:59:24Z jonesde $ * *  Copyright (c) 2001-2005 The Open For Business Project - www.ofbiz.org * *  Permission is hereby granted, free of charge, to any person obtaining a *  copy of this software and associated documentation files (the "Software"), *  to deal in the Software without restriction, including without limitation *  the rights to use, copy, modify, merge, publish, distribute, sublicense, *  and/or sell copies of the Software, and to permit persons to whom the *  Software is furnished to do so, subject to the following conditions: * *  The above copyright notice and this permission notice shall be included *  in all copies or substantial portions of the Software. * *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY *  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT *  OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *  THE USE OR OTHER DEALINGS IN THE SOFTWARE. */package org.ofbiz.product.price;import java.math.BigDecimal;import java.sql.Timestamp;import java.util.Collection;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.TreeSet;import javolution.util.FastList;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.product.ProductWorker;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ServiceUtil;/** * PriceServices - Workers and Services class for product price related functionality * * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 7275 $ * @since      2.0 */public class PriceServices {    public static final String module = PriceServices.class.getName();    public static final BigDecimal ONE_BASE = new BigDecimal("1.000");     public static final BigDecimal PERCENT_SCALE = new BigDecimal("100.000");     /**     * <p>Calculates the price of a product from pricing rules given the following input, and of course access to the database:</p>     * <ul>     *   <li>productId     *   <li>partyId     *   <li>prodCatalogId     *   <li>webSiteId     *   <li>productStoreId     *   <li>productStoreGroupId     *   <li>quantity     *   <li>currencyUomId     *   <li>checkIncludeVat     * </ul>     */    public static Map calculateProductPrice(DispatchContext dctx, Map context) {        boolean optimizeForLargeRuleSet = false;        // UtilTimer utilTimer = new UtilTimer();        // utilTimer.timerString("Starting price calc", module);        // utilTimer.setLog(false);        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        Map result = new HashMap();        Timestamp nowTimestamp = UtilDateTime.nowTimestamp();        boolean isSale = false;        List orderItemPriceInfos = new LinkedList();        GenericValue product = (GenericValue) context.get("product");        String productId = product.getString("productId");        String prodCatalogId = (String) context.get("prodCatalogId");        String webSiteId = (String) context.get("webSiteId");        String checkIncludeVat = (String) context.get("checkIncludeVat");        String productStoreId = (String) context.get("productStoreId");        String productStoreGroupId = (String) context.get("productStoreGroupId");        GenericValue productStore = null;        try {            // we have a productStoreId, if the corresponding ProductStore.primaryStoreGroupId is not empty, use that            productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));        } catch (GenericEntityException e) {            String errMsg = "Error getting product store info from the database while calculating price" + e.toString();            Debug.logError(e, errMsg, module);            return ServiceUtil.returnError(errMsg);        }        if (UtilValidate.isEmpty(productStoreGroupId)) {            if (productStore != null) {                try {                    if (UtilValidate.isNotEmpty(productStore.getString("primaryStoreGroupId"))) {                        productStoreGroupId = productStore.getString("primaryStoreGroupId");                    } else {                        // no ProductStore.primaryStoreGroupId, try ProductStoreGroupMember                        List productStoreGroupMemberList = delegator.findByAndCache("ProductStoreGroupMember", UtilMisc.toMap("productStoreId", productStoreId), UtilMisc.toList("sequenceNum", "-fromDate"));                        productStoreGroupMemberList = EntityUtil.filterByDate(productStoreGroupMemberList, true);                        if (productStoreGroupMemberList.size() > 0) {                            GenericValue productStoreGroupMember = EntityUtil.getFirst(productStoreGroupMemberList);                            productStoreGroupId = productStoreGroupMember.getString("productStoreGroupId");                        }                    }                } catch (GenericEntityException e) {                    String errMsg = "Error getting product store info from the database while calculating price" + e.toString();                    Debug.logError(e, errMsg, module);                    return ServiceUtil.returnError(errMsg);                }            }            // still empty, default to _NA_            if (UtilValidate.isEmpty(productStoreGroupId)) {                productStoreGroupId = "_NA_";            }        }                // if currencyUomId is null get from properties file, if nothing there assume USD (USD: American Dollar) for now        String currencyUomId = (String) context.get("currencyUomId");        if (UtilValidate.isEmpty(currencyUomId)) {            currencyUomId = UtilProperties.getPropertyValue("general", "currency.uom.id.default", "USD");        }        // productPricePurposeId is null assume "PURCHASE", which is equivalent to what prices were before the purpose concept        String productPricePurposeId = (String) context.get("productPricePurposeId");        if (UtilValidate.isEmpty(productPricePurposeId)) {            productPricePurposeId = "PURCHASE";        }                // termUomId, for things like recurring prices specifies the term (time/frequency measure for example) of the recurrence        // if this is empty it will simply not be used to constrain the selection        String termUomId = (String) context.get("termUomId");        // if this product is variant, find the virtual product and apply checks to it as well        String virtualProductId = null;        if ("Y".equals(product.getString("isVariant"))) {            try {                virtualProductId = ProductWorker.getVariantVirtualId(product);            } catch (GenericEntityException e) {                String errMsg = "Error getting virtual product id from the database while calculating price" + e.toString();                Debug.logError(e, errMsg, module);                return ServiceUtil.returnError(errMsg);            }        }        // get prices for virtual product if one is found; get all ProductPrice entities for this productId and currencyUomId        List virtualProductPrices = null;        if (virtualProductId != null) {            try {                virtualProductPrices = delegator.findByAndCache("ProductPrice", UtilMisc.toMap("productId", virtualProductId, "currencyUomId", currencyUomId, "productStoreGroupId", productStoreGroupId), UtilMisc.toList("-fromDate"));            } catch (GenericEntityException e) {                Debug.logError(e, "An error occurred while getting the product prices", module);            }            virtualProductPrices = EntityUtil.filterByDate(virtualProductPrices, true);        }        // NOTE: partyId CAN be null        String partyId = (String) context.get("partyId");        if (UtilValidate.isEmpty(partyId) && context.get("userLogin") != null) {            GenericValue userLogin = (GenericValue) context.get("userLogin");            partyId = userLogin.getString("partyId");        }        // check for auto-userlogin for price rules

⌨️ 快捷键说明

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