I have a controller that counts the number of transaction and group it by store, year, month & day.
I am trying to do a user input box in VF page to allow user to enter the month only so that it will display those data with the selected month.
But it is not able to work properly.
Pls help. Thank you.
My controller:
public with sharing class TestController {
public Summary[] Summaries { get; set; }
public Summary[] displaySummaries {get; set; }
public integer userinput{get; set;}
public TestController() {
//constructor
AggregateResult[] results = [Select Store_Code__C, calendar_year(Transaction_Date_Time__c) OOB, calendar_month(Transaction_Date_Time__c) KKB, DAY_IN_MONTH(Transaction_Date_Time__c) CCB, count_distinct(Termin_Receipt__C) NNP FROM Member_Transaction__c group by Store_Code__C, calendar_year(Transaction_Date_Time__c), calendar_month(Transaction_Date_Time__c), DAY_IN_MONTH(Transaction_Date_Time__c) order by Store_Code__C, calendar_year(Transaction_Date_Time__c), calendar_month(Transaction_Date_Time__c), DAY_IN_MONTH(Transaction_Date_Time__c)];
Summaries = new List<Summary>();
for (AggregateResult ar : results) {
Summaries.add(new Summary(ar));
}
displaySummaries = new List<Summary>(Summaries);
}
//wrapper class to hold aggregate data
public class Summary {
public String Store { get; private set; }
public Integer yyear { get; private set; }
public Integer mmonth { get; set; }
public Integer dday { get; private set; }
public Integer CCount { get; private set; }
public Summary(AggregateResult ar) {
Store = (String) ar.get('Store_Code_POS__C');
yyear = (Integer) ar.get('OOB');
mmonth = (Integer) ar.get('KKB');
dday = (Integer) ar.get('CCB');
CCount = (Integer) ar.get('NNP');
}
}
public void filter(){
displaySummaries = new List<Summary>();
for(Summary o : Summaries){
if (userinput == o.mmonth){
displaySummaries.add(o);
}
}
}
}
My VF page:
<apex:page controller="TestController">
<apex:sectionheader title="Transaction Count Report" />
<apex:form >
<apex:pageblock title="Filter">
<apex:pageblocksection >
<apex:outputlabel value="Enter month here"/>
<apex:inputtext value="{!userinput}">
<apex:actionsupport event="onchange" action="{!filter}" rerender="TxCTable" />
</apex:inputtext>
</apex:pageblocksection>
</apex:pageblock>
<apex:pageblock title="Transaction Count " id="TxCTable">
<apex:pageblocktable value="{!displaySummaries}" var="o">
<apex:column value="{!o.Store}" headervalue="Store"/>
<apex:column value="{!o.yyear}" headervalue="Year"/>
<apex:column value="{!o.mmonth}" headervalue="Month"/>
<apex:column value="{!o.dday}" headervalue="Day"/>
<apex:column value="{!o.Ccount}" headervalue="Count"/>
</apex:pageblocktable>
</apex:pageblock>
</apex:form>