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
Bookmarks