Log in

View Full Version : Adding tax and build fee in php



viper102464
07-15-2006, 12:36 AM
Hello all, im trying to build a website where you can build your own computer. The site is at: http://www.oharanetworks.com/jcr/build/4000/
Im trying to add a sales tax and a 30% build fee onto all of the items in the array. Right now im doing this myself and putting the final value in the array but I know there is an easier way, because that is very time consuming. The entire code is here, sorry but it is a lot, too big to paste in here:
http://www.oharanetworks.com/script.txt

I know what your saying: Why did he do it like this? But this script works flawlessly, I have almost perfected it, but I wanted to add on a final sales tax and build fee on the final price, I dont know how to calculate that in php. Either you could do it for every individual item, or at the end have it calculate it for everything not sure, but please help. Please help me with what I need to get done though, please dont tell me what I should and should not do with either sections of the code that are not related. Thanks, :eek: this is the second time ive had to rewrite this.:confused: :confused:

viper102464
07-15-2006, 03:59 AM
Nevermind, I just added in a couple of functions and solved it, now my problem is with rounding. I cant figure out how to get it to round my tax value. Here are my two functions:


function tax($items) {
$html .= "" . total($items) * .0725 . "";
return $html;
}
function formatItemList($items) {
$si = getSelectedItems($items);
$rt = 0;
$html = '<table style="text-align:right; border-left:1px solid; border-right:1px solid; border-top:1px solid; border-bottom:1px solid;"><tr><th width="737">Item</th><th width="79">Price</th><th width="84">Running Total</th></tr>';
for($i = 0; $i < count($si); ++$i)
$html .= "<tr><td>" . $si[$i]['name'] . "</td><td>\$" . toCurrency($si[$i]['price']) . "</td><td>\$" . toCurrency($rt += $si[$i]['price']) . "</tr>";
$html .= "<tr><td>Tax:</td><td>\$"round(tax($items),2)"</td><td></tr>";
$html .= "<tr><td>JCR Gaming Systems Build Fee:</td><td>\$" . jcrbuildfee($items) . "</td><td></tr>";
$html .= "<tr><td></td></tr><tr><td></td></tr><tr><td><b>Total:</b></td><td>\$" . finaltotal($items) . "</td></tr></table>";
return $html;
}
The tax function gives me a tax, but with like 5 decimal places afterwards, I have tried incorporating the round function into it but it wont work. Please help, thx.:)

jr_yeo
07-15-2006, 04:03 AM
Nevermind, I just added in a couple of functions and solved it

good for u :D

Jesdisciple
07-15-2006, 05:25 AM
You might try echoing javascript into the PHP for the additional costs.

viper102464
07-15-2006, 06:50 AM
Thanks but I just need to know what's wrong with the rounding code posted above? I dont know why it doesn't work. Please help Thnks:) :confused: