Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

[b]How does OSC work out the TAX Rate?[/b]


shaky

Recommended Posts

Posted

[using MS1]

 

I have my tax rate set at 17.5% on my website, this is creating problems because when I have an item like this:

$1.40 + TAX (17.5%) = $1.645

 

But oscommerce works this out as being $1.64 by rounding down.

 

I want oscommerce to round UP to the next decimal with anything above or equal a 0.005 increment so that the price including TAX should be $1.65 on the website (and not $1.64)

 

Does anyone know where oscommmerce works out the TAX calculation and how I can change it?

 

Modules?

Classes?

SQLDB?

 

Thanks. :lol:

Posted

Hi,

 

I'm not 100% sure if this will work but its worth a go. Back up befor you try!

 

The tax is calculated and rounded in the catalog/includes/functions/general.php file. Around line 336 you'll find the following lines

 

// Calculates Tax rounding the result

 function tep_calculate_tax($price, $tax) {

   global $currencies;



   return tep_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

 }

 

try changing it to....

 

// Calculates Tax rounding the result

 function tep_calculate_tax($price, $tax) {

   global $currencies;



   return tep_round($price * $tax / 100, 3);

 }

 

 

If that doesnt work change the 3 to a 2!

 

If neither works then im stumped :D

 

Goodluck

Reddy to Rumble

 

Thank you osCommerce and all who Contribute to her!

Posted

Woaaaaaaaaaaaahhhh, at first glance it seems to work!!! :D

 

Thank you, thank you so much Rumble, I nearly gave up on this problem.

 

I have absolutely no idea how your syntax operates but the code seems to do the trick, I will check each price individually over the next few days and report any problems for other oscommerce users, but like I said this seems to work at first glance.

 

Many thanks again Rumble, this piece of advice is well worth twenty bucks any day, if you PM me a Paypal link I will be more than happy to honour this just to say thanks.

 

Cheers :lol:

Posted

Ok,

 

I found I was getting some price problems using the above code, however if I change Rumble's code from 3 to 4 as set below, it seems to work really well on my site.

 

// Calculates Tax rounding the result 

 function tep_calculate_tax($price, $tax) { 

   global $currencies; 



   return tep_round($price * $tax / 100, 4); 

 }

 

I think this code is saying: "round total price using the Tax divided by 100 and accurate to the fourth digit" ?

Posted

Now this is really weird, check out what happens at the checkout process after using the above TAX modifying code:

 

whatsinmycarterror.gif

 

I have 4 items listed at $4.95).

 

--------------------------------------------

 

I think the reason for this error is this:

 

The Sub-Total is being worked out from the prices exclusive of TAX.

 

Each item is $4.21 exclusive of TAX, now:

$4.21 x 4 = $16.84

 

The TAX at the rate for $16.84 .

 

So, $16.84 .

 

But it should be $19.80.....

 

How can I tell oscommerce to work out the Sub-Total from the prices including TAX instead of working out the Sub-Total from the prices excluding TAX??

 

:shock:

Posted

I think I have found the answer to this problem:

 

In includes/functions/general.php, replace this line of code:

 

////

// Wrapper function for round() for php3 compatibility

 function tep_round($value, $precision) { 

   if (PHP_VERSION < 4) { 

     $exp = pow(10, $precision); 

     return round($value * $exp) / $exp; 

   } else { 

     return round($value, $precision); 

   } 

 }

 

With this:

 

////

// Wrapper function for round() for php3 compatibility

function tep_round($number, $precision) { 

   if (strpos($number, '.') && (strlen(substr($number, strpos($number, '.')+1)) > $precision)) { 

     $number = substr($number, 0, strpos($number, '.') + 1 + $precision + 1); 



     if (substr($number, -1) >= 5) { 

       if ($precision > 1) { 

         $number = substr($number, 0, -1) + ('0.' . str_repeat(0, $precision-1) . '1'); 

       } elseif ($precision == 1) { 

         $number = substr($number, 0, -1) + 0.1; 

       } else { 

         $number = substr($number, 0, -1) + 1; 

       } 

     } else { 

       $number = substr($number, 0, -1); 

     } 

   } 



   return $number; 

 }

 

And in includes/classes/currencies.php in the format() method, replace this line:

 

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format($number * $rate, $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

 

With this line:

 

$format_string = $this->currencies[$currency_type]['symbol_left'] . number_format(tep_round($number * $rate, $this->currencies[$currency_type]['decimal_places']), $this->currencies[$currency_type]['decimal_places'], $this->currencies[$currency_type]['decimal_point'], $this->currencies[$currency_type]['thousands_point']) . $this->currencies[$currency_type]['symbol_right'];

 

Checkout the full discussion on this topic here:

http://www.oscommerce.com/forums/viewtopic.php?t=37569

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...