function commerce_avatax_manual_calculate_sales_tax in Drupal Commerce Connector for AvaTax 7.4
Same name and namespace in other branches
- 7.3 commerce_avatax.module \commerce_avatax_manual_calculate_sales_tax()
Calculate sales tax for manual order entry.
1 call to commerce_avatax_manual_calculate_sales_tax()
- commerce_avatax_line_item_add_form in ./
commerce_avatax.module - Returns form for adding an AvaTax line item through line item manager widget.
File
- ./
commerce_avatax.module, line 159 - Calculate Sales Tax using AvaTax service from Avalara, Inc.
Code
function commerce_avatax_manual_calculate_sales_tax($order) {
$product_version = variable_get('commerce_avatax_product_version', COMMERCE_AVATAX_BASIC_VERSION);
if (commerce_avatax_check_address($order, $product_version)) {
$sales_tax = commerce_avatax_retrieve_sales_tax($order, $product_version);
}
else {
drupal_set_message(t('AvaTax error: Invalid state or incomplete address'), 'error');
return TRUE;
}
// If we have a sales tax amount.
if ($sales_tax) {
// Create a new AvaTax line item.
$line_item = commerce_avatax_line_item_create($sales_tax, $order->order_id);
// Add the line item data as a property of the order.
$order->avatax['avatax'] = $line_item;
}
else {
drupal_set_message(t('AvaTax error: Sales tax could not be calculated'), 'error');
return TRUE;
}
}