Rounding Error in VM 2.0.24


  • Default avatar
    am    
     2 years ago
    0

    Hi,

    I am having issues with rounding on some of my orders. It only seems to be happening with order that contain one of my 15% off order coupon codes. I think it has to do with the coupon code being calculated to three digits when the total is being displayed but it is saved as two digits in the backend. The main issue is that these orders are showing a $0.01 overpayment when I invoice the orders in QuickBooks.

    I am trying to see what I can do to fix this issue. I just wanted to ask here first in case anyone has had the same issues.

    Thanks!

    Link to order breakdown: https://www.morroccomethod.com/uploads/order_total.jpg
  • Your avatar
    seyi    
     2 years ago
    0

    Hello,

    Is the image from Virtuemart order detailed view?

    Can you look directly in the database at #__virtuemart_orders, what numbers do you see for each value? 15% of 113.50 is 17.025, so can see how it might be borderline.
  • Default avatar
    am    
     2 years ago
    0

    This image is from the VM backend order view. Below are the values in the virtuemart_orders table. The value saved in the table for coupon discount looks like its only to two digits, but maybe when it does the calculation during checkout it uses 3 digits?

    order_total: $110.85500
    order_salesPrice: $113.50000
    order_subtotal: $113.50000
    order_shipment: $14.38
    coupon_discount: $-17.03

    Thanks
  • Your avatar
    seyi    
     2 years ago
    0

    Looks like the total is being calculated with:
    113.5 + 14.38 - 17.025 = 110.855
    and rounds to 110.86.

    It does not matter if the database stored the discount in 2 or 3 digits, this would still happen.

    The only thing I can think to do is round the coupon discount to 2 digits and use that in the calculation, and see if that works.

    To do that, you would have to alter this file:
    www/administrator/components/com_awocoupon/helpers/estore/virtuemart/couponhandler.php, line 257 is this
    <?php
            $this
    ->vmcartPrices['couponTax'] = ($coupon_session['product_discount_tax'] + $coupon_session['shipping_discount_tax'] + $coupon_taxbill) * $negative_multiplier;
            
    $this->vmcartPrices['couponValue'] = ($coupon_session['product_discount_notax'] + $coupon_session['shipping_discount_notax']) * $negative_multiplier;
            
    $this->vmcartPrices['salesPriceCoupon'] = ($coupon_session['product_discount'] + $coupon_session['shipping_discount'] + $coupon_taxbill) * $negative_multiplier;
    ?>


    Change it to this
    <?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;
    ?>


    See if that makes a difference.
  • Default avatar
    am    
     2 years ago
    0

    I have applied the changes and will do a few test orders that had issues to see if those calculate correctly and will see if there are anymore issues today. I will update you tomorrow to see if the issue is resolved.

    Thanks
  • Default avatar
    am    
     2 years ago
    0

    Just following up on the issue. All the orders for the past two days have been fine so it looks like the rounding error has been resolved. Thanks for the quick support.
  • Your avatar
    seyi    
     2 years ago
    0

    Great to hear. Thanks for checking back in. Will be added to the code base so you do not need to hack it in the future.