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
Sheslie SenatSheslie Senat 

Passing selectlist value to controller

I've been trying do many methods to get this accomplished with no success. 
I have two visualforce pages and one controller. 
The first visualforce page consist of three select list fields - a search button and a generate report button
The second VF page, renders as PDF and essentially renders the requested report.
The controller contains methods to search based on the select list inputted from the first visualforce page as well as methods to List the required data in the report.  One is a simple list and the other is an aggregated list. 

My issues is that I'm having a hard time getting the where clause in my list and aggregated list to work and filter to show the filtered data on the report.  
The search filters well and the results are correct, but whenever I try to fitler (where clause) by the same string on the other list, the second visualforce page just shows the results.  If I remove the where clause then everything works but the report shows me unfiltered results. 

Code is below.  Any help would be appreciated.  I'm new to this so any help would be appreciated. 

VF Page 1 - Inputs go here
<apex:page Controller="ExpenseReport" >

    <apex:form >
    
        <apex:pageBlock title="Select Report Parameters">
<apex:pageBlockSection columns="1">

                <apex:selectList size="1" value="{!obj}" Label="Incurrer" id="obj">
                    <apex:selectOption itemValue="None" itemLabel="None"/>
                    <apex:selectOption itemValue="Christian Ricci" itemLabel="Christian Ricci"/>
                    <apex:selectOption itemValue="Abi Tamot" itemLabel="Abi Tamot"/>
                    <apex:selectOption itemValue="Angela Gates" itemLabel="Angela Gates"/>                                        
                </apex:selectList>

                <apex:selectList size="1" value="{!per}" Label="Expense Period" id="per">
                    <apex:selectOption itemValue="None" itemLabel="None"/>
                    <apex:selectOption itemValue="Aug 31" itemLabel="Aug 31"/>
                    <apex:selectOption itemValue="Sept 15" itemLabel="Sept 15"/>
                    <apex:selectOption itemValue="Oct 15" itemLabel="Oct 15"/>                                        
                </apex:selectList>
                
                <apex:selectList size="1" value="{!sta}" Label="Expense Status" id="sta" >
                    <apex:selectOption itemValue="None" itemLabel="None"/>
                    <apex:selectOption itemValue="Approved" itemLabel="Approved"/>
                    <apex:selectOption itemValue="Submitted for Approval" itemLabel="Submitted for Approval"/>
                    <apex:selectOption itemValue="Not Approved" itemLabel="Not Approved"/>                                        
                </apex:selectList>                

</apex:pageBlockSection>
>

<apex:pageBlockButtons >
   <apex:commandButton action="{!Search}" value="Search"/>
   <apex:commandButton action="{!ExpenseReport}" value="Generate Report" />
</apex:pageBlockButtons>


<apex:pageBlockTable value="{!OpList}" var="c">
    <apex:column headerValue="Incurrer">
        <apex:outputField value="{!c.Expense_Incurred_by1__c}"/>
        </apex:column>
    <apex:column headerValue="Expense Period">
        <apex:outputField value="{!c.Expense_Period__c}"/>
        </apex:column>
    <apex:column headerValue="Status">
        <apex:outputField value="{!c.Expense_Status__c }"/>
        </apex:column>
    <apex:column headerValue="Total Amount">
        <apex:outputField value="{!c.Total_Expense_Amount__c}"/>
        </apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

CONTROLLER -- 
public class ExpenseReport
{
    Public String obj {get; set;}
    Public String per {get; set;}
    Public String sta {get; set;}
    Public List <Expenses__c> Oplist {get; set;}                
    public List<Expenses__c> expLst {get; set;} 
    public Summary[] Summaries { get; set; }
    public List<MyWrapper> wrapper {get; set;}

    public ExpenseReport()
    {
                                                      
        List<Expenses__c> expLst = [select id, Expense_Status__c, Expense_Incurred_by1__c, Total_Expense_Amount__c, RecordTypeId, Date__c, Description__c, GST_Claim__c, HST_Claim__c, QST_Claim__c, Golf_100_Amount__c, Meal_Entertainment_50_Amount__c, Gross_Tip_PST__c, GST__c, HST__c, QST__c, 
                          Expense_Budget_Owner1__c, Type__c, Number_of_Attendees__c, Per_Advisor_Share__c, Company_Name__c, Expense_Period__c, Name from Expenses__c 
                          WHERE CreatedDate = Last_N_Days:330 And Expense_Incurred_by1__c  = :obj 
                          order by Type__c];
        
        AggregateResult[] results= [select Type__c, SUM(Total_Expense_Amount__c) totexp, SUM(GST_Claim__c) GSTc, SUM(HST_Claim__c) HSTc, SUM(QST_Claim__c) QSTc, SUM(Golf_100_Amount__c) Golfamt, SUM(Meal_Entertainment_50_Amount__c)Mealamt, SUM(Gross_Tip_PST__c) Gross, SUM(GST__c) GST, SUM(HST__c) HST, SUM(QST__c) QST 
                          from Expenses__c 
                          WHERE Expense_Status__c = 'Submitted for Approval' AND CreatedDate = Last_N_Days:330 And Expense_Incurred_by1__c  = 'Christian Ricci'
                          Group by rollup (Type__c)];
                          
                            Summaries = new List<Summary>();
                            for (AggregateResult ar : results) {
                            Summaries.add(new Summary(ar));
                            }
             

                         
        if(Wrapper == null){        
        wrapper = new List<MyWrapper>() ;
        for(Integer i=0 ; i <expLst.size() ; i++)
            wrapper.add(new MyWrapper(expLst[i])) ;
           }
           

    }
    
    public pageReference ExpenseReport()
    {
        PageReference pg = new PageReference('/apex/Expense_Report');
        pg.setRedirect(false);
        return pg;
    }
    

            
    public void Search() {
    string objquery='select name, ID, Total_Expense_Amount__c, Expense_incurred_by1__c,Expense_period__c, Expense_Status__c From Expenses__c where Expense_incurred_by1__c like \'%'+obj+'%\' AND Expense_period__c like\'%'+per+'%\' AND Expense_Status__c like \'%'+sta+'%\'';
    Oplist = Database.query(objquery);
    }
    public void clear(){
    oplist.clear();
    } 
    
        
    public class MyWrapper
    {
        public Expenses__c expRec {get; set;}
        
        
        public MyWrapper(Expenses__c exp)
        {
           

            expRec = exp ;
           
       

        }
                   }
                   
     public class Summary {
        public Decimal Totalexp { get; set; }
        public Decimal GSTc { get; set; }
        public Decimal HSTc { get; set; }
        public Decimal QSTc { get; set; }
        public Decimal Golfamt { get; set; }
        public Decimal Mealamt { get; set; }
        public Decimal Gross { get; set; }
        public Decimal GST { get; set; }
        public Decimal HST { get; set; }
        public Decimal QST { get; set; }
        public String Type { get; set; }
        
        
        public Summary(AggregateResult ar) {
            Totalexp = (Decimal) ar.get('totexp');
            GSTc = (Decimal) ar.get('GSTc');
            HSTc = (Decimal) ar.get('HSTc');
            QSTc = (Decimal) ar.get('QSTc');
            Golfamt = (Decimal) ar.get('Golfamt');
            Mealamt= (Decimal) ar.get('Mealamt');
            Gross= (Decimal) ar.get('Gross');
            GST = (Decimal) ar.get('GST');
            HST = (Decimal) ar.get('HST');
            QST = (Decimal) ar.get('QST');
            Type = (String) ar.get('Type__c');
            
        }
    }                  


    }

VF Page 2 (parts of it) - Report 

<apex:page controller="ExpenseReport" showHeader="false"   applyBodyTag="false">

                <span style="font-size:12px;">
                    Expenses Incurred by: {!obj} <br/>
                    Expense Period: {!per}<br/>
                    Expense Status: {!sta}<br/>
                    Year Printed: {!YEAR(TODAY())} <br/><br/>
                </span>
            </td>
            
            </tr>
    </table>   
    
<apex:form >
<apex:inputtext id="obj" value="{!obj}"/>

<tr>
            <td style="width:40%; vertical-align:top;">
                <span style="font-weight:bold; font-size:16px;">
                    Summary by Type
                </span>
                <br/>
                            </td>
            
            </tr>
<apex:dataTable value="{!Summaries}" var="summary" id="table" style="font-size:12px;" border="1" cellpadding="3" headerClass="tHeader">

         <apex:column headerValue="Type"><apex:outputLabel value="{!summary.Type}"></apex:outputLabel></apex:column>
         
         <apex:column headerValue="Total Expense Amount">
              <b><apex:outputText value="{0,number,$#,##0.00}">
                    <apex:param value="{!summary.Totalexp}"/>
                        </apex:outputText></b></apex:column>
                  
         <apex:column headerValue="Gross Amount">
              <apex:outputText value="{0,number,$#,##0.00}">
                   <apex:param value="{!summary.Gross}" />
                        </apex:outputText></apex:column>    

</apex:form>

<apex:form >
<tr>
            <td style="width:40%; vertical-align:top;">
                <span style="font-weight:bold; font-size:16px;">
                    Expense Details
                </span>
                <br/>
                            </td>
            
            </tr>
<apex:pageBlock >
<div style="width=100%; display:inline;"> 
      
  <apex:dataTable value="{!Wrapper}" var="c" id="table" style="font-size:12px;" border="1" cellpadding="3" headerClass="tHeader">

        <apex:column headerValue="Type"><apex:outputLabel value="{!c.expRec.Type__c}"></apex:outputLabel></apex:column>
        <apex:column headerValue="Company Name"><apex:outputLabel value="{!c.expRec.Company_Name__c}"></apex:outputLabel></apex:column>
        
        <apex:column headerValue="Receipt Date">
            <apex:outputText value="{0,date,dd'/'MM'/'yyyy}"> 
            <apex:param value="{!c.expRec.Date__c}"/>
            </apex:outputText></apex:column>
   
        <apex:column headerValue="Details"><apex:outputLabel value="{!c.expRec.Description__c}"></apex:outputLabel></apex:column>
        
        <apex:column headerValue="Total Amount">
                        <apex:outputText value="{0,number,$#,##0.00}">
                        
                    <apex:param value="{!c.expRec.Total_Expense_Amount__c}" />

                </apex:outputText></apex:column>

        <apex:column headerValue="Gross+Tip+PST">
                        <apex:outputText value="{0,number,$#,##0.00}">
                    <apex:param value="{!c.expRec.Gross_Tip_PST__c}" />
                </apex:outputText></apex:column>    

</div>
</apex:pageBlock>
</apex:form>
</apex:page>