redarrow Posted March 18, 2008 Share Posted March 18, 2008 <?php define("VAT",17.5); $price=100.00; $total=$price * VAT; echo $total; ?> shouldnt the total be £117.50 .... i no i can add the + to get the correct result, but that dosent work with all numbered results. Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/ Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 how do i calculate vat at 17.5 sorry please help cheers....... Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495143 Share on other sites More sharing options...
Tjorriemorrie Posted March 18, 2008 Share Posted March 18, 2008 Amount $100 VAT $17.50 (100 x 17.5%) Total $117.50 Thus: $total = $price * (1+ $vat/100); or do it in two steps $VATrate = 17.5; $VATamt = $price * $VATrate; $total = $price + $VATamt; Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495155 Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 that dosent make sence please provide a working example please cheers. Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495166 Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 code i done and it correct thank god SOLVED result <?php DEFINE("VAT",17.5); $price_without_vat=100; $price_with_vat = $price_without_vat + (VAT*($price_without_vat/100)); echo number_format($price_with_vat,2); ?> define example <?php DEFINE("VAT",17.5); $price_without_vat=10; $price_with_vat = $price_without_vat + (VAT*($price_without_vat/100)); echo $price_with_vat; ?> plain varable example <?php $price_without_vat=10; $vat = 17.5; $price_with_vat = $price_without_vat + ($vat*($price_without_vat/100)); echo $price_with_vat; ?> Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495173 Share on other sites More sharing options...
Barand Posted March 18, 2008 Share Posted March 18, 2008 $price_with_vat = $price * 1.175 Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495181 Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 i thort the my solved code is correct is it? solved Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495184 Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 i have designed this code to calculate the current users price with country vat........ any more idears please sugest cheers... <?php session_start(); #database connection.... $db=mysql_connect_db("localhost","username","password"); $db_result=mysql_select_db("database_name",$db); if(!$db_result){ echo "SORRY THERE A DATABASE ERROR!"; exit; } # This code is for users coutry vat #current countrys are: # #Madeira 15 #Cyprus 15 #Luxembourg #Germany #Spain #UK #Estonia #Greece #Latvia #Lithuania #Malta #Czech Rep #Netherlands #Portugal #Slovak Rep #France #Austria #Italy #Slovenia #Belgium #Ireland #Finland #Poland #Denmark #Hungary #Sweden $sql="SELECT * FROM table WHERE vat_added='yes' AND id='".$_SESSION['id']."'"; $sql_result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_assoc($sql_result)){ $_SESSION['current_price']=$row['price']; $_SESSION['country']=$row['country']; } $Vat_country=$_SESSION['country']; switch($Vat_country){ case "Madeira": DEFINE("VAT_Madeira",15); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Madeira*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Cyprus": DEFINE("VAT_Cyprus",15); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Cyprus*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Luxembourg": DEFINE("VAT_Luxembourg",15); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Luxembourg*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Germany": DEFINE("VAT_Germany",16); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Germany*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Spain": DEFINE("VAT_Spain",16); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Spain*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Uk": DEFINE("VAT_UK",17.5); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_UK*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Estonia": DEFINE("VAT_Estonia",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Estonia*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Greece": DEFINE("VAT_Greece",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Greece*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Latvia": DEFINE("VAT_Latvia",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Latvia*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Lithuania": DEFINE("VAT_Lithuania",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Lithuania*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Malta": DEFINE("VAT_Malta",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Malta*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "czech_Rep": DEFINE("VAT_Czech_Rep",18); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Czech_Rep*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Netherlands": DEFINE("VAT_Netherlands",19); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Netherlands*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Portugal": DEFINE("VAT_Portugal",19); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Portugal*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Slovak_Rep": DEFINE("VAT_Slovak_Rep",19); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Slovak_Rep*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "France": DEFINE("VAT_France",19.6); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_France*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case " Austria": DEFINE("VAT_Austria",20); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Austria*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Italy": DEFINE("VAT_Italy",20); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Italy*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Slovenia": DEFINE("VAT_Slovenia",20); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Slovenia*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Belgium": DEFINE("VAT_Belgium",21); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Belgium*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Ireland": DEFINE("VAT_Ireland",21); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Ireland*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Finland": DEFINE("VAT_Finland",22); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Finland*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Poland": DEFINE("VAT_Poland",22); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Poland*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Denmark": DEFINE("VAT_Denmark",25); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Denmark*($price_without_vat/100)); echo number_format($price_with_vat,2); break; case "Hungary": DEFINE("VAT_Hungary",25); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Hungary*($price_without_vat/100)); echo number_format($price_with_vat,2); break; default; DEFINE("VAT_Sweden",25); $price_without_vat=$_SESSION['current_price']; $price_with_vat = $price_without_vat + (VAT_Sweden*($price_without_vat/100)); echo number_format($price_with_vat,2); break; } ?> Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495255 Share on other sites More sharing options...
Barand Posted March 18, 2008 Share Posted March 18, 2008 perhaps <?php $vatrate = array ( 'Madeira' => 15, 'Cyprus' => 15, 'Luxembourg'=> 15, 'Germany' => 16, 'Spain' => 16, 'Uk' => 17.5, 'Estonia' => 18, 'Greece' => 18, // etc ); $price_with_vat = $price * (1 + $vatrate[$country]/100); echo $price_with_vat; ?> Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495261 Share on other sites More sharing options...
redarrow Posted March 18, 2008 Author Share Posted March 18, 2008 Barand your code wins lol, mine took 1 hour your was 1 min cheers mate....... But i was also trying to learn the concept of the vat adding........ I also have now marster the switch as the fingers are blue........ I no you always told me use arrays and functions if your code somethink more then once... But this was a refresh course thanks for your grate support...... Link to comment https://forums.phpfreaks.com/topic/96758-define-to-add-vat-please-help-cheers/#findComment-495280 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.