function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Hersh321Hersh321 

Column keeps repeating in Data Table

Hi Everyone,

 

I'm trying to create a custome report via Visualforce.  I have a custom object called Quota's.  For each month I'm trying to sum all the closed opp amount values per a particular user and divide it by the users quota for that month.

 

EX: Jims Quota for January is $10,000.  He has Closed $20,000.  So his % is 200% for January.  I'm geting all the values correct but it shows 200% for everyone in the Jan column.  I've tried converting values into a string and storing them in a list but i can't seem to get it working properly.  I've attached the code on the bottom.  Any help is greatly appreciated.

 

-Hersh

 

Class:

 

public class QuotaReport {
    
    public User[] SalesRep            {get; set;}
    public Opportunity[] OppList      {get; set;}
    public Quota_Custom__c[] Quota    {get; set;}
    public decimal Jan                {get; set;}
    public decimal Feb                {get; set;}
    public decimal Mar                {get; set;}
    public decimal Apr                {get; set;}
    public decimal May                {get; set;}
    public decimal Jun                {get; set;}
    public decimal Jul                {get; set;}
    public decimal Aug                {get; set;}
    public decimal Sept               {get; set;}
    public decimal Oct                {get; set;}
    public decimal Nov                {get; set;}
    public decimal Dec                {get; set;}
    public String CurrYear = String.valueOf(Date.today().year());
    Public Date Jan1 = Date.valueOf(CurrYear+'-01-01');
    Public Date Jan31 = Date.valueOf(CurrYear+'-01-31');   
    Public Date Feb1 = Date.valueOf(CurrYear+'-02-01');
    Public Date Feb28 = Date.valueOf(CurrYear+'-02-28');   
    Public Date Mar1 = Date.valueOf(CurrYear+'-03-01');
    Public Date Mar31 = Date.valueOf(CurrYear+'-03-31');   
    Public Date Apr1 = Date.valueOf(CurrYear+'-04-01');
    Public Date Apr30 = Date.valueOf(CurrYear+'-04-30');
    Public Date May1 = Date.valueOf(CurrYear+'-05-01');
    Public Date May31 = Date.valueOf(CurrYear+'-05-31');
    Public Date Jun1 = Date.valueOf(CurrYear+'-06-01');
    Public Date Jun30 = Date.valueOf(CurrYear+'-06-30');
    Public Date Jul1 = Date.valueOf(CurrYear+'-07-01');
    Public Date Jul31 = Date.valueOf(CurrYear+'-07-31');
    Public Date Aug1 = Date.valueOf(CurrYear+'-08-01');
    Public Date Aug31 = Date.valueOf(CurrYear+'-08-31');
    Public Date Sept1 = Date.valueOf(CurrYear+'-09-01');
    Public Date Sept30 = Date.valueOf(CurrYear+'-09-30');
    Public Date Oct1 = Date.valueOf(CurrYear+'-10-01');
    Public Date Oct31 = Date.valueOf(CurrYear+'-10-31');
    Public Date Nov1 = Date.valueOf(CurrYear+'-11-01');
    Public Date Nov30 = Date.valueOf(CurrYear+'-11-30');
    Public Date Dec1 = Date.valueOf(CurrYear+'-12-01');
    Public Date Dec31 = Date.valueOf(CurrYear+'-12-31');
    
    public QuotaReport(){
    
        SalesRep = [Select Id, Name, ProfileId FROM User];


        Quota = [Select Id, Name, January__c, February__c, March__c, April__c, May__c, June__c, July__c, August__c, September__c, October__c, November__c, December__c, Year__c, Salesperson__c, Salesperson__r.Name FROM Quota_Custom__c WHERE Year__c=:CurrYear AND Salesperson__c=:Salesrep];


        OppList = [Select Id, Name, OwnerId, CloseDate, StageName, Closed_Deal_Booking_Value__c, Amount, CreatedDate FROM Opportunity WHERE OwnerID=:Salesrep];
        
        //List<String> Jan=new List<String>();
        
        //for(User USR : SalesRep){
        
            for(Quota_Custom__c UsrSP : Quota){
            
                for(Opportunity Opp : OppList) {

                    if(Opp.CloseDate > Jan1 && Opp.CloseDate < Jan31){

                       Jan=(Opp.Closed_Deal_Booking_Value__c/UsrSP.January__c)*100;
                        //Jan.add(string.ValueOf((Opp.Closed_Deal_Booking_Value__c/UsrSP.January__c)*100));
                    }
                    if(Opp.CloseDate > Feb1 && Opp.CloseDate < Feb28){
                    
                        Feb= (Opp.Closed_Deal_Booking_Value__c/UsrSP.February__c)*100;
                    }
                    if(Opp.CloseDate > Mar1 && Opp.CloseDate < Mar31){
                    
                        Mar= (Opp.Closed_Deal_Booking_Value__c/UsrSP.March__c)*100;
                    }
                    if(Opp.CloseDate > Apr1 && Opp.CloseDate < Apr30){
                    
                        Apr= (Opp.Closed_Deal_Booking_Value__c/UsrSP.April__c)*100;
                    }
                    if(Opp.CloseDate > May1 && Opp.CloseDate < May31){
                    
                        May= (Opp.Closed_Deal_Booking_Value__c/UsrSP.May__c)*100;
                    }
                    if(Opp.CloseDate > Jun1 && Opp.CloseDate < Jun30){
                    
                        Jun= (Opp.Closed_Deal_Booking_Value__c/UsrSP.June__c)*100;
                    }
                    if(Opp.CloseDate > Jul1 && Opp.CloseDate < Jul31){
                    
                        Jul= (Opp.Closed_Deal_Booking_Value__c/UsrSP.July__c)*100;
                    }
                    if(Opp.CloseDate > Aug1 && Opp.CloseDate < Aug31){
                    
                        Aug= (Opp.Closed_Deal_Booking_Value__c/UsrSP.August__c)*100;
                    }
                    if(Opp.CloseDate > Sept1 && Opp.CloseDate < Sept30){
                    
                        Sept= (Opp.Closed_Deal_Booking_Value__c/UsrSP.September__c)*100;
                    }
                    if(Opp.CloseDate > Oct1 && Opp.CloseDate < Oct31){
                    
                        Oct= (Opp.Closed_Deal_Booking_Value__c/UsrSP.October__c)*100;
                    }
                    if(Opp.CloseDate > Nov1 && Opp.CloseDate < Nov30){
                    
                        Nov= (Opp.Closed_Deal_Booking_Value__c/UsrSP.November__c)*100;
                    }
                    if(Opp.CloseDate > Dec1 && Opp.CloseDate < Dec31){
                    
                        Dec= (Opp.Closed_Deal_Booking_Value__c/UsrSP.December__c)*100;
                    }
                }
            }
       // }
    }
}

 

VF:

 

<apex:page controller="QuotaReport">
<apex:pageBlock >
<apex:dataTable value="{!Salesrep}" var="Table" cellpadding="5">
<apex:facet name="header"><apex:outputText value="Quota Report" escape="false"/></apex:facet>
<apex:column width="10%">
<apex:facet name="header">Sales Person</apex:facet>
<apex:OutputText value="{!Table.Name}" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Jan</apex:facet>
<apex:OutputText value="{!Jan}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Feb</apex:facet>
<apex:OutputText value="{!Feb}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Mar</apex:facet>
<apex:OutputText value="{!Mar}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Apr</apex:facet>
<apex:OutputText value="{!Apr}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">May</apex:facet>
<apex:OutputText value="{!May}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Jun</apex:facet>
<apex:OutputText value="{!Jun}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Jul</apex:facet>
<apex:OutputText value="{!Jul}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Aug</apex:facet>
<apex:OutputText value="{!Aug}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Sept</apex:facet>
<apex:OutputText value="{!Sept}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Oct</apex:facet>
<apex:OutputText value="{!Oct}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Nov</apex:facet>
<apex:OutputText value="{!Nov}%" />
</apex:column>
<apex:column width="10%">
<apex:facet name="header">Dec</apex:facet>
<apex:OutputText value="{!Dec}%" />
</apex:column>
</apex:dataTable>
</apex:pageBlock>
</apex:page>

 

MTBRiderMTBRider
Datatables iterate over collections of data.  You have your datatable iterating over the user collction called salesRep, but the problem is that there is no assocatiate between the salesRep collection and the quotes you are calculating.  The months that contain the quota calc are simply decimals, so they are all left equally the last Opportunity that was processed in the for loop.  You have to build a collection that has the Salesrep name and that salesrep's quota calculation in the same colection element, then have your datatable iterate over that collection.