Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class timeAllocation_handler {
- Report currentReport;
- Reports.ReportMetadata reportMeta;
- Reports.ReportResults reportResult;
- public timeAllocation_handler()
- {
- currentReport = [SELECT Id FROM Report WHERE DeveloperName = 'Time_Allocation_for_Account'];
- Account a = [SELECT Id FROM Account WHERE Name = 'Account Name'];
- Reports.ReportDescribeResult reportDescribe = Reports.ReportManager.describeReport(currentReport.Id);
- reportMeta = reportDescribe.getReportMetadata();
- Reports.ReportFilter[] reportFilters = new Reports.ReportFilter[]{};
- Reports.ReportFilter rf = new Reports.ReportFilter('FK_ACC_ID','equals',a.Id+'');
- rf = new Reports.ReportFilter('FK_ACC_ID','equals',a.Id);
- reportFilters.add(rf);
- //this will be set to equals in the live version
- rf = new Reports.ReportFilter('for__Timesheet2__c.for__ActivityDate__c','lessThan','LAST_MONTH');
- reportFilters.add(rf);
- rf = new Reports.ReportFilter('for__Timesheet2__c.for__ActivityDate__c','equals','THIS_YEAR');
- reportFilters.add(rf);
- reportMeta.setReportFilters(reportFilters);
- }
- public Reports.ReportResults getReport()
- {
- if(reportResult == null)
- {
- reportResult = Reports.ReportManager.runReport(currentReport.Id, reportMeta);
- }
- return reportResult;
- }
- Map<String,reportItem> reportItemMap = new Map<String,ReportItem>();
- Map<String,Reports.GroupingValue> downMap = new Map<String,Reports.GroupingValue>();
- Map<String,Reports.GroupingValue> acrossMap = new Map<String,Reports.GroupingValue>();
- public void build(Reports.Dimension rD, Reports.GroupingValue rG)
- {
- //level 1
- for(Reports.GroupingValue rG1:rD.getGroupings())
- {
- setValue(rG1.getKey()+'!'+rG.getKey(),rG1);
- //level 2
- for(Reports.GroupingValue rG2:rG1.getgroupings())
- {
- setValue(rG2.getKey()+rG.getKey(),rG2);
- //level 3
- for(Reports.GroupingValue rG3:rG2.getgroupings())
- {
- setValue(rG3.getKey()+'!'+rG.getKey(),rG3);
- }
- }
- }
- }
- public void setValue(string s,Reports.GroupingValue rG)
- {
- if(reportItemMap.containsKey(s))
- {
- //reportItemMap.get(s).cellValue = rG.getLabel();
- }
- }
- public reportItem[] getFilteredList()
- {
- cell v0 = new cell(null,null);
- cell v1 = new cell(null,null);
- cell v2 = new cell(null,null);
- cell v3 = new cell(null,null);
- return getFilteredList(v0,v1,v2,v3);
- }
- private reportItem[] getFilteredList(cell v0,cell v1,cell v2,cell v3)
- {
- reportItem[] newList = new reportItem[]{};
- for(reportItem rItem:getReportList())
- {
- if(v0.cellKey == rItem.cellValue0.cellKey && v0.cellKey != null)
- {
- }
- }
- return newList;
- }
- public integer getFactSize()
- {
- return getreport().getFactMap().size();
- }
- reportItem[] rList = new reportItem[]{};
- public reportItem[] getReportList()
- {
- if(rList.size() == 0)
- {
- getReport();
- for(Reports.GroupingValue rG:reportResult.getgroupingsDown().getGroupings())
- {
- reportItem xItem = new reportItem();
- xItem.xKey = rG.getKey();
- xItem.cellValue0 = new cell(rG.getLabel(),rG.getKey());
- rList.add(xItem);
- //sub totals
- yList = new reportItem[]{};
- for(reportItem yItem:getyList())
- {
- yItem.cellValue3 = yItem.cellValue1;
- yItem.cellValue2 = yItem.cellValue0;
- yItem.cellValue1 = null;
- yItem.cellValue0 = xItem.cellValue0;
- yItem.xKey = xItem.xKey;
- rList.add(yItem);
- }
- for(Reports.GroupingValue rG1:rG.getgroupings())
- {
- reportItem xItem1 = new reportItem();
- xItem1.cellValue0 = xItem.cellValue0;
- xItem1.cellValue1 = new cell(rG1.getLabel(),rG1.getKey().replace(rG.getKey()+'_',''));
- xItem1.xKey = rG1.getKey();
- rList.add(xItem1);
- yList = new reportItem[]{};
- for(reportItem yItem:getyList())
- {
- yItem.cellValue3 = yItem.cellValue1;
- yItem.cellValue2 = yItem.cellValue0;
- yItem.cellValue1 = xItem1.cellValue1;
- yItem.cellValue0 = xItem.cellValue0;
- yItem.xKey = xItem1.xKey;
- rList.add(yItem);
- }
- for(Reports.GroupingValue rG2:rG1.getgroupings())
- {
- reportItem xItem2 = new reportItem();
- xItem2.cellValue0 = xItem.cellValue0;
- xItem2.cellValue1 = xItem1.cellValue1;
- xItem2.cellValue2 = new cell(rG2.getLabel(),rG2.getKey());
- xItem2.xKey = rG2.getKey();
- rList.add(xItem2);
- yList = new reportItem[]{};
- for(reportItem yItem:getyList())
- {
- yItem.cellValue3 = yItem.cellValue1;
- yItem.cellValue2 = yItem.cellValue0;
- yItem.cellValue1 = xItem1.cellValue1;
- yItem.cellValue0 = xItem.cellValue0;
- yItem.xKey = xItem2.xKey;
- rList.add(yItem);
- }
- }
- }
- }
- yList = new reportItem[]{};
- for(reportItem yItem:getyList())
- {
- yItem.cellValue3 = yItem.cellValue1;
- yItem.cellValue2 = yItem.cellValue0;
- yItem.cellValue1 = null;
- yItem.cellValue0 = null;
- rList.add(yItem);
- }
- reportItem xItem = new reportItem();
- xItem.cellValue0 = new cell('Grand Total','T!T');
- rList.add(xItem);
- for(reportItem rItem:rList)
- {
- if(rItem.xKey == null)
- {
- rItem.xKey = 'T';
- }
- if(rItem.yKey == null)
- {
- rItem.yKey = 'T';
- }
- //set the label
- if(getreport().getFactMap().containsKey(rItem.getKey()))
- {
- rItem.reportFact = getreport().getFactMap().get(rItem.getKey());
- }
- if(rItem.cellValue0 == null)
- {
- rItem.cellValue0 = new cell(null,'T');
- }
- if(rItem.cellValue2 == null)
- {
- rItem.cellValue2 = new cell(null,'T');
- }
- }
- }
- return rList;
- }
- reportItem[] yList = new reportItem[]{};
- public reportItem[] getyList()
- {
- if(yList.size() == 0)
- {
- Reports.GroupingValue[] rGs = reportResult.getgroupingsAcross().getGroupings();
- for(Reports.GroupingValue rG:rGs)
- {
- reportItem yItem = new reportItem();
- yItem.cellValue0 = new cell(rG.getLabel(),rG.getKey());
- yItem.yKey = rG.getKey();
- yList.add(yItem);
- Reports.GroupingValue[] rG1s = rG.getgroupings();
- for(Reports.GroupingValue rG1:rG1s)
- {
- reportItem yItem1 = new reportItem();
- yItem1.cellValue0 = yItem.cellValue0;
- yItem1.cellValue1 = new cell(rG1.getLabel(),rG1.getKey().replace(rG.getKey()+'_',''));
- yItem1.yKey = rG1.getKey();
- yList.add(yItem1);
- Reports.GroupingValue[] rG2s = rG1.getgroupings();
- for(Reports.GroupingValue rG2:rG2s)
- {
- reportItem yItem2 = new reportItem();
- yItem2.cellValue0 = yItem.cellValue0;
- yItem2.cellValue1 = yItem1.cellValue1;
- yItem2.cellValue2 = new cell(rG2.getLabel(),rG2.getKey());
- yItem.yKey = rG2.getKey();
- yList.add(yItem2);
- }
- }
- }
- }
- return yList;
- }
- public class reportItem
- {
- public cell cellValue0 {get;set;}
- public cell cellValue1 {get;set;}
- public cell cellValue2 {get;set;}
- public cell cellValue3 {get;set;}
- public string xKey {get;set;}
- public string yKey {get;set;}
- public Reports.ReportFact reportFact {get;set;}
- public string getKey()
- {
- return xKey + '!' + yKey;
- }
- }
- public class cell
- {
- public string cellValue {get;set;}
- public string cellKey {get;set;}
- public cell(string v,string k)
- {
- cellValue = v;
- cellKey = k;
- }
- }
- public class filteredResult
- {
- public reportItem[] reportItems {get;set;}
- public totalRow[] totals {get;set;}
- public filteredResult()
- {
- reportItems = new reportItem[]{};
- totals = new totalRow[]{};
- }
- }
- public class totalRow
- {
- public string label {get;set;}
- public double value {get;set;}
- public totalRow(string l,string v)
- {
- label = l;
- value = double.valueOf(v);
- }
- }
- }
- <apex:page controller="timeAllocation_handler" sidebar="false" >
- <apex:pageBlock >
- <apex:pageBlockSection columns="1">
- <apex:pageBlockTable value="{!ReportList}" var="r" >
- <apex:column headerValue="0" value="{!r.cellValue0.cellKey}"/>
- <apex:column headerValue="0" value="{!r.cellValue0.cellValue}"/>
- <apex:column headerValue="1" value="{!r.cellValue1.cellKey}"/>
- <apex:column headerValue="1" value="{!r.cellValue1.cellValue}"/>
- <apex:column headerValue="2" value="{!r.cellValue2.cellKey}"/>
- <apex:column headerValue="2" value="{!r.cellValue2.cellValue}"/>
- <apex:column headerValue="3" value="{!r.cellValue3.cellKey}"/>
- <apex:column headerValue="3" value="{!r.cellValue3.cellValue}"/>
- <apex:column value="{!r.key}"/>
- <apex:column value="{!reportList.size}"/>
- <apex:column value="{!Factsize}"/>
- <apex:repeat value="{!r.reportFact.aggregates}" var="agg">
- <apex:column headerValue="asf" value="{!agg.label}"/>
- </apex:repeat>
- </apex:pageBlockTable>
- </apex:pageBlockSection>
- </apex:pageBlock>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement