📄 mreportline.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.report;
import java.util.*;
import java.sql.*;
import java.math.*;
import java.io.Serializable;
import org.compiere.model.*;
import org.compiere.util.*;
/**
* Report Line Model
*
* @author Jorg Janke
* @version $Id: MReportLine.java,v 1.6 2003/03/15 07:02:38 jjanke Exp $
*/
public class MReportLine
extends PO
{
/**
* Constructor
* @param ctx context
* @param PA_ReportLine_ID id
*/
public MReportLine (Properties ctx, int PA_ReportLine_ID)
{
super (ctx, PA_ReportLine_ID);
if (PA_ReportLine_ID == 0)
{
setPA_ReportLineSet_ID (0);
setSeqNo (0);
setLineType (null);
setName (null);
setIsSummary (false);
setIsPrinted (false);
}
else
loadSources();
} // MReportLine
/**
* Constructor
* @param ctx context
* @param rs ResultSet to load from
*/
public MReportLine (Properties ctx, ResultSet rs)
{
super (ctx, rs);
loadSources();
} // MReportLine
/**
* Copy Constructor
* @param ctx context
* @param AD_Client_ID parent
* @param AD_Org_ID parent
* @param PA_ReportLineSet_ID parent
* @param source copy source
*/
public MReportLine (Properties ctx, int AD_Client_ID, int AD_Org_ID, int PA_ReportLineSet_ID, MReportLine source)
{
super (ctx, source, AD_Client_ID, AD_Org_ID);
setPA_ReportLineSet_ID(PA_ReportLineSet_ID);
} // MReportLine
/** Containt Sources */
private MReportSource[] m_sources = null;
/** Cache result */
private String m_whereClause = null;
/**
* Initialize
* @param ctx context
* @return meta data
*/
protected POInfo initPO (Properties ctx)
{
int AD_Table_ID = 448;
POInfo poi = POInfo.getPOInfo (ctx, AD_Table_ID);
return poi;
} // initPO
/**
* Load contained Sources
*/
private void loadSources()
{
ArrayList list = new ArrayList();
String sql = "SELECT * FROM PA_ReportSource WHERE PA_ReportLine_ID=? AND IsActive='Y'";
PreparedStatement pstmt = null;
try
{
pstmt = DB.prepareStatement(sql);
pstmt.setInt(1, getPA_ReportLine_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next())
list.add(new MReportSource (getCtx(), rs));
rs.close();
pstmt.close();
pstmt = null;
}
catch (Exception e)
{
Log.error("MReportLine.loadSources", e);
}
finally
{
try
{
if (pstmt != null)
pstmt.close ();
}
catch (Exception e)
{}
pstmt = null;
}
//
m_sources = new MReportSource[list.size()];
list.toArray(m_sources);
Log.trace(9, "MReportLine.loadSources ID=" + getPA_ReportLine_ID(),
"Size=" + list.size());
} // loadSources
/**
* Get Sources
* @return sources
*/
public MReportSource[] getSources()
{
return m_sources;
} // getSources
/**
* List Info
*/
public void list()
{
System.out.println("- " + toString());
if (m_sources == null)
return;
for (int i = 0; i < m_sources.length; i++)
System.out.println(" - " + m_sources[i].toString());
} // list
/**
* Get Source Column Name
* @return Source ColumnName
*/
public String getSourceColumnName()
{
String ColumnName = null;
for (int i = 0; i < m_sources.length; i++)
{
String col = AcctSchemaElement.getColumnName (m_sources[i].getElementType());
if (ColumnName == null || ColumnName.length() == 0)
ColumnName = col;
else if (!ColumnName.equals(col))
{
Log.trace(Log.l4_Data, "MReportLine.getSourceColumnName - more than one: " + ColumnName + " - " + col);
return null;
}
}
return ColumnName;
} // getColumnName
/**
* Get Value Query for Segment Type
* @return Query for first source element or null
*/
public String getSourceValueQuery()
{
if (m_sources != null && m_sources.length > 0)
return AcctSchemaElement.getValueQuery(m_sources[0].getElementType());
return null;
} //
/**
* Get SQL Select Clause.
* @param withSum with SUM() function
* @return select clause - AmtAcctCR+AmtAcctDR/etc or "null" if not defined
*/
public String getSelectClause (boolean withSum)
{
String at = getAmountType().substring(0,1);
StringBuffer sb = new StringBuffer();
if (withSum)
sb.append("SUM(");
if (AmountType_Balance.equals(at))
sb.append("AmtAcctDr-AmtAcctCr");
else if (AmountType_CR.equals(at))
sb.append("AmtAcctCr");
else if (AmountType_DR.equals(at))
sb.append("AmtAcctDr");
else if (AmountType_Qty.equals(at))
sb.append("Qty");
else
{
Log.error ("MReportLine.getSelectClause - AmountType=" + getAmountType () + ", at=" + at);
return "NULL";
}
if (withSum)
sb.append(")");
return sb.toString();
} // getSelectClause
/**
* Is it Period Balance?
* @return true if Period Balance
*/
public boolean isPeriodBalance()
{
if (getAmountType() == null)
return false;
String at = getAmountType().substring(1);
return AmountType_Period.equals(at);
} // isPeriodBalance
/**
* Is it Year Balance?
* @return true if Year Balance
*/
public boolean isYearBalance()
{
if (getAmountType() == null)
return false;
String at = getAmountType().substring(1);
return AmountType_Year.equals(at);
} // isYearBalance
/**
* Is it Total Balance?
* @return true if Year Balance
*/
public boolean isTotalBalance()
{
if (getAmountType() == null)
return false;
String at = getAmountType().substring(1);
return AmountType_Total.equals(at);
} // isTotalBalance
/**
* Get SQL where clause
* @return where clause
*/
public String getWhereClause()
{
if (m_sources == null)
return "";
if (m_whereClause == null)
{
// Only one
if (m_sources.length == 0)
m_whereClause = "";
else if (m_sources.length == 1)
m_whereClause = m_sources[0].getWhereClause ();
else
{
// Multiple
StringBuffer sb = new StringBuffer ("(");
for (int i = 0; i < m_sources.length; i++)
{
if (i > 0)
sb.append (" OR ");
sb.append (m_sources[i].getWhereClause ());
}
sb.append (")");
m_whereClause = sb.toString ();
}
Log.trace(Log.l5_DData, "MReportLine.getWhereClause", m_whereClause);
}
return m_whereClause;
} // getWhereClause
/**
* String Representation
* @return info
*/
public String toString ()
{
StringBuffer sb = new StringBuffer ("MReportLine[")
.append(getID()).append(" - ").append(getName()).append(" - ").append(getDescription())
.append(", SeqNo=").append(getSeqNo()).append(", AmountType=").append(getAmountType())
.append(" - LineType=").append(getLineType());
if (isLineTypeCalculation())
sb.append(" - Calculation=").append(getCalculationType())
.append(" - ").append(getOper_1_ID()).append(" - ").append(getOper_2_ID());
else // SegmentValue
sb.append(" - SegmentValue - PostingType=").append(getPostingType())
.append(", AmountType=").append(getAmountType());
sb.append ("]");
return sb.toString ();
} // toString
public boolean save ()
{
Log.trace (Log.l4_Data, "MReportLine.save");
return super.save ();
}
public void setIsPrinted (boolean IsPrinted)
{
setValue ("IsPrinted", IsPrinted ? "Y" : "N");
}
public boolean isPrinted ()
{
Boolean bb = (Boolean)getValue ("IsPrinted");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setGL_Budget_ID (int GL_Budget_ID)
{
setValue ("GL_Budget_ID", new Integer (GL_Budget_ID));
}
public int getGL_Budget_ID ()
{
Integer ii = (Integer)getValue ("GL_Budget_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setDescription (String Description)
{
setValue ("Description", Description);
}
public String getDescription ()
{
return (String)getValue ("Description");
}
public static final String AmountType_Balance = "B";
public static final String AmountType_CR = "C";
public static final String AmountType_DR = "D";
public static final String AmountType_Qty = "Q";
//
public static final String AmountType_Period = "P";
public static final String AmountType_Year = "Y";
public static final String AmountType_Total = "T";
public void setAmountType (String AmountType)
{
setValue ("AmountType", AmountType);
}
public String getAmountType ()
{
return (String)getValue ("AmountType");
}
public int getPA_ReportLine_ID ()
{
return getID();
}
public void setPostingType (String PostingType)
{
if (PostingType.equals ("A") || PostingType.equals ("B")
|| PostingType.equals ("E") || PostingType.equals ("S"))
;
else
throw new IllegalArgumentException (
"PostingType Invalid value - Reference_ID=125 - A - B - E - S");
setValue ("PostingType", PostingType);
}
public String getPostingType ()
{
return (String)getValue ("PostingType");
}
void setPA_ReportLineSet_ID (int PA_ReportLineSet_ID)
{
setValueNoCheck ("PA_ReportLineSet_ID", new Integer (PA_ReportLineSet_ID));
}
public int getPA_ReportLineSet_ID ()
{
Integer ii = (Integer)getValue ("PA_ReportLineSet_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setSeqNo (int SeqNo)
{
setValue ("SeqNo", new Integer (SeqNo));
}
public int getSeqNo ()
{
Integer ii = (Integer)getValue ("SeqNo");
if (ii == null)
return 0;
return ii.intValue ();
}
private static final String LineType_Calculation = "C";
private static final String LineType_SegmentValue = "S";
public void setLineType (String LineType)
{
if (LineType.equals ("C") || LineType.equals ("S"))
;
else
throw new IllegalArgumentException (
"LineType Invalid value - Reference_ID=241 - C - S");
if (LineType == null)
throw new IllegalArgumentException ("LineType is mandatory");
setValue ("LineType", LineType);
}
public String getLineType ()
{
return (String)getValue ("LineType");
}
public boolean isLineTypeCalculation()
{
return LineType_Calculation.equals(getLineType());
}
public boolean isLineTypeSegmentValue()
{
return LineType_SegmentValue.equals(getLineType());
}
public void setCalculationType (String CalculationType)
{
if (CalculationType.equals ("A") || CalculationType.equals ("P")
|| CalculationType.equals ("R") || CalculationType.equals ("S"))
;
else
throw new IllegalArgumentException (
"CalculationType Invalid value - Reference_ID=236 - A - P - R - S");
setValue ("CalculationType", CalculationType);
}
public String getCalculationType ()
{
return (String)getValue ("CalculationType");
}
public boolean isCalculationTypeRange()
{
return "R".equals(getCalculationType());
}
public boolean isCalculationTypeAdd()
{
return "A".equals(getCalculationType());
}
public boolean isCalculationTypeSubtract()
{
return "S".equals(getCalculationType());
}
public boolean isCalculationTypePercent()
{
return "P".equals(getCalculationType());
}
public void setOper_1_ID (int Oper_1_ID)
{
setValue ("Oper_1_ID", new Integer (Oper_1_ID));
}
public int getOper_1_ID ()
{
Integer ii = (Integer)getValue ("Oper_1_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setOper_2_ID (int Oper_2_ID)
{
setValue ("Oper_2_ID", new Integer (Oper_2_ID));
}
public int getOper_2_ID ()
{
Integer ii = (Integer)getValue ("Oper_2_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
public void setName (String Name)
{
if (Name == null)
throw new IllegalArgumentException ("Name is mandatory");
setValue ("Name", Name);
}
public String getName ()
{
return (String)getValue ("Name");
}
public void setIsSummary (boolean IsSummary)
{
setValue ("IsSummary", IsSummary ? "Y" : "N");
}
public boolean isSummary ()
{
Boolean bb = (Boolean)getValue ("IsSummary");
if (bb != null)
return bb.booleanValue ();
return false;
}
public void setParent_ID (int Parent_ID)
{
setValue ("Parent_ID", new Integer (Parent_ID));
}
public int getParent_ID ()
{
Integer ii = (Integer)getValue ("Parent_ID");
if (ii == null)
return 0;
return ii.intValue ();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -