You are here

function invoice_settings_form in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_form.inc \invoice_settings_form()

Invoice settings form

1 string reference to 'invoice_settings_form'
invoice_settings in ./invoice.module
Invoice settings

File

./invoice_form.inc, line 365
Invoice module

Code

function invoice_settings_form() {

  // Get template names
  $templates = _invoice_get_templates();
  $form['general'] = array(
    '#type' => 'fieldset',
    '#title' => t('General settings'),
    '#collapsible' => TRUE,
    '#collapsed' => FALSE,
  );
  $form['general']['locale'] = array(
    '#type' => 'textfield',
    '#title' => t('Locale'),
    '#required' => TRUE,
    '#default_value' => variable_get('invoice_locale', ''),
    '#description' => t('Category/locale names can be found in !rfc1766 and !iso639. Systems can have different naming schemes for locales.', array(
      '!rfc1766' => l(t('» RFC 1766'), 'http://www.faqs.org/rfcs/rfc1766', array(
        'absolute' => TRUE,
      )),
      '!iso639' => l(t('» ISO 639'), 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm', array(
        'absolute' => TRUE,
      )),
    )) . ' ' . t('On linux you can check the available locales on the server with the command "locale -a" or click below to see the same list.') . ' ' . t('If your system/server is ubuntu (debian like) you can install more languages with the aptitude or synaptic package manager. Search for -language-pack-*-base.') . ' ' . t('If you install for example -language-pack-en-base you get over 10+ locales extra, like en_US, en_GB, en_AU, en_CA etc.') . ' ' . t('For more information see !link.', array(
      '!link' => l(t('http://www.php.net/setlocale'), 'http://www.php.net/setlocale', array(
        'absolute' => TRUE,
      )),
    )) . ' ' . l(t('Click here to see an overview of installed locales on your system.'), 'invoice/installed_locales'),
    '#size' => 8,
  );
  $form['general']['date_format'] = array(
    '#type' => 'textfield',
    '#title' => t('Date format'),
    '#required' => TRUE,
    '#default_value' => variable_get('invoice_date_format', ''),
    '#description' => t('For example m/d/Y.') . ' ' . t('See !link.', array(
      '!link' => l(t('http://www.php.net/date'), 'http://www.php.net/date', array(
        'absolute' => TRUE,
      )),
    )) . ' ' . t('The date on the invoice will look like: @date_format', array(
      '@date_format' => date(variable_get('invoice_date_format', '')),
    )),
    '#size' => 20,
  );
  $form['general']['vat'] = array(
    '#type' => 'textfield',
    '#title' => t('Default VAT precentage'),
    '#required' => TRUE,
    '#default_value' => variable_get('invoice_vat', ''),
    '#size' => 3,
  );
  $form['general']['pay_limit'] = array(
    '#type' => 'textfield',
    '#title' => t('Pay limit'),
    '#required' => TRUE,
    '#default_value' => variable_get('invoice_pay_limit', ''),
    '#description' => t('Pay limit in days'),
    '#size' => 3,
  );
  $form['general']['invoice_number_zerofill'] = array(
    '#type' => 'textfield',
    '#title' => t('Invoice number zerofill'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_invoice_number_zerofill', ''),
    '#description' => t('If you want an invoice number to be displayed as "0001" fill in 4. If you just want to display invoice number "1" leave/set empty.'),
    '#size' => 3,
  );
  $form['general']['invoice_number_prefix'] = array(
    '#type' => 'textfield',
    '#title' => t('Invoice number prefix'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_invoice_number_prefix', ''),
    '#description' => t('If you want an invoice number to be displayed as "@year0001" fill in "%Y". Fillin 4 in the zerofill field above for extra zero values.', array(
      '@year' => date('Y'),
    )) . ' ' . t('If a new year is reached the numbering will still continue sequentially, so if the year ended with "@year0578", the next year will start with "@next_year0579"', array(
      '@year' => date('Y'),
      '@next_year' => date('Y') + 1,
    )) . ' ' . t('All !date values may be entered here with a "%" sign before it or every other text you like.', array(
      '!date' => l(t('date'), 'http://www.php.net/date', array(
        'absolute' => TRUE,
      )),
    )),
    '#size' => 20,
  );

  /* ------------------------------------------------------ */
  $form['general']['display_column'] = array(
    '#type' => 'fieldset',
    '#title' => t('Display invoice columns'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['general']['display_column']['display_column_vat'] = array(
    '#type' => 'checkbox',
    '#title' => t('VAT'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_display_column_vat', ''),
  );
  $form['general']['display_column']['display_column_exunitcost'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unitcost (ex)'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_display_column_exunitcost', ''),
  );
  $form['general']['display_column']['display_column_incunitcost'] = array(
    '#type' => 'checkbox',
    '#title' => t('Unitcost (inc)'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_display_column_incunitcost', ''),
  );
  $form['general']['display_column']['display_column_extotal'] = array(
    '#type' => 'checkbox',
    '#title' => t('Total (ex)'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_display_column_extotal', ''),
  );
  $form['general']['display_column']['display_column_inctotal'] = array(
    '#type' => 'checkbox',
    '#title' => t('Total (inc)'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_display_column_inctotal', ''),
  );

  /* ------------------------------------------------------ */
  $form['general']['supplier'] = array(
    '#type' => 'fieldset',
    '#title' => t('Supplier details'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['general']['supplier']['supplier_company_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Company name'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_company_name', ''),
  );
  $form['general']['supplier']['supplier_street'] = array(
    '#type' => 'textfield',
    '#title' => t('Street'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_street', ''),
  );
  $form['general']['supplier']['supplier_building_number'] = array(
    '#type' => 'textfield',
    '#title' => t('Building number'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_building_number', ''),
  );
  $form['general']['supplier']['supplier_zipcode'] = array(
    '#type' => 'textfield',
    '#title' => t('Zipcode'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_zipcode', ''),
  );
  $form['general']['supplier']['supplier_city'] = array(
    '#type' => 'textfield',
    '#title' => t('City'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_city', ''),
  );
  $form['general']['supplier']['supplier_state'] = array(
    '#type' => 'textfield',
    '#title' => t('State'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_state', ''),
  );
  $form['general']['supplier']['supplier_country'] = array(
    '#type' => 'textfield',
    '#title' => t('Country'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_country', ''),
  );
  $form['general']['supplier']['supplier_phone'] = array(
    '#type' => 'textfield',
    '#title' => t('Phone'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_phone', ''),
  );
  $form['general']['supplier']['supplier_fax'] = array(
    '#type' => 'textfield',
    '#title' => t('Fax'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_fax', ''),
  );
  $form['general']['supplier']['supplier_email'] = array(
    '#type' => 'textfield',
    '#title' => t('Email'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_email', ''),
  );
  $form['general']['supplier']['supplier_web'] = array(
    '#type' => 'textfield',
    '#title' => t('Web address'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_web', ''),
  );
  $form['general']['supplier']['supplier_coc_number'] = array(
    '#type' => 'textfield',
    '#title' => t('CoC Number'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_coc_number', ''),
  );
  $form['general']['supplier']['supplier_vat_number'] = array(
    '#type' => 'textfield',
    '#title' => t('VAT Number'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_supplier_vat_number', ''),
  );

  /* ------------------------------------------------------ */
  $form['general']['api'] = array(
    '#type' => 'fieldset',
    '#title' => t('API details'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
  );
  $form['general']['api']['api_root_username'] = array(
    '#type' => 'textfield',
    '#title' => t('API root username'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_api_root_username', ''),
    '#description' => t('The username defined here has access to perform all invoice API operations. But you can also' . ' only set an API username per template or both.'),
  );
  $form['general']['api']['api_allowed_ips'] = array(
    '#type' => 'textfield',
    '#title' => t('Allowed ips'),
    '#required' => FALSE,
    '#default_value' => variable_get('invoice_api_allowed_ips', ''),
    '#description' => t('Restrict authentication access to these ips (multiple comma seperated)'),
  );

  // Build array for selecting the default template
  $default_templates = array();
  foreach ($templates as $template) {
    $default_templates[$template] = ucfirst($template);
  }
  $form['general']['default_template'] = array(
    '#type' => 'select',
    '#title' => t('Default template'),
    '#options' => $default_templates,
    '#default_value' => variable_get('invoice_default_template', 'default'),
    '#required' => TRUE,
    '#size' => 1,
  );

  /* ------------------------------------------------------ */

  // Build form for template values
  foreach ($templates as $template) {
    $form[$template] = array(
      '#type' => 'fieldset',
      '#title' => t('Template') . ' (' . $template . ')',
      '#collapsible' => TRUE,
      '#collapsed' => $template == 'default' ? FALSE : TRUE,
      '#description' => t('If fields are also set in invoice general settings and the template field is empty, the general setting of the field will be used.'),
    );
    $form[$template][$template . '_locale'] = array(
      '#type' => 'textfield',
      '#title' => t('Locale'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'locale', ''),
      '#description' => t('Category/locale names can be found in !rfc1766 and !iso639. Systems can have different naming schemes for locales.', array(
        '!rfc1766' => l(t('» RFC 1766'), 'http://www.faqs.org/rfcs/rfc1766', array(
          'absolute' => TRUE,
        )),
        '!iso639' => l(t('» ISO 639'), 'http://www.w3.org/WAI/ER/IG/ert/iso639.htm', array(
          'absolute' => TRUE,
        )),
      )) . ' ' . t('On linux you can check the available locales on the server with the command "locale -a" or click below to see the same list.') . ' ' . t('If your system/server is ubuntu (debian like) you can install more languages with the aptitude or synaptic package manager. Search for -language-pack-*-base.') . ' ' . t('If you install for example -language-pack-en-base you get over 10+ locales extra, like en_US, en_GB, en_AU, en_CA etc.') . ' ' . t('For more information see !link.', array(
        '!link' => l(t('http://www.php.net/setlocale'), 'http://www.php.net/setlocale', array(
          'absolute' => TRUE,
        )),
      )) . ' ' . l(t('Click here to see an overview of installed locales on your system.'), 'invoice/installed_locales'),
      '#size' => 20,
    );
    $form[$template][$template . '_date_format'] = array(
      '#type' => 'textfield',
      '#title' => t('Date format'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'date_format', ''),
      '#description' => t('For example m/d/Y.') . ' ' . t('See !link.', array(
        '!link' => l(t('http://www.php.net/date'), 'http://www.php.net/date', array(
          'absolute' => TRUE,
        )),
      )) . ' ' . t('The date on the invoice will look like: @date_format', array(
        '@date_format' => date(_invoice_get_variable($template, 'date_format')),
      )),
      '#size' => 20,
    );
    $form[$template][$template . '_vat'] = array(
      '#type' => 'textfield',
      '#title' => t('Default vat percentage'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'vat', ''),
      '#size' => 3,
    );
    $form[$template][$template . '_pay_limit'] = array(
      '#type' => 'textfield',
      '#title' => t('Pay limit'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'pay_limit', ''),
      '#description' => t('Pay limit in days'),
      '#size' => 3,
    );

    /* ------------------------------------------------------ */
    $s_fieldset_name = '_display_column';
    $form[$template][$template . '_display_column'] = array(
      '#type' => 'fieldset',
      '#title' => t('Display invoice columns'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form[$template][$template . '_display_column'][$template . $s_fieldset_name . '_vat'] = array(
      '#type' => 'checkbox',
      '#title' => t('VAT'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'display_column_vat', ''),
    );
    $form[$template][$template . '_display_column'][$template . $s_fieldset_name . '_exunitcost'] = array(
      '#type' => 'checkbox',
      '#title' => t('Unitcost (ex)'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'display_column_exunitcost', ''),
    );
    $form[$template][$template . '_display_column'][$template . $s_fieldset_name . '_incunitcost'] = array(
      '#type' => 'checkbox',
      '#title' => t('Unitcost (inc)'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'display_column_incunitcost', ''),
    );
    $form[$template][$template . '_display_column'][$template . $s_fieldset_name . '_extotal'] = array(
      '#type' => 'checkbox',
      '#title' => t('Total (ex)'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'display_column_extotal', ''),
    );
    $form[$template][$template . '_display_column'][$template . $s_fieldset_name . '_inctotal'] = array(
      '#type' => 'checkbox',
      '#title' => t('Total (inc)'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'display_column_inctotal', ''),
    );

    /* ------------------------------------------------------ */
    $form[$template][$template . '_supplier'] = array(
      '#type' => 'fieldset',
      '#title' => t('Supplier details'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_company_name'] = array(
      '#type' => 'textfield',
      '#title' => t('Company name'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_company_name', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_street'] = array(
      '#type' => 'textfield',
      '#title' => t('Street'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_street', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_building_number'] = array(
      '#type' => 'textfield',
      '#title' => t('Building number'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_building_number', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_zipcode'] = array(
      '#type' => 'textfield',
      '#title' => t('Zipcode'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_zipcode', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_city'] = array(
      '#type' => 'textfield',
      '#title' => t('City'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_city', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_state'] = array(
      '#type' => 'textfield',
      '#title' => t('State'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_state', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_country'] = array(
      '#type' => 'textfield',
      '#title' => t('Country'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_country', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_phone'] = array(
      '#type' => 'textfield',
      '#title' => t('Phone'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_phone', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_fax'] = array(
      '#type' => 'textfield',
      '#title' => t('Fax'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_fax', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_email'] = array(
      '#type' => 'textfield',
      '#title' => t('Email'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_email', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_web'] = array(
      '#type' => 'textfield',
      '#title' => t('Web address'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_web', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_coc_number'] = array(
      '#type' => 'textfield',
      '#title' => t('CoC number'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_coc_number', ''),
    );
    $form[$template][$template . '_supplier'][$template . '_supplier_vat_number'] = array(
      '#type' => 'textfield',
      '#title' => t('VAT number'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'supplier_vat_number', ''),
    );

    /* ------------------------------------------------------ */
    $form[$template][$template . '_api'] = array(
      '#type' => 'fieldset',
      '#title' => t('API details'),
      '#collapsible' => TRUE,
      '#collapsed' => TRUE,
    );
    $form[$template][$template . '_api'][$template . '_api_username'] = array(
      '#type' => 'textfield',
      '#title' => t('Username'),
      '#required' => FALSE,
      '#default_value' => _invoice_get_variable($template, 'api_username', ''),
      '#description' => t('Username must exist in the database, the corresponding password is used'),
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Submit'),
  );
  return $form;
}