📄 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 Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.util.*;
/**
* Order Line Model.
* <code>
* MOrderLine ol = new MOrderLine(m_order);
ol.setM_Product_ID(wbl.getM_Product_ID());
ol.setQtyOrdered(wbl.getQuantity());
ol.setPrice();
ol.setPriceActual(wbl.getPrice());
ol.setTax();
ol.save();
* </code>
* @author Jorg Janke
* @version $Id: MOrderLine.java,v 1.66 2006/01/28 01:28:28 jjanke Exp $
*/
public class MOrderLine extends X_C_OrderLine
{
/**
* Get Order Unreserved Qty
* @param ctx context
* @param M_Warehouse_ID wh
* @param M_Product_ID product
* @param M_AttributeSetInstance_ID asi
* @param excludeC_OrderLine_ID exclude C_OrderLine_ID
* @return Unreserved Qty
*/
public static BigDecimal getNotReserved (Properties ctx, int M_Warehouse_ID,
int M_Product_ID, int M_AttributeSetInstance_ID, int excludeC_OrderLine_ID)
{
BigDecimal retValue = Env.ZERO;
String sql = "SELECT SUM(QtyOrdered-QtyDelivered-QtyReserved) "
+ "FROM C_OrderLine ol"
+ " INNER JOIN C_Order o ON (ol.C_Order_ID=o.C_Order_ID) "
+ "WHERE ol.M_Warehouse_ID=?" // #1
+ " AND M_Product_ID=?" // #2
+ " AND o.IsSOTrx='Y' AND o.DocStatus='DR'"
+ " AND QtyOrdered-QtyDelivered-QtyReserved<>0"
+ " AND ol.C_OrderLine_ID<>?";
if (M_AttributeSetInstance_ID != 0)
sql += " AND M_AttributeSetInstance_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, null);
pstmt.setInt (1, M_Warehouse_ID);
pstmt.setInt (2, M_Product_ID);
pstmt.setInt (3, excludeC_OrderLine_ID);
if (M_AttributeSetInstance_ID != 0)
pstmt.setInt (4, M_AttributeSetInstance_ID);
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
retValue = rs.getBigDecimal(1);
rs.close ();
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
s_log.log (Level.SEVERE, sql, e);
}
try
{
if (pstmt != null)
pstmt.close ();
pstmt = null;
}
catch (Exception e)
{
pstmt = null;
}
if (retValue == null)
s_log.fine("-");
else
s_log.fine(retValue.toString());
return retValue;
} // getNotReserved
/** Logger */
private static CLogger s_log = CLogger.getCLogger (MOrderLine.class);
/**************************************************************************
* Default Constructor
* @param ctx context
* @param C_OrderLine_ID order line to load
* @param trxName trx name
*/
public MOrderLine (Properties ctx, int C_OrderLine_ID, String trxName)
{
super (ctx, C_OrderLine_ID, trxName);
if (C_OrderLine_ID == 0)
{
// setC_Order_ID (0);
// setLine (0);
// setM_Warehouse_ID (0); // @M_Warehouse_ID@
// setC_BPartner_ID(0);
// setC_BPartner_Location_ID (0); // @C_BPartner_Location_ID@
// setC_Currency_ID (0); // @C_Currency_ID@
// setDateOrdered (new Timestamp(System.currentTimeMillis())); // @DateOrdered@
//
// setC_Tax_ID (0);
// setC_UOM_ID (0);
//
setFreightAmt (Env.ZERO);
setLineNetAmt (Env.ZERO);
//
setPriceEntered(Env.ZERO);
setPriceActual (Env.ZERO);
setPriceLimit (Env.ZERO);
setPriceList (Env.ZERO);
//
setM_AttributeSetInstance_ID(0);
//
setQtyEntered (Env.ZERO);
setQtyOrdered (Env.ZERO); // 1
setQtyDelivered (Env.ZERO);
setQtyInvoiced (Env.ZERO);
setQtyReserved (Env.ZERO);
//
setIsDescription (false); // N
setProcessed (false);
setLine (0);
}
} // MOrderLine
/**
* Parent Constructor.
ol.setM_Product_ID(wbl.getM_Product_ID());
ol.setQtyOrdered(wbl.getQuantity());
ol.setPrice();
ol.setPriceActual(wbl.getPrice());
ol.setTax();
ol.save();
* @param order parent order
*/
public MOrderLine (MOrder order)
{
this (order.getCtx(), 0, order.get_TrxName());
if (order.get_ID() == 0)
throw new IllegalArgumentException("Header not saved");
setC_Order_ID (order.getC_Order_ID()); // parent
setOrder(order);
} // MOrderLine
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MOrderLine (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrderLine
private int m_M_PriceList_ID = 0;
//
private boolean m_IsSOTrx = true;
// Product Pricing
private MProductPricing m_productPrice = null;
/** Cached Precision */
private Integer m_precision = null;
/** Product */
private MProduct m_product = null;
/** Parent */
private MOrder m_parent = null;
/**
* Set Defaults from Order.
* Does not set Parent !!
* @param order order
*/
public void setOrder (MOrder order)
{
setClientOrg(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());
setC_Currency_ID(order.getC_Currency_ID());
//
setHeaderInfo(order); // sets m_order
} // setOrder
/**
* Set Header Info
* @param order order
*/
public void setHeaderInfo (MOrder order)
{
m_parent = order;
m_precision = new Integer(order.getPrecision());
m_M_PriceList_ID = order.getM_PriceList_ID();
m_IsSOTrx = order.isSOTrx();
} // setHeaderInfo
/**
* Get Parent
* @return parent
*/
public MOrder getParent()
{
if (m_parent == null)
m_parent = new MOrder(getCtx(), getC_Order_ID(), get_TrxName());
return m_parent;
} // getParent
/**
* Set Price Entered/Actual.
* Use this Method if the Line UOM is the Product UOM
* @param PriceActual price
*/
public void setPrice (BigDecimal PriceActual)
{
setPriceEntered(PriceActual);
setPriceActual (PriceActual);
} // setPrice
/**
* Set Price Actual.
* (actual price is not updateable)
* @param PriceActual actual price
*/
public void setPriceActual (BigDecimal PriceActual)
{
if (PriceActual == null)
throw new IllegalArgumentException ("PriceActual is mandatory");
set_ValueNoCheck("PriceActual", PriceActual);
} // setPriceActual
/**
* Set Price for Product and PriceList.
* Use only if newly created.
* Uses standard price list of not set by order constructor
*/
public void setPrice()
{
if (getM_Product_ID() == 0)
return;
if (m_M_PriceList_ID == 0)
throw new IllegalStateException("PriceList unknown!");
setPrice (m_M_PriceList_ID);
} // setPrice
/**
* Set Price for Product and PriceList
* @param M_PriceList_ID price list
*/
public void setPrice (int M_PriceList_ID)
{
if (getM_Product_ID() == 0)
return;
//
log.fine("M_PriceList_ID=" + M_PriceList_ID);
getProductPricing (M_PriceList_ID);
setPriceActual (m_productPrice.getPriceStd());
setPriceList (m_productPrice.getPriceList());
setPriceLimit (m_productPrice.getPriceLimit());
//
if (getQtyEntered().compareTo(getQtyOrdered()) == 0)
setPriceEntered(getPriceActual());
else
setPriceEntered(getPriceActual().multiply(getQtyOrdered()
.divide(getQtyEntered(), 12, BigDecimal.ROUND_HALF_UP))); // recision
// Calculate Discount
setDiscount(m_productPrice.getDiscount());
// Set UOM
setC_UOM_ID(m_productPrice.getC_UOM_ID());
} // setPrice
/**
* Get and calculate Product Pricing
* @param M_PriceList_ID id
* @return product pricing
*/
private MProductPricing getProductPricing (int M_PriceList_ID)
{
m_productPrice = new MProductPricing (getM_Product_ID(),
getC_BPartner_ID(), getQtyOrdered(), m_IsSOTrx);
m_productPrice.setM_PriceList_ID(M_PriceList_ID);
m_productPrice.setPriceDate(getDateOrdered());
//
m_productPrice.calculatePrice();
return m_productPrice;
} // getProductPrice
/**
* Set Tax
*/
public boolean 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(), m_IsSOTrx);
if (ii == 0)
{
log.log(Level.SEVERE, "No Tax found");
return false;
}
setC_Tax_ID (ii);
return true;
} // setTax
/**
* Calculate Extended Amt.
* May or may not include tax
*/
public void setLineNetAmt ()
{
BigDecimal bd = getPriceActual().multiply(getQtyOrdered());
if (bd.scale() > getPrecision())
bd = bd.setScale(getPrecision(), BigDecimal.ROUND_HALF_UP);
super.setLineNetAmt (bd);
} // setLineNetAmt
/**
* Get Currency Precision from Currency
* @return precision
*/
public int getPrecision()
{
if (m_precision != null)
return m_precision.intValue();
//
if (getC_Currency_ID() == 0)
{
setOrder (getParent());
if (m_precision != null)
return m_precision.intValue();
}
if (getC_Currency_ID() != 0)
{
MCurrency cur = MCurrency.get(getCtx(), getC_Currency_ID());
if (cur.get_ID() != 0)
{
m_precision = new Integer (cur.getStdPrecision());
return m_precision.intValue();
}
}
// Fallback
String sql = "SELECT c.StdPrecision "
+ "FROM C_Currency c INNER JOIN C_Order x ON (x.C_Currency_ID=c.C_Currency_ID) "
+ "WHERE x.C_Order_ID=?";
int i = DB.getSQLValue(get_TrxName(), sql, getC_Order_ID());
m_precision = new Integer(i);
return m_precision.intValue();
} // getPrecision
/**
* Set Product
* @param product product
*/
public void setProduct (MProduct product)
{
m_product = product;
if (m_product != null)
{
setM_Product_ID(m_product.getM_Product_ID());
setC_UOM_ID (m_product.getC_UOM_ID());
}
else
{
setM_Product_ID(0);
set_ValueNoCheck ("C_UOM_ID", null);
}
setM_AttributeSetInstance_ID(0);
} // setProduct
/**
* Set M_Product_ID
* @param M_Product_ID product
*/
public void setM_Product_ID (int M_Product_ID, boolean setUOM)
{
if (setUOM)
setProduct(MProduct.get(getCtx(), M_Product_ID));
else
super.setM_Product_ID (M_Product_ID);
setM_AttributeSetInstance_ID(0);
} // setM_Product_ID
/**
* Set Product and UOM
* @param M_Product_ID product
* @param C_UOM_ID uom
*/
public void setM_Product_ID (int M_Product_ID, int C_UOM_ID)
{
super.setM_Product_ID (M_Product_ID);
if (C_UOM_ID != 0)
super.setC_UOM_ID(C_UOM_ID);
setM_AttributeSetInstance_ID(0);
} // setM_Product_ID
/**
* Get Product
* @return product or null
*/
public MProduct getProduct()
{
if (m_product == null && getM_Product_ID() != 0)
m_product = MProduct.get (getCtx(), getM_Product_ID());
return m_product;
} // getProduct
/**
* Set M_AttributeSetInstance_ID
* @param M_AttributeSetInstance_ID id
*/
public void setM_AttributeSetInstance_ID (int M_AttributeSetInstance_ID)
{
if (M_AttributeSetInstance_ID == 0) // 0 is valid ID
set_Value("M_AttributeSetInstance_ID", new Integer(0));
else
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -