You are here

function uc_taxes_form in Ubercart 6.2

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

Builds a form to add or edit a tax rate.

Parameters

$rate_id: The ID of the tax rate to edit; leave NULL to add a new rate.

See also

uc_taxes_form_validate()

uc_taxes_form_submit()

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

File

uc_taxes/uc_taxes.admin.inc, line 60
Taxes administration menu items.

Code

function uc_taxes_form($form_state, $rate_id = NULL) {
  $form = array();

  // If a rate ID was specified...
  if ($rate_id) {

    // Load the tax rate and set the page title.
    $rate = uc_taxes_rate_load($rate_id);
    drupal_set_title($rate->name);
  }
  $form['id'] = array(
    '#type' => 'value',
    '#value' => $rate_id,
  );
  $form['name'] = array(
    '#type' => 'textfield',
    '#title' => t('Name'),
    '#description' => t('This name will appear to the customer when this tax is applied to an order.<br />It will also be used to name the corresponding predicate for this rate.'),
    '#default_value' => $rate_id ? $rate->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' => $rate_id ? $rate->rate : '',
    '#size' => 15,
    '#required' => TRUE,
  );
  $options = array(
    '0' => t('Apply tax to any product regardless of its shipability.'),
    1 => t('Apply tax to shippable products only.'),
  );
  $form['shippable'] = array(
    '#type' => 'radios',
    '#title' => t('Taxed products'),
    '#options' => $options,
    '#default_value' => $rate_id ? $rate->shippable : 0,
  );

  // TODO: Remove the need for a special case for product kit module.
  $options = uc_product_type_names();
  unset($options['product_kit']);
  $options['blank-line'] = t('"Blank line" product');
  $form['taxed_product_types'] = array(
    '#type' => 'checkboxes',
    '#title' => t('Taxed product types'),
    '#description' => t('Apply taxes to the specified product types/classes.'),
    '#options' => $options,
    '#default_value' => $rate_id ? $rate->taxed_product_types : array(),
  );
  $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'),
    '#description' => t('Adds the checked line item types to the total before applying this tax.'),
    '#options' => $options,
    '#default_value' => $rate_id ? $rate->taxed_line_items : array(),
  );
  $form['weight'] = array(
    '#type' => 'weight',
    '#title' => t('Weight'),
    '#description' => t('Taxes are sorted by weight and then applied to the order sequentially. This value is important when taxes need to include other tax line items.'),
    '#default_value' => $rate_id ? $rate->weight : 0,
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
    '#suffix' => l(t('Cancel'), 'admin/store/settings/taxes'),
  );
  return $form;
}