Fixes #2906 - adds manufacturer searching to licenses

This commit is contained in:
snipe 2016-11-11 19:46:18 -08:00
parent 49ce630bb8
commit 2ddee9b44c
2 changed files with 59 additions and 10 deletions

View file

@ -954,11 +954,22 @@ class LicensesController extends Controller
$licenses = $licenses->TextSearch(Input::get('search'));
}
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial'];
$allowed_columns = ['id','name','purchase_cost','expiration_date','purchase_order','order_number','notes','purchase_date','serial','manufacturer','company'];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
$sort = in_array(Input::get('sort'), $allowed_columns) ? e(Input::get('sort')) : 'created_at';
switch ($sort) {
case 'manufacturer':
$licenses = $licenses->OrderManufacturer($order);
break;
case 'company':
$licenses = $licenses->OrderCompany($order);
break;
default:
$licenses = $licenses->orderBy($sort, $order);
break;
}
$licenseCount = $licenses->count();
$licenses = $licenses->skip(Input::get('offset'))->take(Input::get('limit'))->get();
@ -1003,7 +1014,7 @@ class LicensesController extends Controller
'order_number' => ($license->order_number) ? e($license->order_number) : '',
'notes' => ($license->notes) ? e($license->notes) : '',
'actions' => $actions,
'companyName' => is_null($license->company) ? '' : e($license->company->name),
'company' => is_null($license->company) ? '' : e($license->company->name),
'manufacturer' => $license->manufacturer ? (string) link_to('/admin/settings/manufacturers/'.$license->manufacturer_id.'/view', $license->manufacturer->name) : ''
);
}

View file

@ -234,13 +234,51 @@ class License extends Depreciable
return $query->where(function ($query) use ($search) {
$query->where('name', 'LIKE', '%'.$search.'%')
->orWhere('serial', 'LIKE', '%'.$search.'%')
->orWhere('notes', 'LIKE', '%'.$search.'%')
->orWhere('order_number', 'LIKE', '%'.$search.'%')
->orWhere('purchase_order', 'LIKE', '%'.$search.'%')
->orWhere('purchase_date', 'LIKE', '%'.$search.'%')
->orWhere('purchase_cost', 'LIKE', '%'.$search.'%');
$query->where('licenses.name', 'LIKE', '%'.$search.'%')
->orWhere('licenses.serial', 'LIKE', '%'.$search.'%')
->orWhere('licenses.notes', 'LIKE', '%'.$search.'%')
->orWhere('licenses.order_number', 'LIKE', '%'.$search.'%')
->orWhere('licenses.purchase_order', 'LIKE', '%'.$search.'%')
->orWhere('licenses.purchase_date', 'LIKE', '%'.$search.'%')
->orWhere('licenses.purchase_cost', 'LIKE', '%'.$search.'%')
->orWhereHas('manufacturer', function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
});
})
->orWhereHas('company', function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('companies.name', 'LIKE', '%'.$search.'%');
});
});
});
}
/**
* Query builder scope to order on manufacturer
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderManufacturer($query, $order)
{
return $query->leftJoin('manufacturers', 'licenses.manufacturer_id', '=', 'manufacturers.id')->select('licenses.*')
->orderBy('manufacturers.name', $order);
}
/**
* Query builder scope to order on company
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderCompany($query, $order)
{
return $query->leftJoin('companies as companies', 'licenses.company_id', '=', 'companies.id')->select('licenses.*')
->orderBy('companies.name', $order);
}
}