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
nikkeynikkey 

On wrapper class can we get the subtotals and grandtotals calculation in a table at footer ,VF page in PDF

I have a custom visual force page created on "Quote "Object in a PDF format where the data gets displayed .Writing Wrapper class i have achieved the data of opportunity forecast details.Now i would Like to get

1) To Filter the Product Name ,With Quantity and Amount for Every Quarter.

2)To Achieve the Subtotals and Grandtotals for the Quantity and Amount .

PFA Screen Shot

VISUAL FORCE CODE :

 
<h2>OpportunityForecast Details</h2>
 <table class="bordered">
        <thead>
            <tr>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Part Numbers</td>
                <td class="header-table-heading" bgcolor="#C0C0C0">Quantity</td>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Price</td>
                <td class="header-table-heading" bgcolor="#C0C0C0"> Amount</td>
               <!-- <td class="header-table-heading" bgcolor="#C0C0C0">Quarter</td>-->
                <td class="header-table-heading" bgcolor="#C0C0C0">Month</td>  
               <!-- <td class="header-table-heading" bgcolor="#C0C0C0">Actual Price</td>-->
                <td class="header-table-heading" bgcolor="#C0C0C0">Year</td>
               <!-- <td class="header-table-heading" bgcolor="#C0C0C0">Date</td> --> 
                <td class="header-table-heading" bgcolor="#C0C0C0">MonthText</td> 
                <td class="header-table-heading" bgcolor="#C0C0C0">ForecastDate</td> 
                <td class="header-table-heading" bgcolor="#C0C0C0">ForecastName</td>  
            </tr>
        </thead>
        <tbody>
           <apex:repeat value="{!disp_list}" var="opf">
            <tr>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Product}"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Quantity}"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Price }"/></td>
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Amount }"/></td>
               <!-- <td class="header-table-data"><apex:outputText value="{!opf.gmod_Quarter }"/></td>-->
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Month }"/></td>
               <!-- <td class="header-table-data"><apex:outputText value="{!opf.Actual_Price }"/></td>-->
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Year }"/></td>
              <!--  <td class="header-table-data"><apex:outputText value="{!opf.gmod_date }"/></td> -->  
                <td class="header-table-data"><apex:outputText value="{!opf.gmod_Month_Text }"/></td> 
                <td class="header-table-data"><apex:outputText value="{!opf.Forecast_Date }"/></td> 
                <td class="header-table-data"><apex:outputText value="{!opf.Name }"/></td>
             </tr>
            </apex:repeat> 
        </tbody>
    </table>

APEX CODE :

 
public with sharing class QuoteContentController {

       public Competitor__c com{get;set;}
    
       public gmod__Opportunity_Forecast__c oppf{get;set;}
   
       public Id qId {get;set;}
    
//Declare a wrapper class  
   
       public class Wrapperclass{
      
 //custom wrapper datatype  
       
       Public string Name{get;set;}  
       Public string AccountType{get;set;}  
       Public date todaysDate{get;set;}  
       Public date Expected_Order_Date{get;set;}
       Public string Probability{get;set;}  
       Public string Internal_Comment{get;set;}  
       Public string External_Comment{get;set;}  
     
       Public string Segment{get;set;}  
       Public string Application{get;set;}  
       Public string Persona{get;set;}  
       Public string Geogrpahy{get;set;}  
       
       Public string PartNumbers{get;set;}  
       Public Decimal  Price{get;set;}  
       Public Decimal End_Customer_Price{get;set;}  
       Public Decimal Quantity {get;set;}  
       Public Decimal Total{get;set;}  
      
       Public string RFQ_justification{get;set;}  
       Public string Main_Customer_of_Account{get;set;}  
       Public string Bridgelux_competition_at_account{get;set;}
       Public string Geographic_regions_serviced{get;set;}  
       Public string Annual_lighting_revenue{get;set;}  
       Public string Annual_LED_revenue_or_percent{get;set;}  
       Public string Annual_purchases_of_LED_light_sources{get;set;}
       Public string Percent_of_LED_purchases_that_are_COB{get;set;}  
       Public string Other_information{get;set;}  
      
       Public string Product_Series{get;set;}  
       Public string Volume{get;set;} 
       Public string Date_Price_is_Valid{get;set;} 
      
       Public string gmod_Product{get;set;}
       Public Decimal gmod_Quantity{get;set;}
       Public Decimal gmod_Price{get;set;}
       Public Decimal gmod_Quarter{get;set;}
       Public Decimal gmod_Month{get;set;}
       Public Decimal gmod_Amount{get;set;}
       Public Decimal Actual_Price{get;set;}
       Public Decimal  gmod_Year{get;set;}
       Public Date gmod_date{get;set;}
       Public string gmod_Month_Text{get;set;}
       Public Date  Forecast_Date{get;set;}
       
       Public wrapperClass(){} 
      
  }
  
       Public QuoteContentController(){}
  
       Public QuoteContentController(ApexPages.StandardController controller) {
       
       qId=Apexpages.currentPage().getparameters().get('Id');
    
    }
    
       Public List<wrapperClass> disp_list {get;set;}{
      
     // Public List<wrapperClass> disp_list(){
    //define constructor to instantiate the wrapper data type 

       disp_list=new list<wrapperclass>();

    //Query all the list 
    
    list<Quote> q =[select id ,Name ,Effective_Date__c ,Comments__c ,
                    Quote.Opportunity.Probability ,Quote.Opportunity.AccSegment__c ,Quote.Opportunity.AccApplication__c,Quote.Opportunity.Persona__c,Quote.Opportunity.Region__c
                    from Quote where id=:apexpages.currentpage().getparameters().get('id')];
                     
    list<QuoteLineItem> qli =[Select QuoteId , PricebookEntry.Product2.Name ,Unitprice ,End_Customer_Price__c ,Quantity , TotalPrice from QuoteLineItem where QuoteId =:qId ];
    
    list<Account> a = [Select id ,Name ,Main_Customers_of_Account__c ,Bridgelux_Competition_at_Account__c,Servicing_Region__c ,
                      Annual_LED_Revenue__c,Annual_Purchases_of_LED_Sources_SAM__c ,Percent_of_LED_purchases_that_are_COB__c from Account where account.id =:qId ];
                      
   list<Competitor__c>  com = [Select id ,Part_Number__c,Product_Series__c,Price_Offered__c,Volume__c,Date_Price_is_Valid__c from Competitor__c ]  ; 
   
   opp =[select id ,Name , probability,AccSegment__c from Opportunity where opportunity.Id =:q[0].Id];
    
   list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__c,gmod__Quantity__c,gmod__Price__c ,   gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c,gmod__Year__c , gmod__Month__c, gmod__date__c ,gmod__Month_Text__c ,Forecast_Date__c from gmod__Opportunity_Forecast__c where name!=null   ];
   
    list<gmod__Opportunity_Forecast__c>  opflist = [Select id ,Name ,gmod__Product__r.name,gmod__Quantity__c,gmod__Price__c , gmod__Month__c,    gmod__date__c,  gmod__Quarter__c ,gmod__Amount__c ,Actual_Price__c ,gmod__Year__c ,gmod__Month_Text__c ,Forecast_Date__c from gmod__Opportunity_Forecast__c  where gmod__Product__r.name!=null and gmod__Opportunity__r;id=:opp.id order by  gmod__Month__c asc];
      

//SELECT  gmod__product__r.name ,gmod__opportunity__c,sum(gmod__Price__c) gmod__Price__c ,SUm(gmod__Amount__c) gmod__Amount__c,Sum(gmod__Quantity__c)gmod__Qunatity__c,COUNT(id) Quantity 
FROM gmod__Opportunity_Forecast__c 
GROUP BY  gmod__product__r.name ,gmod__opportunity__c
       //Iterate through each list to extract the values and add it to the custom wrapper data type  

         for (Quote qt :q){

            for(integer i=0;i<opflist.size();i++){

                //Instantiating the wrapper SObject 
                
                wrapperclass w = new wrapperclass();
  
  //Assigning the wrapper variables from the SObject Fields in the database. 
  
  w.gmod_Product = opflist[i].gmod__Product__c;
 
  w.gmod_Quantity =opflist[i].gmod__Quantity__c;
  
  w.gmod_Price=opflist[i].gmod__Price__c;
 
  w.Name =opflist[i].Name;
  
  w.gmod_Quarter=opflist[i].gmod__Quarter__c;
  
  w.gmod_Month=opflist[i].gmod__Month__c;
  
  w.gmod_Amount=opflist[i]. gmod__Amount__c;
  
  w.Actual_Price=opflist[i].Actual_Price__c;
  
  w.gmod_Year=opflist[i].gmod__Year__c;
  
  w.gmod_date=opflist[i].gmod__date__c;
  
  w.gmod_Month_Text=opflist[i].gmod__Month_Text__c;
  
  w.Forecast_Date=opflist[i].Forecast_Date__c;
  
      //Adding everthing to the List  
    
    
    // w.name =qt.name;
     
      disp_list.add(w);
      
      // return disp_list;  
       }
     }
   }  
 } //End of Class





Any Suggestion Plz.

TABLE1TABLE2
HawkedHawked
Did you take a look at reporting API, you can exactly recreate a report in a VF page using analytics / reporitng API.

User-added image

If you do not want to go the above route 


Integer subtotalofquantity{get;set;}
 
Public List<wrapperClass> disp_list {get;set;}{

subtottalofquantity = 0;
subtotalofamount  = 0;
.
.
.
for(integer i=0;i<opflist.size();i++){
   subtotalofquantity += opflist[i].gmod__Quantity__c;
   subtotalofamount  += opflist[i]. gmod__Amount__c;
}

}


 
nikkeynikkey
Hi Hawked, Thanks for your reply. I tried adding your code ,Integer subtotalofquantity{get;set;} but i couldnot see any totals getting added to the Quantity and amount.I shall appreciate your help.