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>]
* @since [v2.5]
* @return Array
* @return array
*/
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;
}

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',
Setting::getSettings());
} 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) {
$this->authorize('delete',$asset);
});
@ -1317,7 +1317,7 @@ class AssetsController extends Controller
public function getDatatable(Request $request, $status = null)
{
$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();
if ($request->has('search')) {

View file

@ -247,7 +247,7 @@ class CategoriesController extends Controller
public function getDataViewAssets(Request $request, $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();
if (Input::has('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)
{
$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();
if ($request->has('search')) {

View file

@ -121,7 +121,7 @@ class ReportsController extends Controller
// Open output stream
$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=[
trans('general.company'),
trans('admin/hardware/table.asset_tag'),
@ -194,7 +194,7 @@ class ReportsController extends Controller
{
// 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();
return View::make('reports/depreciation', compact('assets'));
@ -212,7 +212,7 @@ class ReportsController extends Controller
{
// 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();
$csv = \League\Csv\Writer::createFromFileObject(new \SplTempFileObject());
@ -488,7 +488,7 @@ class ReportsController extends Controller
*/
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();
$rows = [ ];

View file

@ -69,7 +69,7 @@ class ViewAssetsController extends Controller
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();
return View::make('account/requestable-assets', compact('user', 'assets', 'models'));

View file

@ -154,8 +154,8 @@ class Asset extends Depreciable
public function getDetailedNameAttribute()
{
if ($this->assignedUser) {
$user_name = $this->assignedUser->present()->fullName();
if ($this->assignedTo) {
$user_name = $this->assignedTo->present()->name();
} else {
$user_name = "Unassigned";
}
@ -204,6 +204,12 @@ class Asset extends Depreciable
->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()
{
return $this->belongsTo('\App\Models\User', 'assigned_to')
@ -233,9 +239,6 @@ class Asset extends Depreciable
}
// Default to User
// var_dump($this);
if(!$this->assignedTo) {
dd($this);
}
return $this->assignedTo->userLoc();
}
return $this->defaultLoc();

View file

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

View file

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

View file

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

View file

@ -336,13 +336,14 @@
@endif
@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>
<ul>
<li>
<img src="{{ $asset->assigneduser->present()->gravatar() }}" class="img-circle" style="width: 100px; margin-right: 20px;" /><br /><br />
</li>
<li>
<a href="{{ route('users.show', $asset->assigned_to) }}">{{ $asset->assigneduser->present()->fullName() }}</a>
{{ $asset->assignedTo->present()->nameUrl() }}
</li>
@if (isset($asset->assetloc->address))

View file

@ -602,8 +602,8 @@
@endif
@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. --}}
@if ($log->item->assigneduser)
{{ $log->item->assigneduser->present()->fullName() }}
@if ($log->item->assignedTo)
{{ $log->item->assignedTo->present()->name() }}
@else
Unknown
@endif

View file

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

View file

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

View file

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

View file

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