Fixed #5151 - added asset tag to maintenances

This commit is contained in:
snipe 2018-03-05 16:26:40 -08:00
parent 9effa3d2ab
commit 36cd63836e
5 changed files with 63 additions and 3 deletions

View file

@ -56,6 +56,8 @@ class AssetMaintenancesController extends Controller
'start_date',
'completion_date',
'notes',
'asset_tag',
'asset_name',
'user_id'
];
$order = Input::get('order') === 'asc' ? 'asc' : 'desc';
@ -65,6 +67,12 @@ class AssetMaintenancesController extends Controller
case 'user_id':
$maintenances = $maintenances->OrderAdmin($order);
break;
case 'asset_tag':
$maintenances = $maintenances->OrderByTag($order);
break;
case 'asset_name':
$maintenances = $maintenances->OrderByAssetName($order);
break;
default:
$maintenances = $maintenances->orderBy($sort, $order);
break;

View file

@ -22,8 +22,19 @@ class AssetMaintenancesTransformer
{
$array = [
'id' => (int) $assetmaintenance->id,
'asset_name' => ($assetmaintenance->asset) ? ['id' => $assetmaintenance->asset->id,'name'=> e($assetmaintenance->asset->name)] : null,
'asset' => ($assetmaintenance->asset) ? [
'id' => (int) $assetmaintenance->asset->id,
'name'=> ($assetmaintenance->asset->name) ? e($assetmaintenance->asset->name) : null,
'asset_tag'=> e($assetmaintenance->asset->asset_tag)
] : null,
'title' => ($assetmaintenance->title) ? e($assetmaintenance->title) : null,
'location' => ($assetmaintenance->asset->location) ? [
'id' => (int) $assetmaintenance->asset->location->id,
'name'=> e($assetmaintenance->asset->location->name),
] : null,
'notes' => ($assetmaintenance->notes) ? e($assetmaintenance->notes) : null,
'supplier' => ($assetmaintenance->supplier) ? ['id' => $assetmaintenance->supplier->id,'name'=> e($assetmaintenance->supplier->name)] : null,
'cost' => Helper::formatCurrencyOutput($assetmaintenance->cost),

View file

@ -177,4 +177,32 @@ class AssetMaintenance extends Model implements ICompanyableChild
->orderBy('users.first_name', $order)
->orderBy('users.last_name', $order);
}
/**
* Query builder scope to order on asset tag
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByTag($query, $order)
{
return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id')
->orderBy('assets.asset_tag', $order);
}
/**
* Query builder scope to order on asset tag
*
* @param Illuminate\Database\Query\Builder $query Query builder instance
* @param text $order Order
*
* @return Illuminate\Database\Query\Builder Modified query builder
*/
public function scopeOrderByAssetName($query, $order)
{
return $query->leftJoin('assets', 'asset_maintenances.asset_id', '=', 'assets.id')
->orderBy('assets.name', $order);
}
}

View file

@ -42,7 +42,9 @@
<tr>
<th data-sortable="true" data-field="id" data-visible="true">{{ trans('general.id') }}</th>
<th data-field="company" data-sortable="false" data-visible="true">{{ trans('admin/companies/table.title') }}</th>
<th data-sortable="false" data-visible="true" data-field="asset_name" data-formatter="hardwareLinkObjFormatter">{{ trans('admin/asset_maintenances/table.asset_name') }}</th>
<th data-sortable="true" data-visible="false" data-field="asset_name" data-formatter="assetNameLinkFormatter">{{ trans('admin/asset_maintenances/table.asset_name') }}</th>
<th data-field="asset_tag" data-sortable="true" data-visible="true" data-formatter="assetTagLinkFormatter">{{ trans('admin/hardware/table.asset_tag') }}</th>
<th data-sortable="false" data-visible="true" data-field="location" data-formatter="locationsLinkObjFormatter">{{ trans('admin/hardware/table.location') }}</th>
<th data-sortable="false" data-visible="true" data-field="supplier" data-formatter="suppliersLinkObjFormatter">{{ trans('general.supplier') }}</th>
<th data-searchable="true" data-visible="true" data-sortable="true" data-field="asset_maintenance_type">{{ trans('admin/asset_maintenances/form.asset_maintenance_type') }}</th>
<th data-searchable="true" data-visible="true" data-sortable="true" data-field="title">{{ trans('admin/asset_maintenances/form.title') }}</th>

View file

@ -413,6 +413,17 @@
return '<a href="{{ url('/') }}/admin/groups/' + row.id + '"> ' + value + '</a>';
}
function assetTagLinkFormatter(value, row) {
return '<a href="{{ url('/') }}/hardware/' + row.asset.id + '"> ' + row.asset.asset_tag + '</a>';
}
function assetNameLinkFormatter(value, row) {
if ((row.asset) && (row.asset.name)) {
return '<a href="{{ url('/') }}/hardware/' + row.asset.id + '"> ' + row.asset.name + '</a>';
}
}
function trueFalseFormatter(value, row) {
if ((value) && ((value == 'true') || (value == '1'))) {
return '<i class="fa fa-check text-success"></i>';