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

📄 orderreadhelper.java

📁 Sequoia ERP是一个真正的企业级开源ERP解决方案。它提供的模块包括:电子商务应用(e-commerce), POS系统(point of sales),知识管理,存货与仓库管理
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * $Id: OrderReadHelper.java 7124 2006-03-30 06:19:11Z jacopo $ * *  Copyright (c) 2002-2004 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.util.ArrayList;import java.util.Arrays;import java.util.HashMap;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.Set;import org.apache.commons.collections.set.ListOrderedSet;import org.ofbiz.base.util.Debug;import org.ofbiz.base.util.UtilFormatOut;import org.ofbiz.base.util.UtilMisc;import org.ofbiz.base.util.UtilNumber;import org.ofbiz.base.util.UtilValidate;import org.ofbiz.common.DataModelConstants;import org.ofbiz.entity.GenericDelegator;import org.ofbiz.entity.GenericEntity;import org.ofbiz.entity.GenericEntityException;import org.ofbiz.entity.GenericValue;import org.ofbiz.entity.condition.EntityCondition;import org.ofbiz.entity.condition.EntityExpr;import org.ofbiz.entity.condition.EntityOperator;import org.ofbiz.entity.condition.EntityConditionList;import org.ofbiz.entity.util.EntityUtil;import org.ofbiz.product.product.ProductWorker;import org.ofbiz.security.Security;/** * Utility class for easily extracting important information from orders * * <p>NOTE: in the current scheme order adjustments are never included in tax or shipping, * but order item adjustments ARE included in tax and shipping calcs unless they are * tax or shipping adjustments or the includeInTax or includeInShipping are set to N.</p> * * @author     <a href="mailto:jaz@ofbiz.org">Andy Zeneski</a> * @author     <a href="mailto:jonesde@ofbiz.org">David E. Jones</a> * @author     Eric Pabst * @author     <a href="mailto:ray.barlow@whatsthe-point.com">Ray Barlow</a> * @version    $Rev: 7124 $ * @since      2.0 */public class OrderReadHelper {    public static final String module = OrderReadHelper.class.getName();    // scales and rounding modes for BigDecimal math    public static final int scale = UtilNumber.getBigDecimalScale("order.decimals");    public static final int rounding = UtilNumber.getBigDecimalRoundingMode("order.rounding");    public static final int taxCalcScale = UtilNumber.getBigDecimalScale("salestax.calc.decimals");    public static final int taxFinalScale = UtilNumber.getBigDecimalRoundingMode("salestax.final.decimals");    public static final int taxRounding = UtilNumber.getBigDecimalRoundingMode("salestax.rounding");    public static final BigDecimal ZERO = (new BigDecimal("0")).setScale(scale, rounding);    protected GenericValue orderHeader = null;    protected List orderItemAndShipGrp = null;    protected List orderItems = null;    protected List adjustments = null;    protected List paymentPrefs = null;    protected List orderStatuses = null;    protected List orderItemPriceInfos = null;    protected List orderItemShipGrpInvResList = null;    protected List orderItemIssuances = null;    protected List orderReturnItems = null;    protected BigDecimal totalPrice = null;    protected OrderReadHelper() {}    public OrderReadHelper(GenericValue orderHeader, List adjustments, List orderItems) {        this.orderHeader = orderHeader;        this.adjustments = adjustments;        this.orderItems = orderItems;        if (this.orderHeader != null && !this.orderHeader.getEntityName().equals("OrderHeader")) {            try {                this.orderHeader = orderHeader.getDelegator().findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId",                        orderHeader.getString("orderId")));            } catch (GenericEntityException e) {                Debug.logError(e, module);                this.orderHeader = null;            }        } else if (this.orderHeader == null && orderItems != null) {            GenericValue firstItem = EntityUtil.getFirst(orderItems);            try {                this.orderHeader = firstItem.getRelatedOne("OrderHeader");            } catch (GenericEntityException e) {                Debug.logError(e, module);                this.orderHeader = null;            }        }        if (this.orderHeader == null) {            throw new IllegalArgumentException("Order header is not valid");        }    }    public OrderReadHelper(GenericValue orderHeader) {        this(orderHeader, null, null);    }    public OrderReadHelper(List adjustments, List orderItems) {        this.adjustments = adjustments;        this.orderItems = orderItems;    }    public OrderReadHelper(GenericDelegator delegator, String orderId) {        try {            this.orderHeader = delegator.findByPrimaryKey("OrderHeader", UtilMisc.toMap("orderId", orderId));        } catch (GenericEntityException e) {            throw new IllegalArgumentException("Invalid orderId");        }    }    // ==========================================    // ========== Order Header Methods ==========    // ==========================================    public String getOrderId() {        return orderHeader.getString("orderId");    }    public String getWebSiteId() {        return orderHeader.getString("webSiteId");    }    public String getProductStoreId() {        return orderHeader.getString("productStoreId");    }    /**     * Returns the ProductStore of this Order or null in case of Exception     */     public GenericValue getProductStore() {        String productStoreId = orderHeader.getString("productStoreId");        try {            GenericDelegator delegator = orderHeader.getDelegator();            GenericValue productStore = delegator.findByPrimaryKeyCache("ProductStore", UtilMisc.toMap("productStoreId", productStoreId));            return productStore;        } catch (GenericEntityException ex) {            Debug.logError("Failed to get product store for order header [" + orderHeader + "] due to exception "+ ex.getMessage(), module);            return null;        }    }        public String getOrderTypeId() {        return orderHeader.getString("orderTypeId");    }    public String getCurrency() {        return orderHeader.getString("currencyUom");    }    public List getAdjustments() {        if (adjustments == null) {            try {                adjustments = orderHeader.getRelated("OrderAdjustment");            } catch (GenericEntityException e) {                Debug.logError(e, module);            }            if (adjustments == null)                adjustments = new ArrayList();        }        return (List) adjustments;    }    public List getPaymentPreferences() {        if (paymentPrefs == null) {            try {                paymentPrefs = orderHeader.getRelated("OrderPaymentPreference", UtilMisc.toList("orderPaymentPreferenceId"));            } catch (GenericEntityException e) {                Debug.logError(e, module);            }        }        return paymentPrefs;    }    public List getOrderPayments() {        return getOrderPayments(null);    }    public List getOrderPayments(GenericValue orderPaymentPreference) {        List orderPayments = new ArrayList();        List prefs = null;        if (orderPaymentPreference == null) {            prefs = getPaymentPreferences();        } else {            prefs = UtilMisc.toList(orderPaymentPreference);        }        if (prefs != null) {            Iterator i = prefs.iterator();            while (i.hasNext()) {                GenericValue payPref = (GenericValue) i.next();                try {                    orderPayments.addAll(payPref.getRelated("Payment"));                } catch (GenericEntityException e) {                    Debug.logError(e, module);                    return null;                }            }        }        return orderPayments;    }    public List getOrderStatuses() {        if (orderStatuses == null) {            try {                orderStatuses = orderHeader.getRelated("OrderStatus");            } catch (GenericEntityException e) {                Debug.logError(e, module);            }        }        return (List) orderStatuses;    }    public List getOrderTerms() {        try {           return orderHeader.getRelated("OrderTerm");        } catch (GenericEntityException e) {            Debug.logError(e, module);            return null;        }    }    /**     * @return Long number of days from termDays of first FIN_PAYMENT_TERM     */    public Long getOrderTermNetDays() {        List orderTerms = EntityUtil.filterByAnd(getOrderTerms(), UtilMisc.toMap("termTypeId", "FIN_PAYMENT_TERM"));        if ((orderTerms == null) || (orderTerms.size() == 0)) {            return null;        } else if (orderTerms.size() > 1) {            Debug.logWarning("Found " + orderTerms.size() + " FIN_PAYMENT_TERM order terms for orderId [" + getOrderId() + "], using the first one ", module);        }        return ((GenericValue) orderTerms.get(0)).getLong("termDays");    }    /** @deprecated */    public String getShippingMethod() {        throw new IllegalArgumentException("You must call the getShippingMethod method with the shipGroupdSeqId parameter, this is no londer supported since a single OrderShipmentPreference is no longer used.");    }    public String getShippingMethod(String shipGroupSeqId) {        try {            GenericValue shipGroup = orderHeader.getDelegator().findByPrimaryKey("OrderItemShipGroup",                    UtilMisc.toMap("orderId", orderHeader.getString("orderId"), "shipGroupSeqId", shipGroupSeqId));            if (shipGroup != null) {                GenericValue carrierShipmentMethod = shipGroup.getRelatedOne("CarrierShipmentMethod");                if (carrierShipmentMethod != null) {                    GenericValue shipmentMethodType = carrierShipmentMethod.getRelatedOne("ShipmentMethodType");                    if (shipmentMethodType != null) {                        return UtilFormatOut.checkNull(shipGroup.getString("carrierPartyId")) + " " +                                UtilFormatOut.checkNull(shipmentMethodType.getString("description"));                    }                }                return UtilFormatOut.checkNull(shipGroup.getString("carrierPartyId"));            }        } catch (GenericEntityException e) {            Debug.logWarning(e, module);        }        return "";    }    /** @deprecated */    public String getShippingMethodCode() {        throw new IllegalArgumentException("You must call the getShippingMethodCode method with the shipGroupdSeqId parameter, this is no londer supported since a single OrderShipmentPreference is no longer used.");    }    public String getShippingMethodCode(String shipGroupSeqId) {        try {            GenericValue shipGroup = orderHeader.getDelegator().findByPrimaryKey("OrderItemShipGroup",                    UtilMisc.toMap("orderId", orderHeader.getString("orderId"), "shipGroupSeqId", shipGroupSeqId));            if (shipGroup != null) {                GenericValue carrierShipmentMethod = shipGroup.getRelatedOne("CarrierShipmentMethod");                if (carrierShipmentMethod != null) {                    GenericValue shipmentMethodType = carrierShipmentMethod.getRelatedOne("ShipmentMethodType");                    if (shipmentMethodType != null) {

⌨️ 快捷键说明

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