function commerce_vat_total_amount in Commerce VAT 7
Returns the total amount of vat included in a price components array.
Parameters
$components: A price's components array including potential vat components.
$included: Boolean indicating whether or not to include in the total vates that were included in the price amount already.
$currency_code: The currency to return the vat amount in.
Return value
The consolidated vat collected for an order expressed as an integer amount.
File
- ./
commerce_vat.module, line 614 - Defines VAT rates and Rules integration for configuring vat rules for applicability and display.
Code
function commerce_vat_total_amount($components, $included, $currency_code) {
$component_types = commerce_vat_commerce_price_component_type_info();
$amount = 0;
// Loop over each component passed in...
foreach ($components as $component) {
// Looking for components that match one of the defined vat price components.
if (in_array($component['name'], array_keys($component_types))) {
// If the component matches the requested "included" value...
if (!$included && empty($component['included']) || $included && !empty($component['included'])) {
// Add the converted price amount to the running total.
$amount += commerce_currency_convert($component['price']['amount'], $component['price']['currency_code'], $currency_code);
}
}
}
return $amount;
}