Documentation

Vat
in package

Tags
copyright

CLOUDREXX CMS - CLOUDREXX AG

author

Reto Kohli reto.kohli@comvation.com

access

public

version
3.0.0
subpackage

module_shop

Table of Contents

Constants

TEXT_CLASS  = 'vat_class'
Text key

Properties

$arrVat  : array<string|int, mixed>
entries look like VAT ID => array( 'id' => VAT ID, 'rate' => VAT rate (in percent, double), 'class' => VAT class name, )
$arrVatEnabled  : array<string|int, mixed>
$arrVatIncluded  : bool
$is_home_country  : bool
The current order goes to the shop country if true.
$is_reseller  : bool
The current user is a reseller if true Defaults to false.
$vatDefaultId  : float
$vatDefaultRate  : float
$vatOtherId  : float

Methods

addVat()  : bool
Add the VAT class and rate to the database.
amount()  : float
Calculate the VAT amount using the given rate (percentage) and price.
calculateDefaultTax()  : float
Returns the VAT amount using the default rate for the given price.
calculateOtherTax()  : float
Returns the VAT amount using the other rate for the given price.
deleteVat()  : bool
Remove the VAT with the given ID from the database
errorHandler()  : bool
Tries to fix database problems
format()  : string
Return the vat rate with a trailing percent sign for the given percentage.
getArray()  : array<string|int, mixed>
Return the array of IDs, rates, and class names
getArrayById()  : array<string|int, mixed>
Returns an array with all VAT record data for the given VAT ID
getAssociatedTaxRate()  : float
Return the VAT rate associated with the product.
getClass()  : string
Return the vat class for the given VAT ID, if available, or a warning message if the entry could not be found.
getDefaultId()  : int
Returns the default VAT ID
getDefaultRate()  : float
Returns the default VAT rate
getLong()  : string
Return the long VAT rate, including the class, rate and a trailing percent sign for the given Vat ID, if available, or a warning message if the entry could not be found.
getLongMenuString()  : string
Returns a HTML dropdown menu with IDs as values and VAT classes plus rates as text.
getMenuoptions()  : string
Return the HTML dropdown menu options code with IDs as values and VAT classes plus rates as text.
getOtherId()  : int
Returns the other VAT ID
getOtherRate()  : float
Returns the other VAT rate
getRate()  : float
Return the vat rate for the given VAT ID, if available, or '0.0' if the entry could not be found.
getShort()  : string
Return the short vat rate with a trailing percent sign for the given Vat ID, if available, or '0.0%' if the entry could not be found.
getShortMenuString()  : string
Returns a HTML dropdown menu with IDs as values and VAT rates as text.
init()  : void
Initialize the Vat object with current values from the database.
is_home_country()  : bool
Get or set the home country flag
is_reseller()  : mixed
Set the reseller flag
isEnabled()  : bool
Returns true if VAT is enabled, false otherwise
isIncluded()  : bool
Returns true if VAT is included, false otherwise
isIncludedInRetailButNotInReseller()  : bool
Check if retail-prices are VAT-inclusive, but not reseller-prices.
updateVat()  : bool
Update the VAT entries found in the array arguments in the database.

Constants

TEXT_CLASS

Text key

public mixed TEXT_CLASS = 'vat_class'

Properties

$arrVat

entries look like VAT ID => array( 'id' => VAT ID, 'rate' => VAT rate (in percent, double), 'class' => VAT class name, )

private static array<string|int, mixed> $arrVat = false

The Vat rate and class array

Tags
static
access

private

$arrVatEnabled

private static array<string|int, mixed> $arrVatEnabled = false
               Indicates whether VAT is enabled for
               customers or resellers, home or foreign countries

Indexed as follows: $arrVatEnabled[is_home_country ? 1 : 0][is_reseller ? 1 : 0] = is_enabled

Tags
static
access

private

$arrVatIncluded

private static bool $arrVatIncluded = false
               Indicates whether VAT is included for
               customers or resellers, home or foreign countries.

Indexed as follows: $arrVatIncluded[is_home_country ? 1 : 0][is_reseller ? 1 : 0] = is_included

Tags
static
access

private

$is_home_country

The current order goes to the shop country if true.

private static bool $is_home_country = true

Defaults to true.

$is_reseller

The current user is a reseller if true Defaults to false.

private static bool $is_reseller = false

$vatDefaultId

private static float $vatDefaultId = false

The default VAT ID

Tags
static
access

private

$vatDefaultRate

private static float $vatDefaultRate

The default VAT rate.

Tags
see
init()
see
calculateDefaultTax()
static
access

private

$vatOtherId

private static float $vatOtherId = false

The other VAT ID for fees and post & package

Tags
static
access

private

Methods

addVat()

Add the VAT class and rate to the database.

public static addVat(mixed $vatClass, mixed $vatRate[, int $localeId = 0 ]) : bool

Checks if the rate is a non-negative decimal number, the class string may be empty. Note that VAT class names are only visible in the backend. Thus, the backend language is used to display and store those Texts. Remember to re-init() the Vat class after changing the database table.

Parameters
$vatClass : mixed
$vatRate : mixed
$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Tags
static
access

public

global

ADONewConnection

Return values
bool

True if the values were accepted and successfully inserted into the database, false otherwise.

amount()

Calculate the VAT amount using the given rate (percentage) and price.

public static amount(float $rate, float $price) : float

Note: This function returns the correct amount depending on whether VAT is enabled in the shop, and whether it's included or not. It will not behave as a "standard" interest function! Also note that the value returned will neither be rounded nor number_format()ted in any way, so prepare it for displaying yourself. See for a way to do this.

Parameters
$rate : float

The rate in percent (%)

$price : float

The (product) price

Tags
static
author

Reto Kohli reto.kohli@comvation.com

Return values
float

Tax amount

calculateDefaultTax()

Returns the VAT amount using the default rate for the given price.

public static calculateDefaultTax(float $price) : float

Note that the amount returned is not formatted as a currency, nor are any checks performed on whether VAT is active or not!

Parameters
$price : float

The price

Tags
static
Return values
float

The VAT amount

calculateOtherTax()

Returns the VAT amount using the other rate for the given price.

public static calculateOtherTax(float $price) : float

Note that the amount returned is not formatted as a currency.

Parameters
$price : float

The price

Tags
static
Return values
float

The VAT amount

deleteVat()

Remove the VAT with the given ID from the database

public static deleteVat(mixed $vatId) : bool

Note that VAT class names are only visible in the backend. Thus, the backend language is used to display and store those Texts. Remember to re-init() the Vat class after changing the database table.

Parameters
$vatId : mixed
Tags
static
access

public

global

ADONewConnection

Return values
bool

True if the values were accepted and successfully inserted into the database, false otherwise.

errorHandler()

Tries to fix database problems

public static errorHandler() : bool

Also migrates text fields to the new structure. Note that no VAT classes are added here (yet), so neither the old nor the new table exists to begin with, the new structure will be created with no records.

Tags
throws
Update_DatabaseException
Return values
bool

False. Always.

format()

Return the vat rate with a trailing percent sign for the given percentage.

public static format(float $rate) : string
Parameters
$rate : float

The Vat rate in percent

Tags
static
static
access

public

Return values
string

The resulting string

getArray()

Return the array of IDs, rates, and class names

public static getArray() : array<string|int, mixed>

The ID keys correspond to the IDs used in the database. Use these to get the respective VAT class.

Tags
access

public

static
Return values
array<string|int, mixed>

The VAT array

getArrayById()

Returns an array with all VAT record data for the given VAT ID

public static getArrayById(int $vatId) : array<string|int, mixed>

The array returned contains the following elements: array( 'id' => VAT ID, 'class' => VAT class name 'rate' => VAT rate in percent )

Parameters
$vatId : int

The VAT ID

Return values
array<string|int, mixed>

The VAT data array on success, false otherwise

getAssociatedTaxRate()

Return the VAT rate associated with the product.

public static getAssociatedTaxRate(float $product_id) : float

If the product is associated with a VAT rate, the rate is returned. Otherwise, returns -1. Note: This function returns the VAT rate no matter whether it is enabled in the shop or not. Check this yourself!

Parameters
$product_id : float

The product ID

Tags
global

ADONewConnection

static
Return values
float

The (positive) associated vat rate in percent, or -1 if the record could not be found.

getClass()

Return the vat class for the given VAT ID, if available, or a warning message if the entry could not be found.

public static getClass(int $vatId) : string
Parameters
$vatId : int

The VAT ID

Tags
access

public

global

array

static
Return values
string

The VAT class, or a warning

getDefaultId()

Returns the default VAT ID

public static getDefaultId() : int
Tags
static
Return values
int

The default VAT ID

getDefaultRate()

Returns the default VAT rate

public static getDefaultRate() : float
Tags
static
Return values
float

The default VAT rate

getLong()

Return the long VAT rate, including the class, rate and a trailing percent sign for the given Vat ID, if available, or a warning message if the entry could not be found.

public static getLong(int $vatId) : string
Parameters
$vatId : int

The Vat ID

Tags
access

public

global

array

static
Return values
string

The resulting string

getLongMenuString()

Returns a HTML dropdown menu with IDs as values and VAT classes plus rates as text.

public static getLongMenuString([int $selected = '' ][, string $menuname = '' ][, string $attributes = '' ]) : string

The tags are only added if you also specify a name for the menu as second argument. Otherwise you'll have to add them later. The $selectAttributes are added to the tag

$attributes : string = ''

Optional attributes for the ...)

getMenuoptions()

Return the HTML dropdown menu options code with IDs as values and VAT classes plus rates as text.

public static getMenuoptions([int $selected = '' ][, bool $flagLong = false ]) : string
Parameters
$selected : int = ''

The optional preselected VAT ID

$flagLong : bool = false

Include the VAT class name if true

Tags
access

public

static
Return values
string

The dropdown menu options HTML code

getOtherId()

Returns the other VAT ID

public static getOtherId() : int
Tags
static
Return values
int

The other VAT ID

getOtherRate()

Returns the other VAT rate

public static getOtherRate() : float
Tags
static
Return values
float

The other VAT rate

getRate()

Return the vat rate for the given VAT ID, if available, or '0.0' if the entry could not be found.

public static getRate(int $vatId) : float
Parameters
$vatId : int

The VAT ID

Tags
access

public

static
Return values
float

The VAT rate, or '0.0'

getShort()

Return the short vat rate with a trailing percent sign for the given Vat ID, if available, or '0.0%' if the entry could not be found.

public static getShort(int $vatId) : string
Parameters
$vatId : int

The Vat ID

Tags
access

public

global

array

static
Return values
string

The resulting string

getShortMenuString()

Returns a HTML dropdown menu with IDs as values and VAT rates as text.

public static getShortMenuString([int $selected = '' ][, string $menuname = '' ][, string $attributes = '' ]) : string

The tags are only added if you also specify a name for the menu as second argument. Otherwise you'll have to add them later. The $attributes are added to the tag

$attributes : string = ''

Optional attributes for the ...)

init()

Initialize the Vat object with current values from the database.

public static init([int $localeId = 0 ]) : void

Set up two class array variables, one called $arrVatClass, like (ID => "class", ...) and the other called $arrVatRate, like (ID => rate) Plus initializes the various object variables. May die() with a message if it fails to access its settings.

Parameters
$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Tags
global

ADONewConnection $objDatabase Database connection object

static

is_home_country()

Get or set the home country flag

public static is_home_country([mixed $is_home_country = null ]) : bool
Parameters
$is_home_country : mixed = null
Return values
bool

True if the shop home country and the ship-to country are identical

is_reseller()

Set the reseller flag

public static is_reseller(mixed $is_reseller) : mixed
Parameters
$is_reseller : mixed

isEnabled()

Returns true if VAT is enabled, false otherwise

public static isEnabled() : bool
Tags
static
Return values
bool

True if VAT is enabled, false otherwise.

isIncluded()

Returns true if VAT is included, false otherwise

public static isIncluded() : bool
Tags
static
Return values
bool

True if VAT is included, false otherwise.

isIncludedInRetailButNotInReseller()

Check if retail-prices are VAT-inclusive, but not reseller-prices.

public static isIncludedInRetailButNotInReseller() : bool

If this method returns TRUE, then that indicates that the VAT must be subtracted from the retail price.

Return values
bool

TRUE if retail-prices are VAT-inclusive, but not reseller-prices. Any other setup VAT configuration causes FALSE to be returned.

updateVat()

Update the VAT entries found in the array arguments in the database.

public static updateVat(array<string|int, mixed> $vatClasses, array<string|int, mixed> $vatRates[, int $localeId = 0 ]) : bool

Check if the rates are non-negative decimal numbers, and only updates records that have been changed. Remember to re-init() the Vat class after changing the database table.

Parameters
$vatClasses : array<string|int, mixed>

VAT classes (ID => (string) class)

$vatRates : array<string|int, mixed>

VAT rates in percent (ID => rate)

$localeId : int = 0

Optional locale ID. If not set FRONTEND_LANG_ID will be used.

Tags
access

public

global

ADONewConnection

static
Return values
bool

True if all the values were accepted and successfully updated in the database, null on noop, false on failure.


        
On this page

Search results