You are here

commerce_invoice.install in Commerce Invoice 7.2

Same filename and directory in other branches
  1. 8.2 commerce_invoice.install
  2. 7 commerce_invoice.install

Install and uninstall functions for the Commerce Invoice module.

File

commerce_invoice.install
View source
<?php

/**
 * @file
 * Install and uninstall functions for the Commerce Invoice module.
 */

/**
 * Implements hook_schema().
 */
function commerce_invoice_schema() {
  $schema = array();
  $schema['commerce_invoice'] = array(
    'description' => 'The base table for invoices.',
    'fields' => array(
      'invoice_id' => array(
        'description' => 'The primary identifier for an invoice.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'number_sequence' => array(
        'description' => 'The sequential invoice number.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'number_pattern' => array(
        'description' => 'The name of the pattern used to calculate the invoice number.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'number_key' => array(
        'description' => 'The key created from the pattern which differentiates sequential invoice numbers.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'invoice_date' => array(
        'description' => 'The Unix timestamp for the invoice date.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'invoice_due' => array(
        'description' => 'The Unix timestamp for the invoice due date.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ),
      'invoice_status' => array(
        'description' => 'The invoice status.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'revision_id' => array(
        'description' => 'The revision ID for this invoice.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'type' => array(
        'description' => 'The type of this invoice.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'uid' => array(
        'description' => 'The {users}.uid that owns this invoice.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'order_id' => array(
        'description' => 'The order ID.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'order_revision_id' => array(
        'description' => 'The order revision ID.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'created' => array(
        'description' => 'The Unix timestamp when the invoice was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'changed' => array(
        'description' => 'The Unix timestamp when the invoice was most recently saved.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'invoice_id',
    ),
    'unique keys' => array(
      'invoice_number' => array(
        'number_pattern',
        'number_key',
        'number_sequence',
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'order_revision' => array(
        'order_id',
        'order_revision_id',
      ),
    ),
    'foreign keys' => array(
      'order' => array(
        'table' => 'commerce_order',
        'columns' => array(
          'order_id' => 'order_id',
        ),
      ),
      'order_revision' => array(
        'table' => 'commerce_order_revision',
        'columns' => array(
          'order_id' => 'order_id',
          'order_revision_id' => 'revision_id',
        ),
      ),
      'owner' => array(
        'table' => 'users',
        'columns' => array(
          'uid' => 'uid',
        ),
      ),
    ),
  );
  $schema['commerce_invoice_revision'] = array(
    'description' => 'Stores information about each saved revision of an invoice.',
    'fields' => array(
      'invoice_id' => array(
        'description' => 'The {commerce_invoice}.invoice_id of the invoice this revision belongs to.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_id' => array(
        'description' => 'The primary identifier for this revision.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'invoice_date' => array(
        'description' => 'The invoice date for this revision.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'invoice_status' => array(
        'description' => 'The invoice status for this revision.',
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => 'The invoice owner for this revision.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'revision_created' => array(
        'description' => 'The Unix timestamp when the revision was created.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'revision_uid' => array(
        'description' => 'The {users}.uid of the user who created the revision.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'log' => array(
        'description' => 'A log message for the revision.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'revision_id',
    ),
    'indexes' => array(
      'invoice_id' => array(
        'invoice_id',
      ),
    ),
    'foreign keys' => array(
      'invoice' => array(
        'table' => 'commerce_invoice',
        'columns' => array(
          'invoice_id' => 'invoice_id',
        ),
      ),
    ),
  );
  $schema['commerce_invoice_number_pattern'] = array(
    'description' => 'Stores configurable invoice number patterns.',
    'fields' => array(
      'name' => array(
        'description' => 'The pattern machine name.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'label' => array(
        'description' => 'A human-readable label for the pattern.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'skip_sequence' => array(
        'description' => 'Boolean indicating whether to skip the sequence number or not.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'pattern' => array(
        'description' => 'The invoice number pattern.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'status' => array(
        'type' => 'int',
        'not null' => TRUE,
        // Set the default to ENTITY_CUSTOM without using the constant as it is
        // not safe to use it at this point.
        'default' => 0x1,
        'size' => 'tiny',
        'description' => 'The exportable status of the entity.',
      ),
      'module' => array(
        'description' => 'The name of the providing module if the entity has been defined in code.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'name',
    ),
  );
  return $schema;
}

/**
 * Implements hook_install().
 */
function commerce_invoice_install() {
  commerce_invoice_ensure_fields();
}

/**
 * Implements hook_uninstall().
 */
function commerce_invoice_uninstall() {
  drupal_load('module', 'commerce');
  commerce_delete_instances('commerce_invoice');
  variable_del('commerce_invoice_default_number_pattern');
  variable_del('commerce_invoice_net_d');
}

/**
 * Add due date field to {commerce_invoice} table.
 */
function commerce_invoice_update_7200() {
  $field = array(
    'description' => 'The Unix timestamp for the invoice due date.',
    'type' => 'int',
    'not null' => TRUE,
    'unsigned' => TRUE,
    'default' => 0,
  );
  db_add_field('commerce_invoice', 'invoice_due', $field);
}

/**
 * Add due skip_sequence field to {commerce_invoice_number_pattern} table.
 */
function commerce_invoice_update_7201() {
  $field = array(
    'description' => 'Boolean indicating whether to skip the sequence number or not.',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field('commerce_invoice_number_pattern', 'skip_sequence', $field);
}

/**
 * Update the commerce_invoice_invoices view.
 */
function commerce_invoice_update_7202() {
  _commerce_invoice_revert_views();
}
function _commerce_invoice_revert_views() {
  views_invalidate_cache();
  if ($view = views_get_view('commerce_invoice_invoices')) {
    views_revert_view($view);
  }
}

Functions

Namesort descending Description
commerce_invoice_install Implements hook_install().
commerce_invoice_schema Implements hook_schema().
commerce_invoice_uninstall Implements hook_uninstall().
commerce_invoice_update_7200 Add due date field to {commerce_invoice} table.
commerce_invoice_update_7201 Add due skip_sequence field to {commerce_invoice_number_pattern} table.
commerce_invoice_update_7202 Update the commerce_invoice_invoices view.
_commerce_invoice_revert_views