Payment advice report through print management to vendor

Here we will be adding payment advice report to print management of AX 2012 and will make modification to controller class so it will be printed per vendor and can be sent to vendors email address.

\Data Dictionary\Base Enums\PrintMgmtDocumentType
add new value VKBankPaymAdvice

\Data Dictionary\Base Enums\PrintMgmtNodeType
add new value VKBankPaymAdvice

\Data Dictionary\Tables\BankPaymAdviceVendTmp
Add new field VKVendAccount. New relation to VendTable.AccountNum can also be added.

\Data Dictionary\Tables\PrintMgmtReportFormat\Methods\populate
Add one line after the standard one:
...
addAX(PrintMgmtDocumentType::PurchaseOrderConfirmationRequest);
addAX(PrintMgmtDocumentType::VKBankPaymAdvice); // Solution MOD
...

\Data Dictionary\Maps\CustVendAccountMap
add new mapping to BankPaymAdviceVendTmp table:

\Classes\VKBankPaymAdviceVendController
This is a copy of \Classes\BankPaymAdviceVendController , you will need to duplicate it and apply following changes:

\Classes\VKBankPaymAdviceVendController\ClassDeclaration
Different class to extend and following variable no longer required
// basically a modified copy of BankPaymAdviceVendController extending SrsPrintMgmtController
class VKBankPaymAdviceVendController extends SrsPrintMgmtController
...
    SRSPrintDestinationSettings printDestinationSetting;
    container                   printerSetting;
...

\Classes\VKBankPaymAdviceVendController\initPrintMgmtReportRun
New method
protected void initPrintMgmtReportRun()
{
    UsePrintMgmt            paymAdvUsePrintMgmt;

    paymAdvUsePrintMgmt = this.parmArgs().parmEnum();
    printMgmtReportRun=PrintMgmtReportRun::construct(
        PrintMgmtHierarchyType::Purch,
        PrintMgmtNodeType::VKBankPaymAdvice,
        PrintMgmtDocumentType::VKBankPaymAdvice
    );
    printMgmtReportRun.parmForcePrintJobSettings(!paymAdvUsePrintMgmt);
    printMgmtReportRun.parmReportRunController(this);
}

\Classes\VKBankPaymAdviceVendController\insertBankPaymAdviceVendTmp
Additional line
...
    bankPaymAdviceVendTmp.PaymAdviceDate    = systemDateGet();
    bankPaymAdviceVendTmp.PaymentReference  = paymref;
    BankPaymAdviceVendTmp.VKVendAccount    = VendTable.AccountNum; // Solution MOD
...

\Classes\VKBankPaymAdviceVendController\preRunModifyContract
Almost entirely changed
protected void preRunModifyContract()
{
    Query reportQuery;

    reportQuery = this.parmReportContract().parmQueryContracts().lookup(this.getFirstQueryContractKey());

    SrsReportHelper::addParameterValueRangeToQuery(
        reportQuery,
        tableNum(BankPaymAdviceVendTmp),
        fieldNum(BankPaymAdviceVendTmp,SessionId),
        this.currentSessionId()
     );
}

\Classes\VKBankPaymAdviceVendController\processReport
Several changes
    // Solution MOD BEGIN
    // variable declaration section
    Map vendorMap = new Map(Types::Int64, Types::Int64);
    MapEnumerator me;
    // Solution MOD END
...
    currentSessionId = new xSession().sessionId();
    // Solution MOD BEGIN
    /* 
    The right way would be to introduce completely new SessionId field based on guid for example and generate new guid for each vendor.
    But it will require update of report metadata. It is not possible to merge ssrs report changes and it will be a pain for future.
    Therefore existing integer field will be used to devide reports.
    */
    currentSessionId = currentSessionId*100000;
    // Solution MOD END

...

    li = paramOutPaymlist.getEnumerator();
    while (li.moveNext())
    {
...
        vendTable = VendTable::findByCompany(vendOutPaymRecord.parmCustVendPaym().ledgerJournalTrans().Company,
                                            vendOutPaymRecord.parmCustVendPaym().ledgerJournalTrans().parmAccount());
        // Solution MOD BEGIN
        // We need to make sure that SessionId is unique for each vendor and will delete previous records.
        // The delete statement above does not suit, in wrong possition, but still required to delete old data.
        if (vendorMap.exists(vendTable.RecId))
        {
            currentSessionId = vendorMap.lookup(vendTable.RecId);
        }
        else
        {
            currentSessionId++;
            delete_from bankPaymAdviceVendTmp where bankPaymAdviceVendTmp.SessionId == currentSessionId;
            vendorMap.insert(vendTable.RecId, currentSessionId);
        }
        // Solution MOD END

        this.setPaymReferenceStr();

...
    }
    // Solution MOD BEGIN
    // At the end of the method
    if (vendorMap.elements())
    {
        // print data per vendor
        me = vendorMap.getEnumerator();
        while (me.moveNext())
        {
            currentSessionId = me.currentValue();
            select firstOnly BankPaymAdviceVendTmp
                where BankPaymAdviceVendTmp.SessionId == currentSessionId;
            
            if (BankPaymAdviceVendTmp)
            {
                this.initPrintMgmtReportRun();
                printMgmtReportRun.load(BankPaymAdviceVendTmp, BankPaymAdviceVendTmp, CompanyInfo::languageId());
                this.outputReports();
            }            
        }
    }
   // Solution MOD END
 }

\Classes\VKBankPaymAdviceVendController\runPrintMgmt
New method
protected void runPrintMgmt()
{
    vendOutPaym = this.parmArgs().caller();
    vendOutPaymList = this.parmArgs().parmObject();
    this.processReport(vendOutPaymList);
}

\Classes\VKBankPaymAdviceVendController\main
public static void main(Args _args)
{
    SrsPrintMgmtController controller = new VKBankPaymAdviceVendController();
    controller.parmReportName(#ReportName);
    controller.parmArgs(_args);
    controller.parmShowDialog(false);
    controller.startOperation();
}

There are changes to classes to support new print management type:

\Classes\PrintMgmtDocType\getDefaultReportFormat
...
        case PrintMgmtDocumentType::PurchRFQReturn:
            return ssrsReportStr(RFQSend, Report);

        // Solution MOD BEGIN
        case PrintMgmtDocumentType::VKBankPaymAdvice:
            return ssrsReportStr(BankPaymAdviceVend, Report);
        // Solution MOD END

        case PrintMgmtDocumentType::SalesOrderInvoice:
...

\Classes\PrintMgmtDocType\getPartyType
...
    case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest:
    case PrintMgmtDocumentType::VKBankPaymAdvice: // Solution MOD
        return PrintMgmtPrintDestinationPartyType::Vendor;
...

\Classes\PrintMgmtDocType\getQueryTableId
...
            tableId = tableNum(VendRFQJour);
            break;

        // Solution MOD BEGIN
        case PrintMgmtDocumentType::VKBankPaymAdvice:
            tableId = tableNum(BankPaymAdviceVendTmp);
            break;
        // Solution MOD END

        case PrintMgmtDocumentType::SalesOrderInvoice,
...

\Classes\PrintMgmtNode_VendTable\getDocumentTypes
...
        docTypes.addEnd(PrintMgmtDocumentType::PurchRFQReject);
        docTypes.addEnd(PrintMgmtDocumentType::PurchRFQReturn);
        docTypes.addEnd(PrintMgmtDocumentType::VKBankPaymAdvice); // Solution MOD
    }
...

\Classes\PrintMgmtNode_Purch\getDocumentTypes
...
        docTypes.addEnd(PrintMgmtDocumentType::PurchRFQReject);
        docTypes.addEnd(PrintMgmtDocumentType::PurchRFQReturn);
        docTypes.addEnd(PrintMgmtDocumentType::VKBankPaymAdvice); // Solution MOD
    }
...

\Classes\PrintMgmtHierarchy_Purch\getNodesImplementation
...
    supportedNodes.addEnd(PrintMgmtNodeType::PurchAgreement);
    supportedNodes.addEnd(PrintMgmtNodeType::VKBankPaymAdvice); // Solution MOD
...

\Classes\PrintMgmtHierarchy_Purch\getParentImplementation
...
    PurchAgreementHeader purchAgreementHeader;
    BankPaymAdviceVendTmp bankPaymAdviceVendTmp; // Solution MOD
    // <GEEU>
...
        case PrintMgmtNodeType::Purch:
            // When no parent is present, return null
            result = null;
            break;

        // Solution MOD BEGIN
        case PrintMgmtNodeType::VKBankPaymAdvice:
            BankPaymAdviceVendTmp = _nodeInstance.parmReferencedTableBuffer();
            if (BankPaymAdviceVendTmp.VKVendAccount)
            {
                result.parmReferencedTableBuffer(BankPaymAdviceVendTmp.selectRefRecord(fieldnum(BankPaymAdviceVendTmp, VKVendAccount)));
            }
            else
            {
                result.parmReferencedTableBuffer(null);
            }
            result.parmNodeDefinition(PrintMgmtNode::construct(PrintMgmtNodeType::VendTable));
            break;
        // Solution MOD END
    }

    return result;
}

\Classes\PrintMgmtNode\construct
...
        case PrintMgmtNodeType::TMS:
            return new TMSPrintMgmtNode_TMS();

        // Solution MOD BEGIN
        case PrintMgmtNodeType::VKBankPaymAdvice:
            return new PrintMgmtNode_VKBankPaymAdvice();
        // Solution MOD END
    }

\Classes\PrintMgmtNode_VKBankPaymAdvice
class PrintMgmtNode_VKBankPaymAdvice extends PrintMgmtNode
{
}
protected str getDisplayCaptionImplementation(Common _tableBuffer)
{
    return(strfmt("@SYS108944", _tableBuffer.caption()));
}
public List getDocumentTypes()
{
    List docTypes;

    docTypes = new List(Types::Enum);
    if (isConfigurationkeyEnabled(configurationkeynum(LogisticsBasic)))
    {
        docTypes.addEnd(PrintMgmtDocumentType::VKBankPaymAdvice);
    }
    return docTypes;
}
public int getIconImageResNum()
{
    #resAppl

    return #ImagePrintManagementTrans;
}
public PrintMgmtNodeType getNodeType()
{
    return PrintMgmtNodeType::VKBankPaymAdvice;
}
public RefTableId getReferencedTableId()
{
    return tablenum(BankPaymAdviceVendTmp);
}

Dialog modification to include option to use print management.
Depending on the localization you are using the class name may be different:

\Classes\VendOutPaym_UKBACS\classDeclaration
...
    // Solution MOD BEGIN
    DialogField     paymAdviceUsePrintMgmt;
    UsePrintMgmt    paymAdvUsePrintMgmt;
    // Solution MOD END

    #DEFINE.CurrentVersion(1)
    #LOCALMACRO.CurrentList
    numRecords,
    numAmount,
    currencyList,
    amountList
    ,paymAdvUsePrintMgmt // Solution MOD
    #ENDMACRO

\Classes\VendOutPaym_UKBACS\dialog
...
    paymAdviceUsePrintMgmt = dialog.addfieldvalue(enumStr(NoYes), NoYes::Yes, "@SYS93922"); // Solution MOD

    return dialog;
}

\Classes\VendOutPaym_UKBACS\getFromDialog
public boolean getFromDialog()
{
    ;

    paymAdvUsePrintMgmt = paymAdviceUsePrintMgmt.value(); // Solution MOD

    return super();
}

\Classes\VendOutPaym_UKBACS\printPaymAdvice
public void printPaymAdvice()
{
    Args                args = new Args();

    args.caller(this);
    args.parmObject(this.getOutPaymRecords());

    // Solution MOD BEGIN
    args.parmEnumType(enumNum(NoYes));
    args.parmEnum(paymAdvUsePrintMgmt);


    if (paymAdvUsePrintMgmt)
    {
        new MenuFunction(menuitemOutputStr(VKBankPaymAdviceVend), MenuItemType::Output).run(args);
    }
    else
    {
        new MenuFunction(menuitemOutputStr(BankPaymAdviceVend), MenuItemType::Output).run(args);
    }
    // Solution MOD END
}

You will need to duplicate \Menu Items\Output\BankPaymAdviceVend menu item and point to new controller that you have created using BankPaymAdviceVendController class as a basis.

Purchase ledger / Setup / Forms / Form setup / General / Print management:

For additional information refer to Print Management Integration Guide.

 

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