Monday, 26 January 2015

SSRS Report in ax 2012 UI builder and controller

1./// <summary>
///    The <c>StockOnHandController</c> class is a controller class for the <c>StockOnHandController report</c>
///    report.
/// </summary>
class StockOnHandController extends SrsReportRunController
{
    StockOnHandContract                     StockOnHandContract;
    Inventtable                                 _Inventtable;
    #define.ReportName('StockOnHand.design')
}
/// <summary>
///    Override this method to change the report contract before you run the report.
/// </summary>
public void preRunModifyContract()
{
    SrsReportRdlDataContract    rdlContractInfo;
    rdlContractInfo = this.parmReportContract().parmRdlContract();
    StockOnHandContract = this.parmReportContract().parmRdpContract() as StockOnHandContract;
    _Inventtable = this.parmArgs().record();

    StockOnHandContract.parmItemid(_Inventtable.ItemId);
  

}
protected boolean validate()
{
    boolean ret;
    ret = super();
    if (! args.record())
    {
        ret = checkFailed("Windows must be called with active record buffer");
    }
    return ret;
}
public client static void main(Args _args)
{
    StockOnHandController controller = new StockOnHandController();
    controller.parmReportName(#ReportName);
    controller.parmLoadFromSysLastValue(false);
    controller.parmArgs(_args);
    controller.parmShowDialog(false);
    controller.startOperation();
}

2. Create the One out put type menuitem with this class
3. Go To your form and Create one Menuitembutton - select the properties like datasourceName,MenuitemType,MenuItemName

-----------------------------------------
Contract class:-
[
    DataContractAttribute,
    SysOperationContractProcessingAttribute(classStr(StockonHandUIBuilder))
]
class StockonHandContract implements SysOperationValidatable
{
    EcoResCategoryName  bpGroup;
    EcoResCategoryName  prodGroup;
    EcoResCategoryName  ProductCategory;
    Itemid              Itemid;
    InventLocationId    InventLocationId;
}
[
    DataMemberAttribute('BPGroup'),
    SysOperationLabelAttribute('BP Group')
]
public EcoResCategoryName parmBPGroup(EcoResCategoryName _bpGroup = bpGroup)
{
    bpGroup = _bpGroup;
    return bpGroup;
}
[
DataMemberAttribute('Itemid'),
SysOperationLabelAttribute('Item Number')
]
public Itemid parmItemid(Itemid _Itemid = Itemid)
{
    Itemid = _Itemid;
    return Itemid;
}
[
DataMemberAttribute('ProdGroup'),
SysOperationLabelAttribute('Product Group')
]
public EcoResCategoryName parmProdGroup(EcoResCategoryName _prodGroup = prodGroup)
{
    prodGroup = _prodGroup;
    return prodGroup;
}
[
DataMemberAttribute('EcoResCategoryName'),
SysOperationLabelAttribute('Prod Category')
]
public EcoResCategoryName parmProductCategory(EcoResCategoryName _ProductCategory = ProductCategory)
{
    ProductCategory = _ProductCategory;
    return ProductCategory;
}
[
DataMemberAttribute('InventLocationId'),
SysOperationLabelAttribute('Warehouse')
]
public InventLocationId parmWarehouse(InventLocationId _InventLocationId = InventLocationId)
{
    InventLocationId = _InventLocationId;
    return InventLocationId;
}
/// <summary>
///    Determines whether the parameters are valid.
/// </summary>
/// <returns>
///    true when the parameters are valid; otherwise, false.
/// </returns>
public boolean validate()
{
    boolean isValid = true;
    if (prodGroup && !bpGroup)
    {
        isValid = checkFailed(strFmt("BP Group to be filled in"));
    }
    if (ProductCategory && ! ProdGroup)
    {
        isValid = checkFailed(strFmt("Product Group to be filled in"));
    }

    return isValid;
}
public static StockonHandContract construct()
{
    return new StockonHandContract();
}
-----------------------------------DP Class
[
    SRSReportQueryAttribute(querystr(ProductDisplayView)),
    SRSReportParameterAttribute(classStr(StockonHandContract))
]
public class StockOnHandDP extends SRSReportDataProviderBase
{
    StockOnHandTMP StockonHandTMP;
    EcoResCategoryName  bpGrouploc,bpGrouplocvalue;
    EcoResCategoryName  prodGrouploc,prodGrouplocvalue;
    EcoResCategoryName  ProductCategoryloc,ProductCategorylocvalue;
    Itemid              Itemidloc;
    InventLocationId    InventLocationIdloc;
}
[SRSReportDataSetAttribute('StockOnHandTMP')]
public StockOnHandTMP getStockOnHandTMP()
{
    select * from StockOnHandTMP;
    return StockonHandTMP;
}
public void processreport()
{
    Query                   query;
    QueryBuildDataSource    qbds;
    QueryBuildRange         qbr,qbr1,qbr2,qbr3,qbr4,qbr5;
    QueryRun                qr;
    StockonHandContract datacontract;
    InventTable             inventtable;
    ProductDisplayView  _ProductDisplayView;
    InventLocation          inventlocation;
    InventDim               InventDim;
    InventTableModule       InventTableModule;
    InventOnhand    _inventonhand;
    InventDimParm   _inventDimParm;
    InventQty       _inventQty;
    query                  = new query();
    datacontract           = this.parmDataContract();
    bpGrouploc         = datacontract.parmBPGroup();
    prodGrouploc       = datacontract.parmProdGroup();
    ProductCategoryloc = datacontract.parmProductCategory();
    Itemidloc          = datacontract.parmItemid();
    InventLocationIdloc= datacontract.parmWarehouse();
    if(prodGrouploc)
    {
        prodGrouplocvalue = prodGrouploc +"_"+bpGrouploc;
    }
    if(ProductCategoryloc)
    {
        ProductCategorylocvalue =ProductCategoryloc+"_"+prodGrouploc +"_"+bpGrouploc;
    }

    qbds = query.addDataSource(tablenum(ProductDisplayView));
    qbds.addSortField(fieldNum(ProductDisplayView,BPGroup),SortOrder::Ascending);
    if(bpGrouploc)
    {
         qbr = qbds.findRange(fieldnum(ProductDisplayView, BPGroup));
        if (!qbr)
        {
            qbr = qbds.addRange(fieldnum(ProductDisplayView, BPGroup));
        }
        if(!qbr.value())
            qbr.value(queryValue(bpGrouploc));
    }
    if(prodGrouploc)
    {
         qbr1 = qbds.findRange(fieldnum(ProductDisplayView, ProductGroup));
        if (!qbr1)
        {
            qbr1 = qbds.addRange(fieldnum(ProductDisplayView, ProductGroup));
        }
        if(!qbr1.value())
            qbr1.value(queryValue(prodGrouplocvalue));
    }
    if(ProductCategoryloc)
    {
         qbr2 = qbds.findRange(fieldnum(ProductDisplayView, ProductCategory));
        if (!qbr2)
        {
            qbr2 = qbds.addRange(fieldnum(ProductDisplayView, ProductCategory));
        }
        if(!qbr2.value())
            qbr2.value(queryValue(ProductCategorylocvalue));
    }
    if(Itemidloc)
    {
         qbr3 = qbds.findRange(fieldnum(ProductDisplayView, ItemId));
        if (!qbr3)
        {
            qbr3 = qbds.addRange(fieldnum(ProductDisplayView, ItemId));
        }
        if(!qbr3.value())
            qbr3.value(queryValue(Itemidloc));
    }
    qr = new QueryRun(query);
    while(qr.next())
    {
        _ProductDisplayView  = qr.get(tableNum(ProductDisplayView));
        select inventtable where inventtable.itemid  == _ProductDisplayView.ItemId;
        StockonHandTMP.BPGroup             = inventtable.BPGroupName();
        StockonHandTMP.ProdGroup           = inventtable.productGroupName();
        StockonHandTMP.ProdCategory        = inventtable.productCategoryName();
        StockonHandTMP.ItemCode            = _ProductDisplayView.ItemId;
        StockonHandTMP.ItemName            = _ProductDisplayView.Name;
        select InventTableModule where InventTableModule.ItemId == _ProductDisplayView.ItemId;
        StockonHandTMP.UOM = InventTableModule.UnitId;
        while select inventlocation where inventlocation.InventSiteId     == SysUserInfo::find(curUserId()).InventSiteId
                            && (((InventLocationIdloc)   &&(inventlocation.InventLocationId  == InventLocationIdloc))||(!InventLocationIdloc))
        if(inventlocation.RecId)
        {
            StockonHandTMP.InventLocationId    = inventlocation.InventLocationId;
            StockonHandTMP.InventLocationName  = inventlocation.Name;
            StockonHandTMP.InventSiteId        = InventLocation::find(StockonHandTMP.InventLocationId).InventSiteId;
            StockonHandTMP.InventSiteName      = InventSite::find(InventLocation::find(StockonHandTMP.InventLocationId).InventSiteId).Name;
            select InventDim where InventDim.InventLocationId == inventlocation.InventLocationId;
            _inventDimParm.initFromInventDim(InventDim);
            _inventonhand = InventOnhand::newParameters(_ProductDisplayView.ItemId ,InventDim,_inventDimParm);
            _inventQty =_inventonhand.availPhysical();
            StockonHandTMP.AvailPhysical       = _inventQty;//InventSum::find(_ProductDisplayView.ItemId,InventDim.inventDimId).AvailPhysical;
            if(StockonHandTMP.AvailPhysical)
            {
                StockonHandTMP.insert();
            }
        }
    }
}
------------------UI Builder:
class StockonHandUIBuilder extends SrsReportDataContractUIBuilder
{
    DialogField               dialogBPGroup,dialogProductGroup,dialogProductCategory,dialogItemid,dialogLocation;
    StockonHandContract   Contract;
}
public void build()
{
    contract               = this.dataContractObject();
    dialogBPGroup          = this.addDialogField(methodStr(StockonHandContract, parmBPGroup),contract);
    dialogProductGroup     = this.addDialogField(methodStr(StockonHandContract, parmProdGroup),contract);
    dialogProductCategory  = this.addDialogField(methodStr(StockonHandContract, parmProductCategory),contract);
    dialogItemid           = this.addDialogField(methodStr(StockonHandContract, parmItemid),contract);
    dialogLocation         = this.addDialogField(methodStr(StockonHandContract, parmWarehouse),contract);
}
public void getFromDialog()
{
    contract = this.dataContractObject();
    super();
}
public void initializeFields()
{
    contract = this.dataContractObject();
}
public void lookupBPGroup(FormStringControl _control)
{
    Query           query = new Query();
    SysTableLookup  sysTableLookup;
    QueryBuildDataSource qbds;
    QueryBuildDataSource qbdsSet;
    // Create an instance of SysTableLookup using the specified control.
    sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    // Add Name field to be shown in the lookup form.
    sysTableLookup.addLookupfield(fieldNum(EcoResCategory, Name));
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(2));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupItemid(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode,ProdcategoryNode,ecoresCategory;
    EcoResCategoryHierarchyId   defaultCategory;
    name                       _productvalue,productcat;
    recid                       ecoresCategoryrecid;
    ;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode     = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);
    if(dialogProductGroup.value())
    {
         while select  ProdGroupNode where ProdGroupNode.ParentCategory == bpGroupNode.RecId
        {
            if(dialogProductGroup.value() == ProdGroupNode.prodGroupDisplayName())
            {
               _Productvalue        = ProdGroupNode.Name;
                ecoresCategoryrecid = ProdGroupNode.RecId;
            }
        }
    }
    if(dialogProductCategory.value())
    {
         while select  ProdcategoryNode where ProdcategoryNode.ParentCategory == ecoresCategoryrecid
        {
            if(dialogProductCategory.value() == ProdcategoryNode.prodCategorydisplayName())
            {
               productcat = ProdcategoryNode.Name;
            }
        }
    }
    sysTableLookup  = SysTableLookup::newParameters(tableNum(ProductDisplayView), _control);
    sysTableLookup.addLookupfield(fieldNum(ProductDisplayView,ItemId));
    sysTableLookup.addLookupfield(fieldNum(ProductDisplayView,name));
  //  sysTableLookup.addLookupMethod(tableMethodStr(ProductDisplayView, itemName), true);
    qbds = query.addDataSource(tableNum(ProductDisplayView));
    if(dialogBPGroup.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, BPGroup)).value(queryValue(bpGroupNode.Name));
    }
    if(dialogProductGroup.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, ProductGroup)).value(queryValue(_Productvalue));
    }
    if(dialogProductCategory.value())
    {
        qbds.addRange(fieldNum(ProductDisplayView, ProductCategory)).value(queryValue(productcat));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupLocation(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    ;
    sysTableLookup  = SysTableLookup::newParameters(tableNum(InventLocation), _control);
    sysTableLookup.addLookupfield(fieldNum(InventLocation,InventLocationId));
    sysTableLookup.addLookupfield(fieldNum(InventLocation,Name));
    qbds = query.addDataSource(tableNum(InventLocation));
    qbds.addRange(fieldNum(InventLocation, InventSiteId)).value(queryValue(SysUserInfo::find(curUserId()).InventSiteId));
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupProdGroup(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);
    // Create an instance of SysTableLookup using the specified control.
    sysTableLookup = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    // Add Name field to be shown in the lookup form.
    sysTableLookup.addLookupMethod(tableMethodStr(EcoResCategory, prodGroupDisplayName), true);
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(3));
    if(dialogBPGroup.value())
    {
        qbds.addRange(fieldNum(EcoResCategory, ParentCategory)).value(queryValue(bpGroupNode.RecId));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
public void lookupProductCategory(FormStringControl _control)
{
    Query                       query = new Query();
    SysTableLookup              sysTableLookup;
    QueryBuildDataSource        qbds;
    QueryBuildDataSource        qbdsSet;
    EcoResCategory              bpGroupNode,ProdGroupNode;
    EcoResCategoryHierarchyId   defaultCategory;
    RecId                       _Productvalue;
    ;
    defaultCategory = FTPParameters::find().DefaultCategory;
    bpGroupNode = EcoResCategory::findByName(dialogBPGroup.value(), defaultCategory);

    while select  ProdGroupNode where ProdGroupNode.ParentCategory == bpGroupNode.RecId
    {
        if(dialogProductGroup.value() == ProdGroupNode.prodGroupDisplayName())
        {
           _Productvalue = ProdGroupNode.RecId;
        }
    }
    sysTableLookup  = SysTableLookup::newParameters(tableNum(EcoResCategory), _control);
    sysTableLookup.addLookupMethod(tableMethodStr(EcoResCategory, prodCategorydisplayName), true);
    qbds = query.addDataSource(tableNum(EcoResCategory));
    qbds.addRange(fieldNum(EcoResCategory, Level)).value(queryValue(4));
    if(dialogProductGroup.value())
    {
        qbds.addRange(fieldNum(EcoResCategory, ParentCategory)).value(queryValue(_Productvalue));
    }
    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
}
/// <summary>
/// Overrides the default values in order to handle events on dialogs.
/// </summary>
public void postRun()
{
    super();
    dialogBPGroup.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupBPGroup),this);
    dialogProductGroup.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupProdGroup),this);
    dialogProductCategory.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupProductCategory),this);
    dialogItemid.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupItemid),this);
    dialogLocation.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(StockonHandUIBuilder, lookupLocation),this);
    //dialogShowCritical.value(NoYes::Yes);
}

No comments:

Post a Comment