Fixed #6027 - added model to asset maintenances listing

This commit is contained in:
snipe 2018-08-01 18:24:52 -07:00
parent 6f8680efa6
commit 9168979d9e
5 changed files with 33 additions and 15 deletions

View file

@ -34,10 +34,10 @@ class AssetMaintenancesController extends Controller
*/ */
public function index(Request $request) public function index(Request $request)
{ {
$maintenances = AssetMaintenance::with('asset', 'supplier', 'asset.company', 'admin'); $maintenances = AssetMaintenance::with('asset', 'asset.model','asset.location', 'supplier', 'asset.company', 'admin');
if (Input::has('search')) { if ($request->filled('search')) {
$maintenances = $maintenances->TextSearch(e($request->input('search'))); $maintenances = $maintenances->TextSearch($request->input('search'));
} }
if ($request->filled('asset_id')) { if ($request->filled('asset_id')) {

View file

@ -28,6 +28,10 @@ class AssetMaintenancesTransformer
'asset_tag'=> e($assetmaintenance->asset->asset_tag) 'asset_tag'=> e($assetmaintenance->asset->asset_tag)
] : null, ] : null,
'model' => ($assetmaintenance->asset->model) ? [
'id' => (int) $assetmaintenance->asset->model->id,
'name'=> ($assetmaintenance->asset->model->name) ? e($assetmaintenance->asset->model->name).' '.e($assetmaintenance->asset->model->model_number) : null
] : null,
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null, 'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [ 'location' => (($assetmaintenance->asset) && ($assetmaintenance->asset->location)) ? [
'id' => (int) $assetmaintenance->asset->location->id, 'id' => (int) $assetmaintenance->asset->location->id,

View file

@ -48,7 +48,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
* *
* @var array * @var array
*/ */
protected $searchableRelations = []; protected $searchableRelations = [
'asset' => ['name', 'asset_tag'],
'asset.model' => ['name', 'model_number'],
];
public function getCompanyableParents() public function getCompanyableParents()
@ -152,6 +155,7 @@ class AssetMaintenance extends Model implements ICompanyableChild
->withTrashed(); ->withTrashed();
} }
/** /**
* ----------------------------------------------- * -----------------------------------------------
* BEGIN QUERY SCOPES * BEGIN QUERY SCOPES
@ -162,10 +166,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
/** /**
* Query builder scope to order on admin user * Query builder scope to order on admin user
* *
* @param Illuminate\Database\Query\Builder $query Query builder instance * @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order * @param string $order Order
* *
* @return Illuminate\Database\Query\Builder Modified query builder * @return \Illuminate\Database\Query\Builder Modified query builder
*/ */
public function scopeOrderAdmin($query, $order) public function scopeOrderAdmin($query, $order)
{ {
@ -177,10 +181,10 @@ class AssetMaintenance extends Model implements ICompanyableChild
/** /**
* Query builder scope to order on asset tag * Query builder scope to order on asset tag
* *
* @param Illuminate\Database\Query\Builder $query Query builder instance * @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order * @param string $order Order
* *
* @return Illuminate\Database\Query\Builder Modified query builder * @return \Illuminate\Database\Query\Builder Modified query builder
*/ */
public function scopeOrderByTag($query, $order) public function scopeOrderByTag($query, $order)
{ {
@ -191,14 +195,16 @@ class AssetMaintenance extends Model implements ICompanyableChild
/** /**
* Query builder scope to order on asset tag * Query builder scope to order on asset tag
* *
* @param Illuminate\Database\Query\Builder $query Query builder instance * @param \Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order * @param string $order Order
* *
* @return Illuminate\Database\Query\Builder Modified query builder * @return \Illuminate\Database\Query\Builder Modified query builder
*/ */
public function scopeOrderByAssetName($query, $order) public function scopeOrderByAssetName($query, $order)
{ {
return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id') return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id')
->orderBy('assets.name', $order); ->orderBy('assets.name', $order);
} }
} }

View file

@ -17,9 +17,9 @@ trait Searchable {
/** /**
* Performs a search on the model, using the provided search terms * Performs a search on the model, using the provided search terms
* *
* @param Illuminate\Database\Eloquent\Builder $query The query to start the search on * @param \Illuminate\Database\Eloquent\Builder $query The query to start the search on
* @param string $search * @param string $search
* @return Illuminate\Database\Eloquent\Builder A query with added "where" clauses * @return \Illuminate\Database\Eloquent\Builder A query with added "where" clauses
*/ */
public function scopeTextSearch($query, $search) public function scopeTextSearch($query, $search)
{ {

View file

@ -46,6 +46,14 @@ class AssetMaintenancesPresenter extends Presenter
"title" => trans('admin/hardware/table.asset_tag'), "title" => trans('admin/hardware/table.asset_tag'),
"formatter" => "assetTagLinkFormatter" "formatter" => "assetTagLinkFormatter"
], [ ], [
"field" => "model",
"searchable" => true,
"sortable" => true,
"switchable" => true,
"title" => trans('admin/hardware/form.model'),
"visible" => false,
"formatter" => "modelsLinkObjFormatter"
],[
"field" => "supplier", "field" => "supplier",
"searchable" => true, "searchable" => true,
"sortable" => true, "sortable" => true,