1 14 package org.compiere.report; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 import java.io.Serializable ; 20 21 import org.compiere.model.*; 22 import org.compiere.util.*; 23 24 25 31 public class MReportLine extends X_PA_ReportLine 32 { 33 38 public MReportLine (Properties ctx, int PA_ReportLine_ID) 39 { 40 super (ctx, PA_ReportLine_ID); 41 if (PA_ReportLine_ID == 0) 42 { 43 setSeqNo (0); 44 setIsSummary (false); 45 setIsPrinted (false); 46 } 47 else 48 loadSources(); 49 } 51 56 public MReportLine (Properties ctx, ResultSet rs) 57 { 58 super (ctx, rs); 59 loadSources(); 60 } 62 63 private MReportSource[] m_sources = null; 64 65 private String m_whereClause = null; 66 67 70 private void loadSources() 71 { 72 ArrayList list = new ArrayList(); 73 String sql = "SELECT * FROM PA_ReportSource WHERE PA_ReportLine_ID=? AND IsActive='Y'"; 74 PreparedStatement pstmt = null; 75 try 76 { 77 pstmt = DB.prepareStatement(sql); 78 pstmt.setInt(1, getPA_ReportLine_ID()); 79 ResultSet rs = pstmt.executeQuery(); 80 while (rs.next()) 81 list.add(new MReportSource (getCtx(), rs)); 82 rs.close(); 83 pstmt.close(); 84 pstmt = null; 85 } 86 catch (Exception e) 87 { 88 Log.error("MReportLine.loadSources", e); 89 } 90 finally 91 { 92 try 93 { 94 if (pstmt != null) 95 pstmt.close (); 96 } 97 catch (Exception e) 98 {} 99 pstmt = null; 100 } 101 m_sources = new MReportSource[list.size()]; 103 list.toArray(m_sources); 104 Log.trace(9, "MReportLine.loadSources ID=" + getPA_ReportLine_ID(), 105 "Size=" + list.size()); 106 } 108 112 public MReportSource[] getSources() 113 { 114 return m_sources; 115 } 117 120 public void list() 121 { 122 System.out.println("- " + toString()); 123 if (m_sources == null) 124 return; 125 for (int i = 0; i < m_sources.length; i++) 126 System.out.println(" - " + m_sources[i].toString()); 127 } 129 130 134 public String getSourceColumnName() 135 { 136 String ColumnName = null; 137 for (int i = 0; i < m_sources.length; i++) 138 { 139 String col = AcctSchemaElement.getColumnName (m_sources[i].getElementType()); 140 if (ColumnName == null || ColumnName.length() == 0) 141 ColumnName = col; 142 else if (!ColumnName.equals(col)) 143 { 144 Log.trace(Log.l4_Data, "MReportLine.getSourceColumnName - more than one: " + ColumnName + " - " + col); 145 return null; 146 } 147 } 148 return ColumnName; 149 } 151 155 public String getSourceValueQuery() 156 { 157 if (m_sources != null && m_sources.length > 0) 158 return AcctSchemaElement.getValueQuery(m_sources[0].getElementType()); 159 return null; 160 } 162 163 168 public String getSelectClause (boolean withSum) 169 { 170 String at = getAmountType().substring(0,1); 171 StringBuffer sb = new StringBuffer (); 172 if (withSum) 173 sb.append("SUM("); 174 if (AmountType_Balance.equals(at)) 175 sb.append("AmtAcctDr-AmtAcctCr"); 176 else if (AmountType_CR.equals(at)) 177 sb.append("AmtAcctCr"); 178 else if (AmountType_DR.equals(at)) 179 sb.append("AmtAcctDr"); 180 else if (AmountType_Qty.equals(at)) 181 sb.append("Qty"); 182 else 183 { 184 Log.error ("MReportLine.getSelectClause - AmountType=" + getAmountType () + ", at=" + at); 185 return "NULL"; 186 } 187 if (withSum) 188 sb.append(")"); 189 return sb.toString(); 190 } 192 196 public boolean isPeriodBalance() 197 { 198 String at = getAmountType(); 199 if (at == null) 200 return false; 201 return AMOUNTTYPE_PeriodBalance.equals(at); 202 } 204 208 public boolean isYearBalance() 209 { 210 String at = getAmountType(); 211 if (at == null) 212 return false; 213 return AMOUNTTYPE_YearBalance.equals(at); 214 } 216 220 public boolean isTotalBalance() 221 { 222 String at = getAmountType(); 223 if (at == null) 224 return false; 225 return AMOUNTTYPE_TotalBalance.equals(at); 226 } 228 232 public String getWhereClause() 233 { 234 if (m_sources == null) 235 return ""; 236 if (m_whereClause == null) 237 { 238 if (m_sources.length == 0) 240 m_whereClause = ""; 241 else if (m_sources.length == 1) 242 m_whereClause = m_sources[0].getWhereClause (); 243 else 244 { 245 StringBuffer sb = new StringBuffer ("("); 247 for (int i = 0; i < m_sources.length; i++) 248 { 249 if (i > 0) 250 sb.append (" OR "); 251 sb.append (m_sources[i].getWhereClause ()); 252 } 253 sb.append (")"); 254 m_whereClause = sb.toString (); 255 } 256 String PostingType = getPostingType(); 258 if (PostingType != null && PostingType.length() > 0) 259 { 260 if (m_whereClause.length() > 0) 261 m_whereClause += " AND "; 262 m_whereClause += "PostingType='" + PostingType + "'"; 263 } 264 Log.trace(Log.l5_DData, "MReportLine.getWhereClause", m_whereClause); 265 } 266 return m_whereClause; 267 } 269 273 public String toString () 274 { 275 StringBuffer sb = new StringBuffer ("MReportLine[") 276 .append(getID()).append(" - ").append(getName()).append(" - ").append(getDescription()) 277 .append(", SeqNo=").append(getSeqNo()).append(", AmountType=").append(getAmountType()) 278 .append(" - LineType=").append(getLineType()); 279 if (isLineTypeCalculation()) 280 sb.append(" - Calculation=").append(getCalculationType()) 281 .append(" - ").append(getOper_1_ID()).append(" - ").append(getOper_2_ID()); 282 else sb.append(" - SegmentValue - PostingType=").append(getPostingType()) 284 .append(", AmountType=").append(getAmountType()); 285 sb.append ("]"); 286 return sb.toString (); 287 } 289 public static final String AmountType_Balance = "B"; 290 public static final String AmountType_CR = "C"; 291 public static final String AmountType_DR = "D"; 292 public static final String AmountType_Qty = "Q"; 293 public static final String AmountType_Period = "P"; 295 public static final String AmountType_Year = "Y"; 296 public static final String AmountType_Total = "T"; 297 298 299 public boolean isLineTypeCalculation() 300 { 301 return LINETYPE_Calculation.equals(getLineType()); 302 } 303 public boolean isLineTypeSegmentValue() 304 { 305 return LINETYPE_SegmentValue.equals(getLineType()); 306 } 307 308 public boolean isCalculationTypeRange() 309 { 310 return CALCULATIONTYPE_AddRangeOp1ToOp2.equals(getCalculationType()); 311 } 312 public boolean isCalculationTypeAdd() 313 { 314 return CALCULATIONTYPE_AddOp1PlusOp2.equals(getCalculationType()); 315 } 316 public boolean isCalculationTypeSubtract() 317 { 318 return CALCULATIONTYPE_SubtractOp1MinusOp2.equals(getCalculationType()); 319 } 320 public boolean isCalculationTypePercent() 321 { 322 return CALCULATIONTYPE_PercentageOp2OfOp1.equals(getCalculationType()); 323 } 324 325 329 private void setPA_ReportLineSet_ID (int PA_ReportLineSet_ID) 330 { 331 setValueNoCheck ("PA_ReportLineSet_ID", new Integer (PA_ReportLineSet_ID)); 332 } 334 335 336 345 public static MReportLine copy (Properties ctx, int AD_Client_ID, int AD_Org_ID, int PA_ReportLineSet_ID, MReportLine source) 346 { 347 MReportLine retValue = new MReportLine (ctx, 0); 348 MReportLine.copyValues(source, retValue, AD_Client_ID, AD_Org_ID); 349 retValue.setPA_ReportLineSet_ID(PA_ReportLineSet_ID); 350 return retValue; 351 } 353 354 } | Popular Tags |