Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    106
    Plugin Contributions
    0

    help question How is tax rounded off?

    Hi,

    I'm busy adding to my cart the VAT value (20% UK) and I am a little confused on how zen cart calculates it as per the value on the checkout_payment page.

    This is the code I have come up with to do the calculation on my cart:

    Code:
    <div class="cartTotalsColumns">
    <?php
    $tax_vat = 1.2; // 20% Sales tax, 1.2 to give me the amount minus 20% rather than 20% of...
    $total_incl = $_SESSION['cart']->show_total(); // My carts total price inclusive of tax calculated by zen cart.
    $total_excl = ($total_incl/$tax_vat)*100; // The inclusive amount divided by tax to give me exclusive amount (which I multiply by 100 for rounding off purposes as per the next line.
    $total_round_down = floor($total_excl); // round off value to the lowest 10 ('floor' cannot do decimals hence line above).
    $total_decimal = $total_round_down/100; // revert back to decimals for excl. amount.
    $total_decimal2 = number_format($total_decimal,2, '.',''); // ensure 2 decimal places for excl. amount.
    $total_vat = $total_incl - $total_decimal; // calculate actual tax amount.
    $total_vat2 = number_format($total_vat,2, '.',''); // ensure 2 decimal places for tax amount.
    ?>
    	<div class="cartTotalsRight">
    		<?php echo $total_decimal2; ?>
    		<br />
    		<?php echo $total_vat2; ?>
    		<br />
    		<div id="cartSubTotal"><?php echo $cartShowTotal; ?></div>
    	</div>
    	<div class="cartTotalsLeft">
    		Sub-Total excl.:
    		<br />
    		VAT (20% UK):
    		<br />
    		<div id="cartSubTotal">Cart Total:</div>
    	</div>
    </div>
    I did a normal 'round($var, 2);' to round off my values but noticed it was inconsistent with the values shown on the checkout_payments page, hence the reason I have used 'floor' instead. The worked well through my tests but then hit one that did not have the same value.

    So my question is, have I approached this wrongly or am I missing something?

    Thanks,
    Jay

  2. #2
    Join Date
    Jan 2004
    Posts
    66,391
    Blog Entries
    7
    Plugin Contributions
    81

    Default Re: How is tax rounded off?

    Zen Cart calculates tax using the code inside the order-handling code along with also using the active order-totals modules.
    It does NOT do it in the shopping cart page such as your example is doing. Thus the information is not yet available at that point.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Jul 2011
    Posts
    106
    Plugin Contributions
    0

    Default Re: How is tax rounded off?

    Hi Doc,

    Tx for the reply. I understand its not yet available, that's why I am generating the my own exclusive amount and VAT from my carts total i.e. working out my totals backwards. It does work, but only has a couple of issues and I think it has to do with the way zen cart does its rounding off (may be wrong).

    This is how I see Zen Cart doing it (in summary form):

    Item Excluding: £10.00
    VAT: 20%
    VAT Amount: (£10.00 x 20%) or (£10.00 x 0.20) = £2.00
    Inclusive Amount: £10.00 + £2.00 = £12.00

    And this is how get my totals:

    Item Including Tax: £12.00
    VAT: 20%
    Item Excluding: £12.00 / 1.2 = £10.00 = Exclusive amount
    VAT amount: £12.00 - £10.00 = £2.00

    Would I be correct in saying that my method of obtaining such values should give me accurate figures regardless of how zen cart does it?
    And if so, the only discrepancy I can see that would show the values of each method being slightly different would be when it comes to rounding them off to 2 decimals.

    Would I be correct in saying this?

  4. #4
    Join Date
    Jan 2004
    Posts
    66,391
    Blog Entries
    7
    Plugin Contributions
    81

    Default Re: How is tax rounded off?

    You're not going to like this response.

    But, I'm not going to give you a yes or no because there are more factors involved, including products that are not taxable, shipping which is taxable, shipping which is not taxable, prices that are based on even numbers, prices that are based on odd numbers, prices that are multiple decimal places long, sales/specials/discounts based on percentages or based on fixed prices, and so on. Those things are all handled by the order processing and order totals etc code.

    Feel free to suggest to your visitor that your simplified math is offering them an approximation and that the final price will be presented during checkout.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  5. #5
    Join Date
    Jul 2011
    Posts
    106
    Plugin Contributions
    0

    Default Re: How is tax rounded off?

    Hey Doc,

    Good response actually, because I forgot to take into account the non-taxable goods, probably better to just leave it as it was intended.

    thanks for the advice.
    Jay

 

 

Similar Threads

  1. Why sales tax is being rounded up?
    By artcoder in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 4 Apr 2009, 12:26 AM
  2. Replies: 2
    Last Post: 8 Dec 2008, 05:41 PM
  3. Is Tax supposed to be rounded
    By CnTGifts in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 21 Mar 2008, 05:21 PM
  4. Sales tax not being rounded up?
    By birdmag in forum General Questions
    Replies: 5
    Last Post: 14 Feb 2008, 03:30 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR