You are here

function commerce_invoice_settings_form in Commerce Invoice 7

Same name and namespace in other branches
  1. 7.2 commerce_invoice.admin.inc \commerce_invoice_settings_form()

Form callback: edit the global invoice settings.

1 string reference to 'commerce_invoice_settings_form'
commerce_invoice_ui_menu in ./commerce_invoice_ui.module
Implements hook_menu().

File

includes/commerce_invoice_ui.invoices.inc, line 12
Page callbacks and form builder functions for administering invoices.

Code

function commerce_invoice_settings_form($form, &$form_state) {
  $form['commerce_invoice_number_method'] = array(
    '#type' => 'radios',
    '#title' => t('Invoice number creation method'),
    '#description' => t('This determines the way invoice numbers are generated.'),
    '#default_value' => variable_get('commerce_invoice_number_method', COMMERCE_INVOICE_METHOD_YEAR),
    '#options' => array(
      COMMERCE_INVOICE_METHOD_INFINITE => t('Infinite (one single number, that is never reset, and incremented at each invoice generation)'),
      COMMERCE_INVOICE_METHOD_YEAR => t('Reset every year, with an id incremented at each invoice generation (@invoice_number)', array(
        '@invoice_number' => date('Y') . '-[invoice_id]',
      )),
      COMMERCE_INVOICE_METHOD_MONTH => t('Reset every month, with an id incremented at each invoice generation (@invoice_number)', array(
        '@invoice_number' => date('Y-m') . '-[invoice_id]',
      )),
      COMMERCE_INVOICE_METHOD_CALLBACK => t('Invoice number generation is controlled by a callback function that is being passed the invoice object'),
    ),
  );
  $callbacks = module_invoke_all('commerce_invoice_number_callbacks');
  if ($callbacks) {
    $form['commerce_invoice_number_callback'] = array(
      '#type' => 'select',
      '#title' => t('Invoice number creation callback'),
      '#description' => t('This selects the callback function for the callback method.'),
      '#default_value' => variable_get('commerce_invoice_number_callback', ''),
      '#options' => $callbacks,
      '#element_validate' => array(
        'commerce_invoice_ui_validate_invoice_number_callback',
      ),
      '#states' => array(
        'visible' => array(
          ':input[name="commerce_invoice_number_method"]' => array(
            'value' => COMMERCE_INVOICE_METHOD_CALLBACK,
          ),
        ),
      ),
    );
  }
  return system_settings_form($form);
}