SSRS Report by using Controller Class - sample code

Contract Class : Here I am passing an Account number as a parameter
Class Declaration :
[DataContractAttribute]
class FOFS_POTermsAndConditionsContract
{
AccountNum account;
int64 tablenumber;
SalesId salesid;
PurchId purchid;
}
Parm Method1 :
[
DataMemberAttribute(“Purch Id Number”)
]
public AccountNum parmPurchnum(AccountNum _Purchnumber = account)
{
account = _Purchnumber;
return account;
}
So Now I got in Account number I will Pass a Purch ID or Sales ID
so based on menu Item I need to select a design which is either PO report or SO report.
For that i am using a Controller class, There I am differentiate the design.
Controller Class ::
Class declaration method :
class FOFS_POTermsAndConditionsController extends SrsReportRunController
{
PurchTable purch;
SalesTable sales;
}
PreRunModifies Contract method is the main method to do the selection of design but in Main method we will pass one design as a default design but this method will override the design by passing the value.
preRunModifiedContract method :
Protected void preRunModifyContract()
{
str reportnameLocal;
FOFS_POTermsAndConditionsContract contract;
contract = this.parmReportContract().parmRdpContract() as FOFS_POTermsAndConditionsContract;
if(this.parmArgs().menuItemName() == menuitemOutputStr(FOFS_TermsSalesReport))
{
sales = args.record();
// contract.parmAccountnum(sales.CustAccount);
// contract.parmTableid(sales.TableId);
contract.parmPurchnum(sales.SalesId);
reportnameLocal = ssrsReportStr(FOFS_TermsAndCondition,SalesTerms);
}
else if(this.parmArgs().menuItemName() == menuitemOutputStr(FOFS_TermsPurchReport))
{
purch = args.record();
// contract.parmAccountnum(purch.OrderAccount);
// contract.parmTableid(purch.TableId);
contract.parmPurchnum(purch.PurchId);
reportnameLocal = ssrsReportStr(FOFS_TermsAndCondition,PurchTerms);
}
this.parmReportContract().parmReportName(reportnameLocal);
}
this is the mail method which will execute first, here i will pass a default design but prerunmodified method will override the design based on menuitem which is calling.
Main Method :
public static void main(args _args)
{
FOFS_POTermsAndConditionsController controller = new FOFS_POTermsAndConditionsController();
controller.parmReportName(ssrsReportStr(FOFS_TermsAndCondition,PurchTerms));
controller.parmArgs(_args);
controller.parmShowDialog(false);
controller.startOperation();
}
DP class will execute the business logic for the report.
DP class :
Class declaration Method :
[SRSReportParameterAttribute(classStr(FOFS_POTermsAndConditionsContract))]
class FOFS_POTermsAndConditionsDP extends SRSReportDataProviderBase//SRSReportDataProviderBase//SrsReportDataProviderPreProcess
{
FOFS_TermsConditionReportTmp reporttable;
SalesTable sales;
PurchTable purch;
FOFS_TermsCategory categort;
FOFS_TermsHierarchy hierarchy;
FOFS_TermsCategoryValues values;
container companylogo;
}
Get data method :
[SRSReportDataSetAttribute(tableStr(FOFS_TermsConditionReportTmp))]
public FOFS_TermsConditionReportTmp GetData()
{
select * from reporttable;
return reporttable;
}
Insert into report table method1 :
private void insertintoPurch(PurchTable _purch)
{
hierarchy = FOFS_TermsHierarchy::findHierarchyName(_purch.FOFS_HierarchyName);
companylogo = CompanyImage::findByRecord(CompanyInfo::find()).Image;
while select * from categort where categort.CategoryHierarchy == hierarchy.RecId
join values where values.ParentRecId == categort.RecId
{
reporttable.clear();
reporttable.CompanyLogo = companylogo;
reporttable.HierarchyName = _purch.FOFS_HierarchyName;
reporttable.PurchId = _purch.PurchId;
reporttable.VendAccount = _purch.vendorName();
reporttable.ParentName = categort.Name;
reporttable.ChildName = values.CategoryNodeCode;
reporttable.insert();
}
}
Insert into report table method2 :
private void insertintoSales(SalesTable _sales)
{
hierarchy = FOFS_TermsHierarchy::findHierarchyName(_sales.FOFS_HierarchyName);
companylogo = CompanyImage::findByRecord(CompanyInfo::find()).Image;
while select * from categort where categort.CategoryHierarchy == hierarchy.RecId
join values where values.ParentRecId == categort.RecId
{
reporttable.clear();
reporttable.CompanyLogo = companylogo;
reporttable.HierarchyName = _sales.FOFS_HierarchyName;
reporttable.SalesId = _sales.SalesId;
reporttable.CustAccount = _sales.customerName();
reporttable.ParentName = categort.Name;
reporttable.ChildName = values.CategoryNodeCode;
reporttable.insert();
}
}
Process Report Method :
[
SysEntryPointAttribute(false)
]
public void processReport()
{
FOFS_POTermsAndConditionsContract contract = this.parmDataContract();
AccountNum accountNumber;
int64 purchtablenumber,salestablenumber;
SalesId salesid;
PurchId purchid;
purchtablenumber = tableNum(PurchTable);
salestablenumber = tableNum(SalesTable);
accountNumber = contract.parmPurchnum();
select firstOnly * from sales where sales.SalesId == accountNumber;
if(sales)
{
this.insertintoSales(sales);
}
else
{
select * from purch where purch.PurchId == accountNumber;
this.insertintoPurch(purch);
}
}


Comments

Popular posts from this blog

Write/ Read to Excel Sheet

Table Methods in Ax 2012

Financial Dimensions in AX 2012