AX 2012 R3 - X++ CODE TO RESET THE ACTUAL VAT AMOUNT FOR SALES ORDER
#File
IO iO;
SalesTable salesTable;
SalesLine salesLine;
SalesId salesId;
int cnt;
SalesTotals salesTotals;
TaxAmount taxAmount;
;
if (salesTable)
salesTotals.calc();
taxRegulation = TaxRegulation::newTaxRegulation(salesTotals.tax(), null,salestable.TableId, salestable.RecId);
taxRegulation.resetTaxRegulation();
taxRegulation.saveTaxRegulation();
}
cnt++;
}
}
}
}
}
static void RB_ResetVATAmount1(Args _args)
{
#File
IO iO;
FilenameOpen filename = "c:\\VAT1.csv";//file name here
Container con;
boolean first = true;
SalesLine salesLine;
SalesId salesId;
int cnt;
//Manually adjust sales taxes
TaxRegulation taxRegulation;
SalesTotals salesTotals;
TaxAmount taxAmount;
;
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
con = iO.read();// read file
if (con)
{
if (first) //skip header
{
first = false;
}
else
{
salesId = conpeek(con, 1);
salesTable = SalesTable::find(salesId);
if (salesTable)
{
salesTotals = SalesTotals::construct(salesTable, SalesUpdate::All);salesTotals.calc();
taxRegulation = TaxRegulation::newTaxRegulation(salesTotals.tax(), null,salestable.TableId, salestable.RecId);
if (taxRegulation.taxLinesExist()) // * needs to be true
{
//taxRegulation.allocateAmount(20); // manually specify the amount you wish and comment the next line i.e. //taxRegulation.resetTaxRegulation();taxRegulation.saveTaxRegulation();
}
cnt++;
}
}
}
}
info(strFmt("Total number of records updated :- %1",cnt));