Hi NitinR/Sumit Loya,
I am looking into similar issue where the customer wants to import the sales tax using the VendorInvoiceLineEntity. What we did is we added the VAT amount field VendorInvoiceLineEntity and created a method which contains the suggested code from you and which is called on insertEntityDataSource/updateEntityDataSource.
What is happening it is no matter what I do it only creates a sales tax on the first invoice line.
No matter if "class 'PurchCalcTax_ParmTransInvoice' method 'allowSingleLineAdjustment' to return true" or false.
The difference in that scenario if it takes the value from the first or last line.
So basically to summarize I only have one tax record for one invoice (no matter how many invoice lines I have):
public boolean insertEntityDataSource(DataEntityRuntimeContext _entityCtx, DataEntityDataSourceRuntimeContext _dataSourceCtx)
{
boolean returnValue = next insertEntityDataSource(_entityCtx, _dataSourceCtx);
switch (_dataSourceCtx.name())
{
case dataentitydatasourcestr(VendorInvoiceLineEntity, VendInvoiceInfoLine):
VendInvoiceInfoLine vendInvoiceInfoLine = _dataSourceCtx.getBuffer();
VendorInvoiceLineEntity_Handlers::setActualVATLine(vendInvoiceInfoLine, this.TotalActualVatAmount);
break;
}
return returnValue;
}
public static void setActualVATLine(VendInvoiceInfoLine vendInvoiceInfoLine, TaxRegulationAmountCur actualVAT)
{
VendInvoiceInfoTable vendInvoiceInfoTable = VendInvoiceInfoTable::findTableRefId(vendInvoiceInfoLine.tableRefId);
TaxRegulation taxRegulation;
PurchTotals purchTotals;
TmpTaxRegulation tmpTaxRegulation;
TaxRegulationDetail taxRegulationDetail;
TmpTaxWorkTrans tmpTaxWorkTrans;
if (vendInvoiceInfoTable)
{
purchTotals = PurchTotals::newParmTable(vendInvoiceInfoTable,PurchUpdate::ReceiveNow, vendInvoiceInfoTable.ParmId,vendInvoiceInfoTable.PurchId, DocumentStatus::Invoice);
purchTotals.calc();
purchTotals.tax().sourceSingleLine(true, true);
if(vendInvoiceInfoLine)
{
taxRegulation = TaxRegulation::newTaxRegulation(purchTotals.tax(),null, vendInvoiceInfoLine.TableId, vendInvoiceInfoLine.RecId);
tmpTaxRegulation = taxRegulation.tmpTaxRegulation();
tmpTaxWorkTrans = taxRegulation.tmpTaxWorkTrans();
ttsBegin;
while select tmptaxRegulation
{
taxRegulation.updateTaxRegulationAmount(tmpTaxRegulation, actualVAT);
taxRegulation.saveTaxRegulation();
}
ttsCommit;
}
}
}
Thanks,
Riste