Calculation Error Virtuemart


  • Default avatar
    claudio    
     13 years ago
    0

    Hi everyone,
    I've an issue related to the surcharge/fee/negative discount that can be associated to a payment method.
    The fact is that there are some errors during the checkout process that can lead to other problems (misunderstanding above all and I tried once with Paypal and the amount due was even different to the ones that were shown in Virtuemart)
    I know that maybe this isn't the most appropriate place to ask for this, but considering that on the VM forums I didn't get an answer, considering that I bought Awocoupon (not that this fact gives me some sort of right but it's because I needed it and also because I'm posting on this forum as a buyer not as a common user not interested at all in the product) and seen a pair of posts in which it seemed that you could have in mind what the problem is (I'm referring to "Virtuemart Coupon Error with discount before tax" or "Coupon does not work correctly"), so I hope that you could help me.

    My current settings are:
    Joomla! 1.5.22
    Virtuemart 1.1.7
    AwoCoupon 1.3.2

    Subtract payment before tax/shipping is unchecked (But since this attempt I made didn't include shipping charges, even when I tried with it checked there were the same exact issues)
    VAT is 8%
    The product costs 10000 Swiss francs,
    its net price is 9259.25926 and the VAT is 740.74 CHF
    I created a product coupon of 4.5%
    I created a -2.5% discount for certain types of payment

    And I start with the checkout
    http://i53.tinypic.com/2wmkiex.jpg
    Then I insert the coupon:
    http://i54.tinypic.com/nl1i4w.jpg
    Here the tax amount is wrong but it's not a major issue because when I proceed and I am on the shipping method selection screen the amount is correct
    http://i52.tinypic.com/21aeof6.jpg
    Then (even if in the screenshot is selected the first one), I choose the second method of payment so I have no shipping charges and I proceed to the payment selection method:
    http://i52.tinypic.com/2yvt4rs.jpg
    I had set a 2.5% negative discount on certain types of payment, but this 2.5 should be calculated on the total amount of the order (which is 10000 CHF), instead, on the payment selection screen, it shows the 2.5% of 9259.25926 in brackets.
    Anyway I choose Postfinance and I go on:
    http://i53.tinypic.com/dlkc9v.jpg
    In this page, the fee is shown on the total amount and the VAT on the fee (which is 2.5% of 250 = 18,52) is added in the total VAT at the bottom which is correct and exactly what I need.
    The further and probably biggest problem is when I go to the account maintenance screen to view my confirmed orders because here I get another different amount:
    http://i52.tinypic.com/140aej7.jpg
    Here the fee is calculated again on the net price and it is added to the total order! So the total amount is changed, not to mention that the VAT is again different.
    Well, excuse me for this long message but I wanted to be as clear as possible, I hope I'll receive an answer because I don't know what to do and even the latest version of virtuemart (I had this error in the 1.1.6) didn't resolve the issue.
    Thank you in advance.

  • Your avatar
    seyi    
     13 years ago
    0

    this is as detailed as I have seen a question. Virtuemart is powerfull but there are some quirks within it that are very very hard to find. I will address your most pressing issue first and we go from there. I think I found the problem, but please test it fully to make sure it works in all situations. In short, when calculating the payment discount/surcharge, it should calculate it on the order total, including tax. But it is only taking into account the sub total. So the fix for this is to send in the right value.

    In www/administrator/components/com_virtuemart/classes/ps_checkout.php around line 1330, you should see this
    <?php
    $d
    ['order_tax'] = $totals['order_tax'] = round$this->calc_order_tax($totals['order_taxable'], $d), );
    ?>


    Right after that line enter this:
    <?php
    # seyi_code
    if( !empty($d['payment_method_id']))
        
    $totals['payment_discount'
            = 
    $d['payment_discount']
            = 
    $this->get_payment_discount($d['payment_method_id'],$totals['order_subtotal']+$totals['order_tax']);
    ?>


    Now the payment discount is recalculated. If you look at line 1312, you will see similar code, but we need to wait until the order tax is determined in order to send in the correct value. This value gets put into the order table, which should then correct the value you see in account maintenance.
  • Default avatar
    claudio    
     13 years ago
    0

    Thanks for your reply Seyi!
    I did as you instructed me and YES! It works magnificently; now the correct VAT and total amounts are shown correctly in the account maintenance and they are sent correctly to the payment processors (paypal, postfinance...) too!
    You're really the best! You should send the code to the VM developers so it could get finally solved once and for all.
    The only issue that remains is on the payment selection screen, because it still shows the percentage on the net price instead of the total amount in the brackets and that could be confusing for a customer who then would find the correct amount; if you have any idea about how to change it (Probably it's just about changing a simple mathematical formula but I don't know where to look for it), it would extremely kind of you :)
    Thank you again for your answer and in advance if you'll reply again.
  • Your avatar
    seyi    
     13 years ago
    0

    To have it display with tax, you have to pass in the order total with tax.

    in www/administrator/components/com_virtuemart/classes/ps_payment_method.php, in function list_payment_radio, right before the while loop:
    <?php
    while ($db->next_record()) {
    ?>


    enter this
    <?php
    $d 
    = array();
    $subtotal $ps_checkout->get_order_subtotal$d );
    $order_total $subtotal $ps_checkout->calc_order_tax($subtotal$d);
    ?>


    and change this line
    <?php
    $discount  
    $ps_checkout->get_payment_discount$db->f("payment_method_id"));
    ?>


    to this
    <?php
    $discount  
    $ps_checkout->get_payment_discount$db->f("payment_method_id"),$order_total);
    ?>

  • Default avatar
    claudio    
     13 years ago
    0

    I did exactly how you instructed and again it works great!
    Thank YOU very much, you have been really kind and helpful, I hope I won't have to bug you again about issues which are in VM and not in Awocoupon.
    After my thanks the least I could do, apart from using Awocoupon PRO, is leaving a review on Joomla Extension Directory; I wrote it and it should be uploaded shortly.
    Thank you again and keep up the good work.
  • Your avatar
    seyi    
     13 years ago
    0

    Thanks for the review, and you are welcome. Glad you have it working the way you want it.
  • Default avatar
    spopple    
     13 years ago
    0

    Hi Seyi,

    I am having the exact same problem as Claudio, but I tried your fix and it didn't work for me. The Card fee is still being calculated on the before tax/shipping net total, not on the final total. I would like to have a payment fee of 1.76% charged on the total invoice value. I have -1.76 entered as the discount for the payment type and I have it set to percentage, I also have tried having "Subtract payment discount before tax/shipping?" ticked and unticked and the same result.
  • Your avatar
    seyi    
     13 years ago
    0

    what version of virtuemart are you using?
  • Default avatar
    spopple    
     13 years ago
    0

    I was using 1.1.5, But I just upgraded to the latest version 1.1.8. I re-applied the "fix" but it is still not working for me.

  • Your avatar
    seyi    
     13 years ago
    0

    I reviewed the solution below, it does not take into account shipping, only the order tax. To take into account shipping, you have to make a few changes. The below is using vm 1.1.8.


    In www/administrator/components/com_virtuemart/classes/ps_checkout.php, inside function calc_order_totals, around line 1361, you should see this
    <?php
    else {
        
    $d['order_shipping'] = $totals['order_shipping'] = $totals['order_shipping_tax'] = $d['order_shipping_tax'] = 0.00;
    }
    ?>


    Right after that line enter this:
    <?php
    # seyi_code
    if( !empty($d['payment_method_id']))
        
    $totals['payment_discount'
            = 
    $d['payment_discount']
            = 
    $this->get_payment_discount($d['payment_method_id'],
                                            
    $totals['order_subtotal']
                                           + 
    $totals['order_tax']
                                           + 
    $totals['order_shipping']
                                           + 
    $totals['order_shipping_tax']);
    ?>





    To have it display with tax, you have to pass in the order total with tax and shipping.

    in www/administrator/components/com_virtuemart/classes/ps_payment_method.php, in function list_payment_radio, right before the while loop:
    <?php
    while ($db->next_record()) {
    ?>


    enter this
    <?php
    $d 
    = array('shipping_rate_id'=>$_REQUEST['shipping_rate_id']);
    $subtotal $ps_checkout->get_order_subtotal$d );
    $subtotal += $d['shipping_tax'];
    $order_total $subtotal $ps_checkout->calc_order_tax($subtotal$d)+$ps_checkout->calc_order_shipping($d);
    ?>


    and change this line
    <?php
    $discount  
    $ps_checkout->get_payment_discount$db->f("payment_method_id"));
    ?>


    to this
    <?php
    $discount  
    $ps_checkout->get_payment_discount$db->f("payment_method_id"),$order_total);
    ?>


    At the very least, this should get you on the right track.
  • Default avatar
    spopple    
     13 years ago
    0

    Excellent, thanks a lot for that Seyi. The card fee is now closer to what it should be.

    My cart looks like this:
    Name SKU Price Quantity Subtotal
    Blue 4mm Female Bullet Terminal (Pack of 100) BBF-4T $7.21 30 $216.30
    Blue Quick Connect Female Terminal Handi-Pack BQCF-1-THP $1.18 1 $1.18

    Subtotal: $217.48
    Shipping and Handling Fee: $15.00
    Tax Total: $23.23

    Total: $255.71

    Please select a Payment Method!
    Credit Card Payment
    Credit Card (+ $4.47)


    By my calculation the subtotal after freight but before tax should be $232.48 and tax (10%) should be $23.248 (or $23.25 rounded to nearest cent).

    Total after tax and freight should be $255.73
    Card fee is set at discount -1.76%, so card fee should be $4.50 (not $4.47)

    Any idea on how to correct these small discrepancies?
  • Your avatar
    seyi    
     13 years ago
    0

    ((217.48*1.1) + 15) *0.0176 = 4.4744
    It assumes shipping tax is inclusive in the $15

    I altered the code in the previous post to fix that, specifically $subtotal += $d['shipping_tax'];
  • Default avatar
    spopple    
     13 years ago
    0

    This did indeed fix the problem.

    The correct amount is now being shown on the emailorder being sent and on the final screen, but on the last page of the checkout where you confirm your order, it is being still shown incorrectly.

    Checkout Page:
    http://i55.tinypic.com/ifvr5z.jpg

    Checkout Page 2:
    http://i52.tinypic.com/15n6fs7.jpg
  • Your avatar
    seyi    
     13 years ago
    0

    in www/administrator/components/com_virtuemart/html/ro_basket.php, change this line
    <?php
    $payment_discount 
    $ps_checkout->get_payment_discount($payment_method_id$total);
    ?>


    to
    <?php
    if( !empty($shipping_rate_id) && !ps_checkout::noShippingMethodNecessary() && !is_null($ps_checkout->_SHIPPING) ) {
        
    $shipping true;
        
    $vars["weight"] = $weight_total;
        
    $shipping_total round$ps_checkout->_SHIPPING->get_rate $vars ), );
    }
    $payment_discount $ps_checkout->get_payment_discount($payment_method_id$total+$shipping_total);
    ?>
  • Default avatar
    spopple    
     13 years ago
    0

    Hi Seyi,

    I applied your fix above, and this is the result, I placed an order on my site, and the checkout pages had figures as below:

    First Checkout Screen:

    Subtotal: 252.90
    Total: 252.90
    Tax: 22.98

    (Shipping +$16.50)


    Second Checkout Screen (After selecting shipping):

    Subtotal: 252.90
    total: 252.90
    freight: 16.50
    total: 269.40
    tax total 24.48

    (card fee +4.71)


    Final Checkout (After entering C/C details):

    Sub-Total: 252.78
    Sub-Total: 252.78
    Shipping: 16.50
    Fee: 4.74
    Total: 274.02
    Tax Total: 24.91



    The email that is sent to the customer had figures shown below:

    Sub-Total: $252.90
    Shipping: $ 16.50
    Tax total: $ 24.85
    Fee $ 4.74
    total $274.13


    Also the amount charged to the C/C was: $274.13
  • Default avatar
    spopple    
     13 years ago
    0

    Any idea on how to fix this?
  • Your avatar
    seyi    
     13 years ago
    0

    can you specify exactly what the problem is? I cannot tell from all the numbers you posted.
  • Default avatar
    maxlatino74    
     13 years ago
    0

    hi Mr. seyi, i have apply your code and i think the best code on this problem, it work very well but only one for me : The only issue that remains is on the payment selection screen i no see the value of discount.. (without your code i see)
    Can you solve it ?
    I use VM 1.1.8
    Thanks
  • Your avatar
    seyi    
     13 years ago
    0

    this is the code that affects the display of the discount/upcharge on the payment selection screen:
    https://awodev.com/forum/awocoupon/help-section/calculation-error-virtuemart#comment-921

    are you sure you did not make a mistake when copying the code?
  • Default avatar
    maxlatino74    
     13 years ago
    0

    thanks for your support
    I thinkthat have make right, now i have this:

    $array[0] = $VM_LANG->_('PHPSHOP_SELECT');

    $d = array();

    $subtotal = $ps_checkout->get_order_subtotal( $d );

    $order_total = $subtotal + $ps_checkout->calc_order_tax($subtotal, $d);

    while ($db->next_record()) {

    $array[$db->f("payment_method_id")] = $db->f("payment_method_name");

    }

    ps_html::dropdown_display('payment_method_id', $payment_method_id, $array );



    }



    and have change original line with this :

    echo "/>\n";

    $discount = $ps_checkout->get_payment_discount( $db->f("payment_method_id") ,$order_total);

    echo "
  • Your avatar
    seyi    
     13 years ago
    0

    the part after $discount looks like it is missing some code. I dont see a label. It should look something like this:

    <?php
    $discount  
    $ps_checkout->get_payment_discount$db->f("payment_method_id"),$order_total);
    echo 
    "<label for=\"".$db->f("payment_method_name")."\">".$db->f("payment_method_name");
    if (
    $discount 0.00) {
        echo 
    " (- ".$CURRENCY_DISPLAY->getFullValue(abs($discount)).") \n";
    }
    elseif (
    $discount 0.00) {
        echo 
    " (+ ".$CURRENCY_DISPLAY->getFullValue(abs($discount)).") \n";
    }
    echo 
    "</label>";
    if (
    $horiz) {
        echo(
    " ");
    } else {
        echo(
    "
    "
    );
    }
    ?>
  • Default avatar
    maxlatino74    
     13 years ago
    0

    see up, only problem when i make new line
  • Default avatar
    maxlatino74    
     13 years ago
    0

    ok, i have make some test and it work without new line $db->f("payment_method_id"),$order_total);

    The only issue that remains is on the payment selection screen, because it still shows the percentage on the net price instead of the total amount in the brackets and that could be confusing for a customer...
    But if i add ,$order_total , it no work :-(
  • Default avatar
    maxlatino74    
     13 years ago
    0

    this little hack neek only 2 files:

    <?php
    else {
        
    $d['order_shipping'] = $totals['order_shipping'] = $totals['order_shipping_tax'] = $d['order_shipping_tax'] = 0.00;
    }
    ?>


    Right after that line enter this:
    <?php
    # seyi_code
    if( !empty($d['payment_method_id']))
        
    $totals['payment_discount']
            = 
    $d['payment_discount']
            = 
    $this->get_payment_discount($d['payment_method_id'],
                                            
    $totals['order_subtotal']
                                           + 
    $totals['order_tax']
                                           - 
    $totals['coupon_discount']);
                                  
    ?>


    and and change this line
    <?php
    $subtotal 
    $this->get_order_subtotal$vars );
    ?>

    to this

    <?php
    $subtotal 
    $this->get_order_total$vars );
    ?>



    only problem is i know how to add code for coupon discount in ro_basket file (i think is this file but no sure) because need add into to last step , without , payment tax no right in display
    <?php
    $payment_discount 
    $ps_checkout->get_payment_discount($payment_method_id$total);
    ?>

    can you help me?

    if i solve i am ok :-)
  • Your avatar
    seyi    
     13 years ago
    0

    Glad you got it working. To add it to the cart in the confirmation you need to look at the template:

    www/components/com_virtuemart/themes/[default]/templates/basket/ro_basket_b2c.html.php

    The coupon code is stored in the session variable $_SESSION['coupon_code']

This thread is locked.