Adjust tax value using X++ code

Adjust tax value of purchase invoice. commonLine could be either MarkupTrans or VendInvoiceInfoLine.
static void VKTaxRegulation(Args _args)
{
    PurchTotals             purchTotals;
    TaxPurch                taxPurch;
    VendInvoiceInfoTable    vendInvoiceInfoTable;
    MarkupTrans             commonLine;
    //VendInvoiceInfoLine     commonLine;
    TaxRegulation           taxRegulation;
    
    select firstOnly vendInvoiceInfoTable
        where vendInvoiceInfoTable.Num == "VKTest10";


    purchTotals = PurchTotals::newParmTable(
                vendInvoiceInfoTable,
                PurchUpdate::All,
                AccountOrder::None,
                vendInvoiceInfoTable.ParmId,
                '',
                vendInvoiceInfoTable.Ordering);

    purchTotals.calc();
    taxPurch = purchTotals.tax();
    
    select commonLine
        where commonLine.RecId == 5637172328;
        
    taxRegulation = TaxRegulation::newTaxRegulation(
            taxPurch,
            null,
            commonLine.TableId,
            commonLine.RecId
    );
    
    taxRegulation.allocateAmount(22);
    taxRegulation.saveTaxRegulation();

    info('done');
}

Adjust tax value for purchase order:
static void VKTaxRegulationPO(Args _args)
{
    PurchTable              purchTable; 
    PurchLine               purchLine;
    TaxRegulation           taxRegulation;

    purchTable = PurchTable::find('VK-001113');
    purchLine  = PurchLine::find('VK-001113');
    
    taxRegulation = TaxRegulation::newTaxRegulation(
            PurchTotals::getTax(purchTable),
            null,                                                    
            tableNum(PurchLine),
            purchLine.RecId
    );

    if(taxRegulation)
    {
        taxRegulation.allocateAmount(12);
        taxRegulation.saveTaxRegulation();
    }
}
In order to process VAT adjustments at line level, the country region should be added to the list of Consolidation Countries.
\Classes\SysCountryRegionCode\isLegalEntityInConsolidatedCountryRegion




Support The Author

 If you found value in what I share, I've set up a Buy Me a Coffee page as a way to show your support.

Buy Me a Coffee

Post a Comment


All Comments


No comments. Be the first one to comment on this post.

Search

About

DaxOnline.org is free platform that allows you to quickly store and reuse snippets, notes, articles related to Dynamics 365 FO.

Authors are allowed to set their own "buy me a coffee" link.
Join us.

Blog Tags