You are here

function commerce_vat_calculate_rates in Commerce VAT 7

Calculates vates of a particular type by invoking any components that match the vat type.

Parameters

$vat_type: The vat type object whose rates should be calculated.

$line_item: The line item to which the vates should be applied.

1 call to commerce_vat_calculate_rates()
commerce_vat_rules_calculate in ./commerce_vat.rules.inc
Rules action: checks for the application of each vat rate of a certain type.

File

./commerce_vat.module, line 266
Defines VAT rates and Rules integration for configuring vat rules for applicability and display.

Code

function commerce_vat_calculate_rates($line_item, $supply_iso2) {

  // Prepare an array of rules components to load.
  $component_names = array();

  // Loop over each vat rate in search of matching components.
  foreach (commerce_vat_rates() as $name => $vat_rate) {

    // If the current rate matches the type and specifies a default component...
    if (!empty($vat_rate['rules_component']) && $vat_rate['country'] == $supply_iso2) {
      $component_names[] = $vat_rate['rules_component'];
    }
  }

  // Load and invoke the vat rules components.
  if (!empty($component_names)) {
    foreach (rules_config_load_multiple($component_names) as $component_name => $component) {
      rules_invoke_component($component_name, $line_item);
    }
  }
}