www.pudn.com > code_source_compiere_erp_crm_logiciel_java.zip > MOrder.java


/****************************************************************************** 
 * The contents of this file are subject to the   Compiere License  Version 1.1 
 * ("License"); You may not use this file except in compliance with the License 
 * You may obtain a copy of the License at http://www.compiere.org/license.html 
 * Software distributed under the License is distributed on an  "AS IS"  basis, 
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for 
 * the specific language governing rights and limitations under the License. 
 * The Original Code is                  Compiere  ERP & CRM  Business Solution 
 * The Initial Developer of the Original Code is Jorg Janke  and ComPiere, Inc. 
 * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts 
 * created by ComPiere are Copyright (C) ComPiere, Inc.;   All Rights Reserved. 
 * Contributor(s): ______________________________________. 
 *****************************************************************************/ 
package org.compiere.model; 
 
import java.util.*; 
import java.sql.*; 
import java.math.*; 
import java.io.Serializable; 
 
import org.compiere.process.*; 
import org.compiere.util.DB; 
import org.compiere.util.Env; 
import org.compiere.util.Log; 
/** 
 *  Order Model 
 * 
 *  @author Jorg Janke 
 *  @version $Id: MOrder.java,v 1.9 2003/05/04 06:40:55 jjanke Exp $ 
 */ 
public class MOrder extends PO 
{ 
	/** 
	 *  Default Constructor 
	 *  @param ctx context 
	 *  @param  C_Order_ID    order to load, (0 create new order) 
	 */ 
	public MOrder(Properties ctx, int C_Order_ID) 
	{ 
		super (ctx, C_Order_ID); 
		//  New 
		if (C_Order_ID == 0) 
		{ 
			setDeliveryRule (DeliveryRule_Availability); 
			setFreightCostRule (FreightCostRule_Included); 
			setInvoiceRule (InvoiceRule_Immediate); 
			setPaymentRule(PaymentRule_PaymentTerm); 
			setPriorityRule ("5"); 
			setDeliveryViaRule ("P"); 
			// 
			setDocStatus("DR");		//	Draft 
			setDocAction (DocAction_Process); 
			// 
			setIsDiscountPrinted (false); 
			setIsSelected (false); 
			setIsTaxIncluded (false); 
			setIsSOTrx (true); 
			setSendEMail (false); 
			// 
			setIsApproved(false); 
			setIsPrinted(false); 
			setIsCreditApproved(false); 
			setIsDelivered(false); 
			setIsInvoiced(false); 
			setIsTransferred(false); 
			// 
			setProcessed(false); 
			setPosted(false); 
 
			setDateAcct (new Timestamp(System.currentTimeMillis())); 
			setDatePromised (new Timestamp(System.currentTimeMillis())); 
			setDateOrdered (new Timestamp(System.currentTimeMillis())); 
 
			setFreightAmt (Env.ZERO); 
			setChargeAmt (Env.ZERO); 
			setTotalLines (Env.ZERO); 
			setGrandTotal (Env.ZERO); 
		} 
	}	//	MOrder 
 
	/** 
	 *  Load Constructor 
	 *  @param ctx context 
	 *  @param rs result set record 
	 */ 
	public MOrder (Properties ctx, ResultSet rs) 
	{ 
		super (ctx, rs); 
	}	//	MOrder 
 
	/** 
	 *  Initialize and return PO_Info 
	 *  @param ctx context 
	 *  @return POInfo 
	 */ 
	protected POInfo initPO (Properties ctx) 
	{ 
		int AD_Table_ID = 259; 
		POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID); 
		return poi; 
	}	//	initPO 
 
	/*************************************************************************/ 
 
	public static final String		DocSubTypeSO_Standard = "SO"; 
	public static final String		DocSubTypeSO_Quotation = "OB"; 
	public static final String		DocSubTypeSO_Proposal = "ON"; 
	public static final String		DocSubTypeSO_Prepay = "PR"; 
	public static final String		DocSubTypeSO_POS = "WR"; 
	public static final String		DocSubTypeSO_Warehouse = "WP"; 
	public static final String		DocSubTypeSO_OnCredit = "WI"; 
	public static final String		DocSubTypeSO_RMA = "RM"; 
 
	/** 
	 * 	Set Target Document Type 
	 * 	@param DocSubTypeSO_x SO sub type - see DocSubTypeSO_* 
	 */ 
	public void setC_DocTypeTarget_ID (String DocSubTypeSO_x) 
	{ 
		String sql = "SELECT C_DocType_ID FROM C_DocType WHERE AD_Client_ID=? AND DocSubTypeSO=?"; 
		int C_DocType_ID = DB.getSQLValue(sql, getAD_Client_ID(), DocSubTypeSO_x); 
		if (C_DocType_ID <= 0) 
			log.error ("setC_DocTypeTarget_ID - Not found for AC_Client_ID=" + getAD_Client_ID () + ", SubType=" + DocSubTypeSO_x); 
		else 
		{ 
			log.debug("setC_DocTypeTarget_ID - " + DocSubTypeSO_x); 
			setC_DocTypeTarget_ID (C_DocType_ID); 
			setIsSOTrx(true); 
		} 
	}	//	setC_DocTypeTarget_ID 
 
	/** 
	 * 	Set Business Partner Defaults & Details 
	 * 	@param bp business partner 
	 */ 
	public void setBPartner (MBPartner bp) 
	{ 
		if (bp == null) 
			return; 
 
		setC_BPartner_ID(bp.getC_BPartner_ID()); 
		//	Set Defaults 
		int ii = 0; 
		if (isSOTrx()) 
			ii = bp.getC_PaymentTerm_ID(); 
		else 
			ii = bp.getPO_PaymentTerm_ID(); 
		if (ii != 0) 
			setC_PaymentTerm_ID(ii); 
		// 
		if (isSOTrx()) 
			ii = bp.getM_PriceList_ID(); 
		else 
			ii = bp.getPO_PriceList_ID(); 
		if (ii != 0) 
			setM_PriceList_ID(ii); 
		// 
		String ss = bp.getDeliveryRule(); 
		if (ss != null) 
			setDeliveryRule(ss); 
		ss = bp.getDeliveryViaRule(); 
		if (ss != null) 
			setDeliveryViaRule(ss); 
		ss = bp.getInvoiceRule(); 
		if (ss != null) 
			setInvoiceRule(ss); 
		ss = bp.getPaymentRule(); 
		if (ss != null) 
			setPaymentRule(ss); 
 
 
		//	Set Locations 
		MBPartner_Location[] locs = bp.getLocations(); 
		if (locs != null) 
		{ 
			for (int i = 0; i < locs.length; i++) 
			{ 
				if (locs[i].isBillTo()) 
					setBillTo_ID(locs[i].getC_BPartner_Location_ID()); 
				if (locs[i].isShipTo()) 
					setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID()); 
			} 
			//	set to first 
			if (getBillTo_ID() == 0 && locs.length > 0) 
				setBillTo_ID(locs[0].getC_BPartner_Location_ID()); 
			if (getC_BPartner_Location_ID() == 0 && locs.length > 0) 
				setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID()); 
		} 
		if (getBillTo_ID() == 0) 
			log.error("MOrder.setBPartner - Has no Bill To Address: " + bp); 
		if (getC_BPartner_Location_ID() == 0) 
			log.error("MOrder.setBPartner - Has no Ship To Address: " + bp); 
 
		//	Set Contact 
		MBPartner_Contact[] contacts = bp.getContacts(); 
		if (contacts != null && contacts.length == 1) 
			setC_BPartner_Contact_ID(contacts[0].getC_BPartner_Contact_ID()); 
	}	//	setBPartner 
 
	/** 
	 * 	Set Defaults for mandatory values where not set yet 
	 */ 
	private void setDefaults () 
	{ 
		int AD_Client_ID = getAD_Client_ID(); 
		int AD_Org_ID = getAD_Org_ID(); 
		log.debug("setDefaults - " + "Client/Org=" + AD_Client_ID + "/" + AD_Org_ID); 
 
		//	No Partner Info - set Template 
		if (getC_BPartner_ID() == 0) 
			setBPartner(MBPartner.getTemplate(getCtx(), getAD_Client_ID())); 
		if (getC_BPartner_Location_ID() == 0 || getBillTo_ID() == 0) 
			setBPartner(new MBPartner(getCtx(), getC_BPartner_ID())); 
 
		//	Price List 
		if (getM_PriceList_ID() == 0) 
		{ 
			int ii = Env.getContextAsInt(getCtx(), "#M_PriceList_ID"); 
			if (ii != 0) 
				setM_PriceList_ID(ii); 
			else 
			{ 
				String sql = "SLECT M_PriceList_ID FROM M_PriceList WHERE AD_Client_ID=? AND IsDefault='Y'"; 
				ii = DB.getSQLValue (sql, AD_Client_ID); 
				if (ii != 0) 
					setM_PriceList_ID (ii); 
			} 
		} 
		//	Currency 
		if (getC_Currency_ID() == 0) 
		{ 
			String sql = "SLECT C_Currency_ID FROM M_PriceList WHERE M_PriceList_ID=?"; 
			int ii = DB.getSQLValue (sql, getM_PriceList_ID()); 
			if (ii != 0) 
				setC_Currency_ID (ii); 
			else 
				setC_Currency_ID(Env.getContextAsInt(getCtx(), "#C_Currency_ID")); 
		} 
 
		//	Sales Rep 
		if (getSalesRep_ID() == 0) 
		{ 
			int ii = Env.getContextAsInt(getCtx(), "#SalesRep_ID"); 
			if (ii != 0) 
				setSalesRep_ID (ii); 
		} 
 
		//	Document Type 
		if (getC_DocType_ID() == 0) 
			setC_DocType_ID (0);	//	make sure it's set to 0 
		if (getC_DocTypeTarget_ID() == 0) 
			setC_DocTypeTarget_ID(DocSubTypeSO_Standard); 
 
		//	Payment Term 
		if (getC_PaymentTerm_ID() == 0) 
		{ 
			int ii = Env.getContextAsInt(getCtx(), "#C_PaymentTerm_ID"); 
			if (ii != 0) 
				setC_PaymentTerm_ID(ii); 
			else 
			{ 
				String sql = "SELECT C_PaymentTerm_ID FROM C_PaymentTerm WHERE AD_Client_ID=? AND IsDefault='Y'"; 
				ii = DB.getSQLValue(sql, AD_Client_ID); 
				if (ii != 0) 
					setC_PaymentTerm_ID (ii); 
			} 
		} 
		if (getM_Warehouse_ID() == 0) 
		{ 
			int ii = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID"); 
			if (ii != 0) 
				setM_Warehouse_ID(ii); 
		} 
	}	//	setDefaults 
 
	/*************************************************************************/ 
 
	/** 
	 * 	Save Order 
	 * 	@return true if saved 
	 */ 
	public boolean save () 
	{ 
		log.debug ("save"); 
		setDefaults(); 
		setDocumentNo(DB.getDocumentNo(getAD_Client_ID(), getC_DocTypeTarget_ID())); 
		return super.save (); 
	}	//	save 
 
	/** 
	 * 	Process Order 
	 * 	@param docAction doc action 
	 *	@return true if no error 
	 */ 
	public boolean process (String docAction) 
	{ 
		setDocAction(docAction); 
		return process(); 
	}	//	process 
 
	/** 
	 * 	Process Order 
	 *	@return true if no error 
	 */ 
	public boolean process () 
	{ 
		save(); 
		log.debug ("process - " + getDocAction()); 
		int AD_Process_ID = 104;	//	C_Order_Post 
		MProcess pp = new MProcess (getCtx(), AD_Process_ID); 
		boolean ok = pp.process(getC_Order_ID()).isOK(); 
		load();		//	reload 
		log.debug("process - ok=" + ok + " - GradndTotal=" + getGrandTotal()); 
		return ok; 
	}	//	process 
 
	public String toString () 
	{ 
		StringBuffer sb = new StringBuffer ("MOrder[") 
			.append(getID()) 
			.append ("]"); 
		return sb.toString (); 
	} 
 
	public void setC_BPartner_ID (int C_BPartner_ID) 
	{ 
		setValue ("C_BPartner_ID", new Integer (C_BPartner_ID)); 
	} 
 
	public int getC_BPartner_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_BPartner_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public static final String		DeliveryRule_Availability = "A"; 
	public static final String		DeliveryRule_Line = "L"; 
	public static final String		DeliveryRule_Order = "O"; 
	public static final String		DeliveryRule_Receipt = "R"; 
 
	public void setDeliveryRule (String DeliveryRule) 
	{ 
		if (DeliveryRule.equals ("A") || DeliveryRule.equals ("L") 
		  || DeliveryRule.equals ("O") || DeliveryRule.equals ("R")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "DeliveryRule Invalid value - Reference_ID=151 - A - L - O - R"); 
		if (DeliveryRule == null) 
			throw new IllegalArgumentException ("DeliveryRule is mandatory"); 
		setValue ("DeliveryRule", DeliveryRule); 
	} 
 
	public String getDeliveryRule () 
	{ 
		return (String)getValue ("DeliveryRule"); 
	} 
 
	public int getC_Order_ID () 
	{ 
		return getID(); 
	} 
 
	public void setC_BPartner_Contact_ID (int C_BPartner_Contact_ID) 
	{ 
		setValue ("C_BPartner_Contact_ID", new Integer (C_BPartner_Contact_ID)); 
	} 
 
	public int getC_BPartner_Contact_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_BPartner_Contact_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setC_Project_ID (int C_Project_ID) 
	{ 
		setValue ("C_Project_ID", new Integer (C_Project_ID)); 
	} 
 
	public int getC_Project_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Project_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setChargeAmt (BigDecimal ChargeAmt) 
	{ 
		setValue ("ChargeAmt", ChargeAmt); 
	} 
 
	public BigDecimal getChargeAmt () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("ChargeAmt"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	public void setC_Activity_ID (int C_Activity_ID) 
	{ 
		setValue ("C_Activity_ID", new Integer (C_Activity_ID)); 
	} 
 
	public int getC_Activity_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Activity_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public static final String FreightCostRule_Included = "I"; 
	public static final String FreightCostRule_FixPrice = "F"; 
	public static final String FreightCostRule_Calculated = "C"; 
	public static final String FreightCostRule_Line = "L"; 
 
	public void setFreightCostRule (String FreightCostRule) 
	{ 
		if (FreightCostRule.equals ("C") || FreightCostRule.equals ("F") 
		  || FreightCostRule.equals ("I") || FreightCostRule.equals ("L")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "FreightCostRule Invalid value - Reference_ID=153 - C - F - I - L"); 
		if (FreightCostRule == null) 
			throw new IllegalArgumentException ("FreightCostRule is mandatory"); 
		setValue ("FreightCostRule", FreightCostRule); 
	} 
 
	public String getFreightCostRule () 
	{ 
		return (String)getValue ("FreightCostRule"); 
	} 
 
	public void setIsDiscountPrinted (boolean IsDiscountPrinted) 
	{ 
		setValue ("IsDiscountPrinted", new Boolean(IsDiscountPrinted)); 
	} 
 
	public boolean isDiscountPrinted () 
	{ 
		Boolean bb = (Boolean)getValue ("IsDiscountPrinted"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setC_BPartner_Location_ID (int C_BPartner_Location_ID) 
	{ 
		setValue ("C_BPartner_Location_ID", new Integer (C_BPartner_Location_ID)); 
	} 
 
	public int getC_BPartner_Location_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_BPartner_Location_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setDatePrinted (Timestamp DatePrinted) 
	{ 
		setValue ("DatePrinted", DatePrinted); 
	} 
 
	public Timestamp getDatePrinted () 
	{ 
		return (Timestamp)getValue ("DatePrinted"); 
	} 
 
	public void setIsSelected (boolean IsSelected) 
	{ 
		setValue ("IsSelected", new Boolean(IsSelected)); 
	} 
 
	public boolean isSelected () 
	{ 
		Boolean bb = (Boolean)getValue ("IsSelected"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setIsTaxIncluded (boolean IsTaxIncluded) 
	{ 
		setValue ("IsTaxIncluded", new Boolean(IsTaxIncluded)); 
	} 
 
	public boolean isTaxIncluded () 
	{ 
		Boolean bb = (Boolean)getValue ("IsTaxIncluded"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setC_Payment_ID (int C_Payment_ID) 
	{ 
		setValue ("C_Payment_ID", new Integer (C_Payment_ID)); 
	} 
 
	public int getC_Payment_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Payment_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setC_CashLine_ID (int C_CashLine_ID) 
	{ 
		setValue ("C_CashLine_ID", new Integer (C_CashLine_ID)); 
	} 
 
	public int getC_CashLine_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_CashLine_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setIsSOTrx (boolean IsSOTrx) 
	{ 
		setValue ("IsSOTrx", new Boolean(IsSOTrx)); 
	} 
 
	public boolean isSOTrx () 
	{ 
		Boolean bb = (Boolean)getValue ("IsSOTrx"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setSendEMail (boolean SendEMail) 
	{ 
		setValue ("SendEMail", new Boolean(SendEMail)); 
	} 
 
	public boolean isSendEMail () 
	{ 
		Boolean bb = (Boolean)getValue ("SendEMail"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setProcessed (boolean Processed) 
	{ 
		setValueNoCheck ("Processed", new Boolean(Processed)); 
	} 
 
	public boolean isProcessed () 
	{ 
		Boolean bb = (Boolean)getValue ("Processed"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setPosted (boolean Posted) 
	{ 
		setValueNoCheck ("Posted", new Boolean(Posted)); 
	} 
 
	public boolean isPosted () 
	{ 
		Boolean bb = (Boolean)getValue ("Posted"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setDateAcct (Timestamp DateAcct) 
	{ 
		if (DateAcct == null) 
			throw new IllegalArgumentException ("DateAcct is mandatory"); 
		setValue ("DateAcct", DateAcct); 
	} 
 
	public Timestamp getDateAcct () 
	{ 
		return (Timestamp)getValue ("DateAcct"); 
	} 
 
	public void setSalesRep_ID (int SalesRep_ID) 
	{ 
		setValue ("SalesRep_ID", new Integer (SalesRep_ID)); 
	} 
 
	public int getSalesRep_ID () 
	{ 
		Integer ii = (Integer)getValue ("SalesRep_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setDescription (String Description) 
	{ 
		setValue ("Description", Description); 
	} 
 
	public String getDescription () 
	{ 
		return (String)getValue ("Description"); 
	} 
 
	public void setC_DocTypeTarget_ID (int C_DocTypeTarget_ID) 
	{ 
		setValue ("C_DocTypeTarget_ID", new Integer (C_DocTypeTarget_ID)); 
	} 
 
	public int getC_DocTypeTarget_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_DocTypeTarget_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setDatePromised (Timestamp DatePromised) 
	{ 
		if (DatePromised == null) 
			throw new IllegalArgumentException ("DatePromised is mandatory"); 
		setValue ("DatePromised", DatePromised); 
	} 
 
	public Timestamp getDatePromised () 
	{ 
		return (Timestamp)getValue ("DatePromised"); 
	} 
 
	public void setC_PaymentTerm_ID (int C_PaymentTerm_ID) 
	{ 
		setValue ("C_PaymentTerm_ID", new Integer (C_PaymentTerm_ID)); 
	} 
 
	public int getC_PaymentTerm_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_PaymentTerm_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	void setIsApproved (boolean IsApproved) 
	{ 
		setValueNoCheck ("IsApproved", new Boolean(IsApproved)); 
	} 
 
	public boolean isApproved () 
	{ 
		Boolean bb = (Boolean)getValue ("IsApproved"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setC_DocType_ID (int C_DocType_ID) 
	{ 
		setValueNoCheck ("C_DocType_ID", new Integer (C_DocType_ID)); 
	} 
 
	public int getC_DocType_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_DocType_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	/** 
	 * 	Set Price List (and Currency) when valid 
	 * 	@param M_PriceList_ID price list 
	 */ 
	public void setM_PriceList_ID (int M_PriceList_ID) 
	{ 
		String sql = "SELECT M_PriceList_ID, C_Currency_ID " 
			+ "FROM M_PriceList WHERE M_PriceList_ID=?"; 
		PreparedStatement pstmt = null; 
		try 
		{ 
			pstmt = DB.prepareStatement(sql); 
			pstmt.setInt(1, M_PriceList_ID); 
			ResultSet rs = pstmt.executeQuery(); 
			if (rs.next()) 
			{ 
				setValue ("M_PriceList_ID", new Integer(rs.getInt(1))); 
				setC_Currency_ID (rs.getInt(2)); 
			} 
			rs.close(); 
			pstmt.close(); 
			pstmt = null; 
		} 
		catch (Exception e) 
		{ 
			log.error("MOrder.setM_PriceList_ID", e); 
		} 
		finally 
		{ 
			try 
			{ 
				if (pstmt != null) 
					pstmt.close (); 
			} 
			catch (Exception e) 
			{} 
			pstmt = null; 
		} 
	} 
 
	public int getM_PriceList_ID () 
	{ 
		Integer ii = (Integer)getValue ("M_PriceList_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setFreightAmt (BigDecimal FreightAmt) 
	{ 
		if (FreightAmt == null) 
			throw new IllegalArgumentException ("FreightAmt is mandatory"); 
		setValue ("FreightAmt", FreightAmt); 
	} 
 
	public BigDecimal getFreightAmt () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("FreightAmt"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	void setIsPrinted (boolean IsPrinted) 
	{ 
		setValueNoCheck ("IsPrinted", new Boolean(IsPrinted)); 
	} 
 
	public boolean isPrinted () 
	{ 
		Boolean bb = (Boolean)getValue ("IsPrinted"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setIsCreditApproved (boolean IsCreditApproved) 
	{ 
		setValueNoCheck ("IsCreditApproved", new Boolean(IsCreditApproved)); 
	} 
 
	public boolean isCreditApproved () 
	{ 
		Boolean bb = (Boolean)getValue ("IsCreditApproved"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setIsDelivered (boolean IsDelivered) 
	{ 
		setValueNoCheck ("IsDelivered", new Boolean(IsDelivered)); 
	} 
 
	public boolean isDelivered () 
	{ 
		Boolean bb = (Boolean)getValue ("IsDelivered"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setIsInvoiced (boolean IsInvoiced) 
	{ 
		setValueNoCheck ("IsInvoiced", new Boolean(IsInvoiced)); 
	} 
 
	public boolean isInvoiced () 
	{ 
		Boolean bb = (Boolean)getValue ("IsInvoiced"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	void setDocumentNo (String DocumentNo) 
	{ 
		if (DocumentNo == null) 
			throw new IllegalArgumentException ("DocumentNo is mandatory"); 
		setValueNoCheck ("DocumentNo", DocumentNo); 
	} 
 
	public String getDocumentNo () 
	{ 
		return (String)getValue ("DocumentNo"); 
	} 
 
	void setIsTransferred (boolean IsTransferred) 
	{ 
		setValueNoCheck ("IsTransferred", new Boolean(IsTransferred)); 
	} 
 
	public boolean isTransferred () 
	{ 
		Boolean bb = (Boolean)getValue ("IsTransferred"); 
		if (bb != null) 
			return bb.booleanValue (); 
		return false; 
	} 
 
	public void setDateOrdered (Timestamp DateOrdered) 
	{ 
		if (DateOrdered == null) 
			throw new IllegalArgumentException ("DateOrdered is mandatory"); 
		setValue ("DateOrdered", DateOrdered); 
	} 
 
	public Timestamp getDateOrdered () 
	{ 
		return (Timestamp)getValue ("DateOrdered"); 
	} 
 
	public static final String InvoiceRule_AfterOrderDelivered = "O"; 
	public static final String InvoiceRule_AfterDelivery = "D"; 
	public static final String InvoiceRule_CustomerScheduleAfterDelivery = "S"; 
	public static final String InvoiceRule_Immediate = "I"; 
 
	public void setInvoiceRule (String InvoiceRule) 
	{ 
		if (InvoiceRule.equals ("D") || InvoiceRule.equals ("I") 
		  || InvoiceRule.equals ("O") || InvoiceRule.equals ("S")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "InvoiceRule Invalid value - Reference_ID=150 - D - I - O - S"); 
		if (InvoiceRule == null) 
			throw new IllegalArgumentException ("InvoiceRule is mandatory"); 
		setValue ("InvoiceRule", InvoiceRule); 
	} 
 
	public String getInvoiceRule () 
	{ 
		return (String)getValue ("InvoiceRule"); 
	} 
 
	void setC_Currency_ID (int C_Currency_ID) 
	{ 
		setValueNoCheck ("C_Currency_ID", new Integer (C_Currency_ID)); 
	} 
 
	public int getC_Currency_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Currency_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public static final String DocStatus_Drafted = "DR"; 
	public static final String DocStatus_Completed = "CO"; 
	public static final String DocStatus_Approved = "AP"; 
	public static final String DocStatus_Changed = "CH"; 
	public static final String DocStatus_NotApproved = "NA"; 
	public static final String DocStatus_TransferError = "TE"; 
	public static final String DocStatus_Printed = "PR"; 
	public static final String DocStatus_Transferred = "TR"; 
	public static final String DocStatus_Voided = "VO"; 
	public static final String DocStatus_Inactive = "IN"; 
	public static final String DocStatus_PostingError = "PE"; 
	public static final String DocStatus_Posted = "PO"; 
	public static final String DocStatus_Reversed = "RE"; 
	public static final String DocStatus_Closed = "CL"; 
	public static final String DocStatus_Unknown = "??"; 
	public static final String DocStatus_BeingProcessed = "XX"; 
	public static final String DocStatus_InProgress = "IP"; 
	public static final String DocStatus_WaitingPayment = "WP"; 
 
	void setDocStatus (String DocStatus) 
	{ 
		if (DocStatus.equals ("??") || DocStatus.equals ("AP") 
		  || DocStatus.equals ("CH") || DocStatus.equals ("CL") 
		  || DocStatus.equals ("CO") || DocStatus.equals ("DR") 
		  || DocStatus.equals ("IN") || DocStatus.equals ("IP") 
		  || DocStatus.equals ("NA") || DocStatus.equals ("PE") 
		  || DocStatus.equals ("PO") || DocStatus.equals ("PR") 
		  || DocStatus.equals ("RE") || DocStatus.equals ("TE") 
		  || DocStatus.equals ("TR") || DocStatus.equals ("VO") 
		  || DocStatus.equals ("WP") || DocStatus.equals ("XX")) 
			; 
		else 
			throw new IllegalArgumentException ("DocStatus Invalid value - Reference_ID=131 - ?? - AP - CH - CL - CO - DR - IN - IP - NA - PE - PO - PR - RE - TE - TR - VO - WP - XX"); 
		if (DocStatus == null) 
			throw new IllegalArgumentException ("DocStatus is mandatory"); 
		setValueNoCheck ("DocStatus", DocStatus); 
	} 
 
	public String getDocStatus () 
	{ 
		return (String)getValue ("DocStatus"); 
	} 
 
 
	public static final String		DocAction_Nothing = "--"; 
	public static final String		DocAction_Close = "CL"; 
	public static final String		DocAction_Complete = "CO"; 
	public static final String		DocAction_Process = "PR"; 
	public static final String		DocAction_Void = "VO"; 
 
	public void setDocAction (String DocAction) 
	{ 
		if (DocAction.equals ("--") || DocAction.equals ("AP") 
		  || DocAction.equals ("CL") || DocAction.equals ("CO") 
		  || DocAction.equals ("PO") || DocAction.equals ("PR") 
		  || DocAction.equals ("RA") || DocAction.equals ("RC") 
		  || DocAction.equals ("RE") || DocAction.equals ("RJ") 
		  || DocAction.equals ("TR") || DocAction.equals ("VO") 
		  || DocAction.equals ("XL")) 
			; 
		else 
			throw new IllegalArgumentException ("DocAction Invalid value - Reference_ID=135 - __ - AP - CL - CO - PO - PR - RA - RC - TE - RJ - VO - XL"); 
		if (DocAction == null) 
			throw new IllegalArgumentException ("DocAction is mandatory"); 
		setValueNoCheck ("DocAction", DocAction); 
	} 
 
	public String getDocAction () 
	{ 
		return (String)getValue ("DocAction"); 
	} 
 
	public void setM_Warehouse_ID (int M_Warehouse_ID) 
	{ 
		setValue ("M_Warehouse_ID", new Integer (M_Warehouse_ID)); 
	} 
 
	public int getM_Warehouse_ID () 
	{ 
		Integer ii = (Integer)getValue ("M_Warehouse_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setC_Campaign_ID (int C_Campaign_ID) 
	{ 
		setValue ("C_Campaign_ID", new Integer (C_Campaign_ID)); 
	} 
 
	public int getC_Campaign_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Campaign_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	void setTotalLines (BigDecimal TotalLines) 
	{ 
		if (TotalLines == null) 
			throw new IllegalArgumentException ("TotalLines is mandatory"); 
		setValueNoCheck ("TotalLines", TotalLines); 
	} 
 
	public BigDecimal getTotalLines () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("TotalLines"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	void setGrandTotal (BigDecimal GrandTotal) 
	{ 
		if (GrandTotal == null) 
			throw new IllegalArgumentException ("GrandTotal is mandatory"); 
		setValueNoCheck ("GrandTotal", GrandTotal); 
	} 
 
	public BigDecimal getGrandTotal () 
	{ 
		BigDecimal bd = (BigDecimal)getValue ("GrandTotal"); 
		if (bd == null) 
			return Env.ZERO; 
		return bd; 
	} 
 
	public void setPOReference (String POReference) 
	{ 
		setValue ("POReference", POReference); 
	} 
 
	public String getPOReference () 
	{ 
		return (String)getValue ("POReference"); 
	} 
 
	public void setC_Charge_ID (int C_Charge_ID) 
	{ 
		setValue ("C_Charge_ID", new Integer (C_Charge_ID)); 
	} 
 
	public int getC_Charge_ID () 
	{ 
		Integer ii = (Integer)getValue ("C_Charge_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setPriorityRule (String PriorityRule) 
	{ 
		if (PriorityRule.equals ("3") || PriorityRule.equals ("5") 
		  || PriorityRule.equals ("7")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "PriorityRule Invalid value - Reference_ID=154 - 3 - 5 - 7"); 
		if (PriorityRule == null) 
			throw new IllegalArgumentException ("PriorityRule is mandatory"); 
		setValue ("PriorityRule", PriorityRule); 
	} 
 
	public String getPriorityRule () 
	{ 
		return (String)getValue ("PriorityRule"); 
	} 
 
	public static final String DeliveryViaRule_Pickup = "P"; 
	public static final String DeliveryViaRule_Delivery = "D"; 
	public static final String DeliveryViaRule_Shipper = "S"; 
 
	public void setDeliveryViaRule (String DeliveryViaRule) 
	{ 
		if (DeliveryViaRule.equals ("D") || DeliveryViaRule.equals ("P") 
		  || DeliveryViaRule.equals ("S")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "DeliveryViaRule Invalid value - Reference_ID=152 - D - P - S"); 
		if (DeliveryViaRule == null) 
			throw new IllegalArgumentException ("DeliveryViaRule is mandatory"); 
		setValue ("DeliveryViaRule", DeliveryViaRule); 
	} 
 
	public String getDeliveryViaRule () 
	{ 
		return (String)getValue ("DeliveryViaRule"); 
	} 
 
	public void setM_Shipper_ID (int M_Shipper_ID) 
	{ 
		setValue ("M_Shipper_ID", new Integer (M_Shipper_ID)); 
	} 
 
	public int getM_Shipper_ID () 
	{ 
		Integer ii = (Integer)getValue ("M_Shipper_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public void setBillTo_ID (int BillTo_ID) 
	{ 
		setValue ("BillTo_ID", new Integer (BillTo_ID)); 
	} 
 
	public int getBillTo_ID () 
	{ 
		Integer ii = (Integer)getValue ("BillTo_ID"); 
		if (ii == null) 
			return 0; 
		return ii.intValue (); 
	} 
 
	public static final String		PaymentRule_Cash = "B"; 
	public static final String		PaymentRule_Check = "S"; 
	public static final String		PaymentRule_CreditCard = "K"; 
	public static final String		PaymentRule_PaymentTerm = "P"; 
	public static final String		PaymentRule_Transfer = "T"; 
 
	public void setPaymentRule (String PaymentRule) 
	{ 
		if (PaymentRule.equals ("B") || PaymentRule.equals ("K") 
		  || PaymentRule.equals ("P") || PaymentRule.equals ("S") 
		  || PaymentRule.equals ("T")) 
			; 
		else 
			throw new IllegalArgumentException ( 
			  "PaymentRule Invalid value - Reference_ID=195 - B - K - P - S - T"); 
		setValue ("PaymentRule", PaymentRule); 
	} 
 
	public String getPaymentRule () 
	{ 
		return (String)getValue ("PaymentRule"); 
	} 
 
	/*************************************************************************/ 
 
	/** 
	 * 	Get Invoices of Order 
	 * 	@return invoices 
	 */ 
	public MOrderLine[] getLines() 
	{ 
		ArrayList list = new ArrayList(); 
		String sql = "SELECT * FROM C_OrderLine WHERE C_Order_ID=? ORDER BY Line DESC"; 
		PreparedStatement pstmt = null; 
		try 
		{ 
			pstmt = DB.prepareStatement(sql); 
			pstmt.setInt(1, getC_Order_ID()); 
			ResultSet rs = pstmt.executeQuery(); 
			while (rs.next()) 
			{ 
				list.add(new MOrderLine(getCtx(), rs)); 
			} 
			rs.close(); 
			pstmt.close(); 
			pstmt = null; 
		} 
		catch (Exception e) 
		{ 
			log.error("getLines", e); 
		} 
		finally 
		{ 
			try 
			{ 
				if (pstmt != null) 
					pstmt.close (); 
			} 
			catch (Exception e) 
			{} 
			pstmt = null; 
		} 
		// 
		MOrderLine[] retValue = new MOrderLine[list.size()]; 
		list.toArray(retValue); 
		return retValue; 
	}	//	getLines 
 
 
	/** 
	 * 	Get Invoices of Order 
	 * 	@return invoices 
	 */ 
	public MInvoice[] getInvoices() 
	{ 
		ArrayList list = new ArrayList(); 
		String sql = "SELECT * FROM C_Invoice WHERE C_Order_ID=? ORDER BY Created DESC"; 
		PreparedStatement pstmt = null; 
		try 
		{ 
			pstmt = DB.prepareStatement(sql); 
			pstmt.setInt(1, getC_Order_ID()); 
			ResultSet rs = pstmt.executeQuery(); 
			while (rs.next()) 
			{ 
				list.add(new MInvoice(getCtx(), rs)); 
			} 
			rs.close(); 
			pstmt.close(); 
			pstmt = null; 
		} 
		catch (Exception e) 
		{ 
			log.error("getInvoices", e); 
		} 
		finally 
		{ 
			try 
			{ 
				if (pstmt != null) 
					pstmt.close (); 
			} 
			catch (Exception e) 
			{} 
			pstmt = null; 
		} 
		// 
		MInvoice[] retValue = new MInvoice[list.size()]; 
		list.toArray(retValue); 
		return retValue; 
	}	//	getInvoices 
 
	/** 
	 * 	Get Shipments of Order 
	 * 	@return shipments 
	 */ 
	public MInOut[] getShipments() 
	{ 
		ArrayList list = new ArrayList(); 
		String sql = "SELECT * FROM M_InOut WHERE C_Order_ID=? ORDER BY Created DESC"; 
		PreparedStatement pstmt = null; 
		try 
		{ 
			pstmt = DB.prepareStatement(sql); 
			pstmt.setInt(1, getC_Order_ID()); 
			ResultSet rs = pstmt.executeQuery(); 
			while (rs.next()) 
			{ 
				list.add(new MInOut(getCtx(), rs)); 
			} 
			rs.close(); 
			pstmt.close(); 
			pstmt = null; 
		} 
		catch (Exception e) 
		{ 
			log.error("getShipments", e); 
		} 
		finally 
		{ 
			try 
			{ 
				if (pstmt != null) 
					pstmt.close (); 
			} 
			catch (Exception e) 
			{} 
			pstmt = null; 
		} 
		// 
		MInOut[] retValue = new MInOut[list.size()]; 
		list.toArray(retValue); 
		return retValue; 
	}	//	getShipments 
 
 
}	//	MOrder