Add model number column to the hardware list. (#2204)

* Add model number column to the hardware list and allow searching based on model number.   Column is hidden by default.

* Fix sorting.  Add scope to order by model number.
This commit is contained in:
Daniel Meltzer 2016-06-28 01:32:40 -04:00 committed by snipe
parent 084db22cd5
commit d484636bba
3 changed files with 21 additions and 1 deletions

View file

@ -1425,6 +1425,7 @@ class AssetsController extends Controller
'asset_tag',
'serial',
'model',
'model_number',
'last_checkout',
'category',
'manufacturer',
@ -1452,6 +1453,9 @@ class AssetsController extends Controller
case 'model':
$assets = $assets->OrderModels($order);
break;
case 'model_number':
$assets = $assets->OrderModelNumber($order);
break;
case 'category':
$assets = $assets->OrderCategory($order);
break;
@ -1507,6 +1511,7 @@ class AssetsController extends Controller
'asset_tag' => '<a title="'.e($asset->asset_tag).'" href="hardware/'.$asset->id.'/view">'.e($asset->asset_tag).'</a>',
'serial' => e($asset->serial),
'model' => ($asset->model) ? (string)link_to('/hardware/models/'.$asset->model->id.'/view', e($asset->model->name)) : 'No model',
'model_number' => ($asset->model && $asset->model->modelno) ? (string)$asset->model->modelno : '',
'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)) : ''),

View file

@ -736,7 +736,8 @@ class Asset extends Depreciable
$query->whereHas('category', function ($query) use ($search) {
$query->where(function ($query) use ($search) {
$query->where('categories.name', 'LIKE', '%'.$search.'%')
->orWhere('models.name', 'LIKE', '%'.$search.'%');
->orWhere('models.name', 'LIKE', '%'.$search.'%')
->orWhere('models.modelno', 'LIKE', '%'.$search.'%');
});
});
})->orWhereHas('model', function ($query) use ($search) {
@ -794,6 +795,19 @@ class Asset extends Depreciable
return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.name', $order);
}
/**
* Query builder scope to order on model number
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderModelNumber($query, $order)
{
return $query->join('models', 'assets.model_id', '=', 'models.id')->orderBy('models.modelno', $order);
}
/**
* Query builder scope to order on assigned user

View file

@ -78,6 +78,7 @@
<th data-sortable="true" data-field="asset_tag">{{ trans('admin/hardware/table.asset_tag') }}</th>
<th data-sortable="true" data-field="serial">{{ trans('admin/hardware/table.serial') }}</th>
<th data-sortable="true" data-field="model">{{ trans('admin/hardware/form.model') }}</th>
<th data-sortable="true" data-field="model_number" data-visible="false">{{ trans('admin/models/table.modelnumber') }}</th>
<th data-sortable="true" data-field="status_label">{{ trans('admin/hardware/table.status') }}</th>
<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>