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

📄 orderservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: OrderServices.java 7189 2006-04-04 18:57:49Z sichen $ * *  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.order.order;import java.math.BigDecimal;import java.sql.Timestamp;import java.text.NumberFormat;import java.text.ParseException;import java.util.*;import javolution.util.FastMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralException;import org.ofbiz.base.util.GeneralRuntimeException;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;import org.ofbiz.common.DataModelConstants;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.EntityListIterator;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.order.shoppingcart.CartItemModifyException;import org.ofbiz.order.shoppingcart.CheckOutHelper;import org.ofbiz.order.shoppingcart.ItemNotFoundException;import org.ofbiz.order.shoppingcart.ShoppingCart;import org.ofbiz.order.shoppingcart.ShoppingCartItem;import org.ofbiz.order.shoppingcart.shipping.ShippingEvents;import org.ofbiz.party.contact.ContactHelper;import org.ofbiz.party.party.PartyWorker;import org.ofbiz.product.catalog.CatalogWorker;import org.ofbiz.product.product.ProductContentWrapper;import org.ofbiz.product.product.ProductWorker;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.security.Security;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;import org.ofbiz.workflow.WfUtil;/** * Order Processing Services * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:cnelson@einnovation.com">Chris Nelson</a> * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @version    $Rev: 7189 $ * @since      2.0 */public class OrderServices {    public static final String module = OrderServices.class.getName();    public static final String resource = "OrderUiLabels";    public static final String resource_error = "OrderErrorUiLabels";    public static Map salesAttributeRoleMap = FastMap.newInstance();    public static Map purchaseAttributeRoleMap = FastMap.newInstance();    static {        salesAttributeRoleMap.put("placingCustomerPartyId", "PLACING_CUSTOMER");        salesAttributeRoleMap.put("billToCustomerPartyId", "BILL_TO_CUSTOMER");        salesAttributeRoleMap.put("billFromVendorPartyId", "BILL_FROM_VENDOR");        salesAttributeRoleMap.put("shipToCustomerPartyId", "SHIP_TO_CUSTOMER");        salesAttributeRoleMap.put("endUserCustomerPartyId", "END_USER_CUSTOMER");        purchaseAttributeRoleMap.put("billToCustomerPartyId", "BILL_TO_CUSTOMER");        purchaseAttributeRoleMap.put("billFromVendorPartyId", "BILL_FROM_VENDOR");        purchaseAttributeRoleMap.put("shipFromVendorPartyId", "SHIP_FROM_VENDOR");        purchaseAttributeRoleMap.put("supplierAgentPartyId", "SUPPLIER_AGENT");    }    /** Service for creating a new order */    public static Map createOrder(DispatchContext ctx, Map context) {        GenericDelegator delegator = ctx.getDelegator();        LocalDispatcher dispatcher = ctx.getDispatcher();        Security security = ctx.getSecurity();        List toBeStored = new LinkedList();        Locale locale = (Locale) context.get("locale");        Map successResult = ServiceUtil.returnSuccess();        GenericValue userLogin = (GenericValue) context.get("userLogin");        // get the order type        String orderTypeId = (String) context.get("orderTypeId");        String partyId = (String) context.get("partyId");        String billFromVendorPartyId = (String) context.get("billFromVendorPartyId");        // check security permissions for order:        //  SALES ORDERS - if userLogin has ORDERMGR_SALES_CREATE or ORDERMGR_CREATE permission, or if it is same party as the partyId, or        //                 if it is an AGENT (sales rep) creating an order for his customer        //  PURCHASE ORDERS - if there is a PURCHASE_ORDER permission        Map resultSecurity = new HashMap();        boolean hasPermission = false;        if (orderTypeId.equals("SALES_ORDER")) {            if (security.hasEntityPermission("ORDERMGR", "_SALES_CREATE", userLogin)) {                hasPermission = true;            } else {                // check sales agent/customer relationship                List repsCustomers = new LinkedList();                try {                    repsCustomers = EntityUtil.filterByDate(userLogin.getRelatedOne("Party").getRelatedByAnd("FromPartyRelationship",                            UtilMisc.toMap("roleTypeIdFrom", "AGENT", "roleTypeIdTo", "CUSTOMER", "partyIdTo", partyId)));                } catch (GenericEntityException ex) {                    Debug.logError("Could not determine if " + partyId + " is a customer of user " + userLogin.getString("userLoginId") + " due to " + ex.getMessage(), module);                }                if ((repsCustomers != null) && (repsCustomers.size() > 0) && (security.hasEntityPermission("SALESREP", "_ORDER_CREATE", userLogin))) {                    hasPermission = true;                }            }        } else if ((orderTypeId.equals("PURCHASE_ORDER") && (security.hasEntityPermission("ORDERMGR", "_PURCHASE_CREATE", userLogin)))) {            hasPermission = true;        }        // final check - will pass if userLogin's partyId = partyId for order or if userLogin has ORDERMGR_CREATE permission        if (!hasPermission) {            partyId = ServiceUtil.getPartyIdCheckSecurity(userLogin, security, context, resultSecurity, "ORDERMGR", "_CREATE");            if (resultSecurity.size() > 0) {                return resultSecurity;            }        }        // get the product store for the order, but it is required only for sales orders        String productStoreId = (String) context.get("productStoreId");        GenericValue productStore = null;        if ((orderTypeId.equals("SALES_ORDER")) && (UtilValidate.isNotEmpty(productStoreId))) {            try {                productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));            } catch (GenericEntityException e) {                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorCouldNotFindProductStoreWithID",UtilMisc.toMap("productStoreId",productStoreId),locale)  + e.toString());            }        }        // figure out if the order is immediately fulfilled based on product store settings        boolean isImmediatelyFulfilled = false;        if (productStore != null) {            isImmediatelyFulfilled = "Y".equals(productStore.getString("isImmediatelyFulfilled"));        }        successResult.put("orderTypeId", orderTypeId);        // lookup the order type entity        GenericValue orderType = null;        try {            orderType = delegator.findByPrimaryKeyCache("OrderType", UtilMisc.toMap("orderTypeId", orderTypeId));        } catch (GenericEntityException e) {            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorOrderTypeLookupFailed",locale) + e.toString());        }        // make sure we have a valid order type        if (orderType == null) {            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error,"OrderErrorInvalidOrderTypeWithID", UtilMisc.toMap("orderTypeId",orderTypeId), locale));        }        // check to make sure we have something to order        List orderItems = (List) context.get("orderItems");        if (orderItems.size() < 1) {            return ServiceUtil.returnError(UtilProperties.getMessage(resource, "items.none", locale));        }        // these need to be retrieved now because they might be needed for exploding MARKETING_PKG_AUTO        List orderAdjustments = (List) context.get("orderAdjustments");        List orderItemShipGroupInfo = (List) context.get("orderItemShipGroupInfo");        List orderItemPriceInfo = (List) context.get("orderItemPriceInfos");        // explode items which are MARKETINGG_PKG_AUTO        if (!orderTypeId.equals("PURCHASE_ORDER")) {            try {                explodeMarketingPkgAutoItem(orderItems, orderAdjustments, orderItemShipGroupInfo, orderItemPriceInfo, orderTypeId, delegator, dispatcher, locale);            } catch (Exception e) {               Debug.logError(e, "Error calling explodeMarketingPkgAutoItem " + e.getMessage(), module);               return ServiceUtil.returnError("Error on exploding marketing_pkg_auto item.[" + e.toString() + "]");            }        }        // check inventory and other things for each item        List errorMessages = new LinkedList();        Map normalizedItemQuantities = new HashMap();        Map normalizedItemNames = new HashMap();        Map itemValuesBySeqId = new HashMap();        Iterator itemIter = orderItems.iterator();        java.sql.Timestamp nowTimestamp = UtilDateTime.nowTimestamp();        //        // need to run through the items combining any cases where multiple lines refer to the        // same product so the inventory check will work correctly        // also count quantities ordered while going through the loop        while (itemIter.hasNext()) {            GenericValue orderItem = (GenericValue) itemIter.next();            // start by putting it in the itemValuesById Map            itemValuesBySeqId.put(orderItem.getString("orderItemSeqId"), orderItem);            String currentProductId = (String) orderItem.get("productId");            if (currentProductId != null) {                // only normalize items with a product associated (ignore non-product items)                if (normalizedItemQuantities.get(currentProductId) == null) {                    normalizedItemQuantities.put(currentProductId, new Double(orderItem.getDouble("quantity").doubleValue()));                    normalizedItemNames.put(currentProductId, new String(orderItem.getString("itemDescription")));                } else {                    Double currentQuantity = (Double) normalizedItemQuantities.get(currentProductId);                    normalizedItemQuantities.put(currentProductId, new Double(currentQuantity.doubleValue() + orderItem.getDouble("quantity").doubleValue()));                }                try {                    // count product ordered quantities                    // run this synchronously so it will run in the same transaction                    dispatcher.runSync("countProductQuantityOrdered", UtilMisc.toMap("productId", currentProductId, "quantity", orderItem.getDouble("quantity"), "userLogin", userLogin));                } catch (GenericServiceException e1) {

⌨️ 快捷键说明

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