PDA

View Full Version : tax calculation



paul
08-05-2004, 07:43 AM
I'm trying locate a custom mod in the global file which adds tax after the shipping costs-here's the code which worked in my old version with the changes in blue and the new file below-I tried uploading the old file into the new version but it doesn't work.
// ###################### apply tax ##################
function applytax ($subtotal){
global $DB_site, $dbprefix;
$userinfo = getuser();
//echo$subtotal = subtotal(2);
//$shipping = subtotal(2);
$tax = "0.00";
if ($userinfo[ctax] == "0") {
return "0.00";
}

$temps=$DB_site->query("SELECT * FROM ".$dbprefix."taxes");
while ($row=$DB_site->fetch_array($temps)) {
if($userinfo[bstate] == $row[tvalue] && $row[type] == 1) {
$tax += p(($subtotal) * ($row[rate]/100));
}
if($userinfo[bcountry] == $row[tvalue] && $row[type] == 2) {
$tax += p(($subtotal) * ($row[rate]/100));
}
if($userinfo[zip] == $row[tvalue] && $row[type] == 3) {
$tax += p(($subtotal) * ($row[rate]/100));
}
}
return $tax;
}
// ###################### apply tax ##################
function applytax () {
global $DB_site, $dbprefix;
$userinfo = getuser();
$subtotal = subtotal(2);
$tax = "0.00";
if ($userinfo[ctax] == "0") {
return $tax;
}

$temps=$DB_site->query("SELECT * FROM ".$dbprefix."taxes");
while ($row=$DB_site->fetch_array($temps)) {
$area=$DB_site->query_first("SELECT * FROM ".$dbprefix."state_country where id='$row[tvalue]'");
if($userinfo[bstatet] == $area[abb] && $row[type] == 1) {
$tax += p($subtotal * ($row[rate]/100));
}
if($userinfo[bcountry] == $area[abb] && $row[type] == 2) {
$tax += p($subtotal * ($row[rate]/100));
}
if($userinfo[zip] == $area[abb] && $row[type] == 3) {
$tax += p($subtotal * ($row[rate]/100));
}
}
return $tax;
}

Here's what the first code displays:

Subtotal: 359.10
Shipping: 7.50
VAT @ 17.5%: 0.00
Total: 366.60