Thursday, 16 January 2020

SO Invoice / PO Conformation new design in D365 FO

Create a new report with proposed design (Report, designName)

//Print management SO&PO

class AC_PrintMgtDocTypeHandlersExt
{
    [SubscribesTo(classStr(PrintMgmtDocType), delegateStr(PrintMgmtDocType, getDefaultReportFormatDelegate))]
    public static void PrintMgmtDocType_getDefaultReportFormatDelegate(PrintMgmtDocumentType _docType, EventHandlerResult _result)
    {

        switch (_docType)
        {
            case PrintMgmtDocumentType::SalesOrderInvoice :
                _result.result(ssrsReportStr(AC_SalesInvoice, Report));
                break;

            case PrintMgmtDocumentType::PurchaseOrderConfirmationRequest :
                _result.result(ssrsReportStr(AC_PurchPurchaseOrder, Report));
                break;
        }
    }

}

//Controller CoC for SO

[ExtensionOf(classStr(SalesInvoiceController))]
final class AC_SalesInvoiceController_Extension
{
    protected void outputReport()
    {
        PrintMgmtPrintSettingDetail     printSettingDetail;
        FormLetterReport                formLetterReport;
        SRSCatalogItemName              reportDesign;

        formLetterReport = this.formLetterReport;
        printSettingDetail = formLetterReport.getCurrentPrintSetting();

        reportDesign = ssrsReportStr(AC_SalesInvoice, Report);

        this.parmReportName(reportDesign);
        this.parmReportContract().parmReportName(reportDesign);
        formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
        next outputReport();
    }

}

//Controller CoC for PO

[ExtensionOf(classStr(PurchPurchaseOrderController))]
final class AC_PurchPurchaseOrderController_Extension
{
    protected void outputReport()
    {
        PrintMgmtPrintSettingDetail     printSettingDetail;
        FormLetterReport                formLetterReport;
        SRSCatalogItemName              reportDesign;

        formLetterReport = this.formLetterReport;
        printSettingDetail = formLetterReport.getCurrentPrintSetting();

        reportDesign = ssrsReportStr(AC_PurchPurchaseOrder, Report);

        this.parmReportName(reportDesign);
        this.parmReportContract().parmReportName(reportDesign);
        formletterReport.parmReportRun().settingDetail().parmReportFormatName(reportDesign);
        next outputReport();
    }

}

//PO Header CoC

[ExtensionOf(tableStr(PurchPurchaseOrderHeader))]
final class AC_PurchPurchaseOrderHeader_Extension
{
    public void insert()
    {
        PurchTable                  purchTable;
        VendTable                   vendTable;
        PurchLine                   purchline;
        PurchRFQReplyLinePurchLine  purchRFQReplyLine;
        AmountMST                   totalValue;
        PurchLine                   purchLineLocal;
        LogisticsElectronicAddress  logisticsElectronicAddress;
        DirPartyTable               dirPartyTable;
        TaxJournalTrans             taxJournalTrans;
        VendPurchOrderJour          vendPurchOrderJour;

        purchTable = PurchTable::find(this.PurchId);
        vendTable = purchTable.vendTable_OrderAccount();

        select vendPurchOrderJour where vendPurchOrderJour.PurchOrderDocNum  ==  this.PurchOrderDocNum;

        select sum(TaxAmount) from taxJournalTrans
            where taxJournalTrans.TransTableId   ==  vendPurchOrderJour.TableId
            && taxJournalTrans.TransRecId   ==  vendPurchOrderJour.RecId;

        select firstonly * from purchline where purchline.PurchId == purchTable.PurchId;
        select sum(LineAmount) from purchLineLocal where purchLineLocal.PurchId == purchTable.PurchId;

        this.AC_VendCity        =   vendTable.countryRegionName();
        this.AC_VendTelephone   =   vendTable.phone();
        this.AC_VendFax         =   vendTable.telefax();
        this.AC_CompanyURL      =   purchTable.companyInfo().url();

        select firstOnly logisticsElectronicAddress
            where logisticsElectronicAddress.RecId == DirPartyTable::findRec
            (VendTable::find(vendTable.AccountNum).Party).PrimaryContactFax
            && logisticsElectronicAddress.IsPrimary ==  NoYes::Yes;
     
        this.CompanyVATNum      =   TaxRegistration::getCompanyTaxRegNum_W(this.PurchOrderDate);
        this.AC_TotalVATAmount  =   taxJournalTrans.TaxAmount;
        this.AC_TotalAmount     =   purchLineLocal.LineAmount + taxJournalTrans.TaxAmount;
        this.AC_AmountInWords   =   Global::numeralsToTxt(this.AC_TotalAmount);
     
        //this.CompanyVATNum =  companyInfo.CoRegNum;
        //this.INTC_VATNum = this.getTax(vendTable.postalAddress().Location);
        //this.AC_VendFax   = logisticsElectronicAddress.Locator;
        next insert();
    }

    public TaxRegistrationNumber getTax(LogisticsLocationRecId   _location)
    {
        TaxRegistration                         taxRegistration;
        TaxRegistrationType                     taxRegistrationType;
        TaxRegistrationTypeApplicabilityRule    taxRegistrationRule;
        LogisticsLocation                       logisticsLocation;
        DirPartyLocation                        dirPartyLocation;

        logisticsLocation = LogisticsLocation::find(_location);

        select taxRegistration
            join taxRegistrationRule
            where taxRegistrationRule.RecId ==  taxRegistration.TaxRegistrationTypeApplicabilityRule
            join taxRegistrationType
            where taxRegistrationType.RecId == taxRegistrationRule.TaxRegistrationType
            join dirPartyLocation
            where taxRegistration.DirPartyLocation == dirPartyLocation.RecID
            && dirPartyLocation.Location == logisticsLocation.RecId;

        return taxRegistration.RegistrationNumber;
    }

    public void initFromCompanyInfoOnBlankPaper(CompanyInfo _companyInfo)
    {
        next initFromCompanyInfoOnBlankPaper(_companyInfo);
        this.CompanyEmail   = _companyInfo.email();
    }

    public void initFromVendPurchOrderJour(VendPurchOrderJour _vendPurchOrderJour)
    {
        next initFromVendPurchOrderJour(_vendPurchOrderJour);
        this.NetAmount  = _vendPurchOrderJour.netAmount();
    }

}

//PO line CoC

[ExtensionOf(tableStr(PurchPurchaseOrderTmp))]
final class AC_PurchPurchaseOrderTmp_Extension
{
    public void insert()
    {
        PurchTable              purchTable;
        PurchLine               purchLine;
        VendPurchOrderJour      vendPurchOrderJour;
        PurchLineAllVersions    purchLineAllVersions;
        TaxJournalTrans         taxJournalTrans;
        PurchTableAllVersions   PurchTableAllVersions;
        TaxTable                taxTable;

        select VendPurchOrderJour
            where VendPurchOrderJour.RecId == this.JournalRecId
            join PurchTableAllVersions
            join PurchLineAllVersions
            join taxJournalTrans
            join purchLine
            where PurchTableAllVersions.PurchTableVersionRecId ==        VendPurchOrderJour.PurchTableVersion
            && PurchLineAllVersions.PurchTableVersionRecId == PurchTableAllVersions.PurchTableVersionRecId
            && PurchLineAllVersions.ItemId == this.ItemId
            && taxJournalTrans.TransTableId == vendPurchOrderJour.TableId
            && taxJournalTrans.TransRecId == vendPurchOrderJour.RecId
            && taxJournalTrans.InventTransId == PurchLineAllVersions.InventTransId
            && purchLine.SourceDocumentLine == PurchLineAllVersions.SourceDocumentLine;

        select taxTable where taxTable.TaxCode == taxJournalTrans.TaxCode;

        this.AC_VATAmount   =   abs(taxJournalTrans.SourceTaxAmountCur);
        this.AC_VATPerc     =   taxTable.showTaxValue();
        this.AC_TotalAmount =   this.AC_VATAmount + this.LineAmount;
       
        next insert();
    }

}

//SO Header CoC

[ExtensionOf(tableStr(SalesInvoiceHeaderFooterTmp))]
final class AC_SalesInvoiceHeaderFooter_Extension
{
    public void insert()
    {
        SalesTable                  salesTable;
        LogisticsElectronicAddress  logisticsElectronicAddress;
        DirPartyTable               dirPartyTable;
        TaxJournalTrans             taxJournalTrans;
        VendPurchOrderJour          vendPurchOrderJour;
        CustInvoiceJour             custInvoiceJour;

        salesTable  =   SalesTable::find(this.SalesId);
        select custInvoiceJour where custInvoiceJour.RecId == this.JournalRecId;
       
        this.AC_CustName    =   CustTable::find(this.InvoiceAccount).name();
        this.AC_CustCity    =   CustTable::find(this.InvoiceAccount).cityName_BR();
        this.AC_CustCountry =   CustTable::find(this.InvoiceAccount).countryName();
        this.AC_InvoiceNum  =   custInvoiceJour.InvoiceId;
     
        next insert();
    }

}

//SO Line CoC

[ExtensionOf(tableStr(SalesInvoiceTmp))]
final class AC_SalesInvoiceTmp_Extension
{
    public void insert()
    {
        SalesTable          salesTable;
        SalesLine           salesLine;
        real                tax1;
        InventTable         inventTable =   InventTable::find(this.ItemId);
        real                totalAmount;
        TaxTrans            taxTrans;
        CustInvoiceTrans    custInvoiceTrans;
        CustInvoiceJour     custInvoiceJour;

        real                taxAmount;
        real                salesPrice;
        select custInvoiceJour where custInvoiceJour.RecId == this.JournalRecId;

        select custInvoiceTrans
            where custInvoiceTrans.SalesId == custInvoiceJour.SalesId
            && custInvoiceTrans.InvoiceId   ==  custInvoiceJour.InvoiceId
            && custInvoiceTrans.InvoiceDate ==  custInvoiceJour.InvoiceDate
            && custInvoiceTrans.numberSequenceGroup ==  custInvoiceJour.numberSequenceGroup
            && custInvoiceTrans.ItemId  ==  this.ItemId;
     
        select taxTrans where taxTrans.InventTransId == custInvoiceTrans.InventTransId;
        this.TaxAmount          =   abs(taxTrans.TaxAmount);
        this.AC_VATPerc         =   taxTrans.TaxValue;
        this.AC_TotalAmount     =   this.LineAmount + this.TaxAmount;
        this.AC_SalesPrice      =   this.AC_TotalAmount/this.Qty;

        next insert();
    }

}

Build and deploy your report.
Select your design in print management settings level.

No comments:

Post a Comment