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

📄 orderchangehelper.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: OrderChangeHelper.java 6536 2006-01-22 23:04:00Z 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.order.order;import java.util.Iterator;import java.util.List;import java.util.Map;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;import org.ofbiz.workflow.WfException;import org.ofbiz.workflow.client.WorkflowClient;/** * Order Helper - Helper Methods For Non-Read Actions * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 6536 $ * @since      2.0 */public class OrderChangeHelper {    public static final String module = OrderChangeHelper.class.getName();    public static boolean approveOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {        return approveOrder(dispatcher, userLogin, orderId, false);    }    public static boolean approveOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId, boolean holdOrder) {        GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);        if (productStore == null) {            throw new IllegalArgumentException("Could not find ProductStore for orderId [" + orderId + "], cannot approve order.");        }        // interal status for held orders        String HEADER_STATUS = "ORDER_PROCESSING";        String ITEM_STATUS = "ITEM_CREATED";        String DIGITAL_ITEM_STATUS = "ITEM_APPROVED";        if (!holdOrder) {            if (productStore.get("headerApprovedStatus") != null) {                HEADER_STATUS = productStore.getString("headerApprovedStatus");            }            if (productStore.get("itemApprovedStatus") != null) {                ITEM_STATUS = productStore.getString("itemApprovedStatus");            }            if (productStore.get("digitalItemApprovedStatus") != null) {                DIGITAL_ITEM_STATUS = productStore.getString("digitalItemApprovedStatus");            }        }        try {            OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, "ITEM_CREATED", ITEM_STATUS, DIGITAL_ITEM_STATUS);            OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);            /*            // call the service to check/run digital fulfillment            Map checkDigi = dispatcher.runSync("checkDigitalItemFulfillment", UtilMisc.toMap("orderId", orderId, "userLogin", userLogin));            // this service will return a message with success if there were any problems. Get this message and return it to the user            String message = (String) checkDigi.get(ModelService.SUCCESS_MESSAGE);            if (UtilValidate.isNotEmpty(message)) {                throw new GeneralRuntimeException(message);            }            */        } catch (GenericServiceException e) {            Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);            return false;        }        return true;    }    public static boolean rejectOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {        GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);        String HEADER_STATUS = "ORDER_REJECTED";        String ITEM_STATUS = "ITEM_REJECTED";        if (productStore.get("headerDeclinedStatus") != null) {              HEADER_STATUS = productStore.getString("headerDeclinedStatus");          }          if (productStore.get("itemDeclinedStatus") != null) {              ITEM_STATUS = productStore.getString("itemDeclinedStatus");          }        try {            OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, null, ITEM_STATUS, null);            OrderChangeHelper.cancelInventoryReservations(dispatcher, userLogin, orderId);            OrderChangeHelper.releasePaymentAuthorizations(dispatcher, userLogin,orderId);            OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);        } catch (GenericServiceException e) {            Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);            return false;        }        return true;    }    public static boolean completeOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {        try {            OrderChangeHelper.createReceivedPayments(dispatcher, userLogin, orderId);            OrderChangeHelper.createOrderInvoice(dispatcher, userLogin, orderId);            OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, "ORDER_COMPLETED", "ITEM_APPROVED", "ITEM_COMPLETED", null);        } catch (GenericEntityException e) {            Debug.logError(e, module);            return false;        } catch (GenericServiceException e) {            Debug.logError(e, module);            return false;        }        return true;    }    public static boolean cancelOrder(LocalDispatcher dispatcher, GenericValue userLogin, String orderId) {        GenericValue productStore = OrderReadHelper.getProductStoreFromOrder(dispatcher.getDelegator(), orderId);        String HEADER_STATUS = "ORDER_CANCELLED";        String ITEM_STATUS = "ITEM_CANCELLED";        if (productStore.get("headerCancelStatus") != null) {              HEADER_STATUS = productStore.getString("headerCancelStatus");          }          if (productStore.get("itemCancelStatus") != null) {              ITEM_STATUS = productStore.getString("itemCancelStatus");          }        try {            OrderChangeHelper.orderStatusChanges(dispatcher, userLogin, orderId, HEADER_STATUS, null, ITEM_STATUS, null);            OrderChangeHelper.cancelInventoryReservations(dispatcher, userLogin, orderId);            OrderChangeHelper.releasePaymentAuthorizations(dispatcher, userLogin,orderId);            OrderChangeHelper.releaseInitialOrderHold(dispatcher, orderId);        } catch (GenericServiceException e) {            Debug.logError(e, "Service invocation error, status changes were not updated for order #" + orderId, module);            return false;        }        return true;    }    public static void orderStatusChanges(LocalDispatcher dispatcher, GenericValue userLogin, String orderId, String orderStatus, String fromItemStatus, String toItemStatus, String digitalItemStatus) throws GenericServiceException {        // set the status on the order header        Map statusFields = UtilMisc.toMap("orderId", orderId, "statusId", orderStatus, "userLogin", userLogin);        Map statusResult = dispatcher.runSync("changeOrderStatus", statusFields);        if (statusResult.containsKey(ModelService.ERROR_MESSAGE)) {            Debug.logError("Problems adjusting order header status for order #" + orderId, module);        }        // set the status on the order item(s)        Map itemStatusFields = UtilMisc.toMap("orderId", orderId, "statusId", toItemStatus, "userLogin", userLogin);        if (fromItemStatus != null) {            itemStatusFields.put("fromStatusId", fromItemStatus);        }        Map itemStatusResult = dispatcher.runSync("changeOrderItemStatus", itemStatusFields);        if (itemStatusResult.containsKey(ModelService.ERROR_MESSAGE)) {            Debug.logError("Problems adjusting order item status for order #" + orderId, module);        }        // now set the status for digital items        if (digitalItemStatus != null && !digitalItemStatus.equals(toItemStatus)) {            GenericDelegator delegator = dispatcher.getDelegator();            GenericValue orderHeader = null;            try {                orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));            } catch (GenericEntityException e) {                Debug.logError(e, "ERROR: Unable to get OrderHeader for OrderID : " + orderId, module);

⌨️ 快捷键说明

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