VM not calcing taz correct with coupon


  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    I have an issue when users use coupons with VM. Example

    Sub total of $159.50 at 7% tax should be $11.17

    However, if a user uses a $100 overall coupon to make the subtotal be $59.50 the tax calculated at 7% by VM is $4.62 when 7% of $59.50 is actually $4.17.

    Looking closer at this the $4.62 appears to be based on a sub of $66 rather than the $59.50 it should be. There is $7.50 somewhere that is part of the calc that is not showing. Or the tax rates is being increased somewhere.

    It Calculates tax correctly without coupons.

    Suggestions?

    - Mike
  • Your avatar
    seyi    
     10 years ago
    0

    Hello,

    Are you using virtuemart calculation rule for tax per bill? If so please try this:
    https://awodev.com/forum/awocoupon/help-section/coupon-discount-amount-incorrect#comment-6926


    I believe this is what is happening:

    Your total discount is 100
    Your discount before tax is 93.46
    Your discount tax is 6.54

    In the calculations your discount tax is being taxed and added to the total tax:
    4.165 + 6.54*.07 = 4.62
  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    Your instructions say to look in /administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php around line 384 for
    <?php
            
    // update cart objects
            
    $this->vmcartPrices['couponTax'] = round($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill,2) * $negative_multiplier;
            
    $this->vmcartPrices['couponValue'] = round($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax'],2) * $negative_multiplier;
            
    $this->vmcartPrices['salesPriceCoupon'] = round($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill,2) * $negative_multiplier;
            
    $this->vmcartPrices['billSub'] -= $this->vmcartPrices['couponValue']*$negative_multiplier;
            
    $this->vmcartPrices['billTaxAmount'] -= $this->vmcartPrices['couponTax']*$negative_multiplier;
            
    $this->vmcartPrices['billTotal'] -= $this->vmcartPrices['salesPriceCoupon']*$negative_multiplier;
    ?>


    However I do not see this at line 384. I see this at about line 753.
    <?php
            $this
    ->vmcartPrices['couponTax'] = round($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill,2) * $negative_multiplier;

            
    $this->vmcartPrices['couponValue'] = round($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax'],2) * $negative_multiplier;

            
    $this->vmcartPrices['salesPriceCoupon'] = round($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill,2) * $negative_multiplier;

            if(isset(
    $this->vmcartPrices['billSub'])) $this->vmcartPrices['billSub'] -= $this->vmcartPrices['couponValue'];

            if(isset(
    $this->vmcartPrices['billTaxAmount'])) $this->vmcartPrices['billTaxAmount'] -= $this->vmcartPrices['couponTax'];

            if(isset(
    $this->vmcartPrices['billTotal'])) $this->vmcartPrices['billTotal'] -= $this->vmcartPrices['salesPriceCoupon'];
    ?>


    Is this the correct place?

    - Mike
  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    then there is this at line 1007

    <?php
                
    // update cart objects

                
    $this->vmcartPrices['couponTax'] = round($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill,2) * $negative_multiplier;

                
    $this->vmcartPrices['couponValue'] = round($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax'],2) * $negative_multiplier;

                
    $this->vmcartPrices['salesPriceCoupon'] = round($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill,2) * $negative_multiplier;

                
    $this->vmcartPrices['billSub'] -= $this->vmcartPrices['couponValue']*$negative_multiplier;

                
    $this->vmcartPrices['billTaxAmount'] -= $this->vmcartPrices['couponTax']*$negative_multiplier;

                
    $this->vmcartPrices['billTotal'] -= $this->vmcartPrices['salesPriceCoupon']*$negative_multiplier;
    ?>


    Should get updated too?

    - Mike
  • Your avatar
    seyi    
     10 years ago
    0

    Wrong post. Please look at post number 9.
  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    Oh okay, I'm trying that one. It is around line 108 not 62. Trying now.

    - Mike
  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    With this change I made a test with 10% tax rate to make simple. Order sub total is 159.50 less $100 coupon makes $59.50 subtotal. Tax should be $5.95 but is coming out as $6.86. It is calculated tax based on $68.60 making for a $9.10 discrepancy in taxable fees.

    - Mike
  • Default avatar
    mbrando    
     10 years ago
    0

    Hello,

    I did not realize that this was enabling a feature in the config area of AWO.

    Setting "Calculate the discount before tax (Coupons)" to yes fixed it.

    - Mike
  • Your avatar
    seyi    
     10 years ago
    0

    Ok great, glad it is working now.
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    New twist on calculation. After enabling 'Calculate the discount before tax (Coupons)' the calculations now appear to deduct a tax calculation based on the discount amount. In this case $7.00

    Here is how the calculation is working for an order:

    1 $145.00
    2 $14.50
    Sub $159.50
    coupon -$100.00
    Sub $59.50

    shipping $6.00
    Free Shipping -$6.00
    SUB $59.50
    Coupon Tax -$7.00
    7% Tax $4.17

    $56.67

    To explain.

    lines 1 and 2 are added together. $159.50

    The coupon is deducted $159.50 - $100 = $59.50

    Free shipping 100% of shipping total $6.00 - $6.00 = $0 shipping

    Tax to be paid it 7% of Subtotal $59.50 * 0.07 = $4.17 tax

    Tax on the $100 discount is deducted from the final total.

    I'd think that the final total is the sub of $59.50 plus 7% tax $4.17 = $63.67

    Instead it looks like it is deducting 7% of the discount too.

    How do we get just the subtotal plus subtotal tax plus shipping if there for a final total?

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    Hi Mike,

    Not sure I fully follow? So the total is showing as 56.67 instead of 63.67?

    In the order are you using 2 coupons to get a coupon discount and free shipping?
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    Yes, correct. It is showing the final fee as 56.67when I think It should be $63.67. Yes there is free shipping and shipping is $6.00.

    There is a parent coupon with 2 children one $100 off and one 100% off shipping.

    This is the site:

    https://catalog.libertyfund.org/

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    Ok, and just to verify you still have injection mode set to yes in awocoupon->configuration?
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    With injection mode set to yes it will accept the coupon. However it does not apply any of the discounts.

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    Ok, set it to yes, then add the below code. There is a problem updating on the later virtuemart versions, which will be fixed in the next update:

    in www/administrator/components/com_virtuemart/helpers/calculationh.php, around line 890 is this:
    <?php
                
    if($this->_cartPrices['billTaxAmount'] < 0){
                    
    $this->_cartPrices['billTaxAmount'] = 0.0;
                }
    ?>


    Right after that add this:
    <?php
                
    # awocoupon_code ===============================================================
                    
    JPluginHelper::importPlugin('vmcoupon');
                    
    $dispatcher JDispatcher::getInstance();
                    
    $dispatcher->trigger('plgVmUpdateTotals', array(&$this->_cartData, &$this->_cartPrices));
                }
    ?>


    Then test the coupon again
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    I made this change to core VM file as indicated. It works correctly now with the core file modification in place.

    $159.50 sub total
    -$106.00 coupon $100 discount plus free shipping.
    $4.17 Tax
    $6.00 shipping

    $63.67 final fee.

    Now the big question. How do we do this using an override or method that will survive VM updates/patches?

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    Hello,

    Glad to see it is working well now.

    There is no way I would override the calculationh class. That is at the heart of calculation of all prices/totals in Virtuemart. On an update you would simply go to awocoupon->installation check and reinstall the code. Granted it does not work now for vm 2.6.10 and up, but it will on the next release.

    The above step in most cases will not be necessary as I would put in a fail safe to first check if the code is there, and if not install it before processing a coupon.
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    We are running VirtueMart 2.6.12.2 version.

    Can you explain, "...I would put in a fail safe to first check if the code is there, and if not install it before processing a coupon."

    How Can I automate this hack? Or have a notice sent if it does not exist?

    - Mike
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    So there is no way to export that additional tax to a variable or to calculate the addition tax so it can be added back to the final fee in the coupon template or something?

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    Basically if the injection does not exist and you have injection mode set to 'yes', then it will install it.
  • Your avatar
    seyi    
     9 years ago
    0

    Yes, spent 2 frustrating days trying to figure out how to send in the tax to virtuemart so it all comes out correctly. Just did not work. The problem is virtuemart does multiple calculations on the data sent from coupons, starting somewhere around virtuemart version 2.0.24. Besides it is just not a clean solution sending in the wrong information so after Virtuemart calculates, the correct information can come back. The calculations could change at any time and would have to repreat the process.
  • Default avatar
    mbrando    
     9 years ago
    0

    Hello,

    >>Basically if the injection does not exist and
    >>you have injection mode set to 'yes',
    >>then it will install it.

    Is this part of the AWO or something I'd have to pay someone to code?

    - Mike
  • Your avatar
    seyi    
     9 years ago
    0

    It will be part of AwoCoupon. Sorry for the confusion.