mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
Add manufacturer name/sorting/searching on assets
This commit is contained in:
parent
c41b47902e
commit
ae8a03fec3
|
@ -1278,7 +1278,7 @@ class AssetsController extends Controller
|
|||
{
|
||||
|
||||
|
||||
$assets = Asset::select('assets.*')->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.fieldset', 'assetstatus', 'assetloc', 'company')
|
||||
$assets = Asset::select('assets.*')->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company')
|
||||
->Hardware();
|
||||
|
||||
if (Input::has('search')) {
|
||||
|
@ -1334,6 +1334,7 @@ class AssetsController extends Controller
|
|||
'model',
|
||||
'last_checkout',
|
||||
'category',
|
||||
'manufacturer',
|
||||
'notes',
|
||||
'expected_checkin',
|
||||
'order_number',
|
||||
|
@ -1360,6 +1361,9 @@ class AssetsController extends Controller
|
|||
case 'category':
|
||||
$assets = $assets->OrderCategory($order);
|
||||
break;
|
||||
case 'manufacturer':
|
||||
$assets = $assets->OrderManufacturer($order);
|
||||
break;
|
||||
case 'companyName':
|
||||
$assets = $assets->OrderCompany($order);
|
||||
break;
|
||||
|
@ -1412,7 +1416,8 @@ class AssetsController extends Controller
|
|||
'status_label' => ($asset->assigneduser) ? 'Deployed' : ((e($asset->assetstatus)) ? e($asset->assetstatus->name) : ''),
|
||||
'assigned_to' => ($asset->assigneduser) ? (string)link_to(config('app.url').'/admin/users/'.$asset->assigned_to.'/view', e($asset->assigneduser->fullName())) : '',
|
||||
'location' => (($asset->assigneduser) && ($asset->assigneduser->userloc!='')) ? (string)link_to('admin/settings/locations/'.$asset->assigneduser->userloc->id.'/edit', e($asset->assigneduser->userloc->name)) : (($asset->defaultLoc!='') ? (string)link_to('admin/settings/locations/'.$asset->defaultLoc->id.'/edit', e($asset->defaultLoc->name)) : ''),
|
||||
'category' => (($asset->model) && ($asset->model->category)) ? e($asset->model->category->name) : '',
|
||||
'category' => (($asset->model) && ($asset->model->category)) ?(string)link_to('/admin/settings/categories/'.$asset->model->category->id.'/view', e($asset->model->category->name)) : '',
|
||||
'manufacturer' => (($asset->model) && ($asset->model->manufacturer)) ? (string)link_to('/admin/settings/manufacturers/'.$asset->model->manufacturer->id.'/view', e($asset->model->manufacturer->name)) : '',
|
||||
'eol' => ($asset->eol_date()) ? $asset->eol_date() : '',
|
||||
'notes' => e($asset->notes),
|
||||
'order_number' => ($asset->order_number!='') ? '<a href="'.config('app.url').'/hardware?order_number='.e($asset->order_number).'">'.e($asset->order_number).'</a>' : '',
|
||||
|
|
|
@ -722,6 +722,12 @@ class Asset extends Depreciable
|
|||
->orWhere('models.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
});
|
||||
})->orWhereHas('model', function ($query) use ($search) {
|
||||
$query->whereHas('manufacturer', function ($query) use ($search) {
|
||||
$query->where(function ($query) use ($search) {
|
||||
$query->where('manufacturers.name', 'LIKE', '%'.$search.'%');
|
||||
});
|
||||
});
|
||||
})->orWhere(function ($query) use ($search) {
|
||||
$query->whereHas('assetstatus', function ($query) use ($search) {
|
||||
$query->where('status_labels.name', 'LIKE', '%'.$search.'%');
|
||||
|
@ -826,6 +832,22 @@ class Asset extends Depreciable
|
|||
->orderBy('categories.name', $order);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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->join('models', 'assets.model_id', '=', 'models.id')
|
||||
->join('manufacturers', 'models.manufacturer_id', '=', 'manufacturers.id')
|
||||
->orderBy('manufacturers.name', $order);
|
||||
}
|
||||
|
||||
/**
|
||||
* Query builder scope to order on model
|
||||
*
|
||||
|
|
|
@ -82,6 +82,7 @@
|
|||
<th data-sortable="true" data-field="assigned_to">{{ trans('admin/hardware/form.checkedout_to') }}</th>
|
||||
<th data-sortable="true" data-field="location" data-searchable="true">{{ trans('admin/hardware/table.location') }}</th>
|
||||
<th data-sortable="true" data-field="category" data-searchable="true">{{ trans('general.category') }}</th>
|
||||
<th data-sortable="true" data-field="manufacturer" data-searchable="true" data-visible="false">{{ trans('general.manufacturer') }}</th>
|
||||
<th data-sortable="false" data-field="eol" data-searchable="true">{{ trans('general.eol') }}</th>
|
||||
<th data-sortable="true" data-searchable="true" data-field="notes">{{ trans('general.notes') }}</th>
|
||||
<th data-sortable="true" data-searchable="true" data-field="order_number">{{ trans('admin/hardware/form.order') }}</th>
|
||||
|
|
Loading…
Reference in a new issue