function uc_taxes_apply_tax in Ubercart 6.2
Same name and namespace in other branches
- 7.3 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.
1 call to uc_taxes_apply_tax()
- uc_taxes_action_apply_tax in uc_taxes/
uc_taxes.ca.inc - Action callback to calculate a tax.
File
- uc_taxes/
uc_taxes.module, line 533
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 += 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 = _line_item_data($line_item['type'], 'tax_adjustment');
if (isset($callback) && function_exists($callback)) {
$taxable_amount += $callback($line_item['amount'], $order, $tax) / $tax->rate;
}
else {
$taxable_amount += $line_item['amount'];
}
}
}
}
if (isset($taxed_line_items['tax'])) {
// 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_id' => $tax->id,
'tax_rate' => $tax->rate,
'taxable_amount' => $taxable_amount,
'tax_jurisdiction' => $tax->name,
);
return $line_item;
}
}