Simple SSRS RPD based report, AX classes

Data provider:
[
    SRSReportParameterAttribute(classStr(ReturnFormContract))
]
class ReturnFormDP extends SrsReportDataProviderPreProcess
{
    ReturnFormHeaderTmp   returnFormHeaderTmp;
    ReturnFormDetailsTmp  returnFormDetailsTmp;
    SalesTable              salesTable;
}
[
    SRSReportDataSetAttribute(tableStr(ReturnFormDetailsTmp))
]
public ReturnFormDetailsTmp getReturnFormDetailsTmp()
{
    select returnFormDetailsTmp;
    return returnFormDetailsTmp;
}
[
    SRSReportDataSetAttribute(tableStr(ReturnFormHeaderTmp))
]
public ReturnFormHeaderTmp getReturnFormHeaderTmp()
{
    select returnFormHeaderTmp;
    return returnFormHeaderTmp;
}
[SysEntryPointAttribute(true)]
public void processReport()
{
    SalesId                 salesId;
    ReturnFormContract    dataContract;

    dataContract    = this.parmDataContract();
    salesId         = dataContract.parmSalesId();
    salesTable      = SalesTable::find(salesId);

    this.setReturnFormHeaderTmp();
    this.setReturnFormDetailsTmp();
}
private void setReturnFormDetailsTmp()
{
    int         recCount        = 5,
                maxRecCount     = 25,
                a;
    SalesLine   salesLine;

    select count(RecId) from salesLine
        where salesLine.SalesId == salesTable.SalesId;

    if (recCount < salesLine.RecId)
    {
        recCount = int642int(salesLine.RecId);
    }
    if (recCount > maxRecCount)
    {
        recCount = maxRecCount;
    }

    for (a = 0; a < recCount; a++)
    {
        returnFormDetailsTmp.insert();
    }
}
private void setReturnFormHeaderTmp()
{
    InventParameters    inventParameters = InventParameters::find();
    Addressing          addressing;
    InventLocation      inventLocation;
    InventSite          inventSite;
    CompanyInfo         companyInfo = CompanyInfo::find();
    CustPackingSlipJour custPackingSlipJour;

    returnFormHeaderTmp.PrintLogo               = NoYes::Yes;
    returnFormHeaderTmp.CompanyName             = companyInfo.name();
    switch (inventParameters.ShipCarrierReturnTo)
    {
        case ShipCarrierReturnTo::Warehouse:
            inventLocation  = InventLocation::find(salesTable.InventLocationId);
            addressing      = inventLocation.logisticsPostalAddress().Address;
            break;
        case ShipCarrierReturnTo::Site:
            inventSite      = inventSite::find(salesTable.InventSiteId);
            addressing      = LogisticsLocationEntity::findPostalAddress(inventSite, LogisticsLocationRoleType::None).Address;
    }
    if (!addressing)
    {
        addressing                              = companyInfo.postalAddress().Address;
    }
    returnFormHeaderTmp.CompanyAddress          = addressing;
    returnFormHeaderTmp.CompanyPhone            = companyInfo.phone();
    returnFormHeaderTmp.CompanyTeleFax          = companyInfo.teleFax();
    returnFormHeaderTmp.CompanyCoRegNum         = companyInfo.CoRegNum;
    returnFormHeaderTmp.CompanyGiro             = companyInfo.Giro;
    returnFormHeaderTmp.CompanyEnterpriseNumber = companyInfo.EnterpriseNumber;
    returnFormHeaderTmp.CompanyLogo             = FormLetter::companyLogo();
    if (companyInfo.EnterpriseCode)
    {
        returnFormHeaderTmp.CompanyEnterpriseCode = companyInfo.EnterpriseCode;
    }

    addressing = '';
    select firstonly custPackingSlipJour
        order by RecId desc
        where custPackingSlipJour.SalesId == salesTable.SalesId;
    if (custPackingSlipJour)
    {
        addressing = custPackingSlipJour.deliveryAddress();
    }
    if (!addressing)
    {
        addressing = salesTable.deliveryAddressing();
    }
    returnFormHeaderTmp.CustomerName            = salesTable.customerName();
    returnFormHeaderTmp.CustomerAddress         = addressing;
    returnFormHeaderTmp.SalesId                 = salesTable.SalesId;

    returnFormHeaderTmp.insert();
}
Controller:
class ReturnFormController extends SrsReportRunController
{
}
/// <summary>
///    Modifies the report query and parameters based on caller settings.
/// </summary>
protected void prePromptModifyContract()
{
    Common                          common;
    CustPackingSlipJour             journal;
    ReturnFormContract            contract;
    SalesPackingSlipJournalPrint    salesPackingSlipJournalPrint;

    contract    = this.parmReportContract().parmRdpContract() as ReturnFormContract;

    this.parmDialogCaption("@SLN6542");

    if (classIdGet(this.parmArgs().caller()) == classNum(SalesPackingSlipJournalPrint))
    {
        salesPackingSlipJournalPrint = this.parmArgs().caller() as SalesPackingSlipJournalPrint;
        this.parmReportContract().parmPrintSettings(new SRSPrintDestinationSettings(salesPackingSlipJournalPrint.ParmPrinterSettingsReturnForm()));
    }

    if (this.parmArgs().record())
    {
        common = this.parmArgs().record();
    }
    if (common.TableId == tableNum(CustPackingSlipJour))
    {
        journal = common;
        contract.parmSalesId(journal.SalesId);
    }
    else
    {
        checkFailed(strFmt("@SYS26348"));
        return;
    }
}
/// <summary>
///    Hides the dialog box, depending on the caller.
/// </summary>
protected void presentDialog()
{
    Args    localArgs = this.parmArgs();
    boolean presentDialog = true;

    if (classIdGet(localArgs.caller()) == classNum(SalesPackingSlipJournalPrint))
    {
        presentDialog = false;
    }

    this.parmShowDialog(presentDialog);
}
public static void main(Args _args)
{
    ReturnFormController    controller = new ReturnFormController();

    controller.parmReportName(ssrsReportStr(ReturnForm, Report));
    controller.parmArgs(_args);
    controller.presentDialog();
    controller.startOperation();
}
Contract:
class ReturnFormContract
{
    SalesId salesId;
}
[DataMemberAttribute('SalesId')]
public SalesId parmSalesId(SalesId _salesId = salesId)
{
    salesId = _salesId;
    return salesId;
}
Output menu item:
ObjectType: Class
Object: ReturnFormController
LinkedPermissionType: SSRSReport
LinkedPermissionObject: ReturnForm
LinkedPermissionObjectChild: Report (design)

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics AX.

Authors are allowed to set their own AdSense units.
Join us.

Blog Tags