Components display on assets page

This commit is contained in:
snipe 2016-05-18 19:26:50 -07:00
parent fb26188e41
commit c1c7fa143d
2 changed files with 40 additions and 1 deletions

View file

@ -213,7 +213,7 @@ class Asset extends Depreciable
} }
/** /**
* Set depreciation relationship * Set depreciation relationship
*/ */
public function depreciation() public function depreciation()
@ -221,6 +221,14 @@ class Asset extends Depreciable
return $this->model->belongsTo('\App\Models\Depreciation', 'depreciation_id'); return $this->model->belongsTo('\App\Models\Depreciation', 'depreciation_id');
} }
/**
* Get components assigned to this asset
*/
public function components()
{
return $this->belongsToMany('\App\Models\Component', 'components_assets', 'asset_id', 'component_id')->withPivot('id')->withTrashed();
}
/** /**
* Get depreciation attribute from associated asset model * Get depreciation attribute from associated asset model
*/ */

View file

@ -50,9 +50,13 @@
<li> <li>
<a href="#software" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-floppy-o"></i></span> <span class="hidden-xs hidden-sm">Licenses</span></a> <a href="#software" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-floppy-o"></i></span> <span class="hidden-xs hidden-sm">Licenses</span></a>
</li> </li>
<li>
<a href="#components" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-hdd-o"></i></span> <span class="hidden-xs hidden-sm">Components</span></a>
</li>
<li> <li>
<a href="#maintenances" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-wrench"></i></span> <span class="hidden-xs hidden-sm">Maintenances</span></a> <a href="#maintenances" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-wrench"></i></span> <span class="hidden-xs hidden-sm">Maintenances</span></a>
</li> </li>
<li> <li>
<a href="#history" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-history"></i></span> <span class="hidden-xs hidden-sm">History</span></a> <a href="#history" data-toggle="tab"><span class="hidden-lg hidden-md"><i class="fa fa-history"></i></span> <span class="hidden-xs hidden-sm">History</span></a>
</li> </li>
@ -292,6 +296,33 @@
</div> </div>
</div><!-- /row --> </div><!-- /row -->
</div><!-- /.tab-pane --> </div><!-- /.tab-pane -->
<div class="tab-pane fade" id="components">
<!-- checked out assets table -->
<div class="row">
<div class="col-md-12">
<table class="table table-striped">
<tbody>
<?php $totalCost = 0; ?>
@foreach ($asset->components as $component)
@if (is_null($component->deleted_at))
<tr>
<td><a href="{{ route('view/component', $component->id) }}">{{ $component->name }}</a></td>
</tr>
@endif
@endforeach
</tbody>
<tfoot>
<tr>
<td colspan="7" class="text-right">{{ $use_currency.$totalCost }}</td>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="software"> <div class="tab-pane fade" id="software">
<div class="row"> <div class="row">
<div class="col-md-12"> <div class="col-md-12">