Wednesday, 5 September 2018

how to extend the DP class methods in D365


[ExtensionOf(ClassStr(PurchPurchaseOrderDP))]
final class PurchPurchaseOrderDP_Extension
{
   
    private void new()
    {
    }
 Protected PurchPurchaseOrderTmp initializeOrderLine(
        PurchPurchaseOrderHeader                    _purchaseOrderHeader,
        boolean                                     _highlightUpdated,
        PurchPurchaseOrderDPOrderLineQuerySelection _orderLineSelection)
    {

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

        if (purchPurchaseOrderTmp.PurchOrderTransOrTaxTrans)
        {
            //purchPurchaseOrderTmp.TRI_LineIsTaxed = this.TRILineIsTaxed(purchLine.RecId);
            purchPurchaseOrderTmp.TRI_LineIsTaxed = this.TRILineIsTaxed(PurchLine::findInventTransId(_orderLineSelection.parmPurchLineAllVersions().InventTransId).RecId, purchPurchaseOrderTmp);
        }
        //purchPurchaseOrderTmp.TRI_AGLRevision   = PurchLine::findRecId(purchline.RecId).TRI_AGLRevision;
        purchPurchaseOrderTmp.TRI_AGLRevision   = PurchLine::findRecId(PurchLine::findInventTransId(_orderLineSelection.parmPurchLineAllVersions().InventTransId).RecId).TRI_AGLRevision;

        return purchPurchaseOrderTmp;

    }

    /// <summary>
    ///  Set boolean if line is taxed
    /// </summary>
    /// <param name = "_purchLineRecId">RecId for purchLine</param>
    /// <returns>Returns true if line is taxed</returns>
    protected boolean TRILineIsTaxed(RefRecId _purchLineRecId, PurchPurchaseOrderTmp _purchPurchaseOrderTmp)
    {
        boolean                 lineIsTaxed;
        PurchTotals             tri_PurchTotals;
        TaxPurch                taxPurch;
        AmountCur               taxAmountCurTotal;
        AmountCur               taxRegulationTotalCur;
        ;

        tri_PurchTotals = PurchTotals::newPurchTable(VendPurchOrderJour::findRecId(_purchPurchaseOrderTmp.JournalRecId).purchTable());
        tri_PurchTotals.calc();
        taxPurch = tri_PurchTotals.tax();

        if (tri_PurchTotals && _purchLineRecId)
        {
            [taxAmountCurTotal, taxRegulationTotalCur] = taxPurch.showTaxesSourceSingleLine(tableNum(PurchLine), _purchLineRecId, true);
            lineIsTaxed = taxAmountCurTotal != 0.00;
        }

        return lineIsTaxed;
    }

}

No comments:

Post a Comment