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

📄 morderline.java

📁 Java写的ERP系统
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 * 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.util.*;


/**
 *  Order Line Model
 *
 *  @author Jorg Janke
 *  @version $Id: MOrderLine.java,v 1.7 2003/05/04 06:40:55 jjanke Exp $
 */
public class MOrderLine extends PO
{
	/**
	 *  Default Constructor
	 *  @param ctx context
	 *  @param  C_OrderLine_ID  order line to load
	 */
	public MOrderLine (Properties ctx, int C_OrderLine_ID)
	{
		this (ctx, C_OrderLine_ID, 0);
	}	//	MOrderLine

	/**
	 *  Full Constructor
	 *  @param ctx context
	 *  @param  C_OrderLine_ID  order line to load, (0 create new order line)
	 * 	@param	C_Order_ID		order - required when oder line is 0
	 */
	public MOrderLine(Properties ctx, int C_OrderLine_ID, int C_Order_ID)
	{
		super (ctx, C_OrderLine_ID);
		//  New
		if (C_OrderLine_ID == 0)
		{
			if (C_Order_ID == 0)
				throw new IllegalArgumentException ("MOrderLine new required Order_ID");
			setC_Order_ID (C_Order_ID);
			//
			setC_Tax_ID (0);
			setC_BPartner_Location_ID (0);
			setLine (0);
			setM_Warehouse_ID (0);
			setC_Currency_ID (0);
			setC_UOM_ID (0);
			//
			setDateOrdered (new Timestamp(System.currentTimeMillis()));
			//
			setPriceList (Env.ZERO);
			setPriceActual (Env.ZERO);
			setPriceLimit (Env.ZERO);
			setLineNetAmt (Env.ZERO);
			//
			setQtyOrdered (Env.ZERO);
			setQtyDelivered (Env.ZERO);
			setQtyReserved (Env.ZERO);
			setQtyInvoiced (Env.ZERO);
			//
			setDirectShip (false);
			setFreightAmt (Env.ZERO);
			setChargeAmt (Env.ZERO);
		}
	}	//	MOrderLine

	/**
	 *  Load Constructor
	 *  @param ctx context
	 *  @param rs result set record
	 */
	public MOrderLine (Properties ctx, ResultSet rs)
	{
		super (ctx, rs);
	}	//	MOrderLine

	private int 	m_M_PriceList_ID = 0;
	private boolean	m_priceSet = false;

	/**
	 *  Initialize and return PO_Info
	 *  @param ctx context
	 *  @return POInfo
	 */
	protected POInfo initPO (Properties ctx)
	{
		int AD_Table_ID = 260;
		POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
		return poi;
	}

	/**
	 * 	Set Defaults from Order.
	 * 	Does not set Parent !!
	 * 	@param order order
	 */
	public void setOrder (MOrder order)
	{
		setC_BPartner_ID(order.getC_BPartner_ID());
		setC_BPartner_Location_ID(order.getC_BPartner_Location_ID());
		setM_Warehouse_ID(order.getM_Warehouse_ID());
		setDateOrdered(order.getDateOrdered());
		setDatePromised(order.getDatePromised());
		m_M_PriceList_ID = order.getM_PriceList_ID();
		setC_Currency_ID(order.getC_Currency_ID());
	}	//	setOrder

	/**
	 * 	Set Price for Product and PriceList
	 */
	public void setPrice()
	{
		if (getM_Product_ID() == 0)
			return;
		//
		Log.trace(Log.l4_Data, "MOrderLine.setPrice - M_PriceList_ID=" + m_M_PriceList_ID);
		MProductPrice pp = new MProductPrice (getM_Product_ID());
		pp.setM_PriceList_ID(m_M_PriceList_ID);
		setPriceActual (pp.getPriceStd());
		setPriceList (pp.getPriceList());
		setPriceLimit (pp.getPriceLimit());
		//	Calculate Discount
		setDiscount(pp.getDiscount());
		//	Set UOM
		setC_UOM_ID(pp.getC_UOM_ID());
		//
		m_priceSet = true;
	}	//	setPrice

	/**
	 *	Set Tax
	 */
	public void setTax()
	{
		int ii = Tax.get(getCtx(), getM_Product_ID(), getC_Charge_ID(), getDateOrdered(), getDateOrdered(),
			getAD_Org_ID(), getM_Warehouse_ID(),
			getC_BPartner_Location_ID(),		//	should be bill to
			getC_BPartner_Location_ID(), true);	//	is SO hard coded
		if (ii != 0)
			setC_Tax_ID (ii);
		else
			log.error("MOrderLine.setTax - No Tax found");
	}	//	setTax

	/**
	 * 	Set Defaults if not set
	 */
	private void setDefaults()
	{
		//	Get Defaults from Parent
		if (getC_BPartner_ID() == 0 || getC_BPartner_Location_ID() == 0
			|| getM_Warehouse_ID() == 0)
		{
			MOrder o = new MOrder (getCtx(), getC_Order_ID());
			setOrder (o);
		}

		//	Set Price
		if (!m_priceSet && Env.ZERO.compareTo(getPriceActual()) == 0)
			setPrice();

		//	Set Tax
		if (getC_Tax_ID() == 0)
			setTax();

		//	Get Line No
		if (getLine() == 0)
		{
			String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM C_OrderLine WHERE C_Order_ID=?";
			int ii = DB.getSQLValue (sql, getC_Order_ID());
			setLine (ii);
		}
		//
		if (getC_UOM_ID() == 0)
			setC_UOM_ID (Env.getContextAsInt(getCtx(), "#C_UOM_ID"));

		//	Calculations
		setLineNetAmt(getPriceActual().multiply(getQtyOrdered()));
		setDiscount();
	}	//	setDefaults


	public boolean save ()
	{
		Log.trace (Log.l4_Data, "MOrderLine.save");
		setDefaults();
		return super.save ();
	}

	public String toString ()
	{
		StringBuffer sb = new StringBuffer ("MOrderLine[")
			.append(getID())
			.append ("]");
		return sb.toString ();
	}

	/**
	 * 	Get Name
	 *	@return get the name of the line (from Product)
	 */
	public String getName()
	{
		String retValue = "";
		int M_Product_ID = getM_Product_ID();
		if (M_Product_ID == 0)
			return retValue;
		//
		String sql = "SELECT Name FROM M_Product WHERE M_Product_ID=?";
		PreparedStatement pstmt = null;
		try
		{
			pstmt = DB.prepareStatement(sql);
			pstmt.setInt(1, M_Product_ID);
			ResultSet rs = pstmt.executeQuery();
			if (rs.next())
				retValue = rs.getString(1);
			rs.close();
			pstmt.close();
			pstmt = null;
		}
		catch (Exception e)
		{
			log.error("getName", e);
		}
		finally
		{
			try
			{
				if (pstmt != null)
					pstmt.close ();
			}
			catch (Exception e)
			{}
			pstmt = null;
		}
		return retValue;
	}	//	getName

	/*************************************************************************/

	/**
	 * 	Set Discount
	 *	@param Discount discount
	 */
	public void setDiscount (BigDecimal Discount)
	{
		setValue ("Discount", Discount);
	}

	public void setDiscount ()
	{
		BigDecimal list = getPriceList();
		//	No List Price
		if (Env.ZERO.compareTo(list) == 0)
			return;
		BigDecimal discount = list.subtract(getPriceActual())
			.multiply(new BigDecimal(100))
			.divide(list, 2, BigDecimal.ROUND_HALF_UP);
		setDiscount(discount);
	}

	public BigDecimal getDiscount ()
	{
		BigDecimal bd = (BigDecimal)getValue ("Discount");
		if (bd == null)
			return Env.ZERO;
		return bd;
	}

	public void setPriceActual (BigDecimal PriceActual)
	{
		if (PriceActual == null)
			throw new IllegalArgumentException ("PriceActual is mandatory");
		setValue ("PriceActual", PriceActual);
	}

	public BigDecimal getPriceActual ()
	{
		BigDecimal bd = (BigDecimal)getValue ("PriceActual");
		if (bd == null)
			return Env.ZERO;
		return bd;
	}

	public void setC_Tax_ID (int C_Tax_ID)
	{
		setValue ("C_Tax_ID", new Integer (C_Tax_ID));
	}

	public int getC_Tax_ID ()
	{
		Integer ii = (Integer)getValue ("C_Tax_ID");
		if (ii == null)
			return 0;
		return ii.intValue ();
	}

	public void setLot (String Lot)
	{
		setValue ("Lot", Lot);
	}

	public String getLot ()
	{
		return (String)getValue ("Lot");
	}

	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 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 ();
	}

⌨️ 快捷键说明

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