Jump to content

define to add vat please help cheers......


redarrow

Recommended Posts

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;       
?>

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;

}
?>

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;     
?>

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......

Archived

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

×
×
  • 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.