📄 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. 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.*;
/**
* Invoice Line Model
*
* @author Jorg Janke
* @version $Id: MInvoiceLine.java,v 1.65 2006/02/12 02:18:12 jjanke Exp $
*/
public class MInvoiceLine extends X_C_InvoiceLine
{
/**
* Get Invoice Line referencing InOut Line
* @param sLine shipment line
* @return (first) invoice line
*/
public static MInvoiceLine getOfInOutLine (MInOutLine sLine)
{
if (sLine == null)
return null;
MInvoiceLine retValue = null;
String sql = "SELECT * FROM C_InvoiceLine WHERE M_InOutLine_ID=?";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement (sql, sLine.get_TrxName());
pstmt.setInt (1, sLine.getM_InOutLine_ID());
ResultSet rs = pstmt.executeQuery ();
if (rs.next ())
{
retValue = new MInvoiceLine (sLine.getCtx(), rs, sLine.get_TrxName());
if (rs.next())
s_log.warning("More than one C_InvoiceLine of " + sLine);
}
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;
}
return retValue;
} // getOfInOutLine
/** Static Logger */
private static CLogger s_log = CLogger.getCLogger (MInvoiceLine.class);
/**************************************************************************
* Invoice Line Constructor
* @param ctx context
* @param C_InvoiceLine_ID invoice line or 0
* @param trxName transaction name
*/
public MInvoiceLine (Properties ctx, int C_InvoiceLine_ID, String trxName)
{
super (ctx, C_InvoiceLine_ID, trxName);
if (C_InvoiceLine_ID == 0)
{
setIsDescription(false);
setIsPrinted (true);
setLineNetAmt (Env.ZERO);
setPriceEntered (Env.ZERO);
setPriceActual (Env.ZERO);
setPriceLimit (Env.ZERO);
setPriceList (Env.ZERO);
setM_AttributeSetInstance_ID(0);
setTaxAmt(Env.ZERO);
//
setQtyEntered(Env.ZERO);
setQtyInvoiced(Env.ZERO);
}
} // MInvoiceLine
/**
* Parent Constructor
* @param invoice parent
*/
public MInvoiceLine (MInvoice invoice)
{
this (invoice.getCtx(), 0, invoice.get_TrxName());
if (invoice.get_ID() == 0)
throw new IllegalArgumentException("Header not saved");
setClientOrg(invoice.getAD_Client_ID(), invoice.getAD_Org_ID());
setC_Invoice_ID (invoice.getC_Invoice_ID());
setInvoice(invoice);
} // MInvoiceLine
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MInvoiceLine (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MInvoiceLine
private int m_M_PriceList_ID = 0;
private Timestamp m_DateInvoiced = null;
private int m_C_BPartner_ID = 0;
private int m_C_BPartner_Location_ID = 0;
private boolean m_IsSOTrx = true;
private boolean m_priceSet = false;
private MProduct m_product = null;
/** Cached Name of the line */
private String m_name = null;
/** Cached Precision */
private Integer m_precision = null;
/** Product Pricing */
private MProductPricing m_productPricing = null;
/** Parent */
private MInvoice m_parent = null;
/**
* Set Defaults from Order.
* Called also from copy lines from invoice
* Does not set Parent !!
* @param invoice invoice
*/
public void setInvoice (MInvoice invoice)
{
m_parent = invoice;
m_M_PriceList_ID = invoice.getM_PriceList_ID();
m_DateInvoiced = invoice.getDateInvoiced();
m_C_BPartner_ID = invoice.getC_BPartner_ID();
m_C_BPartner_Location_ID = invoice.getC_BPartner_Location_ID();
m_IsSOTrx = invoice.isSOTrx();
m_precision = new Integer(invoice.getPrecision());
} // setOrder
/**
* Get Parent
* @return parent
*/
public MInvoice getParent()
{
if (m_parent == null)
m_parent = new MInvoice(getCtx(), getC_Invoice_ID(), get_TrxName());
return m_parent;
} // getParent
/**
* Set values from Order Line.
* Does not set quantity!
* @param oLine line
*/
public void setOrderLine (MOrderLine oLine)
{
setC_OrderLine_ID(oLine.getC_OrderLine_ID());
//
setLine(oLine.getLine());
setIsDescription(oLine.isDescription());
setDescription(oLine.getDescription());
//
setC_Charge_ID(oLine.getC_Charge_ID());
//
setM_Product_ID(oLine.getM_Product_ID());
setM_AttributeSetInstance_ID(oLine.getM_AttributeSetInstance_ID());
setS_ResourceAssignment_ID(oLine.getS_ResourceAssignment_ID());
setC_UOM_ID(oLine.getC_UOM_ID());
//
setPriceEntered(oLine.getPriceEntered());
setPriceActual(oLine.getPriceActual());
setPriceLimit(oLine.getPriceLimit());
setPriceList(oLine.getPriceList());
//
setC_Tax_ID(oLine.getC_Tax_ID());
setLineNetAmt(oLine.getLineNetAmt());
} // setOrderLine
/**
* Set values from Shipment Line.
* Does not set quantity!
* @param sLine ship line
*/
public void setShipLine (MInOutLine sLine)
{
setM_InOutLine_ID(sLine.getM_InOutLine_ID());
setC_OrderLine_ID(sLine.getC_OrderLine_ID());
//
setLine(sLine.getLine());
setIsDescription(sLine.isDescription());
setDescription(sLine.getDescription());
//
setM_Product_ID(sLine.getM_Product_ID());
setC_UOM_ID(sLine.getC_UOM_ID());
setM_AttributeSetInstance_ID(sLine.getM_AttributeSetInstance_ID());
// setS_ResourceAssignment_ID(sLine.getS_ResourceAssignment_ID());
setC_Charge_ID(sLine.getC_Charge_ID());
//
int C_OrderLine_ID = sLine.getC_OrderLine_ID();
if (C_OrderLine_ID != 0)
{
MOrderLine oLine = new MOrderLine (getCtx(), C_OrderLine_ID, get_TrxName());
setS_ResourceAssignment_ID(oLine.getS_ResourceAssignment_ID());
//
setPriceEntered(oLine.getPriceEntered());
setPriceActual(oLine.getPriceActual());
setPriceLimit(oLine.getPriceLimit());
setPriceList(oLine.getPriceList());
//
setC_Tax_ID(oLine.getC_Tax_ID());
setLineNetAmt(oLine.getLineNetAmt());
}
else
{
setPrice();
setTax();
}
} // setOrderLine
/**
* Add to Description
* @param description text
*/
public void addDescription (String description)
{
String desc = getDescription();
if (desc == null)
setDescription(description);
else
setDescription(desc + " | " + description);
} // addDescription
/**
* 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
super.setM_AttributeSetInstance_ID (M_AttributeSetInstance_ID);
} // setM_AttributeSetInstance_ID
/**************************************************************************
* Set Price for Product and PriceList.
* Uses standard SO price list of not set by invoice constructor
*/
public void setPrice()
{
if (getM_Product_ID() == 0 || isDescription())
return;
if (m_M_PriceList_ID == 0 || m_C_BPartner_ID == 0)
setInvoice(getParent());
if (m_M_PriceList_ID == 0 || m_C_BPartner_ID == 0)
throw new IllegalStateException("setPrice - PriceList unknown!");
setPrice (m_M_PriceList_ID, m_C_BPartner_ID);
} // setPrice
/**
* Set Price for Product and PriceList
* @param M_PriceList_ID price list
* @param C_BPartner_ID business partner
*/
public void setPrice (int M_PriceList_ID, int C_BPartner_ID)
{
if (getM_Product_ID() == 0 || isDescription())
return;
//
log.fine("M_PriceList_ID=" + M_PriceList_ID);
m_productPricing = new MProductPricing (getM_Product_ID(),
C_BPartner_ID, getQtyInvoiced(), m_IsSOTrx);
m_productPricing.setM_PriceList_ID(M_PriceList_ID);
m_productPricing.setPriceDate(m_DateInvoiced);
//
setPriceActual (m_productPricing.getPriceStd());
setPriceList (m_productPricing.getPriceList());
setPriceLimit (m_productPricing.getPriceLimit());
//
if (getQtyEntered().compareTo(getQtyInvoiced()) == 0)
setPriceEntered(getPriceActual());
else
setPriceEntered(getPriceActual().multiply(getQtyInvoiced()
.divide(getQtyEntered(), 6, BigDecimal.ROUND_HALF_UP))); // precision
//
if (getC_UOM_ID() == 0)
setC_UOM_ID(m_productPricing.getC_UOM_ID());
//
m_priceSet = true;
} // setPrice
/**
* 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 Tax - requires Warehouse
* @return true if found
*/
public boolean setTax()
{
if (isDescription())
return true;
//
int M_Warehouse_ID = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID");
//
int C_Tax_ID = 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 (C_Tax_ID == 0)
{
log.log(Level.SEVERE, "No Tax found");
return false;
}
setC_Tax_ID (C_Tax_ID);
if (m_IsSOTrx)
{
}
return true;
} // setTax
/**
* Calculare Tax Amt.
* Assumes Line Net is calculated
*/
public void setTaxAmt ()
{
BigDecimal TaxAmt = Env.ZERO;
if (getC_Tax_ID() == 0)
return;
// setLineNetAmt();
MTax tax = MTax.get (getCtx(), getC_Tax_ID());
if (tax.isDocumentLevel() && m_IsSOTrx) // AR Inv Tax
return;
//
TaxAmt = tax.calculateTax(getLineNetAmt(), isTaxIncluded(), getPrecision());
if (isTaxIncluded())
setLineTotalAmt(getLineNetAmt());
else
setLineTotalAmt(getLineNetAmt().add(TaxAmt));
super.setTaxAmt (TaxAmt);
} // setTaxAmt
/**
* Calculate Extended Amt.
* May or may not include tax
*/
public void setLineNetAmt ()
{
// Calculations & Rounding
BigDecimal net = getPriceActual().multiply(getQtyInvoiced());
if (net.scale() > getPrecision())
net = net.setScale(getPrecision(), BigDecimal.ROUND_HALF_UP);
super.setLineNetAmt (net);
} // setLineNetAmt
/**
* Set Qty Invoiced/Entered.
* @param Qty Invoiced/Ordered
*/
public void setQty (int Qty)
{
setQty(new BigDecimal(Qty));
} // setQtyInvoiced
/**
* Set Qty Invoiced
* @param Qty Invoiced/Entered
*/
public void setQty (BigDecimal Qty)
{
setQtyEntered(Qty);
setQtyInvoiced(Qty);
} // setQtyInvoiced
/**
* 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);
setC_UOM_ID (0);
}
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);
super.setC_UOM_ID(C_UOM_ID);
setM_AttributeSetInstance_ID(0);
} // setM_Product_ID
/**
* Get C_Project_ID
* @return project
*/
public int getC_Project_ID()
{
int ii = super.getC_Project_ID ();
if (ii == 0)
ii = getParent().getC_Project_ID();
return ii;
} // getC_Project_ID
/**
* Get C_Activity_ID
* @return Activity
*/
public int getC_Activity_ID()
{
int ii = 0; // super.getC_Activity_ID ();
if (ii == 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -