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

📄 orderreturnservices.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* $$ID$ */package org.ofbiz.order.order;import java.math.BigDecimal;import java.sql.Timestamp;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Locale;import java.util.Map;import java.util.Set;import javolution.util.FastMap;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.GeneralRuntimeException;import org.ofbiz.base.util.UtilDateTime;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilNumber;import org.ofbiz.base.util.UtilProperties;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.base.util.collections.ResourceBundleMapWrapper;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.store.ProductStoreWorker;import org.ofbiz.service.DispatchContext;import org.ofbiz.service.GenericServiceException;import org.ofbiz.service.LocalDispatcher;import org.ofbiz.service.ModelParam;import org.ofbiz.service.ModelService;import org.ofbiz.service.ServiceUtil;/** * OrderReturnServices * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @version    $Rev: 7232 $ * @since      3.5 */public class OrderReturnServices {    public static final String module = OrderReturnServices.class.getName();    public static final String resource = "OrderUiLabels";    public static final String resource_error = "OrderErrorUiLabels";    //  set some BigDecimal properties    private static BigDecimal ZERO = new BigDecimal("0");    private static int decimals = -1;    private static int rounding = -1;    static {        decimals = UtilNumber.getBigDecimalScale("invoice.decimals");        rounding = UtilNumber.getBigDecimalRoundingMode("invoice.rounding");        // set zero to the proper scale        if (decimals != -1) ZERO.setScale(decimals);    }    // locate the return item's initial inventory item cost    public static Map getReturnItemInitialCost(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        String returnId = (String) context.get("returnId");        String returnItemSeqId = (String) context.get("returnItemSeqId");        Map result = ServiceUtil.returnSuccess();        result.put("initialItemCost", getReturnItemInitialCost(delegator, returnId, returnItemSeqId));        return result;    }    // obtain order/return total information    public static Map getOrderAvailableReturnedTotal(DispatchContext dctx, Map context) {        GenericDelegator delegator = dctx.getDelegator();        String orderId = (String) context.get("orderId");        OrderReadHelper orh = null;        try {            orh = new OrderReadHelper(delegator, orderId);        } catch (IllegalArgumentException e) {            return ServiceUtil.returnError(e.getMessage());        }        // an adjustment value to test        Double adj = (Double) context.get("adjustment");        if (adj == null) {            adj = new Double(0);        }        double returnTotal = orh.getOrderReturnedTotal(true);        double orderTotal = orh.getOrderGrandTotal();        double available = orderTotal - returnTotal - adj.doubleValue();        Map result = ServiceUtil.returnSuccess();        result.put("availableReturnTotal", new Double(available));        result.put("orderTotal", new Double(orderTotal));        result.put("returnTotal", new Double(returnTotal));        return result;    }    // worker method which can be used in screen iterations    public static Double getReturnItemInitialCost(GenericDelegator delegator, String returnId, String returnItemSeqId) {        if (delegator == null || returnId == null || returnItemSeqId == null) {            throw new IllegalArgumentException("Method parameters cannot contain nulls");        }        Debug.log("Finding the initial item cost for return item : " + returnId + " / " + returnItemSeqId, module);        // the cost holder        Double itemCost = new Double(0.00);        // get the return item information        GenericValue returnItem = null;        try {            returnItem = delegator.findByPrimaryKey("ReturnItem", UtilMisc.toMap("returnId", returnId, "returnItemSeqId", returnItemSeqId));        } catch (GenericEntityException e) {            Debug.logError(e, module);            throw new GeneralRuntimeException(e.getMessage());        }        Debug.log("Return item value object - " + returnItem, module);        // check for an orderItem association        if (returnItem != null) {            String orderId = returnItem.getString("orderId");            String orderItemSeqId = returnItem.getString("orderItemSeqId");            if (orderItemSeqId != null && orderId != null) {                Debug.log("Found order item reference", module);                // locate the item issuance(s) for this order item                List itemIssue = null;                try {                    itemIssue = delegator.findByAnd("ItemIssuance", UtilMisc.toMap("orderId", orderId, "orderItemSeqId", orderItemSeqId));                } catch (GenericEntityException e) {                    Debug.logError(e, module);                    throw new GeneralRuntimeException(e.getMessage());                }                if (itemIssue != null && itemIssue.size() > 0) {                    Debug.log("Found item issuance referece", module);                    // just use the first one for now; maybe later we can find a better way to determine which was the                    // actual item being returned; maybe by serial number                    GenericValue issue = EntityUtil.getFirst(itemIssue);                    GenericValue inventoryItem = null;                    try {                        inventoryItem = issue.getRelatedOne("InventoryItem");                    } catch (GenericEntityException e) {                        Debug.logError(e, module);                        throw new GeneralRuntimeException(e.getMessage());                    }                    if (inventoryItem != null) {                        Debug.log("Located inventory item - " + inventoryItem.getString("inventoryItemId"), module);                        if (inventoryItem.get("unitCost") != null) {                            itemCost = inventoryItem.getDouble("unitCost");                        } else {                            Debug.logInfo("Found item cost; but cost was null. Returning default amount (0.00)", module);                        }                    }                }            }        }        Debug.log("Initial item cost - " + itemCost, module);        return itemCost;    }    // helper method for sending return notifications    private static Map sendReturnNotificationScreen(DispatchContext dctx, Map context, String emailType) {        GenericDelegator delegator = dctx.getDelegator();        LocalDispatcher dispatcher = dctx.getDispatcher();        GenericValue userLogin = (GenericValue) context.get("userLogin");        String returnId = (String) context.get("returnId");        Locale locale = (Locale) context.get("locale");        // get the return header        GenericValue returnHeader = null;        try {            returnHeader = delegator.findByPrimaryKey("ReturnHeader", UtilMisc.toMap("returnId", returnId));        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderErrorUnableToGetReturnHeaderForID", UtilMisc.toMap("returnId",returnId), locale));        }        // get the return items        List returnItems = null;        try {            returnItems = returnHeader.getRelated("ReturnItem");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderErrorUnableToGetReturnItemRecordsFromReturnHeader", locale));        }        // get the order header -- the first item will determine which product store to use from the order        String productStoreId = null;        String emailAddress = null;        if (returnItems != null && returnItems.size() > 0) {            GenericValue firstItem = EntityUtil.getFirst(returnItems);            GenericValue orderHeader = null;            try {                orderHeader = firstItem.getRelatedOne("OrderHeader");            } catch (GenericEntityException e) {                Debug.logError(e, module);                return ServiceUtil.returnError(UtilProperties.getMessage(resource_error, "OrderErrorUnableToGetOrderHeaderFromReturnItem", locale));            }            if (orderHeader != null && UtilValidate.isNotEmpty(orderHeader.getString("productStoreId"))) {                OrderReadHelper orh = new OrderReadHelper(orderHeader);                productStoreId = orh.getProductStoreId();                emailAddress = orh.getOrderEmailString();            }        }        // get the email setting and send the mail        if (productStoreId != null && productStoreId.length() > 0) {            Map sendMap = FastMap.newInstance();            GenericValue productStoreEmail = null;            try {                productStoreEmail = delegator.findByPrimaryKey("ProductStoreEmailSetting", UtilMisc.toMap("productStoreId", productStoreId, "emailType", emailType));            } catch (GenericEntityException e) {                Debug.logError(e, module);            }            if (productStoreEmail != null && emailAddress != null) {                String bodyScreenLocation = productStoreEmail.getString("bodyScreenLocation");                if (UtilValidate.isEmpty(bodyScreenLocation)) {                    bodyScreenLocation = (String) ProductStoreWorker.getDefaultProductStoreEmailScreenLocation(emailType);                }                sendMap.put("bodyScreenUri", bodyScreenLocation);                ResourceBundleMapWrapper uiLabelMap = (ResourceBundleMapWrapper) UtilProperties.getResourceBundleMap("EcommerceUiLabels", locale);                uiLabelMap.addBottomResourceBundle("OrderUiLabels");                uiLabelMap.addBottomResourceBundle("CommonUiLabels");                Map bodyParameters = UtilMisc.toMap("returnHeader", returnHeader, "returnItems", returnItems, "uiLabelMap", uiLabelMap, "locale", locale);                sendMap.put("bodyParameters", bodyParameters);                sendMap.put("subject", productStoreEmail.getString("subject"));                sendMap.put("contentType", productStoreEmail.get("contentType"));                sendMap.put("sendFrom", productStoreEmail.get("fromAddress"));                sendMap.put("sendCc", productStoreEmail.get("ccAddress"));                sendMap.put("sendBcc", productStoreEmail.get("bccAddress"));                sendMap.put("sendTo", emailAddress);                sendMap.put("userLogin", userLogin);

⌨️ 快捷键说明

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