public with sharing class MFG_BSAPP_RPT_ROUTELIST_CTRL { public String g_userId {set; get;} public String g_userName {set; get;} public String g_userLocationId {set; get;} public String g_userRole {set; get;}
//report content
public List<String> reportContentList {set;
get {
if (reportContentList==null) {
reportContentList = new List<String>();
}
return reportContentList;
}
}
//nested list
public List<List<String>> reportContentListX {set;
get {
if (reportContentListX==null) {
reportContentListX = new List<List<String>>();
}
return reportContentListX;
}
}
public MFG_BSAPP_RPT_ROUTELIST_CTRL() {
//retrieve cookies
Cookie cookieItem;
cookieItem= ApexPages.currentPage().getCookies().get('bsckUserId');
if (cookieItem != null) {
g_userId = cookieItem.getValue();
}
cookieItem= ApexPages.currentPage().getCookies().get('bsckUserName');
if (cookieItem != null) {
g_userName = cookieItem.getValue();
}
cookieItem= ApexPages.currentPage().getCookies().get('bsckSelectedLocId');
if (cookieItem != null) {
g_userLocationId = cookieItem.getValue();
}
cookieItem= ApexPages.currentPage().getCookies().get('bsckSelectedRoleName');
if (cookieItem != null) {
g_userRole = cookieItem.getValue();
}
}
//access validation method
public PageReference accessValidation() {
MFG_BSAPP_LOCATION__c locationObj = [SELECT id, NAME__c, SITE_ID__r.NAME__c
FROM MFG_BSAPP_LOCATION__c
WHERE ACTIVE_FLAG__c = true
AND id=:g_userLocationId];
String locName = 'Location: ' + locationObj.NAME__c;
String siteName = 'Site: ' + locationObj.SITE_ID__r.NAME__c;
String dateString = 'Date: ' + MFG_BSAPP_UTIL_CLS.convertDate2String(Date.today());
//add report name
reportContentList.add( locationObj.SITE_ID__r.NAME__c + ' Bus Route Listing Report');
//add site, location, date info in a line
String sldString = siteName + ',' + locName.escapeCsv() + ',' + dateString;
reportContentList.add(sldString);
String line = '';
List<MFG_BSAPP_ROUTE_MASTER__c> RouteList = [SELECT id,ROUTE__c FROM MFG_BSAPP_ROUTE_MASTER__c WHERE LOCATION_ID__c = :g_userLocationId and id in (SELECT ROUTE_ID__c FROM MFG_BSAPP_CODE_MASTER__c
WHERE LOCATION_ID__c = :g_userLocationId) ORDER BY ROUTE__c];
for (Integer j=0;j<RouteList.size();j++) {
MFG_BSAPP_ROUTE_MASTER__c RouteObj = RouteList[j];
reportContentList.add('Bus Route: ' + RouteObj.ROUTE__c);
List <MFG_BSAPP_CODE_DETAIL__c> CodeList = [SELECT ROUTE_ID__r.Route__c,SHIFT_ID__r.DESCRIPTION__c,TIME1__c,TIME2__c,TIME3__c,STOP_ID__r.STOP_CODE__c,STOP_ID__r.DESCRIPTION1__c,STOP_ID__r.DESCRIPTION2__c FROM MFG_BSAPP_CODE_DETAIL__c WHERE LOCATION_ID__c = :g_userLocationId AND ROUTE_ID__c = :RouteObj.id ORDER BY ROUTE_ID__r.Route__c,SHIFT_ID__r.DESCRIPTION__c,TIME1__c,TIME2__c,TIME3__c];
reportContentList.add('Bus Shift,Stop Time1,Stop Time2,Stop Time3,Stop Code,Stop Description');
for (Integer i=0; i<CodeList.size(); i++) {
if (reportContentList.size() < 1000) {
MFG_BSAPP_CODE_DETAIL__c CodeObj = CodeList[i];
if (CodeObj.STOP_ID__r.DESCRIPTION2__c == null) {
CodeObj.STOP_ID__r.DESCRIPTION2__c = '';
}
if (CodeObj.TIME2__c == null) {
CodeObj.TIME2__c = '';
}
if (CodeObj.TIME3__c == null) {
CodeObj.TIME3__c = '';
}
line = CodeObj.SHIFT_ID__r.DESCRIPTION__c + ',' + CodeObj.TIME1__c +','+ CodeObj.TIME2__c +','+ CodeObj.TIME3__c +',' + CodeObj.STOP_ID__r.STOP_CODE__c +','+ CodeObj.STOP_ID__r.DESCRIPTION1__c +'/'+ CodeObj.STOP_ID__r.DESCRIPTION2__c;
reportContentList.add(line);
line = '';
} else {
reportContentListX.add(reportContentList);
reportContentList = new List<String>();
MFG_BSAPP_CODE_DETAIL__c CodeObj = CodeList[i];
if (CodeObj.STOP_ID__r.DESCRIPTION2__c == null) {
CodeObj.STOP_ID__r.DESCRIPTION2__c = '';
}
if (CodeObj.TIME2__c == null) {
CodeObj.TIME2__c = '';
}
if (CodeObj.TIME3__c == null) {
CodeObj.TIME3__c = '';
}
line = CodeObj.SHIFT_ID__r.DESCRIPTION__c + ',' + CodeObj.TIME1__c +','+ CodeObj.TIME2__c +',' + CodeObj.TIME3__c +',' + CodeObj.STOP_ID__r.STOP_CODE__c +','+ CodeObj.STOP_ID__r.DESCRIPTION1__c +'/'+ CodeObj.STOP_ID__r.DESCRIPTION2__c;
reportContentList.add(line);
line = '';
}
}
}
reportContentListX.add(reportContentList);
return null;
}
}