Port more assignedUser to assignedTo.

This commit is contained in:
Daniel Meltzer 2016-12-29 09:31:16 -05:00
parent 165487ac92
commit 8cc695b65f
16 changed files with 37 additions and 46 deletions

View file

@ -337,11 +337,11 @@ class Helper
* *
* @author [A. Gianotto] [<snipe@snipe.net>] * @author [A. Gianotto] [<snipe@snipe.net>]
* @since [v2.5] * @since [v2.5]
* @return Array * @return array
*/ */
public static function detailedAssetList() public static function detailedAssetList()
{ {
$assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedUser', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray(); $assets = array('' => trans('general.select_asset')) + Company::scopeCompanyables(Asset::with('assignedTo', 'model'), 'assets.company_id')->get()->pluck('detailed_name', 'id')->toArray();
return $assets; return $assets;
} }

View file

@ -1164,7 +1164,7 @@ class AssetsController extends Controller
return View::make('hardware/labels')->with('assets', Asset::find($asset_ids))->with('settings', Setting::getSettings())->with('count', $count)->with('settings', return View::make('hardware/labels')->with('assets', Asset::find($asset_ids))->with('settings', Setting::getSettings())->with('count', $count)->with('settings',
Setting::getSettings()); Setting::getSettings());
} elseif (Input::get('bulk_actions')=='delete') { } elseif (Input::get('bulk_actions')=='delete') {
$assets = Asset::with('assigneduser', 'assetloc')->find($asset_ids); $assets = Asset::with('assignedTo', 'assetloc')->find($asset_ids);
$assets->each(function($asset) { $assets->each(function($asset) {
$this->authorize('delete',$asset); $this->authorize('delete',$asset);
}); });
@ -1317,7 +1317,7 @@ class AssetsController extends Controller
public function getDatatable(Request $request, $status = null) public function getDatatable(Request $request, $status = null)
{ {
$this->authorize('index', Asset::class); $this->authorize('index', Asset::class);
$assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assigneduser', 'assigneduser.userloc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'assetloc', 'company') $assets = Company::scopeCompanyables(Asset::select('assets.*'))->with('model', 'assignedTo', 'assetLoc', 'assetstatus', 'defaultLoc', 'assetlog', 'model', 'model.category', 'model.manufacturer', 'model.fieldset', 'assetstatus', 'company')
->Hardware(); ->Hardware();
if ($request->has('search')) { if ($request->has('search')) {

View file

@ -247,7 +247,7 @@ class CategoriesController extends Controller
public function getDataViewAssets(Request $request, $categoryID) public function getDataViewAssets(Request $request, $categoryID)
{ {
$category = Category::find($categoryID); $category = Category::find($categoryID);
$category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assigneduser'); $category = $category->load('assets.company', 'assets.model', 'assets.assetstatus', 'assets.assignedTo');
$category_assets = $category->assets(); $category_assets = $category->assets();
if (Input::has('search')) { if (Input::has('search')) {
$category_assets = $category_assets->TextSearch(e($request->input('search'))); $category_assets = $category_assets->TextSearch(e($request->input('search')));

View file

@ -246,7 +246,7 @@ class ManufacturersController extends Controller
protected function getDataAssetsView(Manufacturer $manufacturer, Request $request) protected function getDataAssetsView(Manufacturer $manufacturer, Request $request)
{ {
$manufacturer = $manufacturer->load('assets.model', 'assets.assigneduser', 'assets.assetstatus', 'assets.company'); $manufacturer = $manufacturer->load('assets.model', 'assets.assignedTo', 'assets.assetstatus', 'assets.company');
$manufacturer_assets = $manufacturer->assets(); $manufacturer_assets = $manufacturer->assets();
if ($request->has('search')) { if ($request->has('search')) {

View file

@ -121,7 +121,7 @@ class ReportsController extends Controller
// Open output stream // Open output stream
$handle = fopen('php://output', 'w'); $handle = fopen('php://output', 'w');
Asset::with('assignedTo', 'assetLoc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) { Asset::with('assignedTo', 'assetLoc','defaultLoc','assignedTo','model','supplier','assetstatus','model.manufacturer')->orderBy('created_at', 'DESC')->chunk(500, function($assets) use($handle, $customfields) {
$headers=[ $headers=[
trans('general.company'), trans('general.company'),
trans('admin/hardware/table.asset_tag'), trans('admin/hardware/table.asset_tag'),
@ -194,7 +194,7 @@ class ReportsController extends Controller
{ {
// Grab all the assets // Grab all the assets
$assets = Asset::with('model', 'assigneduser', 'assetstatus', 'defaultLoc', 'assetlog', 'company') $assets = Asset::with('model', 'assignedTo', 'assetstatus', 'defaultLoc', 'assetlog', 'company')
->orderBy('created_at', 'DESC')->get(); ->orderBy('created_at', 'DESC')->get();
return View::make('reports/depreciation', compact('assets')); return View::make('reports/depreciation', compact('assets'));
@ -212,7 +212,7 @@ class ReportsController extends Controller
{ {
// Grab all the assets // Grab all the assets
$assets = Asset::with('model', 'assigneduser', 'assetstatus', 'defaultLoc', 'assetlog') $assets = Asset::with('model', 'assignedTo', 'assetstatus', 'defaultLoc', 'assetlog')
->orderBy('created_at', 'DESC')->get(); ->orderBy('created_at', 'DESC')->get();
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject()); $csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
@ -488,7 +488,7 @@ class ReportsController extends Controller
*/ */
public function postCustom() public function postCustom()
{ {
$assets = Asset::orderBy('created_at', 'DESC')->with('company','assigneduser', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->get(); $assets = Asset::orderBy('created_at', 'DESC')->with('company','assignedTo', 'assetloc','defaultLoc','assigneduser.userloc','model','supplier','assetstatus','model.manufacturer')->get();
$customfields = CustomField::get(); $customfields = CustomField::get();
$rows = [ ]; $rows = [ ];

View file

@ -69,7 +69,7 @@ class ViewAssetsController extends Controller
public function getRequestableIndex() public function getRequestableIndex()
{ {
$assets = Asset::with('model', 'defaultLoc', 'assetloc', 'assigneduser')->Hardware()->RequestableAssets()->get(); $assets = Asset::with('model', 'defaultLoc', 'assetloc', 'assignedTo')->Hardware()->RequestableAssets()->get();
$models = AssetModel::with('category')->RequestableModels()->get(); $models = AssetModel::with('category')->RequestableModels()->get();
return View::make('account/requestable-assets', compact('user', 'assets', 'models')); return View::make('account/requestable-assets', compact('user', 'assets', 'models'));

View file

@ -154,8 +154,8 @@ class Asset extends Depreciable
public function getDetailedNameAttribute() public function getDetailedNameAttribute()
{ {
if ($this->assignedUser) { if ($this->assignedTo) {
$user_name = $this->assignedUser->present()->fullName(); $user_name = $this->assignedTo->present()->name();
} else { } else {
$user_name = "Unassigned"; $user_name = "Unassigned";
} }
@ -204,6 +204,12 @@ class Asset extends Depreciable
->orderBy('created_at', 'desc'); ->orderBy('created_at', 'desc');
} }
/**
* Even though we allow allow for checkout to things beyond users
* this method is an easy way of seeing if we are checked out to a user.
* @return mixed
*/
public function assigneduser() public function assigneduser()
{ {
return $this->belongsTo('\App\Models\User', 'assigned_to') return $this->belongsTo('\App\Models\User', 'assigned_to')
@ -233,9 +239,6 @@ class Asset extends Depreciable
} }
// Default to User // Default to User
// var_dump($this); // var_dump($this);
if(!$this->assignedTo) {
dd($this);
}
return $this->assignedTo->userLoc(); return $this->assignedTo->userLoc();
} }
return $this->defaultLoc(); return $this->defaultLoc();

View file

@ -39,10 +39,8 @@ class CheckoutRequest extends Model
{ {
if ($this->itemType() == "asset") { if ($this->itemType() == "asset") {
$asset = $this->itemRequested(); $asset = $this->itemRequested();
if ($asset->assigneduser && $asset->assetloc) { if ($asset->assignedTo) {
return $asset->assetloc; return $asset->assetloc;
} elseif ($asset->defaultLoc) {
return $asset->defaultLoc;
} }
} }
return $this->itemRequested()->location; return $this->itemRequested()->location;

View file

@ -60,11 +60,7 @@
<td>{{ $asset->serial }}</td> <td>{{ $asset->serial }}</td>
<td> <td>
@if ($asset->assigneduser && $asset->assetloc)
{{ $asset->assetloc->name }} {{ $asset->assetloc->name }}
@elseif ($asset->defaultLoc)
{{ $asset->defaultLoc->name }}
@endif
</td> </td>
@if ($asset->assigned_to != '' && $asset->assigned_to > 0) @if ($asset->assigned_to != '' && $asset->assigned_to > 0)
<td>Checked out</td> <td>Checked out</td>

View file

@ -47,8 +47,8 @@
@endif @endif
</td> </td>
<td> <td>
@if ($asset->assigneduser) @if ($asset->assignedTo)
{{ $asset->assigneduser->present()->fullName() }} ({{ $asset->assigneduser->username }}) {{ $asset->assignedTo->present()->name().' ' .$asset->assigneduser ? '('.$asset->assigneduser->username. ')' : ''}}
@endif @endif
</td> </td>
</tr> </tr>

View file

@ -336,13 +336,14 @@
@endif @endif
@if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at=='')) @if (($asset->assigneduser) && ($asset->assigned_to > 0) && ($asset->deleted_at==''))
{{-- @TODO This should be extnded for details about non users --}}
<h6><br>{{ trans('admin/hardware/form.checkedout_to') }}</h6> <h6><br>{{ trans('admin/hardware/form.checkedout_to') }}</h6>
<ul> <ul>
<li> <li>
<img src="{{ $asset->assigneduser->present()->gravatar() }}" class="img-circle" style="width: 100px; margin-right: 20px;" /><br /><br /> <img src="{{ $asset->assigneduser->present()->gravatar() }}" class="img-circle" style="width: 100px; margin-right: 20px;" /><br /><br />
</li> </li>
<li> <li>
<a href="{{ route('users.show', $asset->assigned_to) }}">{{ $asset->assigneduser->present()->fullName() }}</a> {{ $asset->assignedTo->present()->nameUrl() }}
</li> </li>
@if (isset($asset->assetloc->address)) @if (isset($asset->assetloc->address))

View file

@ -602,8 +602,8 @@
@endif @endif
@elseif (($log->action_type=='accepted') || ($log->action_type=='declined')) @elseif (($log->action_type=='accepted') || ($log->action_type=='declined'))
{{-- On a declined log, the asset isn't assigned to anyone when we look this up. --}} {{-- On a declined log, the asset isn't assigned to anyone when we look this up. --}}
@if ($log->item->assigneduser) @if ($log->item->assignedTo)
{{ $log->item->assigneduser->present()->fullName() }} {{ $log->item->assignedTo->present()->name() }}
@else @else
Unknown Unknown
@endif @endif

View file

@ -68,11 +68,9 @@
@elseif ($licensedto->asset) @elseif ($licensedto->asset)
@if ($licensedto->asset->assigned_to != 0) @if ($licensedto->asset->assigned_to != 0)
@can('users.view') @can('users.view')
<a href="{{ route('users.show', $licensedto->asset->assigned_to) }}"> {!! $licensedto->asset->assignedTo->present()->nameUrl() !!}
{{ $licensedto->asset->assigneduser->present()->fullName() }}
</a>
@else @else
{{ $licensedto->asset->assigneduser->present()->fullName() }} {{ $licensedto->asset->assignedTo->present()->name() }}
@endcan @endcan
@endif @endif
@endif @endif

View file

@ -74,13 +74,11 @@
@endif @endif
</td> </td>
<td> <td>
@if ($asset->assigneduser) @if ($asset->assignedTo)
@if ($asset->assigneduser->deleted_at!='') @if ($asset->assignedTo->deleted_at!='')
<del>{{ $asset->assigneduser->present()->fullName() }}</del> <del>{{ $asset->assignedTo->present()->name() }}</del>
@else @else
<a href="{{ route('users.show', $asset->assigned_to) }}"> {!! $asset->assignedTo->present()->nameUrl() !!}
{{ $asset->assigneduser->present()->fullName() }}
</a>
@endif @endif
@endif @endif
</td> </td>

View file

@ -48,15 +48,12 @@
<td>{{ $asset->serial }}</td> <td>{{ $asset->serial }}</td>
<td> <td>
@if ($asset->assigned_to != '') @if ($asset->assigned_to != '')
<a href="{{ route('users.show', $asset->assigned_to) }}"> {!! $asset->assignedTo->present->nameUrl() !!}
{{ $asset->assigneduser->present()->fullName() }}
</a>
@endif @endif
</td> </td>
<td> <td>
@if (($asset->assigned_to > 0) && ($asset->assigneduser->location_id > 0)) {{ Location::find($asset->assigneduser->location_id)->city }} @if (($asset->assignedTo) && ($asset->assigneduser->assetLoc))
, {{ $asset->assignedTo->assetLoc->city }}, {{ $asset->assignedTo->assetLoc->state}}
{{ Location::find($asset->assigneduser->location_id)->state }}
@endif @endif
</td> </td>
<td>{{ $asset->purchase_date }}</td> <td>{{ $asset->purchase_date }}</td>

View file

@ -39,9 +39,9 @@
<td>{{ is_null($assetItem->company) ? '' : $assetItem->company->name }}</td> <td>{{ is_null($assetItem->company) ? '' : $assetItem->company->name }}</td>
<td>{{ $assetItem->model->category->name }}</td> <td>{{ $assetItem->model->category->name }}</td>
<td>{{ $assetItem->model->name }}</td> <td>{{ $assetItem->model->name }}</td>
<td>{{ link_to_route('hardware.show',$assetItem->present()->name(), [$assetItem->id]) }}</td> <td>{!! $assetItem->present()->nameUrl() !!}</td>
<td>{{ $assetItem->asset_tag }}</td> <td>{{ $assetItem->asset_tag }}</td>
<td>{{ link_to_route('users.show', $assetItem->assigneduser->present()->fullName(), [$assetItem->assigned_to])}}</td> <td>{!! $assetItem->assignedTo->present()->nameUrl() !!}</td>
</tr> </tr>
@endforeach @endforeach
@endif @endif