Jump to content

[SOLVED] Add 10% to a sum, then add %7 sales tax to that sum


Recommended Posts

Below is the code I am using for my payment processing data capture before relaying to the cc gateway. I need to find out how to add 10% to the total in the script (the $sum), the 10% is the 'buyers premium' (this is for a live physical location auction house) and then after adding that 10% I need to add %7 sales tax onto that and send the data to the merchant gateway with the total updated with the 10% and then the 7%. The basic formula is as follows....

Lets assume the total for the customer is $100 to begin with. Here is what needs to be added..

 

$100 (add the buyers premium of 10%) + 10% = $110 (then add sales tax) + %7 = $117.70

 

Below is the code I am using now, I appreciate any help..

 

<?php
$db_host = "localhost";
$db_user = "xxx_xxx";
$db_pwd = "xxxxxx";
$db_name = "xxx_xxx";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?> 
<?php
$sql = "SELECT * FROM vendor WHERE id=$bidder";
$query = mysql_query($sql);
echo "Bidder Number: " .$_GET[bidder]. "<br>";
while($row = mysql_fetch_array($query)) {
echo "Name: " .$row['name']. "<br>";
echo "Address: " .$row['address1']. "<br>";
echo "City: " .$row['city']. "<br>";
echo "State: " .$row['province']. "<br>";
echo "Postal Code: " .$row['p_code']. "<br>";
echo "Country: " .$row['country']. "<br>";
}
?>
<?php
if ($_GET[method]==cc){
echo "<form method=\"GET\" action=\"cccapture.php\">";
}
else if ($_GET[method]==check){
echo "<form method=\"GET\" action=\"checkcapture.php\">";
}
else if ($_GET[method]==cash){
echo "<form method=\"GET\" action=\"cashdbupdate.php\">";
}
?>
<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}
$sum = number_format(array_sum($sum),2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum;
?>
<br>
</div>
<div style="padding-left:185px;">
<?php
if ($_GET[method]==cc){
echo "<input type=\"submit\" value=\"Process CC Payment\" name=\"submit\">";
}
else if ($_GET[method]==check){
echo "<input type=\"submit\" value=\"Process Check Payment\" name=\"submit\">";
}
else if ($_GET[method]==cash){
echo "<input type=\"submit\" value=\"Process Cash Payment\" name=\"submit\">";
}
?>
</form>

you would need to do something like

 

$sum=100

$suma=$sum*1.10;

$sumb=$suma*1.07;

 

Which SHOULD if the maths is working give you the $sumb value being 117.70, inside the phptags

<?php
$sum=100
$suma=$sum*1.10;
$sumb=$suma*1.07;    // This is the last part and the variable you will want to pass onto the processing form.

$sql = "SELECT * FROM vendor WHERE id=$bidder";
$query = mysql_query($sql);
echo "Bidder Number: " .$_GET[bidder]. "<br>";
while($row = mysql_fetch_array($query)) {
echo "Name: " .$row['name']. "<br>";
echo "Address: " .$row['address1']. "<br>";
echo "City: " .$row['city']. "<br>";
echo "State: " .$row['province']. "<br>";
echo "Postal Code: " .$row['p_code']. "<br>";
echo "Country: " .$row['country']. "<br>";
}
?>
<?php
if ($_GET[method]==cc){
echo "<form method=\"GET\" action=\"cccapture.php\">";
}
else if ($_GET[method]==check){
echo "<form method=\"GET\" action=\"checkcapture.php\">";
}
else if ($_GET[method]==cash){
echo "<form method=\"GET\" action=\"cashdbupdate.php\">";
}
?>
<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}
$sum = number_format(array_sum($sum),2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Due: " .$sum;
?>
<br>
</div>
<div style="padding-left:185px;">
<?php
if ($_GET[method]==cc){
echo "<input type=\"submit\" value=\"Process CC Payment\" name=\"submit\">";
}
else if ($_GET[method]==check){
echo "<input type=\"submit\" value=\"Process Check Payment\" name=\"submit\">";
}
else if ($_GET[method]==cash){
echo "<input type=\"submit\" value=\"Process Cash Payment\" name=\"submit\">";
}
?>
</form>

Please if anyone sees a problem feel free to correct but as far as i can see that is the quickest and simplest way.

Well, im assuming you need to perform this multiplication on the $sum variable used here:

 

$sum = number_format(array_sum($sum),2);

 

In which case, this should do:

 

$sum = number_format(array_sum($sum*1.1*1.07),2);

 

Burtybob: There's no need to use so many variables. The multiplication doesn't need to be done separately.

I must be doing something wrong, none of the above codes are working for me. Here is a copy of the php functions on that page...

 

 

<?php
$db_host = "localhost";
$db_user = "xxx_xxx";
$db_pwd = "xxxxxx";
$db_name = "auction_asset";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?> 
<?php
$sql = "SELECT * FROM vendor WHERE id=$bidder";
$query = mysql_query($sql);
echo "Bidder Number: " .$_GET[bidder]. "<br>";
while($row = mysql_fetch_array($query)) {
echo "Name: " .$row['name']. "<br>";
echo "Address: " .$row['address1']. "<br>";
echo "City: " .$row['city']. "<br>";
echo "State: " .$row['province']. "<br>";
echo "Postal Code: " .$row['p_code']. "<br>";
echo "Country: " .$row['country']. "<br>";
echo "Exempt: ";
if ($row['exempt']==1)
{echo "Not Exempt";}
else if ($row['exempt']==0)
{echo "Exempt";}
echo "<br>";
}
?>
<?php
if ($_GET[method]==cc){
echo "<form method=\"GET\" action=\"cccapture.php\">";
}
else if ($_GET[method]==check){
echo "<form method=\"GET\" action=\"checkcapture.php\">";
}
else if ($_GET[method]==cash){
echo "<form method=\"GET\" action=\"cashdbupdate.php\">";
}
?>
<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}

$sum = number_format(array_sum($sum*1.1*1.07),2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum\">Total Bid Amounts: " .$sum;
?>
<br>
</div>
<div style="padding-left:185px;">
<?php
if ($_GET[method]==cc){
echo "<input type=\"submit\" value=\"Process CC Payment\" name=\"submit\">";
}
else if ($_GET[method]==check){
echo "<input type=\"submit\" value=\"Process Check Payment\" name=\"submit\">";
}
else if ($_GET[method]==cash){
echo "<input type=\"submit\" value=\"Process Cash Payment\" name=\"submit\">";
}
?>

Ok, I found something that is the right direction, someone can easily figure this out (I am obviously retarded at this point). the following function WILL calculate the tax amount, the only problem is it has a code in it that does not pull the variable $sum and I have to type the total in, which will not work for what I am trying to do. Anyone know how to make the $sum filed work on that last line that says Tax($sum); ? I am copying both the code that DOES return the correct percentage (first copy and paste below) but the value for $sum has to be manually typed in, and I am copying the second code that DOES NOT calculate the percentage because where it says Tax($sum) the value for $sum is not being put in as it should.

 

Please help :)

 

function Tax($sum){
$tax=($sum*10)/100;
echo "Tax for ".$sum." is :".$tax;
return;
}
Tax(1007);

 

function Tax($sum){
$tax=($sum*10)/100;
echo "Tax for ".$sum." is :".$tax;
return;
}
Tax($sum);

Thanks Barand! You saved my project!! I greatly appreciate it, the script works correctly now.

 

I do have one more issue with this script... I made an if/elseif statement to only add the buyer premium and not the tax if the customer is listed in our database as being a reseller with a tax exempt certificate on file. The problem is it will not display the tax portion at all now, just the buyer premium (the 10%), which is the final 'elseif' statement that only adds the buyer premium if the database has them set as 'Not Tax Exempt', the begining 'if' statement does not ever display, even on buyers records who are listed in the databse as 'Tax Exempt' here is the code....

 

<?php
$sql = "SELECT * FROM checkout WHERE bidnum=$bidder AND paid='no'";
$query = mysql_query($sql);
$sum = array();
$sum2 = array();
$sum3 = array();
while($row = mysql_fetch_array($query)) {
$sum[] = $row['amt'];
$sum2[] = $row['amt'];
$sum3[] = $row['amt'];
$di = $row['id'];
echo "Lot Number " .$row['lotnum']. ": $" .$row['amt']. "<br>";
}
$sum = number_format(array_sum($sum),2);
echo "Bids Total: " .$sum;
echo "<br>";

if ($row['exempt']==1)
{$sum2 = number_format(array_sum($sum2)*1.1,2);
echo "Total+Premium: " .$sum2;
echo "<br>";
$sum3 = number_format(array_sum($sum3)*1.1*1.07,2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum3\">Total+Premium+Tax: " .$sum3;}
else if ($row['exempt']==0)
{$sum2 = number_format(array_sum($sum2)*1.1,2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum2\">Total+Premium: " .$sum2;}
?>

i figured it out guys..here is the code...

 

if($exempt == "1"){
$sum2 = number_format(array_sum($sum2)*1.1,2);
echo "Total+Premium: " .$sum2;
echo "<br>";
$sum3 = number_format(array_sum($sum3)*1.1*1.07,2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum3\">Total+Premium+Tax: " .$sum3;
} else {
{$sum2 = number_format(array_sum($sum2)*1.1,2);
echo "<input type=\"hidden\" name=\"bidder_number\" value=\"$bidder\">";
echo "<input type=\"hidden\" name=\"idx\" value=\"$di\">";
echo "<input type=\"hidden\" name=\"amount\" value=\"$sum2\">Total+Premium: " .$sum2;}
}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.