Fix advanced search with serial and another field

The advanced search in /hardware produces incorrect results if the serial is combined with another field like category.
There is a typo as the fieldname 'product_key' doesn't exist. Change this to 'serial'.

Also change the last If-Statement from ->orWhere() to ->where(). Now additional fields like custom fields can be combined with other searches in an And-Clause.
I think this function could be simplified further, but this is the minimal bugfix.
This commit is contained in:
Tobias Regnery 2021-08-05 15:07:28 +02:00
parent cdc4940338
commit eced1ab77f

View file

@ -1314,7 +1314,7 @@ class Asset extends Depreciable
$query->where('assets.name', 'LIKE', '%'.$search_val.'%');
}
if ($fieldname =='product_key') {
if ($fieldname =='serial') {
$query->where('assets.serial', 'LIKE', '%'.$search_val.'%');
}
@ -1436,7 +1436,7 @@ class Asset extends Depreciable
*/
if (($fieldname!='category') && ($fieldname!='model_number') && ($fieldname!='rtd_location') && ($fieldname!='location') && ($fieldname!='supplier')
&& ($fieldname!='status_label') && ($fieldname!='model') && ($fieldname!='company') && ($fieldname!='manufacturer')) {
$query->orWhere('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%');
$query->where('assets.'.$fieldname, 'LIKE', '%' . $search_val . '%');
}