You are here

function invoice_get_customer_info in Invoice 7

Same name and namespace in other branches
  1. 6 invoice_ajax.inc \invoice_get_customer_info()

Get customer info

1 string reference to 'invoice_get_customer_info'
invoice_menu in ./invoice.module
Implements hook_menu()

File

./invoice_ajax.inc, line 76
Invoice module

Code

function invoice_get_customer_info() {

  // Create alias
  $fv =& $_GET;
  $query = db_select('invoice_customers', 'ic')
    ->fields('ic', array(
    'company_name',
    'firstname',
    'lastname',
    'street',
    'building_number',
    'zipcode',
    'city',
    'state',
    'country',
    'coc_number',
    'vat_number',
    'description',
  ));
  $query
    ->leftJoin('invoice_invoices', 'ii', 'ic.invoice_id = ii.iid');
  $data = $query
    ->condition('ic.cid', $fv['value'])
    ->orderBy('ic.company_name', 'DESC')
    ->orderBy('ic.lastname', 'DESC')
    ->orderBy('ic.firstname', 'DESC')
    ->orderBy('ic.invoice_id', 'DESC')
    ->range(0, 1)
    ->execute()
    ->fetchAssoc();
  if (count($data) == 0) {
    $data['set_empty'] = TRUE;
  }
  else {
    $data['search_customer'] = '';
    if (!empty($data['company_name'])) {
      $data['search_customer'] = $data['company_name'];
    }
    else {
      $data['search_customer'] = $data['lastname'] . (!empty($data['firstname']) ? ', ' . $data['firstname'] : '');
    }
  }
  drupal_json_output($data);
  exit;
}