📄 docline.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.acct;
import java.math.*;
import java.sql.*;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* Standard Document Line
*
* @author Jorg Janke
* @version $Id: DocLine.java,v 1.18 2005/12/20 04:22:07 jjanke Exp $
*/
public class DocLine
{
/**
* Create Document Line
* @param po line persistent object
* @param doc header
*/
public DocLine (PO po, Doc doc)
{
if (po == null)
throw new IllegalArgumentException("PO is null");
p_po = po;
m_doc = doc;
//
// Document Consistency
if (p_po.getAD_Org_ID() == 0)
p_po.setAD_Org_ID(m_doc.getAD_Org_ID());
} // DocLine
/** Persistent Object */
protected PO p_po = null;
/** Parent */
private Doc m_doc = null;
/** Log */
protected CLogger log = CLogger.getCLogger(getClass());
/** Qty */
private BigDecimal m_qty = null;
// -- GL Amounts
/** Debit Journal Amt */
private BigDecimal m_AmtSourceDr = Env.ZERO;
/** Credit Journal Amt */
private BigDecimal m_AmtSourceCr = Env.ZERO;
/** Net Line Amt */
private BigDecimal m_LineNetAmt = null;
/** List Amount */
private BigDecimal m_ListAmt = Env.ZERO;
/** Discount Amount */
private BigDecimal m_DiscountAmt = Env.ZERO;
/** Converted Amounts */
private BigDecimal m_AmtAcctDr = null;
private BigDecimal m_AmtAcctCr = null;
/** Acct Schema */
private int m_C_AcctSchema_ID = 0;
/** Product Costs */
private ProductCost m_productCost = null;
/** Production indicator */
private boolean m_productionBOM = false;
/** Account used only for GL Journal */
private MAccount m_account = null;
/** Accounting Date */
private Timestamp m_DateAcct = null;
/** Document Date */
private Timestamp m_DateDoc = null;
/** Sales Region */
private int m_C_SalesRegion_ID = -1;
/** Sales Region */
private int m_C_BPartner_ID = -1;
/** Location From */
private int m_C_LocFrom_ID = 0;
/** Location To */
private int m_C_LocTo_ID = 0;
/** Item */
private Boolean m_isItem = null;
/** Currency */
private int m_C_Currency_ID = -1;
/** Conversion Type */
private int m_C_ConversionType_ID = -1;
/** Period */
private int m_C_Period_ID = -1;
/**
* Get Currency
* @return c_Currency_ID
*/
public int getC_Currency_ID ()
{
if (m_C_Currency_ID == -1)
{
int index = p_po.get_ColumnIndex("C_Currency_ID");
if (index != -1)
{
Integer ii = (Integer)p_po.get_Value(index);
if (ii != null)
m_C_Currency_ID = ii.intValue();
}
if (m_C_Currency_ID <= 0)
m_C_Currency_ID = m_doc.getC_Currency_ID();
}
return m_C_Currency_ID;
} // getC_Currency_ID
/**
* Get Conversion Type
* @return C_ConversionType_ID
*/
public int getC_ConversionType_ID ()
{
if (m_C_ConversionType_ID == -1)
{
int index = p_po.get_ColumnIndex("C_ConversionType_ID");
if (index != -1)
{
Integer ii = (Integer)p_po.get_Value(index);
if (ii != null)
m_C_ConversionType_ID = ii.intValue();
}
if (m_C_ConversionType_ID <= 0)
m_C_ConversionType_ID = m_doc.getC_ConversionType_ID();
}
return m_C_ConversionType_ID;
} // getC_ConversionType_ID
/**
* Set C_ConversionType_ID
* @param C_ConversionType_ID id
*/
protected void setC_ConversionType_ID(int C_ConversionType_ID)
{
m_C_ConversionType_ID = C_ConversionType_ID;
} // setC_ConversionType_ID
/**
* Set Amount (DR)
* @param sourceAmt source amt
*/
public void setAmount (BigDecimal sourceAmt)
{
m_AmtSourceDr = sourceAmt == null ? Env.ZERO : sourceAmt;
m_AmtSourceCr = Env.ZERO;
} // setAmounts
/**
* Set Amounts
* @param amtSourceDr source amount dr
* @param amtSourceCr source amount cr
*/
public void setAmount (BigDecimal amtSourceDr, BigDecimal amtSourceCr)
{
m_AmtSourceDr = amtSourceDr == null ? Env.ZERO : amtSourceDr;
m_AmtSourceCr = amtSourceCr == null ? Env.ZERO : amtSourceCr;
} // setAmounts
/**
* Set Converted Amounts
* @param C_AcctSchema_ID acct schema
* @param amtAcctDr acct amount dr
* @param amtAcctCr acct amount cr
*/
public void setConvertedAmt (int C_AcctSchema_ID, BigDecimal amtAcctDr, BigDecimal amtAcctCr)
{
m_C_AcctSchema_ID = C_AcctSchema_ID;
m_AmtAcctDr = amtAcctDr;
m_AmtAcctCr = amtAcctCr;
} // setConvertedAmt
/**
* Line Net Amount or Dr-Cr
* @return balance
*/
public BigDecimal getAmtSource()
{
return m_AmtSourceDr.subtract(m_AmtSourceCr);
} // getAmount
/**
* Get (Journal) Line Source Dr Amount
* @return DR source amount
*/
public BigDecimal getAmtSourceDr()
{
return m_AmtSourceDr;
} // getAmtSourceDr
/**
* Get (Journal) Line Source Cr Amount
* @return CR source amount
*/
public BigDecimal getAmtSourceCr()
{
return m_AmtSourceCr;
} // getAmtSourceCr
/**
* Line Journal Accounted Dr Amount
* @return DR accounted amount
*/
public BigDecimal getAmtAcctDr()
{
return m_AmtAcctDr;
} // getAmtAcctDr
/**
* Line Journal Accounted Cr Amount
* @return CR accounted amount
*/
public BigDecimal getAmtAcctCr()
{
return m_AmtAcctCr;
} // getAmtAccrCr
/**
* Charge Amount
* @return charge amount
*/
public BigDecimal getChargeAmt()
{
int index = p_po.get_ColumnIndex("ChargeAmt");
if (index != -1)
{
BigDecimal bd = (BigDecimal)p_po.get_Value(index);
if (bd != null)
return bd;
}
return Env.ZERO;
} // getChargeAmt
/**
* Set Product Amounts
* @param LineNetAmt Line Net Amt
* @param PriceList Price List
* @param Qty Qty for discount calc
*/
public void setAmount (BigDecimal LineNetAmt, BigDecimal PriceList, BigDecimal Qty)
{
m_LineNetAmt = LineNetAmt == null ? Env.ZERO : LineNetAmt;
if (PriceList != null && Qty != null)
m_ListAmt = PriceList.multiply(Qty);
if (m_ListAmt.equals(Env.ZERO))
m_ListAmt = m_LineNetAmt;
m_DiscountAmt = m_ListAmt.subtract(m_LineNetAmt);
//
setAmount (m_ListAmt, m_DiscountAmt);
// Log.trace(this,Log.l6_Database, "DocLine_Invoice.setAmount",
// "LineNet=" + m_LineNetAmt + ", List=" + m_ListAmt + ", Discount=" + m_DiscountAmt
// + " => Amount=" + getAmount());
} // setAmounts
/**
* Line Discount
* @return discount amount
*/
public BigDecimal getDiscount()
{
return m_DiscountAmt;
} // getDiscount
/**
* Line List Amount
* @return list amount
*/
public BigDecimal getListAmount()
{
return m_ListAmt;
} // getListAmount
/**
* Set Line Net Amt Difference
* @param diff difference (to be subtracted)
*/
public void setLineNetAmtDifference (BigDecimal diff)
{
String msg = "Diff=" + diff
+ " - LineNetAmt=" + m_LineNetAmt;
m_LineNetAmt = m_LineNetAmt.subtract(diff);
m_DiscountAmt = m_ListAmt.subtract(m_LineNetAmt);
setAmount (m_ListAmt, m_DiscountAmt);
msg += " -> " + m_LineNetAmt;
log.fine(msg);
} // setLineNetAmtDifference
/**************************************************************************
* Set Accounting Date
* @param dateAcct acct date
*/
public void setDateAcct (Timestamp dateAcct)
{
m_DateAcct = dateAcct;
} // setDateAcct
/**
* Get Accounting Date
* @return accounting date
*/
public Timestamp getDateAcct ()
{
if (m_DateAcct != null)
return m_DateAcct;
int index = p_po.get_ColumnIndex("DateAcct");
if (index != -1)
{
m_DateAcct = (Timestamp)p_po.get_Value(index);
if (m_DateAcct != null)
return m_DateAcct;
}
m_DateAcct = m_doc.getDateAcct();
return m_DateAcct;
} // getDateAcct
/**
* Set Document Date
* @param dateDoc doc date
*/
public void setDateDoc (Timestamp dateDoc)
{
m_DateDoc = dateDoc;
} // setDateDoc
/**
* Get Document Date
* @return document date
*/
public Timestamp getDateDoc ()
{
if (m_DateDoc != null)
return m_DateDoc;
int index = p_po.get_ColumnIndex("DateDoc");
if (index != -1)
{
m_DateDoc = (Timestamp)p_po.get_Value(index);
if (m_DateDoc != null)
return m_DateDoc;
}
m_DateDoc = m_doc.getDateDoc();
return m_DateDoc;
} // getDateDoc
/**************************************************************************
* Set GL Journal Account
* @param acct account
*/
public void setAccount (MAccount acct)
{
m_account = acct;
} // setAccount
/**
* Get GL Journal Account
* @return account
*/
public MAccount getAccount()
{
return m_account;
} // getAccount
/**
* Line Account from Product (or Charge).
*
* @param AcctType see ProductCost.ACCTTYPE_* (0..3)
* @param as Accounting schema
* @return Requested Product Account
*/
public MAccount getAccount (int AcctType, MAcctSchema as)
{
// Charge Account
if (getM_Product_ID() == 0 && getC_Charge_ID() != 0)
{
BigDecimal amt = new BigDecimal (-1); // Revenue (-)
if (!m_doc.isSOTrx())
amt = new BigDecimal (+1); // Expense (+)
MAccount acct = getChargeAccount(as, amt);
if (acct != null)
return acct;
}
// Product Account
return getProductCost().getAccount (AcctType, as);
} // getAccount
/**
* Get Charge
* @return C_Charge_ID
*/
protected int getC_Charge_ID()
{
int index = p_po.get_ColumnIndex("C_Charge_ID");
if (index != -1)
{
Integer ii = (Integer)p_po.get_Value(index);
if (ii != null)
return ii.intValue();
}
return 0;
} // getC_Charge_ID
/**
* Get Charge Account
* @param as account schema
* @param amount amount for expense(+)/revenue(-)
* @return Charge Account or null
*/
public MAccount getChargeAccount (MAcctSchema as, BigDecimal amount)
{
int C_Charge_ID = getC_Charge_ID();
if (C_Charge_ID == 0)
return null;
return MCharge.getAccount(C_Charge_ID, as, amount);
} // getChargeAccount
/**
* Get Period
* @return C_Period_ID
*/
protected int getC_Period_ID()
{
if (m_C_Period_ID == -1)
{
int index = p_po.get_ColumnIndex("C_Period_ID");
if (index != -1)
{
Integer ii = (Integer)p_po.get_Value(index);
if (ii != null)
m_C_Period_ID = ii.intValue();
}
if (m_C_Period_ID == -1)
m_C_Period_ID = 0;
}
return m_C_Period_ID;
} // getC_Period_ID
/**
* Set C_Period_ID
* @param C_Period_ID id
*/
protected void setC_Period_ID (int C_Period_ID)
{
m_C_Period_ID = C_Period_ID;
} // setC_Period_ID
/**************************************************************************
* Get (Journal) AcctSchema
* @return C_AcctSchema_ID
*/
public int getC_AcctSchema_ID()
{
return m_C_AcctSchema_ID;
} // getC_AcctSchema_ID
/**
* Get Line ID
* @return id
*/
public int get_ID()
{
return p_po.get_ID();
} // get_ID
/**
* Get AD_Org_ID
* @return org
*/
public int getAD_Org_ID()
{
return p_po.getAD_Org_ID();
} // getAD_Org_ID
/**
* Get Order AD_Org_ID
* @return order org if defined
*/
public int getOrder_Org_ID()
{
int C_OrderLine_ID = getC_OrderLine_ID();
if (C_OrderLine_ID != 0)
{
String sql = "SELECT AD_Org_ID FROM C_OrderLine WHERE C_OrderLine_ID=?";
int AD_Org_ID = DB.getSQLValue(null, sql, C_OrderLine_ID);
if (AD_Org_ID > 0)
return AD_Org_ID;
}
return getAD_Org_ID();
} // getOrder_Org_ID
/**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -