public class myController {
public list<SalesRepWrapper> wraps {get; private set;}
Public list<string> getMonthList(){
list<string> months = new list<String>();
for(Integer i = system.today().month(); i <= 12; i++){
months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year(), i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
}
for(Integer i = 1; i < system.today().month(); i++){
months.add(DateTime.newInstanceGMT(System.Date.newInstance(system.today().year() + 1, i, 1), System.Time.newInstance(0, 0, 0, 0)).formatGMT('MMM-yy'));
}
return months;
}
public myController(){
buildData();
}
public void buildData(){
list<User_Stats__c> stats = [Select Id, Sales_Rep__c, Month_Number__c, Year__c, Total Rental_Revenue_Actual__c
From User_Stats__c
Where (Month_Number__c >= system.today().month() && Year__c == system.today().year()) Or
(Month_Number__c < system.today().month() && Year__c == system.today().year() + 1)
Order By Sales_Rep__c, Year__c, Month_Number__c];
set<Id> UserIDs = new set<Id>();
for(User_Stats__c stat : stats){
userIDs.add(Sales_Rep__c);
}
map<Id,User> userMap = new map<Id,User>([Select Id, Name From User Where Id In: userIDs]);
map<Id,list<decimal>> rep2ActualsMap = new map<Id,list<decimal>>();
for(User_Stats__c stat : stats){
if(!rep2ActualsMap.containsKey(stat.Sales_Rep__c){
rep2ActualsMap.put(stat.Sales_Rep__c, new list<User_Stats__c>list<Decimal>());
}
rep2ActualsMap.get(stat.Sales_Rep__c).add(stat.Rental_Revenue_Actual__c);
}
wraps = new list<SalesRepWrapper>();
for(Id uId : rep2ActualsMap.keySet()){
wrap.add(new SalesRepWrapper(userMap.get(uId), rep2ActualsMap.get(uId)));
}
}
public Class SalesRepWrapper {
public list<decimal> actuals {get;set;}
public User rep {get;set}
public SalesRepWrapper(User u, list<decimal> vals){
this.rep = u;
this.actuals = vals;
}
}
}