function uc_taxes_apply_tax in Ubercart 7.3
Same name and namespace in other branches
- 6.2 uc_taxes/uc_taxes.module \uc_taxes_apply_tax()
Applies taxes to an order.
Parameters
$order: The order object being considered.
$tax: The tax rule calculating the amount.
Return value
The line item array representing the amount of tax.
2 calls to uc_taxes_apply_tax()
- hook_uc_calculate_tax in uc_taxes/
uc_taxes.api.php - Calculates tax line items for an order.
- uc_taxes_uc_calculate_tax in uc_taxes/
uc_taxes.module - Calculates the amount and types of taxes that apply to an order.
File
- uc_taxes/
uc_taxes.module, line 612 - Ubercart Taxes module.
Code
function uc_taxes_apply_tax($order, $tax) {
$amount = 0;
$taxable_amount = 0;
if (is_array($order->products)) {
foreach ($order->products as $item) {
$taxable_amount += $item->qty * uc_taxes_apply_item_tax($item, $tax);
}
}
$taxed_line_items = $tax->taxed_line_items;
if (is_array($order->line_items) && is_array($taxed_line_items)) {
foreach ($order->line_items as $key => $line_item) {
if ($line_item['type'] == 'tax') {
// Don't tax old taxes.
continue;
}
if (in_array($line_item['type'], $taxed_line_items)) {
$callback = _uc_line_item_data($line_item['type'], 'tax_adjustment');
if (isset($callback) && function_exists($callback)) {
$taxable_amount += $callback($line_item['amount'], $order, $tax);
}
else {
$taxable_amount += $line_item['amount'];
}
}
}
}
if (in_array('tax', $taxed_line_items)) {
// Tax taxes that were just calculated.
foreach ($order->taxes as $other_tax) {
$taxable_amount += $other_tax->amount;
}
}
$amount = $taxable_amount * $tax->rate;
if ($amount) {
$line_item = (object) array(
'id' => $tax->id,
'name' => $tax->name,
'amount' => $amount,
'weight' => $tax->weight,
'summed' => 1,
);
$line_item->data = array(
'tax_rate' => $tax->rate,
'tax' => $tax,
'taxable_amount' => $taxable_amount,
'tax_jurisdiction' => $tax->name,
);
return $line_item;
}
}