Created method in users.php for adding up all assigned to user and providing an integer value. this then used to grey out buttons on user view if user has nothing assigned.

This commit is contained in:
akemi 2022-12-07 17:46:18 -05:00 committed by akemi
parent 9e8fff6e5b
commit 07ae91b00f
2 changed files with 22 additions and 1 deletions

View file

@ -338,6 +338,24 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id');
}
/**
* Establishes a count of all items assigned
*
* @author J. Vinsmoke
* @since [v6.1]
* @return \Illuminate\Database\Eloquent\Relations\Relation
*/
Public function allassignedcount() {
$assetsCount = $this->assets()->count();
$licensesCount = $this->licenses()->count();
$accessoriesCount = $this->accessories()->count();
$consumablesCount = $this->consumables()->count();
$totalcount = $assetsCount + $licensesCount + $accessoriesCount + $consumablesCount;
return (int) $totalcount;
}
/**
* Establishes the user -> actionlogs relationship
*

View file

@ -179,17 +179,20 @@
@can('view', $user)
<div class="col-md-12" style="padding-top: 5px;">
@if($user->allassignedcount() != '0')
<a href="{{ route('users.print', $user->id) }}" style="width: 100%;" class="btn btn-sm btn-primary hidden-print" target="_blank" rel="noopener">{{ trans('admin/users/general.print_assigned') }}</a>
</div>
@endcan
@can('view', $user)
<div class="col-md-12" style="padding-top: 5px;">
@if(!empty($user->email))
@if(!empty($user->email) && ($user->allassignedcount() != '0'))
<form action="{{ route('users.email',['userId'=> $user->id]) }}" method="POST">
{{ csrf_field() }}
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener">{{ trans('admin/users/general.email_assigned') }}</button>
</form>
@elseif(!empty($user->email) && ($user->allassignedcount() == '0'))
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener" disabled title="{{ trans('admin/users/message.user_has_no_assets_assigned') }}">{{ trans('admin/users/general.email_assigned') }}</button>
@else
<button style="width: 100%;" class="btn btn-sm btn-primary hidden-print" rel="noopener" disabled title="{{ trans('admin/users/message.user_has_no_email') }}">{{ trans('admin/users/general.email_assigned') }}</button>
@endif