📄 minvoiceline.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 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.*;
/**
* Invoice Line Model
*
* @author Jorg Janke
* @version $Id: MInvoiceLine.java,v 1.6 2003/04/28 04:18:58 jjanke Exp $
*/
public class MInvoiceLine
extends PO
{
/**
* Invoice Line Constructor
* @param ctx context
* @param C_InvoiceLine_ID invoice line or 0
*/
public MInvoiceLine (Properties ctx, int C_InvoiceLine_ID)
{
this (ctx, C_InvoiceLine_ID, 0);
} // MInvoiceLine
/**
* Invoice Line Constructor
* @param ctx context
* @param C_InvoiceLine_ID invoice line ot 0
* @param C_Invoice_ID invoice
*/
public MInvoiceLine (Properties ctx, int C_InvoiceLine_ID, int C_Invoice_ID)
{
super (ctx, C_InvoiceLine_ID);
if (C_InvoiceLine_ID == 0)
{
if (C_Invoice_ID == 0)
throw new IllegalArgumentException ("MInvoiceLine new required Invoice_ID");
setC_Invoice_ID (C_Invoice_ID);
setLineNetAmt (Env.ZERO);
setChargeAmt (Env.ZERO);
setPriceActual (Env.ZERO);
setQtyInvoiced (Env.ZERO);
setPriceLimit (Env.ZERO);
setPriceList (Env.ZERO);
}
} // MInvoiceLine
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MInvoiceLine (Properties ctx, ResultSet rs)
{
super (ctx, rs);
} // MInvoiceLine
private int m_M_PriceList_ID = 0;
private Timestamp m_DateInvoiced = null;
private int m_C_BPartner_Location_ID = 0;
private boolean m_IsSOTrx = true;
private boolean m_priceSet = false;
/** Cached Name of the line */
private String m_name;
/**
* Initialize and return PO_Info
* @param ctx context
* @return POInfo
*/
protected POInfo initPO (Properties ctx)
{
int AD_Table_ID = 333;
POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
return poi;
} // initPO
/**
* Set Defaults from Order.
* Does not set Parent !!
* @param invoice invoice
*/
public void setInvoice (MInvoice invoice)
{
m_M_PriceList_ID = invoice.getM_PriceList_ID();
m_DateInvoiced = invoice.getDateInvoiced();
m_C_BPartner_Location_ID = invoice.getC_BPartner_Location_ID();
m_IsSOTrx = invoice.isSOTrx();
} // 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());
if (getC_UOM_ID() == 0)
setC_UOM_ID(pp.getC_UOM_ID());
//
m_priceSet = true;
} // setPrice
/**
* Set Tax
*/
public void setTax()
{
int M_Warehouse_ID = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID");
int ii = Tax.get(getCtx(), getM_Product_ID(), getC_Charge_ID() , m_DateInvoiced, m_DateInvoiced,
getAD_Org_ID(), M_Warehouse_ID,
m_C_BPartner_Location_ID, // should be bill to
m_C_BPartner_Location_ID, m_IsSOTrx);
if (ii != 0)
setC_Tax_ID (ii);
else
Log.error("MOrderLine.setTax - No Tax found");
} // setTax
/**
* Set Defaults if not set
*/
private void setDefaults()
{
// Set Price
if (!m_priceSet && getPriceActual().intValue() == 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_InvoiceLine WHERE C_Invoice_ID=?";
int ii = DB.getSQLValue (sql, getC_Invoice_ID());
setLine (ii);
}
//
if (getC_UOM_ID() == 0)
setC_UOM_ID (Env.getContextAsInt(getCtx(), "#C_UOM_ID"));
// Calculations
setLineNetAmt(getPriceActual().multiply(getQtyInvoiced()));
} // setDefaults
/**
* Save Line
* @return true if saved
*/
public boolean save ()
{
Log.trace (Log.l4_Data, "MInvoiceLine.save");
setDefaults();
return super.save ();
}
public String toString ()
{
StringBuffer sb = new StringBuffer ("MInvoiceLine[")
.append(getID())
.append ("]");
return sb.toString ();
}
void setC_InvoiceLine_ID (int C_InvoiceLine_ID)
{
setValueNoCheck ("C_InvoiceLine_ID", new Integer (C_InvoiceLine_ID));
}
public int getC_InvoiceLine_ID ()
{
Integer ii = (Integer)getValue ("C_InvoiceLine_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 setDescription (String Description)
{
setValue ("Description", Description);
}
public String getDescription ()
{
return (String)getValue ("Description");
}
/**
* Get Name
* @return name
*/
public String getName ()
{
if (m_name == null)
{
String sql = "SELECT COALESCE (p.Name, c.Name) "
+ "FROM C_InvoiceLine il"
+ " LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID)"
+ " LEFT OUTER JOIN C_Charge C ON (il.C_Charge_ID=c.C_Charge_ID) "
+ "WHERE C_InvoiceLine_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, getC_InvoiceLine_ID());
ResultSet rs = pstmt.executeQuery();
if (rs.next())
m_name = rs.getString(1);
rs.close();
pstmt.close();
pstmt = null;
if (m_name == null)
m_name = "??";
}
catch (Exception e)
{
log.error("getName", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
}
return m_name;
} // getName
/**
* Set Temporary (cached) Name
* @param tempName Cached Name
*/
public void setName (String tempName)
{
m_name = tempName;
} // setName
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;
}
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 int getC_OrderLine_ID ()
{
return getID();
}
public void setA_Asset_ID (int A_Asset_ID)
{
setValue ("A_Asset_ID", new Integer (A_Asset_ID));
}
public int getA_Asset_ID ()
{
Integer ii = (Integer)getValue ("A_Asset_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 setC_UOM_ID (int C_UOM_ID)
{
setValue ("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 ();
}
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 ();
}
void setS_ResourceAssignment_ID (int S_ResourceAssignment_ID)
{
setValueNoCheck ("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 setQtyInvoiced (BigDecimal QtyInvoiced)
{
if (QtyInvoiced == null)
throw new IllegalArgumentException ("QtyInvoiced is mandatory");
setValue ("QtyInvoiced", QtyInvoiced);
}
public BigDecimal getQtyInvoiced ()
{
BigDecimal bd = (BigDecimal)getValue ("QtyInvoiced");
if (bd == null)
return Env.ZERO;
return bd;
}
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;
}
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_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 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;
}
void setM_InOutLine_ID (int M_InOutLine_ID)
{
setValueNoCheck ("M_InOutLine_ID", new Integer (M_InOutLine_ID));
}
public int getM_InOutLine_ID ()
{
Integer ii = (Integer)getValue ("M_InOutLine_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
void setC_Invoice_ID (int C_Invoice_ID)
{
setValueNoCheck ("C_Invoice_ID", new Integer (C_Invoice_ID));
}
public int getC_Invoice_ID ()
{
Integer ii = (Integer)getValue ("C_Invoice_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -