Customization on Po Report part 1

 Today we have a requirement to customize the Po report .

1) Create a extension of the controller class.

2) Create a Dp class extension .


1) Create a extension of the controller class.


class AVAPurchPurchaseOrderControllerExt extends PurchPurchaseOrderController

{

    public static void main(Args _args)

    {

        SrsReportRunController              formLetterController = AVAPurchPurchaseOrderControllerExt::construct();

        AVAPurchPurchaseOrderControllerExt  controller = formLetterController;

       

        controller.parmReportName(ssrsReportStr(AVAPurchPurchaseOrder, Report));

        controller.parmArgs(_args);

        controller.parmShowDialog(false);

        controller.startOperation();

    }


    public static AVAPurchPurchaseOrderControllerExt construct()

    {

        return new AVAPurchPurchaseOrderControllerExt();

    }


    public static SrsReportDataContract newDataContract(Args _args)

    {

        AVAPurchPurchaseOrderControllerExt formLetterController = AVAPurchPurchaseOrderControllerExt::construct();


        if (_args.dataset() != tableNum(VendPurchOrderJour))

        {

            throw error(strFmt("@SYS19306",funcName()));

        }

        

        formLetterController.initDataContract(_args, PrintMgmtDocType::construct(PrintMgmtDocumentType::PurchaseOrderConfirmationRequest).getDefaultReportFormat());

      

        return formLetterController.parmReportContract();

    }


    /// <summary>

    /// 34124  - add the PO number in the email subject

    /// </summary>

    public void runReport()

    {

        PurchaseOrderId purchId = vendPurchOrderJour::findByPurchId(vendPurchOrderJour.PurchId).PurchOrderDocNum;

        

        if (reportContract.parmPrintSettings().printMediumType() == SRSPrintMediumType::Email)

        {

            reportContract.parmPrintSettings().emailSubject(Global::strReplace(reportContract.parmPrintSettings().emailSubject(),"@PurchId@",purchId));

        }

        super();

    }


}

================================================================


2) Create a Dp class extension :- 


[ExtensionOf(classStr(PurchPurchaseOrderDP))]

final class AVAPurchPurchaseOrderDp_Extension

{

    protected PurchPurchaseOrderHeader initializePurchaseInquiryHeader(PurchConfirmationRequestJour _purchConfirmationRequestJour)

    {

        PurchPurchaseOrderHeader purchPurchaseOrderHeader = next initializePurchaseInquiryHeader(_purchConfirmationRequestJour);

        LogisticsElectronicAddress  logisticsElectronicAddress;

        HcmWorker                   hcmWorker;

        DirPerson                   dirPerson;

        DirPartyTable               dirPartyTable;

        DocuRef                     docuRefLocal;

        DirPartyLocation            dirPartyLocation;

        LogisticsLocation           location;

        LogisticsAddressing         billToaddress;

        PurchTable                  purchTable           = _purchConfirmationRequestJour.purchTable();

        DocuOnFormularTypeId        docuTypePurch;// added for 33817

              

        purchPurchaseOrderHeader.Payment                 = purchTable.Payment;

        purchPurchaseOrderHeader.AVADlvMode              = purchTable.DlvMode;

        purchPurchaseOrderHeader.AVAVendAccount          =_purchConfirmationRequestJour.OrderAccount;

        purchPurchaseOrderHeader.SalesOrderBalance       =_purchConfirmationRequestJour.OrderBalance;

        purchPurchaseOrderHeader.Amount                  =_purchConfirmationRequestJour.Amount;

        purchPurchaseOrderHeader.AVACharges              =_purchConfirmationRequestJour.Amount - _purchConfirmationRequestJour.OrderBalance;

        purchPurchaseOrderHeader.AVAReturnItemNum        = purchTable.ReturnItemNum;

        if(purchTable.BillToAddress)

        {

            location = LogisticsLocation::find(purchTable.BillToAddress);

        }

        else

        {

            location = LogisticsLocation::find(DirPartyLocation::findPrimaryPartyLocation(CompanyInfo::current()).Location);

        }

        billToaddress = LogisticsPostalAddress::findByLocation(location.RecId).Address;

        purchPurchaseOrderHeader.AVABillToAddress        = billToaddress;

        purchPurchaseOrderHeader.AVABillToAddressName    = location.Description;

        purchPurchaseOrderHeader.AVABuyerName            = HcmWorker::find(purchTable.WorkerPurchPlacer).name();

        purchPurchaseOrderHeader.AVABuyerEmail           = xUserInfo::find(false,HcmWorker::findPersonUser(purchTable.WorkerPurchPlacer,false).User).networkAlias;

      /*  select RecId from hcmWorker

            where hcmWorker.RecId == purchTable.WorkerPurchPlacer

        join dirPerson

            where dirPerson.RecId == hcmWorker.Person

        join dirPartyTable

            where dirPartyTable.RecId == dirPerson.RecId

        join dirPartyLocation

            where dirPartyLocation.Party == dirPartyTable.RecId

        join Locator from logisticsElectronicAddress

            where logisticsElectronicAddress.Location == dirPartyLocation.Location

               && logisticsElectronicAddress.Type     == LogisticsElectronicAddressMethodType::Email;

        purchPurchaseOrderHeader.AVABuyerEmail         =  logisticsElectronicAddress.Locator;*/


        purchPurchaseOrderHeader.AVARequestorName      = HcmWorker::find(purchTable.Requester).name();

        purchPurchaseOrderHeader.AVARequestorEmail     = xUserInfo::find(false,HcmWorker::findPersonUser(purchTable.Requester,false).User).networkAlias;

        purchPurchaseOrderHeader.AVAEmail              = purchTable.Email; // added for 33817

       /* select RecId from hcmWorker

            where hcmWorker.RecId == purchTable.Requester

        join dirPerson

            where dirPerson.RecId == hcmWorker.Person

        join dirPartyTable

            where dirPartyTable.RecId == dirPerson.RecId

        join dirPartyLocation

            where dirPartyLocation.Party == dirPartyTable.RecId

        join Locator from logisticsElectronicAddress

            where logisticsElectronicAddress.Location == dirPartyLocation.Location

               && logisticsElectronicAddress.Type     == LogisticsElectronicAddressMethodType::Email;

        purchPurchaseOrderHeader.AVARequestorEmail    =  logisticsElectronicAddress.Locator;*/


        select firstonly Notes from docuRefLocal

            where docuRefLocal.RefTableId == purchTable.TableId

               && docuRefLocal.RefRecId   == purchTable.RecId

               && docuRefLocal.TypeId     == 'Note'

               && docuRefLocal.Restriction == DocuRestriction::External; //DevOps#34172 : Only external notes should go to Vendor

        purchPurchaseOrderHeader.AVANotes = docuRefLocal.Notes;


        // added for 33817 - start {

        docuTypePurch = VendFormletterDocument::find().DocuTypePurchOrder;


        if(docuTypePurch)

        {

            select firstonly Notes from docuRefLocal

                where docuRefLocal.RefTableId == purchTable.TableId

                   && docuRefLocal.RefRecId   == purchTable.RecId

                   && docuRefLocal.TypeId     == docuTypePurch;

            if(docuRefLocal)

            {

                purchPurchaseOrderHeader.AVAAdvanceNotes = docuRefLocal.Notes;

            }

        }

        if( !purchPurchaseOrderHeader.AVAAdvanceNotes)

        {

            purchPurchaseOrderHeader.AVAAdvanceNotes =  purchPurchaseOrderHeader.AVANotes;

            purchPurchaseOrderHeader.AVANotes        = "";

        }

        // } end - added for 33817

        

        

        return purchPurchaseOrderHeader;

    }


    /// <summary>

    /// Initializes the purchase order header.

    /// </summary>

    /// <param name = "_vendPurchOrderJour">

    /// A <c>VendPurchOrderJour</c> purchase order journal header which the order header is initialized from.

    /// </param>

    /// <returns>

    /// The initialized <c>PurchPurchaseOrderHeader</c> record.

    /// </returns>

    protected PurchPurchaseOrderHeader initializePurchaseOrderHeader(VendPurchOrderJour _vendPurchOrderJour)

    {

        PurchPurchaseOrderHeader purchPurchaseOrderHeader = next initializePurchaseOrderHeader(_vendPurchOrderJour);

        LogisticsElectronicAddress  logisticsElectronicAddress;

        HcmWorker                   hcmWorker;

        DirPerson                   dirPerson;

        DirPartyTable               dirPartyTable;

        DocuRef                     docuRefLocal;

        DirPartyLocation            dirPartyLocation;

        LogisticsLocation           location;

        LogisticsAddressing         billToaddress;

        PurchTable                  purchTable           = _vendPurchOrderJour.purchTable();

        DocuOnFormularTypeId        docuTypePurch;// added for 33817

              

        purchPurchaseOrderHeader.Payment                 = purchTable.Payment;

        purchPurchaseOrderHeader.AVADlvMode              = purchTable.DlvMode;

        purchPurchaseOrderHeader.AVAVendAccount          =_vendPurchOrderJour.OrderAccount;

        purchPurchaseOrderHeader.SalesOrderBalance       =_vendPurchOrderJour.SalesOrderbalance;

        purchPurchaseOrderHeader.Amount                  =_vendPurchOrderJour.Amount;

        purchPurchaseOrderHeader.AVACharges              =_vendPurchOrderJour.Amount - _vendPurchOrderJour.SalesOrderbalance;

        purchPurchaseOrderHeader.AVAReturnItemNum        = purchTable.ReturnItemNum;

        if(purchTable.BillToAddress)

        {

            location = LogisticsLocation::find(purchTable.BillToAddress);

        }

        else

        {

            location = LogisticsLocation::find(DirPartyLocation::findPrimaryPartyLocation(CompanyInfo::current()).Location);

        }

        billToaddress = LogisticsPostalAddress::findByLocation(location.RecId).Address;

        purchPurchaseOrderHeader.AVABillToAddress        = billToaddress;

        purchPurchaseOrderHeader.AVABillToAddressName    = location.Description;

        purchPurchaseOrderHeader.AVABuyerName            = HcmWorker::find(purchTable.WorkerPurchPlacer).name();

        purchPurchaseOrderHeader.AVABuyerEmail           = xUserInfo::find(false,HcmWorker::findPersonUser(purchTable.WorkerPurchPlacer,false).User).networkAlias;

        purchPurchaseOrderHeader.AVARequestorName        = HcmWorker::find(purchTable.Requester).name();

        purchPurchaseOrderHeader.AVARequestorEmail       = xUserInfo::find(false,HcmWorker::findPersonUser(purchTable.Requester,false).User).networkAlias;

        purchPurchaseOrderHeader.AVAEmail                = purchTable.Email; // added for 33817

       

         select firstonly Notes from docuRefLocal

            where docuRefLocal.RefTableId == purchTable.TableId

               && docuRefLocal.RefRecId   == purchTable.RecId

               && docuRefLocal.TypeId     == 'Note'

               && docuRefLocal.Restriction == DocuRestriction::External; //DevOps#34172 : Only external notes should go to Vendor

        purchPurchaseOrderHeader.AVANotes = docuRefLocal.Notes;


        // added for 33817 - start {

        docuTypePurch = VendFormletterDocument::find().DocuTypePurchOrder;


        if(docuTypePurch)

        {

            select firstonly Notes from docuRefLocal

                where docuRefLocal.RefTableId == purchTable.TableId

                   && docuRefLocal.RefRecId   == purchTable.RecId

                   && docuRefLocal.TypeId     == docuTypePurch;

            if(docuRefLocal)

            {

                purchPurchaseOrderHeader.AVAAdvanceNotes = docuRefLocal.Notes;

            }

        }

        if( !purchPurchaseOrderHeader.AVAAdvanceNotes)

        {

            purchPurchaseOrderHeader.AVAAdvanceNotes =  purchPurchaseOrderHeader.AVANotes;

            purchPurchaseOrderHeader.AVANotes        = "";

        }

        // } end - added for 33817


        return purchPurchaseOrderHeader;


    }


    /// <summary>

    /// Initializes an order line.

    /// </summary>

    /// <param name = "_purchaseOrderHeader">

    /// A <c>PurchPurchaseOrderHeader</c> record which is the order header.

    /// </param>

    /// <param name = "_highlightUpdated">

    /// A Boolean describing whether an updated order line must be highlighted.

    /// </param>

    /// <param name = "_orderLineSelection">

    /// A <c>PurchPurchaseOrderDPOrderLineQuerySelection</c> object which the order line should be created for.

    /// </param>

    /// <returns>

    /// The initialized <c>PurchPurchaseOrderTmp</c> order line record.

    /// </returns>

    protected PurchPurchaseOrderTmp initializeOrderLine(

        PurchPurchaseOrderHeader                    _purchaseOrderHeader,

        boolean                                     _highlightUpdated,

        PurchPurchaseOrderDPOrderLineQuerySelection _orderLineSelection)

    {

        PurchPurchaseOrderTmp purchPurchaseOrderTmp = next initializeOrderLine(_purchaseOrderHeader,_highlightUpdated,_orderLineSelection);


        PurchLine             purchLine             = PurchLine::find(_orderLineSelection.parmPurchLineAllVersions().PurchId,_orderLineSelection.parmPurchLineAllVersions().LineNumber);

        InventDim             inventDim             = InventDim::find(_orderLineSelection.parmPurchLineAllVersions().InventDimId);

        purchPurchaseOrderTmp.AVARevLevel           = inventDim.InventDimension1;

        PurchPurchaseOrderTmp.ExternalItemNum       = purchLine.ExternalItemId;

        purchPurchaseOrderTmp.AVAVendDeliveryDate   = _orderLineSelection.parmPurchLineAllVersions().ConfirmedDlv;// added for 33817

        return purchPurchaseOrderTmp;

    }


}

========================================================================

Comments

Popular posts from this blog

Customization on Sales invoice Report in D365 F&O

75) COC - Create a coc of the table modified method

46) D365 FO: SHAREPOINT FILE UPLOAD USING X++