# Drupal Commerce: How to perform a complex calculation of order's final cost (VATs & discounts)?

Here's is what I want to accomplish:

• There are 2 taxes in my country: 6.5% & 23%. Every product has to be matched with 1 of these 2 VATs (I'm currently using a taxonomy vocabulary holding these 2 VAT values instead of using commerce tax module)
• A discount should always be available, based on total order's amount, excluding tax e.g. an order's total (with no tax included in base prices) of €0,01-€50,00 awards the customer with a discount to the order's total (including tax) of -5%, from €50,01 to €80,00 gives a discount of -8% etc etc

What I want to accomplish: - Customer adds products to cart (product prices are displayed excluding tax, ie w/o components) and heads to checkout. According to order's total (addition of products' base prices w/o tax), the appropriate discount will be applied. - Final Price = (Products' base prices + their appropriate taxes)*Pre-calculated Discount + Shipping Cost

Example: Shopping cart includes: - Product 1: €20 base price (6.5% VAT) - Product 2: €25 base price (23% VAT) Checkout Process:

1. Discount pre-calculation: Total base price is €20 + €25 = €45. As a result, the customer should be awarded with a -5% discount (see available discount rates above).

2. Order's total including products' VATs = (€20 + €20*0.065) + (€25 + €25*0.23) = €21.30 + €30.75 = €52.05

3. The pre-calculated -5% discount from step 1 is applied: €52.05 - €52.05*0.05 = €49.45 and that's what the customer has to pay for the products in his/her cart.

4. Order's weight is calculated and a shipping flat rate is applied (I have this functionality already working). As a result, the shipping cost is added to €49.45 and we finally get the sum that the customer will have to pay using one of available payment methods.*

I would appreciate your suggestions on how to make this happen.

Tricky parts:

• different products can have different VAT (23% or 6.5%).
• The discount has to be calculated by adding all products' base prices (NOT including tax) and THEN applied to line item (including tax) prices.
• It would also be nice if VATs & discount were displayed to customer in order's review.