You are here

function _invoice_get_new_invoice_number in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_helpers.inc \_invoice_get_new_invoice_number()

Helper function to get invoice id

Return value

integer

2 calls to _invoice_get_new_invoice_number()
invoice_node_presave in ./invoice.module
Implements hook_node_presave()
invoice_validate in ./invoice.module
Implements hook_validate()

File

./invoice_helpers.inc, line 368
Invoice module

Code

function _invoice_get_new_invoice_number($user_defined_invoice_number_check = FALSE) {
  if ($user_defined_invoice_number_check == TRUE) {
    $count = db_query("SELECT COUNT(*) FROM {invoice_invoices}")
      ->fetchField();
    if ($count == 0) {
      return 0;
    }
    else {
      return db_query_range("SELECT iid FROM {invoice_invoices} ORDER BY nid DESC", array(), 1)
        ->fetchField();
    }
  }
  $new_invoice_number = db_query_range("SELECT iid FROM {invoice_invoices} ORDER BY nid DESC", array(), 1)
    ->fetchField() + 1;
  return $new_invoice_number;
}