You are here

function uc_taxes_form in Ubercart 5

Same name and namespace in other branches
  1. 6.2 uc_taxes/uc_taxes.admin.inc \uc_taxes_form()
  2. 7.3 uc_taxes/uc_taxes.admin.inc \uc_taxes_form()

Create or edit a tax rule.

See also

uc_taxes_form_submit

1 string reference to 'uc_taxes_form'
uc_taxes_menu in uc_taxes/uc_taxes.module
Implementation of hook_menu().

File

uc_taxes/uc_taxes.module, line 194

Code

function uc_taxes_form($tax_id = 0) {
  $form = array();
  if ($tax_id != 0) {
    $form_values = db_fetch_array(db_query("SELECT * FROM {uc_taxes} WHERE id = %d", $tax_id));
    $form_values['taxed_product_types'] = array_values(unserialize($form_values['taxed_product_types']));
    $form_values['taxed_line_items'] = array_values(unserialize($form_values['taxed_line_items']));
  }
  $form['id'] = array(
    '#type' => 'hidden',
    '#value' => $form_values['id'],
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#default_value' => isset($form_values['name']) ? $form_values['name'] : '',
    '#required' => true,
  );
  $form['rate'] = array(
    '#type' => 'textfield',
    '#title' => t('Rate'),
    '#description' => t('The tax rate as a percent or decimal. Examples: 6%, .06'),
    '#default_value' => isset($form_values['rate']) ? $form_values['rate'] : '',
    '#size' => 15,
    '#required' => true,
  );
  $shippable_options = array(
    '0' => t('Tax all products regardless of shipping status'),
    1 => t('Tax only shippable products'),
  );
  $form['shippable'] = array(
    '#type' => 'radios',
    '#title' => t('Tax products based on shipping status?'),
    '#options' => $shippable_options,
    '#default_value' => $form_values['shippable'],
  );
  $types = array();
  $node_types = module_invoke_all('node_info');
  $product_types = module_invoke_all('product_types');
  foreach ($product_types as $type) {
    $types[$type] = $node_types[$type]['name'];
  }
  $form['taxed_product_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Taxed product types'),
    '#multiple' => true,
    '#options' => $types,
    '#default_value' => $form_values['taxed_product_types'],
    '#description' => t('Apply taxes to specific product types.'),
  );
  $options = array();
  foreach (_line_item_list() as $line_item) {
    if (!in_array($line_item['id'], array(
      'subtotal',
      'tax_subtotal',
      'total',
    ))) {
      $options[$line_item['id']] = $line_item['title'];
    }
  }
  $form['taxed_line_items'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Taxed line items'),
    '#multiple' => true,
    '#options' => $options,
    '#default_value' => $form_values['taxed_line_items'],
    '#description' => t('Adds the checked line item types to the total before applying this tax.'),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#default_value' => isset($form_values['weight']) ? $form_values['weight'] : 0,
    '#description' => t('Lighter taxes are applied to an order first. This value is unimportant if there are no taxes on tax line items.'),
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}