You are here

function commerce_billy_invoice_nr in Commerce Billy 7

Sets invoice number on order.

Used as Rules action callback.

See also

commerce_billy_rules_action_info()

File

./commerce_billy.module, line 69
Commerce Billy module.

Code

function commerce_billy_invoice_nr($order) {

  // Lock down this function so that other requests do not interfere.
  $lock_name = 'commerce_billy_invoice_nr';
  while (!lock_acquire($lock_name)) {
    lock_wait($lock_name);
  }
  $method = variable_get('commerce_billy_invoice_nr_method', COMMERCE_BILLY_INVOICE_METHOD_YEARLY);
  switch ($method) {
    case COMMERCE_BILLY_INVOICE_METHOD_MONTHLY:
      $invoice_nr = commerce_billy_invoice_nr_monthly();
      break;
    case COMMERCE_BILLY_INVOICE_METHOD_YEARLY:
      $invoice_nr = commerce_billy_invoice_nr_yearly();
      break;
    case COMMERCE_BILLY_INVOICE_METHOD_INFINITE:
      $invoice_nr = commerce_billy_invoice_nr_infinite();
      break;
  }

  // Check if we have a unique order number. If not, write a watchdog error and
  // do not change the order number.
  if (!commerce_order_validate_number_unique($invoice_nr, $order->order_id)) {
    watchdog('commerce_billy', 'Error: Order number %number for order %id already exists.', array(
      '%number' => $invoice_nr,
      '%id' => $order->order_id,
    ), WATCHDOG_ERROR);
  }
  else {
    $order->order_number = $invoice_nr;
  }
  lock_release($lock_name);
}