Thursday, September 27, 2018

AX 2012 - Displaying Sales Tax line wise on Purchase order confirmation report

In order to display sales tax on purchase order confirmation report in AX 2012, one need to modify PurchPurchaseOrderDP class. The table where the sales tax will be residing is TaxJournalTrans table, where you can use TransRecId, TransTableId and InventTransId fields to have relationship based upon posted Purchase order journal. For the posted journal, you would need  already available vendPurchOrderJour and purchLineAllVersions table and view buffer in the DP class as shown in the mentioned code. A line needs to be added in the DP class method, setPurchPurchaseOrderDetails,  to assign the value calculated in a customized new method PKR_SalesTaxPerPurchLine() as shown below:

purchPurchaseOrderTmp.TaxAmount = this.PKR_SalesTaxPerPurchLine(); 

The method to calculate sales tax per posted purchase journal line is as follows:

private AmountCur PKR_SalesTaxPerPurchLine()
{
    AmountCur               taxAmountPerPurchLine;
    TaxJournalTrans         taxJournalTrans;

    select SourceTaxAmountCur from taxJournalTrans
        where taxJournalTrans.InventTransId == purchLineAllVersions.InventTransId
        && taxJournalTrans.TransRecId == vendPurchOrderJour.RecId
        && taxJournalTrans.TransTableId == vendPurchOrderJour.TableId;

    taxAmountPerPurchLine = taxJournalTrans.SourceTaxAmountCur;

    return taxAmountPerPurchLine;

}