Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / Sales tax override on ...
Finance forum

Sales tax override on pending vendor invoice lines

(0) ShareShare
ReportReport
Posted on by

I have a requirement to override/adjust sales tax for individual pending vendor invoice lines through code.

I am able to adjust the sales tax for the pending vendor invoice header from AP > Invoices > Pending vendor invoices > select/open any invoice > Financials (Action pane) > Sales Tax > Adjustment (tab). Even-though, we can see the sales tax for each vendor invoice line, by selecting a vendor invoice line > Financials (on top of lines grid) > Sales Tax, it doesn't have an option to adjust the Sales Tax amounts.

  • Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    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

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Sumit,

    The above changes helped me. I had to add one more extension. Had to do a COC on class 'PurchCalcTax_ParmTransInvoice' method 'allowSingleLineAdjustment' to return true when my conditions are met.

    Thanks,

    Nitin Rajan

  • Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Sourav,

    Thank you for your response. I think my latest response to Sumit will clarify your questions also.

    Thanks

    Nitin Rajan

  • Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Sumit,

    Thank you again for the response, I was busy yesterday and tried your suggestion today. For me the results are same as of my previous code as I update on the header. The amount I pass is distributed across multiple lines which have same sales tax code. Example as below.

    Before update

    Line 1 - Item A, Line amount: 1000, Tax code : ABC,  Tax amount 180  - Calculated with 18%

    Line 2 -  Item B, Line amount: 1200, Tax code : ABC,  Tax amount 216  - Calculated with 18%

    After update (Actual) - I tried the update of Line 2 with tax amount '120.10' identifying the vendor invoice line record using RECID

    Line 1 - Item A, Line amount: 1000, Tax code : ABC,  Tax amount 54.59  - Calculated by distributing the value I passed

    Line 2 -  Item B, Line amount: 1200, Tax code : ABC,  Tax amount 65.51  - Calculated by distributing the value I passed

    As you can see in the above example, the tax amount i passed (120.10) for line 2 has been distributed on both the lines based on the line amount.

    This is in-line with the manual update which we do on the header level through UI

    My Requirement (Expectation) -  When I pass tax amount '120.10'  for Line 2 identifying the vendor invoice line record using RECID.

    Line 1 - Item A, Line amount: 1000, Tax code : ABC,  Tax amount 180   - Tax amount not changed

    Line 2 -  Item B, Line amount: 1200, Tax code : ABC,  Tax amount 120.10   - Tax amount changed with the value I passed.

    Thanks
    Nitin rajan

  • SouravDam Profile Picture
    11,728 on at
    RE: Sales tax override on pending vendor invoice lines

    Hi NitinR,

    Appreciate if you kindly elaborate and help to understand what is the business expectation for such requirement as you mentioned in your last post in this thread "I would need the sales tax to be updated on one of the invoice line and leave the sales tax of other line unchanged.?

    If anyhow through coding if you achieve this; based on what criteria you will pick a line (out of many lines) in pending vendor invoice form to adjust the sales tax in that line ?

    Best regards,
    Sourav Dam

  • Verified answer
    Sumit Loya Profile Picture
    2,230 on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Nitin,

    Can you try this?

    Replace purchTotals.calc(false, false, true); with following 2 lines

    purchTotals.calc();

    purchTotals.tax().sourceSingleLine(true, true);

    Also inside the if() statement, comment all update code and just call following

    taxRegulation.updateTaxRegulationAmount(tmpTaxRegulation, _salesTaxOverrides.lookup(tmpTaxRegulation.taxCode);

    Please try this and let me know how this goes.

  • Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Ludwig,

    Thank you for your response.

    For my requirement, I would need the sales tax to be be updated on one of the invoice line and leave the sales tax of other line unchanged.

    On the vendor invoice sales tax form, when we navigate to Adjustment tab, sales tax amount for all lines gets summed up by sales tax codes. When I change the value there, the new value get split against the lines which are associated. Not just one line which I want to change.

    Regards

    Nitin Rajan

  • Community Member Profile Picture
    on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Sumit,

    Thank you for your response. I was trying the similar logic as below. This works when I have to update the sales tax at vendor invoice header. However, I when have more than one line in the invoice with sales tax code (eg ABCD), the amount which I pass (eg 100), will get split as 50 on one line and 50 for other line. I am not able to update sales tax for just one invoice line (say line 1) and leave the sales tax of the second line unchanged.

       public void overrideVendInvoiceTax(TradeLineRefId    tableRefId, Map _salesTaxOverrides, RefRecID _vendInvoiceLineRecID)

       {

           VendInvoiceInfoTable    vendInvoiceInfoTable = VendInvoiceInfoTable::findTableRefId(tableRefId);

           TaxRegulation           taxRegulation;

           PurchTotals             purchTotals;

           TmpTaxRegulation        tmpTaxRegulation;

           TaxRegulationDetail     taxRegulationDetail;

           VendInvoiceInfoLine     vendInvoiceInfoLine;

           if (vendInvoiceInfoTable)

           {

               purchTotals = PurchTotals::newParmTable(vendInvoiceInfoTable,PurchUpdate::All, vendInvoiceInfoTable.ParmId,vendInvoiceInfoTable.PurchId, DocumentStatus::Invoice);

               purchTotals.calc(false,false, true);

               select vendInvoiceInfoLine where vendInvoiceInfoLine.RecId == _vendInvoiceLineRecID;            

               if(vendInvoiceInfoLine)

               {

                   taxRegulation = TaxRegulation::newTaxRegulation(purchTotals.tax(),null, vendInvoiceInfoLine.TableId, vendInvoiceInfoLine.RecId);

    tmpTaxRegulation  = taxRegulation.tmpTaxRegulation();

    ttsBegin;

    while select tmptaxRegulation

    {

    if(_salesTaxOverrides.exists(tmpTaxRegulation.taxCode))

    {  

    tmptaxRegulation.SourceRegulateAmountCur = _salesTaxOverrides.lookup(tmpTaxRegulation.taxCode);

    tmptaxRegulation.SourceRecId = vendInvoiceInfoLine.RecId;

    tmptaxRegulation.SourceTableId = vendInvoiceInfoLine.TableId;

    tmptaxRegulation.OverrideCalculatedTax =true;

    tmpTaxRegulation.update();

    taxRegulation.updateOverrideCalculatedTax(tmptaxRegulation);

    }              

    }

    taxRegulation.saveTaxRegulation();

    ttsCommit;

               }      

           }

       }

  • Suggested answer
    Sumit Loya Profile Picture
    2,230 on at
    RE: Sales tax override on pending vendor invoice lines

    Hi Nitin,

    Sometime back I had similar requirement to auto adjust sales tax amount to a specific value based on manual input for Free text invoice. I used following code for my requirement.

    For your requirement, you can use PurchTotals class or corresponding class and use this code.

    custFreeInvoiceCalcTotals = new CustFreeInvoiceCalcTotals(custInvoiceTable);
    custFreeInvoiceCalcTotals.calc();
    tax             = custFreeInvoiceCalcTotals.tax();
    taxRegulation   = TaxRegulation::newTaxRegulation(tax, null, custInvoiceTable.TableId, custInvoiceTable.RecId);
    taxRegulation.allocateAmount(_overrideTaxAmount);
    taxRegulation.saveTaxRegulation(dateNull());
  • Suggested answer
    Ludwig Reinhard Profile Picture
    Microsoft Employee on at
    RE: Sales tax override on pending vendor invoice lines

    Hello NitinR,

    If you open the sales tax form from the header then you should see a multiple lines for each of the lines that is included in your pending vendor invoice form and that has sales tax associated because of the item sales tax group / sales tax group combination selected.

    You can thus make the changes in the header and they apply to your respective lines.

    Best regards,

    Ludwig

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans