function invoice_search_customer in Invoice 6
Same name and namespace in other branches
- 7 invoice_ajax.inc \invoice_search_customer()
Search if the customer already exists
1 string reference to 'invoice_search_customer'
- invoice_menu in ./
invoice.module - Implementation of hook_menu()
File
- ./
invoice_ajax.inc, line 26 - Invoice module
Code
function invoice_search_customer($value) {
$a_items = array();
$customer_value = check_plain($value);
$result = db_query("SELECT * FROM {invoice_customers} ic\n LEFT JOIN {invoice_invoices} ii ON ic.invoice_id=ii.iid \n WHERE (company_name LIKE '%%" . $customer_value . "%' OR lastname LIKE '%%" . $customer_value . "%' OR firstname LIKE '%%" . $customer_value . "%')\n GROUP BY vat_number,coc_number,company_name,country,city,zipcode,building_number,lastname,firstname\n ORDER BY company_name, lastname, firstname, invoice_id DESC");
while ($row = db_fetch_object($result)) {
$key = $row->cid;
$value = NULL;
if (!empty($row->company_name)) {
$value = $row->company_name;
$value = !empty($row->zipcode) ? $value . " - " . $row->zipcode : $value;
$value = !empty($row->building_number) ? $value . " - " . $row->building_number : $value;
$value = !empty($row->city) ? $value . " - " . $row->city : $value;
$value = !empty($row->country) ? $value . " - " . $row->country : $value;
$value = !empty($row->vat_number) ? $value . " - " . $row->vat_number : $value;
$value = !empty($row->coc_number) ? $value . " - " . $row->coc_number : $value;
$value = !empty($row->lastname) ? $value . "\n " . $row->lastname : $value;
$value = !empty($row->firstname) ? $value . "\n " . $row->firstname : $value;
}
else {
$value = $row->lastname . (!empty($row->firstname) ? ', ' . $row->firstname : '');
}
$a_items[$key] = check_plain($value);
}
drupal_json($a_items);
exit;
}