PHP Class Mpociot\VatCalculator\VatCalculator

Show file Open project: mpociot/vat-calculator Class Usage Examples

Protected Properties

Property Type Description
$businessCountryCode string
$company boolean
$config Illuminate\Contracts\Config\Repository
$countryCode string
$netPrice float
$postalCode string
$postalCodeExceptions array All possible postal code exceptions.
$soapClient
$taxRate float
$taxRules array Taken from: http://ec.europa.eu/taxation_customs/resources/documents/taxation/vat/how_vat_works/rates/vat_rates_en.pdf
$taxValue float
$value float The calculate net + tax value.

Public Methods

Method Description
__construct ( $config = null )
calculate ( integer | float $netPrice, null | string $countryCode = null, null | string $postalCode = null, null | boolean $company = null ) : float Calculate the VAT based on the net price, country code and indication if the customer is a company or not.
getCountryCode ( ) : string
getIPBasedCountry ( ) : boolean | string Returns the ISO 3166-1 alpha-2 two letter country code for the client IP. If the IP can't be resolved it returns false.
getNetPrice ( ) : float
getPostalCode ( ) : string
getTaxRate ( ) : float
getTaxRateForCountry ( $countryCode, boolean $company = false ) : float Returns the tax rate for the given country code.
getTaxRateForLocation ( string $countryCode, string | null $postalCode = null, boolean | false $company = false ) : float Returns the tax rate for the given country code.
getTaxValue ( ) : float
isCompany ( ) : boolean
isValidVATNumber ( $vatNumber ) : boolean
setBusinessCountryCode ( string $businessCountryCode )
setCompany ( boolean $company )
setCountryCode ( mixed $countryCode )
setPostalCode ( mixed $postalCode )
setSoapClient ( SoapClient $soapClient )
shouldCollectVAT ( $countryCode ) : boolean Determines if you need to collect VAT for the given country code.

Private Methods

Method Description
getClientIP ( ) : mixed Finds the client IP address.

Method Details

__construct() public method

public __construct ( $config = null )

calculate() public method

Calculate the VAT based on the net price, country code and indication if the customer is a company or not.
public calculate ( integer | float $netPrice, null | string $countryCode = null, null | string $postalCode = null, null | boolean $company = null ) : float
$netPrice integer | float The net price to use for the calculation
$countryCode null | string The country code to use for the rate lookup
$postalCode null | string The postal code to use for the rate exception lookup
$company null | boolean
return float

getCountryCode() public method

public getCountryCode ( ) : string
return string

getIPBasedCountry() public method

Returns the ISO 3166-1 alpha-2 two letter country code for the client IP. If the IP can't be resolved it returns false.
public getIPBasedCountry ( ) : boolean | string
return boolean | string

getNetPrice() public method

public getNetPrice ( ) : float
return float

getPostalCode() public method

public getPostalCode ( ) : string
return string

getTaxRate() public method

public getTaxRate ( ) : float
return float

getTaxRateForCountry() public method

This method is used to allow backwards compatibility.
public getTaxRateForCountry ( $countryCode, boolean $company = false ) : float
$countryCode
$company boolean
return float

getTaxRateForLocation() public method

If a postal code is provided, it will try to lookup the different postal code exceptions that are possible.
public getTaxRateForLocation ( string $countryCode, string | null $postalCode = null, boolean | false $company = false ) : float
$countryCode string
$postalCode string | null
$company boolean | false
return float

getTaxValue() public method

public getTaxValue ( ) : float
return float

isCompany() public method

public isCompany ( ) : boolean
return boolean

isValidVATNumber() public method

public isValidVATNumber ( $vatNumber ) : boolean
$vatNumber
return boolean

setBusinessCountryCode() public method

public setBusinessCountryCode ( string $businessCountryCode )
$businessCountryCode string

setCompany() public method

public setCompany ( boolean $company )
$company boolean

setCountryCode() public method

public setCountryCode ( mixed $countryCode )
$countryCode mixed

setPostalCode() public method

public setPostalCode ( mixed $postalCode )
$postalCode mixed

setSoapClient() public method

public setSoapClient ( SoapClient $soapClient )
$soapClient SoapClient

shouldCollectVAT() public method

Determines if you need to collect VAT for the given country code.
public shouldCollectVAT ( $countryCode ) : boolean
$countryCode
return boolean

Property Details

$businessCountryCode protected property

protected string $businessCountryCode
return string

$company protected property

protected bool $company
return boolean

$config protected property

protected Repository,Illuminate\Contracts\Config $config
return Illuminate\Contracts\Config\Repository

$countryCode protected property

protected string $countryCode
return string

$netPrice protected property

protected float $netPrice
return float

$postalCode protected property

protected string $postalCode
return string

$postalCodeExceptions protected property

All possible postal code exceptions.
protected array $postalCodeExceptions
return array

$soapClient protected property

protected $soapClient

$taxRate protected property

protected float $taxRate
return float

$taxRules protected property

Taken from: http://ec.europa.eu/taxation_customs/resources/documents/taxation/vat/how_vat_works/rates/vat_rates_en.pdf
protected array $taxRules
return array

$taxValue protected property

protected float $taxValue
return float

$value protected property

The calculate net + tax value.
protected float $value
return float