KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > report > MReportColumn


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Smart Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2003 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.report;
15
16 import java.util.*;
17 import java.sql.*;
18 import java.math.*;
19 import java.io.Serializable JavaDoc;
20
21 import org.compiere.model.*;
22 import org.compiere.util.*;
23
24 /**
25  * Report Column Model
26  *
27  * @author Jorg Janke
28  * @version $Id: MReportColumn.java,v 1.10 2003/10/31 05:28:35 jjanke Exp $
29  */

30 public class MReportColumn extends X_PA_ReportColumn
31 {
32     /**
33      * Constructor
34      * @param ctx context
35      * @param PA_ReportColumn_ID id
36      */

37     public MReportColumn (Properties ctx, int PA_ReportColumn_ID)
38     {
39         super (ctx, PA_ReportColumn_ID);
40         if (PA_ReportColumn_ID == 0)
41         {
42             setIsPrinted (true);
43             setSeqNo (0);
44         }
45     } // MReportColumn
46

47     /**
48      * Constructor
49      * @param ctx context
50      * @param rs ResultSet to load from
51      */

52     public MReportColumn (Properties ctx, ResultSet rs)
53     {
54         super (ctx, rs);
55     } // MReportColumn
56

57     /*************************************************************************/
58
59     /**
60      * Get SQL Select Clause.
61      * @param withSum with SUM() function
62      * @return select clause - AmtAcctCR+AmtAcctDR/etc or "null" if not defined
63      */

64     public String JavaDoc getSelectClause (boolean withSum)
65     {
66         String JavaDoc at = getAmountType().substring(0,1); // first character
67
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
68         if (withSum)
69             sb.append("SUM(");
70         if (AmountType_Balance.equals(at))
71             sb.append("AmtAcctDr-AmtAcctCr");
72         else if (AmountType_CR.equals(at))
73             sb.append("AmtAcctCr");
74         else if (AmountType_DR.equals(at))
75             sb.append("AmtAcctDr");
76         else if (AmountType_Qty.equals(at))
77             sb.append("Qty");
78         else
79         {
80             Log.error ("MReportColumn.getSelectClause - AmountType=" + getAmountType () + ", at=" + at);
81             return "NULL";
82         }
83         if (withSum)
84             sb.append(")");
85         return sb.toString();
86     } // getSelectClause
87

88     /**
89      * Is it Period Balance?
90      * @return true if Period Balance
91      */

92     public boolean isPeriodBalance()
93     {
94         String JavaDoc at = getAmountType();
95         if (at == null)
96             return false;
97         return AMOUNTTYPE_PeriodBalance.equals(at);
98     } // isPeriodBalance
99

100     /**
101      * Is it Year Balance?
102      * @return true if Year Balance
103      */

104     public boolean isYearBalance()
105     {
106         String JavaDoc at = getAmountType();
107         if (at == null)
108             return false;
109         return AMOUNTTYPE_YearBalance.equals(at);
110     } // isYearBalance
111

112     /**
113      * Is it Total Balance?
114      * @return true if Year Balance
115      */

116     public boolean isTotalBalance()
117     {
118         String JavaDoc at = getAmountType();
119         if (at == null)
120             return false;
121         return AMOUNTTYPE_TotalBalance.equals(at);
122     } // isTotalBalance
123

124
125     /**
126      * Get String Representation
127      * @return String Representation
128      */

129     public String JavaDoc toString ()
130     {
131         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MReportColumn[")
132             .append(getID()).append(" - ").append(getName()).append(" - ").append(getDescription())
133             .append(", SeqNo=").append(getSeqNo()).append(", AmountType=").append(getAmountType())
134             .append(", CurrencyType=").append(getCurrencyType()).append("/").append(getC_Currency_ID())
135             .append(" - ColumnType=").append(getColumnType());
136         if (isColumnTypeCalculation())
137             sb.append(" - Calculation=").append(getCalculationType())
138                 .append(" - ").append(getOper_1_ID()).append(" - ").append(getOper_2_ID());
139         else if (isColumnTypeRelativePeriod())
140             sb.append(" - Period=").append(getRelativePeriod());
141         else
142             sb.append(" - SegmentValue ElementType=").append(getElementType());
143         sb.append ("]");
144         return sb.toString ();
145     } // toString
146

147     public static final String JavaDoc AmountType_Balance = "B";
148     public static final String JavaDoc AmountType_CR = "C";
149     public static final String JavaDoc AmountType_DR = "D";
150     public static final String JavaDoc AmountType_Qty = "Q";
151     //
152
public static final String JavaDoc AmountType_Period = "P";
153     public static final String JavaDoc AmountType_Year = "Y";
154     public static final String JavaDoc AmountType_Total = "T";
155
156
157     public boolean isCalculationTypeRange()
158     {
159         return CALCULATIONTYPE_AddRangeOp1ToOp2.equals(getCalculationType());
160     }
161     public boolean isCalculationTypeAdd()
162     {
163         return CALCULATIONTYPE_AddOp1PlusOp2.equals(getCalculationType());
164     }
165     public boolean isCalculationTypeSubtract()
166     {
167         return CALCULATIONTYPE_SubtractOp1MinusOp2.equals(getCalculationType());
168     }
169     public boolean isCalculationTypePercent()
170     {
171         return CALCULATIONTYPE_PercentageOp2OfOp1.equals(getCalculationType());
172     }
173
174
175     public boolean isColumnTypeCalculation()
176     {
177         return COLUMNTYPE_Calculation.equals(getColumnType());
178     }
179     public boolean isColumnTypeRelativePeriod()
180     {
181         return COLUMNTYPE_RelativePeriod.equals(getColumnType());
182     }
183     public boolean isColumnTypeSegmentValue()
184     {
185         return COLUMNTYPE_SegmentValue.equals(getColumnType());
186     }
187
188     public int getRelativePeriodAsInt ()
189     {
190         BigDecimal bd = getRelativePeriod();
191         if (bd == null)
192             return 0;
193         return bd.intValue();
194     } // getRelativePeriodAsInt
195

196     /**
197      * Set Parent.
198      * @param PA_ReportColumnSet_ID parent
199      */

200     private void setPA_ReportColumnSet_ID (int PA_ReportColumnSet_ID)
201     {
202         setValueNoCheck ("PA_ReportColumnSet_ID", new Integer JavaDoc(PA_ReportColumnSet_ID));
203     } // setPA_ReportColumnSet_ID
204

205
206     /*************************************************************************/
207
208     /**
209      * Copy
210      * @param ctx context
211      * @param AD_Client_ID parent
212      * @param AD_Org_ID parent
213      * @param PA_ReportColumnSet_ID parent
214      * @param source copy source
215      * @return Report Column
216      */

217     public static MReportColumn copy (Properties ctx, int AD_Client_ID, int AD_Org_ID, int PA_ReportColumnSet_ID, MReportColumn source)
218     {
219         MReportColumn retValue = new MReportColumn (ctx, 0);
220         MReportColumn.copyValues(source, retValue, AD_Client_ID, AD_Org_ID);
221         retValue.setPA_ReportColumnSet_ID(PA_ReportColumnSet_ID); // parent
222
return retValue;
223     } // copy
224

225 } // MReportColumn
226
Popular Tags