Methods summary
public
|
#
__construct( )
Initialize Currencies
Overrides
|
public
mixed
|
#
getList( integer $company_id, integer $page = 1, string $order_by = ['code' => 'ASC'] )
Fetches a list of all currencies for a given company
Fetches a list of all currencies for a given company
Parameters
- $company_id
- The ID of the company to fetch currencies for
- $page
- The page to return results for (optional, default 1)
- $order_by
- The sort and order conditions (e.g. array('sort_field'=>"ASC"), optional)
Returns
mixed An array of stdClass objects representing currencies, false if no currencies found
|
public
integer
|
#
getListCount( integer $company_id )
Returns the total number of currencies returned from Currencies::getList(),
useful in constructing pagination for the getList() method.
Returns the total number of currencies returned from Currencies::getList(),
useful in constructing pagination for the getList() method.
Parameters
- $company_id
- The ID of the company to fetch currencies for
Returns
integer The total number of currencies
See
|
public
mixed
|
#
getAll( integer $company_id )
Fetches a full list of all currencies for a given company
Fetches a full list of all currencies for a given company
Parameters
- $company_id
- The ID of the company to fetch currencies for
Returns
mixed An array of stdClass objects representing all currencies, or false if no currencies found
|
public
mixed
|
#
get( string $currency_code, integer $company_id )
Fetches a currency using the given currency code
Fetches a currency using the given currency code
Parameters
- $currency_code
- The ISO 4217 currency code to fetch on
- $company_id
- The ID of the company whose currency to fetch
Returns
mixed stdClass object representing the currency if it exists, false otherwise
|
public
array
|
#
getFormats( )
Returns an array containing every supported currency format with an example in key/value pairs
Returns an array containing every supported currency format with an example in key/value pairs
Returns
array An array of currency formats in key/value pairs where the
key is the format and the value is an example
|
public
|
#
add( array $vars )
Adds a new currency
Parameters
- $vars
An array of currency info including:
- code The ISO 4217 currency code
- company_id The Company ID
- format The format code to use for this currency
- precision The decimal precision to use for this currency
- prefix The prefix to use for this currency
- suffix The suffix to use for this currency
- exchange_rate The exchange rate in relation to the primary currency
- exchange_updated The datetime the exchange_rate was last updated
|
public
|
#
edit( string $currency_code, integer $company_id, array $vars )
Edits an existing currency
Edits an existing currency
Parameters
- $currency_code
- The ISO 4217 currency code we are updating
- $company_id
- The Company ID for this currency code
- $vars
An array of currency info including:
- format The format code to use for this currency
- precision The decimal precision to use for this currency
- prefix The prefix to use for this currency
- suffix The suffix to use for this currency
- exchange_rate The exchange rate in relation to the primary currency
- exchange_updated The datetime the exchange_rate was last updated
|
public
|
#
delete( string $currency_code, integer $company_id )
Deletes an existing currency
Deletes an existing currency
Parameters
- $currency_code
- The ISO 4217 currency code we are deleting
- $company_id
- The Company ID for this currency code
|
public
float
|
#
convert( float $amount, string $from_currency, string $to_currency, integer $company_id )
Converts an amount from one currency to another using the exchange rate
Converts an amount from one currency to another using the exchange rate
Parameters
- $amount
- The amount to convert
- $from_currency
- The ISO 4217 currency code format representing $amount
- $to_currency
- The ISO 4217 currency code to format to
- $company_id
- The ID of the company
Returns
float The $amount converted between currencies
|
public
string
|
#
toDecimal( string $value, string $currency, integer $company_id = null, integer $decimals = null )
Converts a currency value into a decimal representation based on ISO 31-0
Converts a currency value into a decimal representation based on ISO 31-0
Parameters
- $value
- A currency value
- $currency
- The ISO 4217 currency code format representing $value
- $company_id
- The company ID to fetch the currency for
- $decimals
The number of decimal places (precision) (optional, default null to use the currency's
defined precision)
Returns
string The value in decimal format based on ISO 31-0
See
|
public
string
|
#
toCurrency( float $value, string $currency, integer $company_id = null, boolean $prefix = true, boolean $suffix = true, boolean $code = false, boolean $with_separator = true, integer $decimals = null )
Converts the given decimal value into a currency value.
Converts the given decimal value into a currency value.
Parameters
- $value
- The decimal value to convert
- $currency
- The ISO 4217 currency code format to apply to $value
- $company_id
- The company ID to fetch the currency for
- $prefix
- True to include the prefix symbol for this currency, false otherwise
- $suffix
- True to include the suffix symbol for this currency, false otherwise
- $code
- True to include the currency code for this currency, false otherwise
- $with_separator
- True to include the separator for this currency, false otherwise
- $decimals
The number of decimal places (precision) (optional, default null to use the currency's
defined precision)
Returns
string The value formatted for the specified currency
See
|
public
string
|
#
toCurrencyValue( float $value, string $currency, boolean $with_separator = true, integer $company_id = null, integer $decimals = null )
Converts the given decimal value into a currency value excluding the prefix, suffix, and currency code symbols
Converts the given decimal value into a currency value excluding the prefix, suffix, and currency code symbols
Parameters
- $value
- The decimal value to convert
- $currency
- The ISO 4217 currency code format to apply to $value
- $with_separator
- True to include the separator for this currency, false otherwise
- $company_id
- The company ID to fetch the currency for
- $decimals
The number of decimal places (precision) (optional, default null to use the currency's
defined precision)
Returns
string The value formatted for the specified currency
See
|
public
boolean
|
#
validateCurrencyInUse( string $currency_code, integer $company_id )
Checks if a currency code is currently in use
Checks if a currency code is currently in use
Parameters
- $currency_code
- The ISO 4217 currency code to check
- $company_id
- The company ID whose currency to check
Returns
boolean True if the currency code is in use, false otherwise
|
public
boolean
|
#
validateCurrencyIsDefault( string $currency_code, integer $company_id )
Checks if the given currency code is set as the default currency
Checks if the given currency code is set as the default currency
Parameters
- $currency_code
- The ISO 4217 currency code to check
- $company_id
- The company ID whose default currency to check
Returns
boolean True if the currency is the default currency for this company, false otherwise
|
public
boolean
|
#
validateCurrencyFormat( string $format )
Validates a currency's 'format' field
Validates a currency's 'format' field
Parameters
- $format
- The format to check, (e.g. "#.###")
Returns
boolean True if validated, false otherwise
|
public
boolean
|
#
validateCurrencyExists( string $code, integer $company_id )
Validates a currency exists
Validates a currency exists
Parameters
- $code
- The currency code
- $company_id
- The company ID
Returns
boolean True if the currency exists, false otherwise
|
public
array
|
#
getExchangeRateProcessors( )
Retrieves a list of exchange rate processors
Retrieves a list of exchange rate processors
Returns
array A list of exchange rate processors
|
public
boolean|ExchangeRate
|
#
getExchangeRateProcessor( string $processor )
Retrieves an instance of the exchange rate processor.
Sets Input errors if the processor cannot not be found.
Retrieves an instance of the exchange rate processor.
Sets Input errors if the processor cannot not be found.
Parameters
- $processor
- The name of the exchange rate processor (e.g. google_finance)
Returns
boolean| ExchangeRate An instance of the ExchangeRate processor if found, otherwise boolean false
|
public
|
#
updateRates( )
Updates all currency exchange rates for the current company using the
configured processor.
Updates all currency exchange rates for the current company using the
configured processor.
|