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 MReportSource extends X_PA_ReportSource 32 { 33 38 public MReportSource (Properties ctx, int PA_ReportSource_ID) 39 { 40 super (ctx, PA_ReportSource_ID); 41 if (PA_ReportSource_ID == 0) 42 { 43 } 44 } 46 51 public MReportSource (Properties ctx, ResultSet rs) 52 { 53 super (ctx, rs); 54 } 56 57 58 private static CCache s_trees = new CCache("reportSourceTrees", 20); 59 60 64 public String getWhereClause() 65 { 66 String et = getElementType(); 67 String TreeType = et; 68 69 String ColumnName = AcctSchemaElement.getColumnName(et); 71 int ID = 0; 72 if (AcctSchemaElement.SEGMENT_Account.equals(et)) 74 { 75 ID = getC_ElementValue_ID (); 76 TreeType = X_AD_Tree.TREETYPE_ElementValueAccountEtc; 77 } 78 else if (AcctSchemaElement.SEGMENT_Activity.equals(et)) 79 ID = getC_Activity_ID (); 80 else if (AcctSchemaElement.SEGMENT_BPartner.equals(et)) 81 ID = getC_BPartner_ID (); 82 else if (AcctSchemaElement.SEGMENT_Campaign.equals(et)) 83 ID = getC_Campaign_ID (); 84 else if (AcctSchemaElement.SEGMENT_LocationFrom.equals(et)) 85 ID = getC_Location_ID (); 86 else if (AcctSchemaElement.SEGMENT_LocationTo.equals(et)) 87 ID = getC_Location_ID (); 88 else if (AcctSchemaElement.SEGMENT_Org.equals(et)) 89 ID = getOrg_ID (); 90 else if (AcctSchemaElement.SEGMENT_Product.equals(et)) 91 ID = getM_Product_ID (); 92 else if (AcctSchemaElement.SEGMENT_Project.equals(et)) 93 ID = getC_Project_ID (); 94 else if (AcctSchemaElement.SEGMENT_SalesRegion.equals(et)) 95 ID = getC_SalesRegion_ID (); 96 else if (AcctSchemaElement.SEGMENT_OrgTrx.equals(et)) 97 ID = getOrg_ID (); else if (AcctSchemaElement.SEGMENT_User1.equals(et)) 99 ID = getC_ElementValue_ID (); 100 else if (AcctSchemaElement.SEGMENT_User2.equals(et)) 101 ID = getC_ElementValue_ID (); 102 103 MTree tree = (MTree)s_trees.get(et); 105 if (tree == null) 106 { 107 tree = MTree.getTree (getCtx(), TreeType); 108 Log.trace(Log.l4_Data, "MReportSource.getWhereClause - create tree for " + TreeType, tree); 109 s_trees.put(et, tree); 110 } 111 if (tree != null) 113 { 114 MTreeNode node = tree.getRoot().findNode(ID); 115 116 System.out.println("Root=" + node); 117 if (node != null && node.isSummary()) 118 { 119 StringBuffer sb = new StringBuffer (); 120 Enumeration en = node.preorderEnumeration(); 121 while (en.hasMoreElements()) 122 { 123 MTreeNode nn = (MTreeNode)en.nextElement(); 124 if (!nn.isSummary()) 125 { 126 if (sb.length () > 0) 127 sb.append (","); 128 sb.append(nn.getID()); 129 System.out.println(" - " + nn); 131 } 132 else 133 System.out.println(" - skipped parent (" + nn + ")"); 134 } 135 return new StringBuffer (ColumnName).append(" IN (").append(sb).append(")").toString(); 136 } 137 } 138 139 return new StringBuffer (ColumnName).append("=").append(ID).toString(); 141 } 143 144 148 public String toString () 149 { 150 StringBuffer sb = new StringBuffer ("MReportSource[") 151 .append(getID()).append(" - ").append(getDescription()) 152 .append(" - ").append(getElementType()) 153 .append(" - ").append(getWhereClause()); 154 sb.append ("]"); 155 return sb.toString (); 156 } 158 162 private void setPA_ReportLine_ID (int PA_ReportLine_ID) 163 { 164 setValueNoCheck ("PA_ReportLine_ID", new Integer (PA_ReportLine_ID)); 165 } 167 168 169 170 179 public static MReportSource copy (Properties ctx, int AD_Client_ID, int AD_Org_ID, int PA_ReportLine_ID, MReportSource source) 180 { 181 MReportSource retValue = new MReportSource (ctx, 0); 182 MReportSource.copyValues(source, retValue, AD_Client_ID, AD_Org_ID); 183 retValue.setPA_ReportLine_ID(PA_ReportLine_ID); 184 return retValue; 185 } 187 } | Popular Tags |