Developer forum

Forum » Integration » BC Code Unit - VAT total and rounding

BC Code Unit - VAT total and rounding

Chris Søgaard
Chris Søgaard
Reply

Hi DW

We have an issue with how VAT are calculated when running live integration towards a BC Cloud version 18 with code unit version 1.2.0.17. New pricing feature is ON for this client.

We have created an order with several order lines and VAT of 25% should be applied to the order. Problem is that it seems like the order total fields, OrderPriceWithVat and OrderPriceWithoutVat are calculated by summing the fields from the order lines (with and without VAT) instead of calculating by an specific rate of VAT. This means that for a specific order we get the following response from BC:

 

The order should be applied 25% VAT rate, so the issue is the following:

  • OrderPriceWithVat from XML is 828.66
  • OrderPriceWithoutVat from XML is 662.92
  • OrderPriceVat from XML is 165.74
  • Calculating with rate of 25% then 662.92 * 0,25 = 165.73 and not 165.74
  • Calculating with rate of 25% then 662.92 * 1.25 = 828.65 and not 828.66

This is also what is reflected on the sales order in BC:

Again this seems to be the case because the VAT fields on each order line is rounded and then in the end summed to give the order total giving this issue with totals that doesn't match. With live integration disabled it seems like DW is calculating order totals correctly.

BR Chris 


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply

Hi Chris,
It looks like we need more information from you.
Could you also show your xml with response for the order lines as well?
Does this problem occurs on Calculate Order only? Or is it also appearing on CreateOrder request?
Have you also compared the order in BC when you manually create a new Sales Order in BC and insert the order lines
(and apply all invoice discounts if there could be any) and get the total order and order lines prices based on quantities/vat/etc?
Thx
BR, Dmitrij

 
Chris Søgaard
Chris Søgaard
Reply

Hi Dmitrij

Because customer's prices have changed this is no longer a valid combination of products to trigger this issue. I have asked the client for another example of the issue, once I have it, I will send you the complete request/response in XML.

The problem occurs both on calculate and create. The image I shared in my previous comment is actually how the order is created in BC with the total VAT of 165,73 DKK while the XML shows 165,74 DKK.

It is created in BC with this logic for VAT calculation regardless of whether the order is created manually in BC or through code unit. In BC we see a logic where it sums up all order lines without VAT and then calculate the VAT based on total order price without VAT like this:

  • Total Order Price Without VAT = Sum of "OrderLines" --> "OrderLinePriceWithoutVAT"
  • Total Order VAT = "Total Order Price Without VAT" * "VATPercent"
  • Total Order Price With VAT = "Total Order Price Without VAT" + "Total Order VAT", then rounded to 2 decimal points.

It seems that code unit returns XML with VAT calculation based on each order line and then does the following to calculate total order price:

  • Total Order Price Without VAT = Sum of "OrderLines" --> "OrderLinePriceWithoutVat"
  • Total Order VAT = Sum of "OrderLines" --> "OrderLinePriceVat"
  • Total Order Price With VAT = Sum of "OrderLines" --> "OrderLinePriceWithVat"

But because each order line's VAT calculation is rounded to 2 decimal points it can then then give the issue we see here, where there's a difference on the order totals.

 
Nicolai Pedersen
Reply

Hi Chris

We do understand the problem, but have to see the entire order and orderlines xml to see if there is a solvable problem.

I think this is a scenario where you would have 1 of 2 issues - and if we change the current behavior, the issue will just 'move around'.

I have created this example to illustrate.

Each orderline is rounded to 2 decimals on the invoice.

If you use the full calculation without rounding on the order totals and then round the result, you will have a problem that the totals (red) will not match the sum of the orderlines (Yellow).

Both scenarios are 'wrong' but what is the solution? Which version is less wrong or more correct?

So we need all of the data to dig deeper.

Thanks, Nicolai

 
Chris Søgaard
Chris Søgaard
Reply

Hi Nicolai

Yes, I'm aware of that, and great that you do understand the issue here.

I have asked the client for another example of the issue, once I have it, I will send you the complete request/response in XML.

BR Chris

 

 

You must be logged in to post in the forum