Calculation Error Virtuemart


  • Default avatar
    maxlatino74    
     12 years ago
    0

    sen in p. m.
    thanks
    Bye
  • Default avatar
    mipava    
     12 years ago
    0

    Hi Seyi,
    sorry to disturb you, I've tried to get answers from different forum but I didn't find any help for my situation, so I'm trying to ask you support, if possible, because I'm going crazy.

    My situation:

    - I've Joomla 1.5.23 + Virtuemart 1.1.8 + AwoCoupon for Virtuemart - Joomla Component 1.0.10.
    - I want to manage discount (coupon and payment discount) in the way that the discount will be applied after the tax (gross price = net price + 20% tax);
    - addictionally I want to calculate the tax after the discount.

    Example:

    Net price = 10€
    Coupon Discount = 4€
    Payment Discount = 5% on the Product Gross Price, After the Coupon.

    So, in that example I want to have:

    Gross price = 10€ + 20% = 12€
    Total after Coupon = 12€ - 4€ = 8€
    Payment Discount = 5%(8€) = 0.4€
    Total After Coupon & After Payment Discount = 7.6€
    I want to have Tax referred to the 7.6€, not on the 8€ and I'm not able. I used your hack named "Calculation Error Virtuemart". I only see the correct value in the confirmation page of the basket (ro_basket_b2c_html.php) but when I click on the confirmation botton on that page, the value change in wrong and the value is calculated on the total before payment discount (8€ in my example above). Nor in the Order details page, nor into the confirmation email, nor in the Virtuemart Orders (administration site)...

    Please, can you support me because I'm really frustrated about that!

    thanks so much for your time!!!

    Michele.

  • Your avatar
    seyi    
     12 years ago
    0

    I am a little confused, you said you want tax to be calculated on the 7.6, but you have already calculated tax on the product. Can you show example of what you are getting and what you want to get?
  • Default avatar
    mipava    
     12 years ago
    0

    Hi Seyi,
    thanks for your answer!

    I try to be more clear, sorry...

    Yes, of course, I have already calculated tax on the product and I show the product price as gross price (VAT included) but I need to show and have, in the order, in the invoice and in the virtuemart database, gross price, net price and VAT, as separated items. It's due to that my question.

    I'm going to do a better described example:

    The Virtuemart tax configuration as below:

    http://www.berenaturale.it/images/vm_calc_error/Virtuemart-Tax-configuration.JPG

    Translation of terms (Italian to English):

    "Configurazione Tasse" = Tax Configuration
    "Imposta Virtuale" = Virtual Tax
    "Modalità d'imposta" = Tax mode
    "Consenti aliquote multiple" = Enable multiple tax rates
    "Calcola lo sconto prima di applicare l'IVA e le spese di spedizione?" = Subtract payment discount before tax/shipping?


    The configuration of the example I'm going to explain:

    Payment Discount = 5% on payment method "Bonifico Bancario"
    Coupon Discount = - 4€
    VAT = 20% (both on product and shipping)
    Shipping cost = 12€ (10€ + 20% VAT)
    Product price (in the example) = 15€ (12.5€ + 20% VAT)
    Basket has 4 steps

    Translation of terms you'll find in all the link below (Italian to English):

    "Prezzo" = Price
    "Subtotale" = Subtotal
    "Totale" = Total
    "Spedizione" = Shipping
    "IVA Spedizione" = Shipping VAT tax
    "Sconto Coupon" = Coupon Discount
    "Sconto" = Payment Discount
    "di cui IVA" = VAT
    "Succ" = Next
    "Conferma Ordine" = Order Confirmation
    "Metodo Pagamento" = Payment Method

    What I want:

    Subtotal = (Product Price - Coupon Discount) = 15€ - 4 = 11€ ;

    Subtotal = Subtotal - (Payment Discount * Product Price) = 11€ - 5%(11€) = 11€ - 0.55€ = 10.45€

    Total = Subtotal + Shipping cost = 10.45€ + 12€ = 22.45€

    VAT = VAT(Total) = 22.45€ / 1.2 * 0,2 = 3.74€

    What I have:

    when I go to the basket, in the first step, I only have the product, so:

    http://www.berenaturale.it/images/vm_calc_error/basket-1.JPG

    Subtotal = 15€
    Total = 15€
    VAT = VAT(Total) = 20%(15€) = 15€ / 1.2 * 0.2 = 2.5€ (it's correct!)

    Basket - second step: I insert the discount coupon code and I have:

    http://www.berenaturale.it/images/vm_calc_error/basket-2-with-coupon-inserted.JPG

    Subtotal = 15€
    Coupon Discount= - 4€
    Total = Subtotal - Coupon Discount = 15€ - 4€ = 11€
    VAT = VAT(Total) = 20%(11€) = 11€ / 1.2 * 0.2 = 1.83€ (it's correct!)

    Basket - Second step: Shipping choice:
    http://www.berenaturale.it/images/vm_calc_error/basket-2-shipping-method.JPG

    and go to the Payment Method choice:
    http://www.berenaturale.it/images/vm_calc_error/basket-3-choice-of-payment-method.JPG

    in this step, then, I have:

    Subtotal = 15€
    Shipping = 12€
    Coupon Discount = - 4€
    Total = (Subtotal + Shipping - Coupon Discount) = 15€ + 12€ - 4€ = 23€
    VAT = VAT(Total) = 20%(23€) = 23€ / 1.2 * 0.2 = 3.83€ (it's correct!)

    I choice "Bonifico Bancario" as Payment Method and I go ahead:

    http://www.berenaturale.it/images/vm_calc_error/basket-4-confirmation-page.JPG

    in this step, then, I have:

    Subtotal = 15€
    Shipping = 12€
    Sconto = 0,75€ (It's wrong because it does not consider the Coupon discount and it calculate discount on 15€, not on 11€!)
    Coupon Discount = - 4€
    Total = (Subtotal + Shipping - payment Discount - Coupon Discount) = 15€ + 12€ - 0,75 - 4€ = 22.25€ (wrong due to the Payment Method calculation error before)
    VAT = VAT(Total) = 20%(22.25€) = 22.25€ / 1.2 * 0.2 = 3.71€ (correct if referred to the Total above but wrong due to the Payment Method calculation error before)

    by the way... I click on the Confirm Order botton and I go ahead:

    Account order details: http://www.berenaturale.it/images/vm_calc_error/Account-order-details.JPG
    Email confirmation: http://www.berenaturale.it/images/vm_calc_error/Email-confirmation-order.JPG
    Virtuemart administration order view: http://www.berenaturale.it/images/vm_calc_error/Virtuemart-order.JPG

    in all the last 3 above situation the VAT tax calculation is wrong and it's different referred to the VAT calculation seen on the Confirmation Page (3.73€ vs 3.71€) (?!?!?!) ...


    so.. that's all. What I'm looking for is to identify the error in the code to solve this problem.

    I hope my example will be useful and I hope, of course, in your support!

    IMPORTANT NOTE: if I disable the Payment Discount (I set to zero in the Virtuemart) all the calculation are OK!

    Thanks very very very much!
    Michele.







  • Your avatar
    seyi    
     12 years ago
    0

    I see, not sure what is going on once submitted, but lets see if we can get the correct discount to display. Take a look at this solution:
    https://awodev.com/forum/awocoupon/help-section/calculation-error-virtuemart#comment-910

    And change the relevant part of my code to this
    <?php
    $this
    ->get_payment_discount$d['payment_method_id'], $totals['order_subtotal'] + $totals['order_tax'] - @$_SESSION['coupon_discount']);
    ?>
  • Default avatar
    mipava    
     12 years ago
    0

    Thanks Seyi!

    I change the code with your suggestion. Now the situation changed in the good way, I suppose:

    Confirmation page as follow: http://www.berenaturale.it/images/vm_calc_error/2nd-try-after-seyi-change-basket-4-confirmation-page.JPG

    (isn't correct)

    Account Order details as follows: http://www.berenaturale.it/images/vm_calc_error/2nd-try-after-seyi-change-account-order-details.JPG (quite close to be correct - the VAT should be 3.74€, not 3.73€ ... I don't know why this 0.01€ differences...)

    Confirmation email and Virtuemart order database as Account Order details.

    So, I think the way is right but I need to see the correct values even in the confirmation page and the tax value should be as follows:

    VAT(Total) = 20%(22.45€) = 22.45€ / 1.2 * 0.2 = 3,741

    Thanks so much for your support Seyi!

    Michele
  • Your avatar
    seyi    
     12 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
    $payment_discount 
    $ps_checkout -> get_payment_discount($payment_method_id$total - @$_SESSION['coupon_discount']);
    ?>


    For the 3.73, I am not sure, it is probably a rounding issue somewhere
  • Default avatar
    mipava    
     12 years ago
    0

    Wow!! :-) Really really close to the results!!!

    After this 2nd change you suggested I've:

    Confirmation page as follow:
    http://www.berenaturale.it/images/vm_calc_error/3rd-try-after-seyi-change-basket-4-confirmation-page.JPG

    IT'S PERFECT!!!

    Account Order Details as follows:
    http://www.berenaturale.it/images/vm_calc_error/3rd-try-after-seyi-change-account-order-details.JPG

    here there is the difference of 0.01€... maybe somewhere there's a rounding issue but it seems really strange... have you any suggestion on where to investigate?

    the Confirm email and Virtuemart order database as Account Order details.

    Thanks so much for your support!!!

    Addictionally I try different tests, with biggest amount than before and It seems that it is not a rounding issue... in a Total amount order of 189.48€, the total tax calculated is 31.80€ (wrong), instead of 31.58€ (correct). There's a 0.22€ difference and I think that this value it souldn't be a rounding issue... don't you? Have you got any idea to support me in that?

    Many many thanks, Seyi!

    Michele.
  • Your avatar
    seyi    
     12 years ago
    0

    I see what you mean. In order to fix it, I have to understand how it arrived at 31.80 instead of 31.58. Can you post all the amounts in that order and indicate which are right and which are wrong? And also, is it calculated correctly on your confirmation screen?
  • Default avatar
    mipava    
     12 years ago
    0

    Hi Seyi,

    I've tried to answer to your question with some screenshots. Please, take a look on the following url:

    http://www.berenaturale.it/index.php?option=com_content&view=article&id=62

    I hope will be useful to better understand the situation and try to have a solution.

    Thanks very much!!
    Michele.
  • Your avatar
    seyi    
     12 years ago
    0

    Thanks, I know the problem but cannot think of a solution. Within the code

    1) Payment discount is calculated -> using subtotal (wrong)
    2) Order tax is calculated, using wrong payment discount
    3) Payment discount is calculated again, using order tax (this is the first solution I gave you)

    The problem is they need each other to work.

    So here it is:
    1) payment discount is calculated as (184.5/1.2)*0.05 = 7.6875
    2) tax -> (184.5+18-4-7.6875)/1.2*.2 = 31.80
    3) now we calculate payment discount again, using the tax

    So the problem is you need the tax to calculate the payment discount and you need the payment discount to calculate the tax.


    ....
    After more investigation, it looks like the product total with tax is already there. This means you can remove the first solution I gave you and around line 1322 is this lines
    <?php
    if( !empty($d['payment_method_id'])) {
        
    $totals['payment_discount'] = $d['payment_discount'] = $this->get_payment_discount($d['payment_method_id'], $totals['order_subtotal']);
    } else {
        
    $totals['payment_discount'] = $d['payment_discount'] = 0.00;
    }
    ?>


    change the get_pament_discount values to this:
    <?php
    $totals
    ['payment_discount'] = $d['payment_discount'] = $this -> get_payment_discount($d['payment_method_id'], $d['order_subtotal_withtax'] - @$_SESSION['coupon_discount']);
    ?>


  • Default avatar
    mipava    
     12 years ago
    0

    Thanks for your support Seyi!

    when you say "This means you can remove the first solution <...>" you mean this one?:

    https://awodev.com/forum/awocoupon/help-section/calculation-error-virtuemart#comment-1939

    and you mean that I have to go back to 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']);
    ?>


    or to this?:

    <?php
    $d
    ['order_tax'] = $totals['order_tax'] = round$this->calc_order_tax($totals['order_taxable'], $d), );
    ?>


    thanks!!!
    Michele.
  • Your avatar
    seyi    
     12 years ago
    0

    yep, remove it.
  • Default avatar
    mipava    
     12 years ago
    0

    yeahhhh!!! thanks Seyi! you're the BEST! really!

    so, I reply to you only now because I tested the solution in different scenarios (with or without dicount, etc.) and all is OK.

    the only strange thing that I get, I get during a big amount order (a different one of the one I sent to you as example last time).

    - in that order I put 16 different products;
    - 15 of them are without "promotion price", so with full price;
    - 1 of them is with "Promotion price" and the promoted/discounted price is 8.85€;

    I go to the basket, I reach the confirmation page and this one is as follows:

    http://www.berenaturale.it/images/vm_calc_error/VM-Confirmation-page-Big-Amount-Order-2.JPG

    the product with promoted/discounted price is the 1st one you see;

    I confirm the order and when I go to the account order details I see this:

    http://www.berenaturale.it/images/vm_calc_error/VM-Account-Details-View-Big-Amount-Order-2.JPG

    As you can see there's a 0.01€ difference on the Total Price.

    Looking on the VM Admin Order view I see this:

    http://www.berenaturale.it/images/vm_calc_error/VM-Order-View-Big-Amount-Order-2.JPG

    the Total Price, here, is the same as the Total Price on the Account order details and is the Price the client have to pay because is, let me say, the official one, due to the fact that this is the value inserted in the VM database.

    so, try to see what is wrong I check that, probably, the difference is that:

    - Total Price in the confirmation page is calculated on the Product Gross Price (the price that the client see during the basket steps;

    - Total Price calculated (and inserted into the VM DB) after the click on teh "Confirm Order" button in the confirmation page i calculated on the rounded Product Net Price...

    So, it seems it's a rounding issue (in this example, but I think it's a good test to identify the problem) due to the fact that:

    - Total Price (calculated on the gross product price) = 307.41€ (VAT is 51.24€ and is embedded, in this situation, into the Total Price)
    - Total Price (calculated on the net product price) = 241.18€ (as you can see in the VM Admin order view above). The VAT is calculated on that net total price and it's: 241.18 * 0.2 = 48.236€ = 48.24€

    - Shipping is 18€ and the VAT is 3€ (already comprise in the 18€)

    - Total VAT is 48.24€ + 3€ = 51.24€

    BUT....

    If you calculate the gross Total Price starting from the rounded Total net price above, you have: 241.18€ + 51.24€ = 307.42€. This is, at all, the correct Total price that VM say the client has to pay.

    So, why the difference between "Confirmation Page" Total Price and "official" Total Price?

    You can see an excel price scheme of the order, with both net and gross price and VAT:

    http://www.berenaturale.it/images/vm_calc_error/excel-price-scheme.JPG

    Here we can see and understand (I think) that the Confirmation Page Total Price has been calculated based on the Product Gross price; the "offical" total price (the value that has been inserted into the database and used for the confirmation email and for the account order details) has been calculated based not on the Net Price but on the rounded net price... maybe if I have only product with 2 decimal digit all is correct. In this example there's 1 product (the first one in the excel list) that has net price with 3 decimal digit and both VAT and Total price are with 3 decimal digit... this is the issue I think.

    In which way can I tell to VM to calculate the Total price based on the real figures and not based on the rounded figures?

    I know that 0.01€ is peanuts but I think that is the principle that is not correct, don't you?

    Thanks so much Seyi!!!!! You're really great!

    Michele.


    I partially solved changing all the "round" function within the ps_checkout.php from

    round($val, 2 )

    to

    round($val, 3 )

    in this way the Total Price (in the VM database, in the confirmation email and in the account order details) is the same as the confirmation page and it's correct!

    the only thing that is pending is that in the VM database the SubTotal and the TAX are rounded, maybe because the values has only 2 decimal digit. Which is the php script responsible for the insertion of the records in the database? is it possible to insert values with 3 digit?

    thanks so much!
    Michele.





  • Default avatar
    madegrow    
     12 years ago
    0

    This comment has been moved here.

This thread is locked.