> For the complete documentation index, see [llms.txt](https://docs.one-cp.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.one-cp.com/reference-materials/tax-calculation.md).

# Tax Calculation

Totals and Tax Calculation System

## Introduction

The tax calculation system calculates the total tax and item total based on various parameters such as item price, quantity, tax types, tax values, and units. The calculation is recursive and backward, starting from the last applied tax.

## Parameters

* **Item Price (price)**: An integer value representing the single unit price of the item. It follows the Currency Codes and Minor Units specified [here](/reference-materials/currency-codes.md).
* **Item Quantity (quantity)**: An integer value representing the quantity of the item.\
  Item quantity consists of two properties:\
  \- amount: integer value\
  \- per: ( FLAT\_FEE | PER\_HOUR | PER\_DAY | PER\_NIGHT | PER\_WEEK | PER\_MONTH | PER\_YEAR | PER\_PERSON )
* **Tax Type (type)**:

```
VAT, BED_TAX, CITY_HOTEL_FEES, COUNTRY_TAX, CITY_TAX, ENERGY_CHARGE,
FEDERAL_TAX, GST, INCLUSION, LODGING_TAX, MAINTENANCE_FEE, OCCUPANCY_TAX,
PACKAGE_RATE_FEE, ROOM_TAX, RESORT_FEES, SALES_TAX, STATE_PROVINCE_TAX,
SURCHARGE, SERVICE_CHARGE, OTHER_TAX, TOURISM_TAX
```

* **Tax Value (value)**: An integer representing the tax value. If the tax unit is PERCENT, it represents a percentage of the item price. If the tax unit is AMOUNT, it is a constant value following the Currency Codes and Minor Units specified [here](/reference-materials/currency-codes.md).
* **Tax Unit (unit)**: AMOUNT or PERCENT.
* **Tax Applied To (apply\_to)**: Refers to any of the previous tax types in the item taxes list or "NET\_PRICE" for the first tax.
* **Tax Per**: FLAT\_FEE or PER\_QUANTITY.

## Calculation Logic

The tax calculation is recursive and backward, starting from the last applied tax backward to the item value. The total tax and item total are calculated accordingly.

### Examples

#### Case 1

* Item (price: 49999 (499.99 USD), quantity: 2)
* Taxes:

| Tax Type | Tax Value | Tax Per       | Apply To   | Tax Per Item    | Total Tax       |
| -------- | --------- | ------------- | ---------- | --------------- | --------------- |
| VAT      | 20 %      | PER\_QUANTITY | NET\_PRICE | 10000 (100 USD) | 20000 (200 USD) |

* Item Total: 119998 (1199.98 USD)
* Total Tax: 20000 (200 USD)

#### Case 2

* Item (price: 10000 (100 USD), quantity: 1)
* Taxes:

| Tax Type         | Tax Value | Tax Per   | Apply To   | Tax Per Item    | Total Tax       |
| ---------------- | --------- | --------- | ---------- | --------------- | --------------- |
| VAT              | 10 %      | FLAT\_FEE | NET\_PRICE | 1000 (10 USD)   | 1000 (10 USD)   |
| BED\_TAX         | 20 %      | FLAT\_FEE | VAT        | 2200 (22 USD)   | 2200 (22 USD)   |
| MAINTENANCE\_FEE | 15 %      | FLAT\_FEE | BED\_TAX   | 1980 (19.8 USD) | 1980 (19.8 USD) |

* Item Total: 15180 (151.8 USD)
* Total Tax: 5180 (51.8 USD)

#### Case 3

* Item (price: 10000 (100 USD), quantity: 2)
* Taxes:

| Tax Type         | Tax Value | Tax Per       | Apply To   | Tax Per Item    | Total Tax       |
| ---------------- | --------- | ------------- | ---------- | --------------- | --------------- |
| VAT              | 10 %      | PER\_QUANTITY | NET\_PRICE | 1000 (10 USD)   | 2000 (20 USD)   |
| BED\_TAX         | 20 %      | PER\_QUANTITY | VAT        | 2200 (22 USD)   | 4400 (44 USD)   |
| MAINTENANCE\_FEE | 15 %      | PER\_QUANTITY | BED\_TAX   | 1980 (19.8 USD) | 3960 (39.6 USD) |

* Item Total: 30360 (303.6 USD)
* Total Tax: 10360 (103.6 USD)

#### Case 4

* Item (price: 10000 (100 USD), quantity: 1)
* Taxes:

| Tax Type         | Tax Value | Tax Per       | Apply To     | Tax Per Item     | Total Tax        |
| ---------------- | --------- | ------------- | ------------ | ---------------- | ---------------- |
| VAT              | 10 %      | PER\_QUANTITY | NET\_PRICE   | 1000 (10 USD)    | 1000 (10 USD)    |
| BED\_TAX         | 20 %      | PER\_QUANTITY | VAT          | 2200 (22 USD)    | 2200 (22 USD)    |
| FEDERAL\_TAX     | 7 %       | PER\_QUANTITY | NET\_PRICE   | 700 (7 USD)      | 700 (7 USD)      |
| MAINTENANCE\_FEE | 15 %      | PER\_QUANTITY | FEDERAL\_TAX | 1605 (16.05 USD) | 1605 (16.05 USD) |

* Item Total: 15505 (155.05 USD)
* Total Tax: 5505 (55.05 USD)

#### Case 5

* Item (price: 10000 (100 USD), quantity: 3)
* Taxes:

| Tax Type         | Tax Value | Tax Per       | Apply To     | Tax Per Item     | Total Tax        |
| ---------------- | --------- | ------------- | ------------ | ---------------- | ---------------- |
| VAT              | 10 %      | PER\_QUANTITY | NET\_PRICE   | 1000 (10 USD)    | 3000 (30 USD)    |
| BED\_TAX         | 20 %      | PER\_QUANTITY | VAT          | 2200 (22 USD)    | 6600 (66 USD)    |
| FEDERAL\_TAX     | 7 %       | PER\_QUANTITY | NET\_PRICE   | 700 (7 USD)      | 2100 (21 USD)    |
| MAINTENANCE\_FEE | 15 %      | PER\_QUANTITY | FEDERAL\_TAX | 1605 (16.05 USD) | 4815 (48.15 USD) |

* Item Total: 46515 (465.15 USD)
* Total Tax: 16515 (165.15 USD)

#### Case 6

* Item (price: 4400 (44 USD), quantity: 1)
* Taxes:

| Tax Type | Tax Value | Tax Per   | Apply To   | Tax Per Item   | Total Tax      |
| -------- | --------- | --------- | ---------- | -------------- | -------------- |
| VAT      | 7 %       | FLAT\_FEE | NET\_PRICE | 308 (3.08 USD) | 308 (3.08 USD) |
| BED\_TAX | 3 %       | FLAT\_FEE | VAT        | 144 (1.44 USD) | 144 (1.44 USD) |

* Item Total: 4849 (48.49 USD)
* Total Tax: 449 (4.49 USD)

#### Case 7

* Item (price: 4400 (44 USD), quantity: 3)
* Taxes:

| Tax Type | Tax Value | Tax Per       | Apply To   | Tax Per Item   | Total Tax      |
| -------- | --------- | ------------- | ---------- | -------------- | -------------- |
| VAT      | 7 %       | PER\_QUANTITY | NET\_PRICE | 308 (3.08 USD) | 924 (9.24 USD) |
| BED\_TAX | 3 %       | PER\_QUANTITY | VAT        | 144 (1.44 USD) | 423 (4.23 USD) |

* Item Total: 14547 (145.47 USD)
* Total Tax: 1347 (13.47 USD)

#### Case 8

* Item (price: 4400 (44 USD), quantity: 1)
* Taxes:

<table><thead><tr><th width="139">Tax Type</th><th width="104">Tax Value</th><th width="166">Tax Per</th><th width="190">Apply To</th><th>Tax Per Item</th><th>Total Tax</th></tr></thead><tbody><tr><td>VAT</td><td>10 %</td><td>PER_QUANTITY</td><td>NET_PRICE</td><td>440 (4.4 USD)</td><td>440 (4.4 USD)</td></tr><tr><td>BED_TAX</td><td>3 %</td><td>PER_QUANTITY</td><td>VAT</td><td>145 (1.45 USD)</td><td>145 (1.45 USD)</td></tr><tr><td>MAINTENANCE_FEE</td><td>7 %</td><td>PER_QUANTITY</td><td>NET_PRICE</td><td>308 (3.08 USD)</td><td>308 (3.08 USD)</td></tr><tr><td>BED_TAX</td><td>15 %</td><td>PER_QUANTITY</td><td>MAINTENANCE_FEE</td><td>706 (7.06 USD)</td><td>706 (7.06 USD)</td></tr></tbody></table>

* Item Total: 5999 (59.99 USD)
* Total Tax: 1599 (15.99 USD)

#### Case 9

* Item (price: 4400 (44 USD), quantity: 2)
* Taxes:

| Tax Type         | Tax Value | Tax Per       | Apply To         | Tax Per Item   | Total Tax        |
| ---------------- | --------- | ------------- | ---------------- | -------------- | ---------------- |
| VAT              | 10 %      | PER\_QUANTITY | NET\_PRICE       | 440 (4.4 USD)  | 880 (8.8 USD)    |
| BED\_TAX         | 3 %       | PER\_QUANTITY | VAT              | 145 (1.45 USD) | 290 (2.9 USD)    |
| MAINTENANCE\_FEE | 7 %       | PER\_QUANTITY | NET\_PRICE       | 308 (3.08 USD) | 616 (6.16 USD)   |
| BED\_TAX         | 15 %      | PER\_QUANTITY | MAINTENANCE\_FEE | 706 (7.06 USD) | 1412 (14.12 USD) |

* Item Total: 11998 (119.98 USD)
* Total Tax: 3198 (31.98 USD)

#### Case 10

* Item (price: 50 (0.50 USD), quantity: 3)
* Taxes:

| Tax Type | Tax Value | Tax Per   | Apply To   | Tax Per Item | Total Tax    |
| -------- | --------- | --------- | ---------- | ------------ | ------------ |
| VAT      | 7 %       | FLAT\_FEE | NET\_PRICE | 4 (0.04 USD) | 4 (0.04 USD) |
| BED\_TAX | 3 %       | FLAT\_FEE | VAT        | 0            | 0            |

* Item Total: 154 (1.54 USD)
* Total Tax: 4 (0.04 USD)

#### Case 11

* Item (price: 100 (1 USD), quantity: 2)
* Taxes:

| Tax Type     | Tax Value | Tax Per       | Apply To         | Tax Per Item  | Total Tax     |
| ------------ | --------- | ------------- | ---------------- | ------------- | ------------- |
| VAT          | 10 %      | PER\_QUANTITY | NET\_PRICE       | 10 (0.1 USD)  | 20 (0.2 USD)  |
| BED\_TAX     | 20 %      | FLAT\_FEE     | VAT              | 22 (0.22 USD) | 22 (0.22 USD) |
| COUNTRY\_TAX | 15 %      | FLAT\_FEE     | MAINTENANCE\_FEE | 0             | 0             |

* Item Total: 242 (2.42 USD)
* Total Tax: 42 (0.42 USD)
