www.pudn.com > code_source_compiere_erp_crm_logiciel_java.zip > MOrderLine.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.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 ();
}
public void setS_ResourceAssignment_ID (int S_ResourceAssignment_ID)
{
setValue ("S_ResourceAssignment_ID",
new Integer (S_ResourceAssignment_ID));
}
public int getS_ResourceAssignment_ID ()
{
Integer ii = (Integer)getValue ("S_ResourceAssignment_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setPriceLimit (BigDecimal PriceLimit)
{
if (PriceLimit == null)
throw new IllegalArgumentException ("PriceLimit is mandatory");
setValue ("PriceLimit", PriceLimit);
}
public BigDecimal getPriceLimit ()
{
BigDecimal bd = (BigDecimal)getValue ("PriceLimit");
if (bd == null)
return Env.ZERO;
return bd;
}
void setRef_OrderLine_ID (int Ref_OrderLine_ID)
{
setValueNoCheck ("Ref_OrderLine_ID", new Integer (Ref_OrderLine_ID));
}
public int getRef_OrderLine_ID ()
{
Integer ii = (Integer)getValue ("Ref_OrderLine_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setLineNetAmt (BigDecimal LineNetAmt)
{
if (LineNetAmt == null)
throw new IllegalArgumentException ("LineNetAmt is mandatory");
setValueNoCheck ("LineNetAmt", LineNetAmt);
}
public BigDecimal getLineNetAmt ()
{
BigDecimal bd = (BigDecimal)getValue ("LineNetAmt");
if (bd == null)
return Env.ZERO;
return bd;
}
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 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 setQtyOrdered (BigDecimal QtyOrdered)
{
if (QtyOrdered == null)
throw new IllegalArgumentException ("QtyOrdered is mandatory");
setValue ("QtyOrdered", QtyOrdered);
}
public BigDecimal getQtyOrdered ()
{
BigDecimal bd = (BigDecimal)getValue ("QtyOrdered");
if (bd == null)
return Env.ZERO;
return bd;
}
void setQtyDelivered (BigDecimal QtyDelivered)
{
if (QtyDelivered == null)
throw new IllegalArgumentException ("QtyDelivered is mandatory");
setValueNoCheck ("QtyDelivered", QtyDelivered);
}
public BigDecimal getQtyDelivered ()
{
BigDecimal bd = (BigDecimal)getValue ("QtyDelivered");
if (bd == null)
return Env.ZERO;
return bd;
}
void setQtyReserved (BigDecimal QtyReserved)
{
if (QtyReserved == null)
throw new IllegalArgumentException ("QtyReserved is mandatory");
setValueNoCheck ("QtyReserved", QtyReserved);
}
public BigDecimal getQtyReserved ()
{
BigDecimal bd = (BigDecimal)getValue ("QtyReserved");
if (bd == null)
return Env.ZERO;
return bd;
}
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 ();
}
void setQtyInvoiced (BigDecimal QtyInvoiced)
{
if (QtyInvoiced == null)
throw new IllegalArgumentException ("QtyInvoiced is mandatory");
setValueNoCheck ("QtyInvoiced", QtyInvoiced);
}
public BigDecimal getQtyInvoiced ()
{
BigDecimal bd = (BigDecimal)getValue ("QtyInvoiced");
if (bd == null)
return Env.ZERO;
return bd;
}
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 void setPriceList (BigDecimal PriceList)
{
if (PriceList == null)
throw new IllegalArgumentException ("PriceList is mandatory");
setValue ("PriceList", PriceList);
}
public BigDecimal getPriceList ()
{
BigDecimal bd = (BigDecimal)getValue ("PriceList");
if (bd == null)
return Env.ZERO;
return bd;
}
public void setDatePromised (Timestamp DatePromised)
{
setValue ("DatePromised", DatePromised);
}
public Timestamp getDatePromised ()
{
return (Timestamp)getValue ("DatePromised");
}
void setDateDelivered (Timestamp DateDelivered)
{
setValueNoCheck ("DateDelivered", DateDelivered);
}
public Timestamp getDateDelivered ()
{
return (Timestamp)getValue ("DateDelivered");
}
void setDateInvoiced (Timestamp DateInvoiced)
{
setValueNoCheck ("DateInvoiced", DateInvoiced);
}
public Timestamp getDateInvoiced ()
{
return (Timestamp)getValue ("DateInvoiced");
}
public void setSerNo (String SerNo)
{
setValue ("SerNo", SerNo);
}
public String getSerNo ()
{
return (String)getValue ("SerNo");
}
public int getC_OrderLine_ID ()
{
return getID();
}
void setC_Order_ID (int C_Order_ID)
{
setValueNoCheck ("C_Order_ID", new Integer (C_Order_ID));
}
public int getC_Order_ID ()
{
Integer ii = (Integer)getValue ("C_Order_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setLine (int Line)
{
setValue ("Line", new Integer (Line));
}
public int getLine ()
{
Integer ii = (Integer)getValue ("Line");
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 setM_Product_ID (int M_Product_ID)
{
setValue ("M_Product_ID", new Integer (M_Product_ID));
}
public int getM_Product_ID ()
{
Integer ii = (Integer)getValue ("M_Product_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setC_UOM_ID (int C_UOM_ID)
{
setValueNoCheck ("C_UOM_ID", new Integer (C_UOM_ID));
}
public int getC_UOM_ID ()
{
Integer ii = (Integer)getValue ("C_UOM_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setDirectShip (boolean DirectShip)
{
setValueNoCheck ("DirectShip", new Boolean(DirectShip));
}
public boolean isDirectShip ()
{
Boolean bb = (Boolean)getValue ("DirectShip");
if (bb != null)
return bb.booleanValue ();
return false;
}
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;
}
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 setChargeAmt (BigDecimal ChargeAmt)
{
if (ChargeAmt == null)
throw new IllegalArgumentException ("ChargeAmt is mandatory");
setValue ("ChargeAmt", ChargeAmt);
}
public BigDecimal getChargeAmt ()
{
BigDecimal bd = (BigDecimal)getValue ("ChargeAmt");
if (bd == null)
return Env.ZERO;
return bd;
}
} // MOrderLine