tax problem with two different tax rates


  • Default avatar
    sattwa    
     12 years ago
    0

    Hi All,

    I am very happy with AWOcoupon, but yesterday I noticed that that the tax is not calculated correctly. After implementing the fix - https://awodev.com/blog/virtuemart-coupon-error-discount-before-tax - the order tax displays correct, but if I add a book (6% VAT) and another product (19% VAT) all things get messy and it's starts calculating horribly wrong after the coupon has been activated. It displays the total tax amount VAT, 6 % tax amount and 19% tax amount. But the total tax amount gives a totally different amount the the added up totals of the 19 and 6 % tax.

    Maybe there is already a topic about this but I couldn't find it.

    Any help would be greatly aprecciated.

    VirtueMart 1.1.9
    Joomla : Version 1.5.25

    Dennis
  • Your avatar
    seyi    
     12 years ago
    0

    Hello Dennis,

    It might be helpful if you gave an actual example with numbers. That way, can figure out what is being calculated and hopefully lead to an easy fix.
  • Default avatar
    sattwa    
     12 years ago
    0

    Hi Seyi,

    I am sorry for the lack of information.

    I have a parent coupon with 5 children coupons attached to it:
    5% discount > € 35,=
    10% discount > € 50,=
    15% discount > € 75,=
    20% discount > € 100,=
    25% discount > € 200,=

    I have two products which are excluded from these discounts.

    The following happens at the moment a discount is enabled:

    1 X € 21.00 > € 21.00 (6% VAT no discount - excluded from discount in AWOcoupon)
    2 X € 29.95 > € 59.90 (19% VAT discount is 10% above € 50
    Subtotal: € 80.90
    Discount - € 5.99

    VAT:
    € 12.34 (total tax (VAT))
    € 1.09292 (6% tax (VAT))
    € 8.87759 (19% tax (VAT))
    Totaal: € 74.91

    All is well if only one tax rate is chosen in the order.

    If you need more information, please dont hesitate to ask.

    Thanks already
  • Your avatar
    seyi    
     12 years ago
    0

    Ok, so I ran through your scenario on a local box. With no coupon code, the total comes out fine:

    Subtotal: $80.90
    Total: $80.90
    Tax Total: $10.75
    Tax Total contains:
    $1.18868 (6% Tax)
    $9.56386 (19% Tax)

    If I enter a coupon code, this is what I see:
    Subtotal: $80.90
    Coupon Discount: - $5.99
    Total: $74.91
    Tax Total: $9.97
    Tax Total contains:
    $1.09292 (6% Tax)
    $8.87758 (19% Tax)

    In my case the tax total adds up. Are you seeing the tax total on the basket page? Have you made any other updates to basket.html? You should try removing all the hacks from basket.html and in awocoupon->configuration setting the "Calculate the discount before tax" to yes.

  • Default avatar
    sattwa    
     12 years ago
    0

    Hi Seyi,

    Thanks for your answer.

    It indeed were custom hacks in basket.html which calculated another discount which messed up the calculation. I am now at the same page as you are, but I am still a little bit confused.

    I have two products which are excluded from these discounts (and also want to exclude their tax from the discount).

    The following happens at the moment a discount is enabled:

    1 X € 21.00 > € 21.00 (6% VAT no discount - excluded from discount in AWOcoupon)
    2 X € 29.95 > € 59.90 (19% VAT discount is 10% above € 50)
    Subtotal: € 80.90
    Discount - € 5.99

    I want the following:
    VAT: € 9.80 (total tax (VAT))
    € 1.19 (6% tax (VAT) - no discount calculated)
    € 8.61 (19% tax (over 53,91 = 59,90-5,99) (VAT))
    Totaal: € 74.91

    I hope I am not asking to much. Hopefully there will be a solutions for this

    Thanks again
  • Your avatar
    seyi    
     12 years ago
    0

    This is a tough one. Ok, so looked at this some more. The main problem is virtuemart assumes once a discount is processed it is on all products, you would have to make changes to the core to get it to work correctly. Here is what I came up with, working with virtuemart 1.1.9:
    in www/administrator/components/com_virtuemart/classes/ps_checkout.php, function calc_order_tax, around line 1617 (in the else loop) is this code

    <?php
                    
    for($i 0$i $cart["idx"]; $i++) {
                        
    $item_weight ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];

                        if (
    $item_weight !=or TAX_VIRTUAL) {
                            
    $price $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
                            
    $price['product_price'] = $GLOBALS['CURRENCY']->convert$price['product_price'], $price['product_currency']);
                            
    $tax_rate $ps_product->get_product_taxrate($cart[$i]["product_id"]);
                    
                            if( (!empty( 
    $_SESSION['coupon_discount'] ) || !empty( $d['payment_discount'] ))
                                && 
    PAYMENT_DISCOUNT_BEFORE == '1' ) {
                                
    $use_coupon_discount= @$_SESSION['coupon_discount'];
                                if( !empty( 
    $_SESSION['coupon_discount'] )) {
                                    if( 
    $auth["show_price_including_tax"] == ) {
                                        
    $use_coupon_discount $_SESSION['coupon_discount'] / ($tax_rate+1);
                                    }
                                }
                                
    $factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $this->_subtotal;
                                
    $price["product_price"] = $price["product_price"] - ($factor $price["product_price"] / 100);
                                @
    $order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate $cart[$i]["quantity"];
                            }
                            
                            
    $order_tax += $price["product_price"] * $tax_rate $cart[$i]["quantity"];
                            
    $total += $price["product_price"] * $cart[$i]["quantity"];
                        }
                    }
    ?>


    change it to this:
    <?php
                    
    # seyi_code
                        
    $coupon_subtotal 0;
                        
    $discount_products = array();
                        if(!empty(
    $_SESSION['coupon_awo_productids'])) {
                            
    $discount_products = @explode(',',$_SESSION['coupon_awo_productids']);
                            for(
    $i 0$i $cart["idx"]; $i++) {
                                if(!
    in_array($cart[$i]["product_id"],$discount_products)) continue;
                                
    $price $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
                                
    $price['product_price'] = $GLOBALS['CURRENCY']->convert$price['product_price'], $price['product_currency']);
                                
    $coupon_subtotal += $price['product_price']*$cart[$i]['quantity'];
                            }
                        }
                        if(
    $coupon_subtotal == 0$coupon_subtotal $this->_subtotal;
                    }
                    for(
    $i 0$i $cart["idx"]; $i++) {
                        
    $item_weight ps_shipping_method::get_weight($cart[$i]["product_id"]) * $cart[$i]['quantity'];

                        if (
    $item_weight !=or TAX_VIRTUAL) {
                            
    $price $ps_product->get_adjusted_attribute_price($cart[$i]["product_id"], $cart[$i]["description"]);
                            
    $price['product_price'] = $GLOBALS['CURRENCY']->convert$price['product_price'], $price['product_currency']);
                            
    $tax_rate $ps_product->get_product_taxrate($cart[$i]["product_id"]);
                    
                            if( (!empty( 
    $_SESSION['coupon_discount'] ) || !empty( $d['payment_discount'] ))
                                && 
    PAYMENT_DISCOUNT_BEFORE == '1' ) {
                                if(!
    in_array($cart[$i]["product_id"],$discount_products)) # seyi_code
                                    
    @$order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate $cart[$i]["quantity"]; # seyi_code
                                
    else {
                                    
    $use_coupon_discount= @$_SESSION['coupon_discount'];
                                    if( !empty( 
    $_SESSION['coupon_discount'] )) {
                                        if( 
    $auth["show_price_including_tax"] == ) {
                                            
    //$use_coupon_discount = $_SESSION['coupon_discount'] / ($tax_rate+1); # seyi_code COMMENT OUT
                                        
    }
                                    }
                                    
    //$factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $this->_subtotal;
                                    
    $factor = (100 * ($use_coupon_discount + @$d['payment_discount'])) / $coupon_subtotal# seyi_code
                                    
    $price["product_price"] = $price["product_price"] - ($factor $price["product_price"] / 100);
                                    @
    $order_tax_details[$tax_rate] += $price["product_price"] * $tax_rate $cart[$i]["quantity"];
                                }
                                
                            }
                            
    $order_tax += $price["product_price"] * $tax_rate $cart[$i]["quantity"];
                            
    $total += $price["product_price"] * $cart[$i]["quantity"];
                        }
                    }
    ?>


    This checks the products that have been discounted and calculates the taxes based on those