 ###### Toolbox Main Page Upload file What links here Recent changes Help

###### PDF Books Add page Show collection (0 pages) Collections help

###### Participate Communicate Report a bug Contribute Talk to us now!

# Price Including Taxes Document Level This feature is available starting from 3.0PR17Q2.

## Introduction

After solving the issue 32265, price including taxes at document level calculation has been improved in order to avoid rounding issues.

Therefore, two main changes have been done:

1. Calculate line net amount from gross amount instead from net price.
2. Adjust line net amount to make sure sum of line net amounts is equals document net amount.

## Calculate Line Net Amount from Gross Amount

We have changed the way we calculate the line net amount of order/invoice lines when using price including taxes in C_ORDERLINE_TRG and C_INVOICELINE_BEFORE_TRG:

In the past, we first calculated the Net Price from the Gross Amount using C_GET_NET_PRICE_FROM_GROSS function: ``` ```

``` gross amount net price = gross amount * ( ------------------------------------------- ) / quantity gross amount + tax amount of gross amount ```

and then the Net Amount from the Net Price: ``` ```

``` net amount = net price * quantity ```

Now, we first calculate the Net Amount from the Gross Amount using C_GET_NET_AMOUNT_FROM_GROSS function: ``` ```

``` gross amount net amount = gross amount * ( ------------------------------------------- ) gross amount + tax amount of gross amount ```

and then the Net Price from the Net Amount: ``` ```

``` net price = net amount / quantity ```

Thus, we avoid precision loss when multiplying by quantity.

## Taxes calculation at Document Level

When calculating taxes at document level, we need to take into account every order/invoice lines with the same tax to calculate the tax base and the tax amount for this tax.

This is hard to do with the current implementation of tax calculation, because logic is done in order/invoice lines triggers incrementally and we can’t have the information about other order/invoice lines at this moment due to mutating tables issue.

The followed approach to avoid this problem, is to calculate the tax bases for line and document taxes without rounding when using taxes at document level and price including taxes, and avoid precision loss when adding every order/invoice line with the same tax.

In order to follow this approach, several changes have been done:

1. Create new line and document taxes without rounding the tax base when calling C_ORDERLINETAX_INSERT/C_INVOICELINETAX_INSERT from C_ORDERLINE_TRG2/C_INVOICELINE_TRG2 in case price including taxes and taxes at document level.

2. In case cascade or dependant taxes at document level, we can’t calculate them by adding every line tax with the same tax, as we will get different tax base and tax amount than expected because we will be adding rounded line tax bases and amounts. We need to calculate them by adding the tax base and the tax amount of the document tax it is based on instead. This change has been done in C_ORDERLINETAX_TRG/C_INVOICELINETAX_TRG.
This change applies to both price excluding and including taxes as it was failing in both flows.

3. Document gross amount and net amount calculation has been changed in case price including taxes as we need to add rounded taxes instead of round the sum of taxes. This change has been done in C_ORDERLINE_TRG2/C_INVOICELINE_TRG2 to calculate document totals by adding rounded document tax bases and amounts instead of adding line net amounts incrementally.

4. When completing the order/invoice with price including taxes, we will round line and document tax bases.