Customize Vendor Aging Report in D365FO (VendAgingReport extension)


03/11/2020- duocnt    2287 Views    

GIỚI THIỆU.

 - Vendor Aging Report (VendAgingReport) là 1 báo cáo chuẩn của ERP D365FO thuộc model Application Suite.

 - Khi làm việc với ERP D365FO thì các bạn đều biết "Vendor Aging Report" mục đích để làm gì, vì vậy trong hướng dẫn này sẽ không đề cập đến ý nghĩa của report.

 - Bài viết này sẽ hướng dẫn cách customize Vendor Aging Report để thêm vào report một số field theo yêu cầu của user như: Posting Profile và một số field khác nếu cần thiết.

TRƯỚC VÀ SAU KHI CUSTOMIZE

- Nguyên bản.

- Customized.


CÁC BƯỚC THỰC HIỆN.

  1. Tạo extension cho table VendAgingReportTmp.
  2. Tạo class VendAgingReportDP_Events.
  3. Tạo class VendAgingReportControllerExt.
  4. Duplicate Report VendAgingReport vào Project.
  5. Tạo extension cho Output MenuItem VendAgingBalance.


THỰC HIỆN

1 - Tạo extension cho table VendAgingReportTmp.

 - Tìm table VendAgingReportTmp trong AOT và Create Extension vào project.

 - Add vào các fied cần thiết ví dụ như PostingProfile.

 - Trong hình đính kèm này mình đã add 1 số field khác do yêu cầu của user, những field này có thể là những field được customize nên sẽ không có trong ERP của bạn.


2 - Tạo class VendAgingReportDP_Events.

 - Add vào project 1 class với name là VendAgingReportDP_Events.


 - Tìm class 
VendAgingReportDP (model Application Suite) trong AOT => Right-click => Open designer.


 - Right-click lên method "processReport" => "Copy event handler method" => "Post-event handler"


 - Paste vào bên trong class 
VendAgingReportDP_Events đã tạo lúc nãy.


 - Viết code bên trong như sau:

class VendAgingReportDP_Events
{
    /// <summary>
    ///
    /// </summary>
    /// <param name="args"></param>
    [PostHandlerFor(classStr(VendAgingReportDP), methodStr(VendAgingReportDP, processReport))]
    public static void VendAgingReportDP_Post_processReport(XppPrePostArgs args)
    {
       
        VendAgingReportDP       _vendAgingReportDP;
        VendAgingReportTmp      _vendAgingReportTmp;
        VendInvoiceJour         _vendInvoiceJour;//Invoice Journal of Vendor
        LedgerJournalTrans      _ledgerJournalTrans; //GL => General journal
        VendInvoiceInfoTable    _vendInvoiceInfoTable;
 
        _vendAgingReportDP     =  args.getThis() as VendAgingReportDP;
        _vendAgingReportTmp    =  _vendAgingReportDP.getVendAgingReportTmp();
 
        update_recordset _vendAgingReportTmp
            setting InvoiceDate     =   _vendInvoiceJour.VASInvoiceDate,
                DueDate             =   _vendInvoiceJour.DueDate,
                VASInvoiceNum       =   _vendInvoiceJour.VASInvoiceNum,
                VASSerialNum        =   _vendInvoiceJour.InvoiceAmount * -1,
                PostingProfile      =   _vendInvoiceJour.PostingProfile,
                InvoiceReceiptDate  =   _vendInvoiceInfoTable.InvoiceReceiptDate
               
            join    _vendInvoiceJour
            where   _vendInvoiceJour.InvoiceId == _vendAgingReportTmp.InvoiceId
            && _vendInvoiceJour.LedgerVoucher   ==  _vendAgingReportTmp.Voucher
 
            join    _vendInvoiceInfoTable
            where   _vendInvoiceInfoTable.ParmId   ==  _vendInvoiceJour.ParmId  ;
 
        update_recordset _vendAgingReportTmp
            setting InvoiceDate =  _ledgerJournalTrans.TransDate,
            DueDate         =  _ledgerJournalTrans.TransDate,
            InvoiceAmount   =  _ledgerJournalTrans.AmountCurDebit - _ledgerJournalTrans.AmountCurCredit,
            PostingProfile  =  _ledgerJournalTrans.PostingProfile
            where   _vendAgingReportTmp.InvoiceId == ""
            join    _ledgerJournalTrans
            where   _ledgerJournalTrans.AccountType == LedgerJournalACType::Vend
            && _ledgerJournalTrans.Voucher  == _vendAgingReportTmp.Voucher;
    }
}


3 - Tạo class VendAgingReportControllerExt.

 - Add vào project 1 class với name VendAgingReportControllerExt.

 - extends class VendAgingReportControllerExt từ class VendAgingReportController.



 - Code cho class 
VendAgingReportControllerExt:

 

class VendAgingReportControllerExt extends VendAgingReportController
{
 
    public static VendAgingReportControllerExt construct()
    {
        return new VendAgingReportControllerExt();
    }
 
    protected final str getReportNameExt(VendAgingReportContract _contract)
    {
        str reportNameLocal;
 
        if (_contract.parmDetailed())
        {
            if (_contract.parmIncludeAmountCur())
            {
                reportNameLocal = ssrsReportStr (VendAgingReportExt,                                                 DesignWithDetailAndWithTransactionCurExt);
            }
            else
            {
                reportNameLocal = ssrsReportStr(VendAgingReportExt,                                                 DesignWithDetailAndNoTransactionCurExt);
            }
        }
        else
        {
            if (_contract.parmIncludeAmountCur())
            {
                reportNameLocal = ssrsReportStr(VendAgingReportExt,                                                 DesignWithNoDetailAndWithTransactionCurExt);
            }
            else
            {
                reportNameLocal = ssrsReportStr(VendAgingReportExt,                                                 DesignWithNoDetailAndNoTransactionCurExt);
            }
        }
 
        return reportNameLocal;
    }
 
    protected void preRunModifyContract()
    {               super();
        VendAgingReportContract contract = this.parmReportContract()                                                 .parmRdpContract() as VendAgingReportContract;
        this.parmReportContract().parmReportName(this.getReportNameExt(contract));
    }
 
    public static void main(Args _args)
    {
        VendAgingReportControllerExt _controller = VendAgingReportControllerExt::construct();
        _controller.parmReportName(ssrsReportStr(VendAgingReportExt,                                                  DesignWithNoDetailAndNoTransactionCurExt));
        _controller.parmArgs(_args);
        _controller.startOperation();
    }
}


4 - Duplicate Report VendAgingReport vào Project.

 - Tìm VendAgingReport chuẩn của D365FO (thuộc model Application Suite) trong AOT.

 - Right-click => "Duplicate in project".


 - Rename 
VendAgingReport  sau khi được duplicate thành "VendAgingReportExt".

- Mở VendAgingReportExt ở chế độ design. Expand node Designs của report sẽ thấy report có tất  cả 4 Design như hình.

 - Rename tất cả các design bằng cách thêm "Ext" vào các design.


- Tiến hành edit các design, trong hướng dẫn này chỉ edit 2 design:

    +    DesignWithDetailAndNoTransactionCurExt.

 
   +    DesignWithDetailAndWithTransactionCurExt.


5 - Tạo extension cho Output MenuItem VendAgingBalance.

 - Tìm Output MeunuItem VendAgingBalance trong AOT (thuộc model Application Suite).

 - Right-click => "Create extension".


 - Sau khi menuitem 
VendAgingBalance được extension vào project, chọn "VendAgingReportControllerExt" cho thuộc tính "Object" trong properties.

 - Build project, Deploy Report và chạy Vendor Aging Report để thấy kết quả.

Góp ý kiến

;
;