mirror of
https://github.com/snipe/snipe-it.git
synced 2026-08-18 11:15:42 +00:00
Merge pull request #18629 from Godmartinz/update-print-invtentory-view-with-assigned2assets
Update print inventory view with indirect assignments table
This commit is contained in:
@ -211,14 +211,19 @@ class ProfileController extends Controller
|
||||
*/
|
||||
public function printInventory(): View
|
||||
{
|
||||
$show_users = User::where('id', auth()->user()->id)->get();
|
||||
$userId = auth()->id();
|
||||
|
||||
return view('users/print')
|
||||
->with('assets', auth()->user()->assets())
|
||||
->with('licenses', auth()->user()->licenses()->get())
|
||||
->with('accessories', auth()->user()->accessories()->get())
|
||||
->with('consumables', auth()->user()->consumables()->get())
|
||||
->with('users', $show_users)
|
||||
$show_user = User::withInventoryRelations($userId)->first();
|
||||
|
||||
$indirectItemsCount =
|
||||
$show_user->assets->flatMap->assignedAssets->count()
|
||||
+ $show_user->assets->flatMap->components->count()
|
||||
+ $show_user->assets->flatMap->licenses->count()
|
||||
+ $show_user->assets->flatMap->assignedAccessories->count();
|
||||
|
||||
return view('users.print')
|
||||
->with('users', [$show_user])
|
||||
->with('indirectItemsCount', $indirectItemsCount)
|
||||
->with('settings', Setting::getSettings());
|
||||
}
|
||||
|
||||
|
||||
@ -649,32 +649,16 @@ class UsersController extends Controller
|
||||
{
|
||||
$this->authorize('view', User::class);
|
||||
|
||||
$user = User::where('id', $id)
|
||||
->with([
|
||||
'assets.log' => fn ($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
|
||||
'assets.assignedAssets.log' => fn ($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
|
||||
'assets.assignedAssets.defaultLoc',
|
||||
'assets.assignedAssets.location',
|
||||
'assets.assignedAssets.model.category',
|
||||
'assets.defaultLoc',
|
||||
'assets.location',
|
||||
'assets.model.category',
|
||||
'accessories.log' => fn ($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
|
||||
'accessories.category',
|
||||
'accessories.manufacturer',
|
||||
'consumables.log' => fn ($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
|
||||
'consumables.category',
|
||||
'consumables.manufacturer',
|
||||
'licenses.category',
|
||||
])
|
||||
->withTrashed()
|
||||
->first();
|
||||
$user = User::withInventoryRelations($id)->first();
|
||||
|
||||
$indirectItemsCount = $user?->assets?->flatMap->assignedAssets->count() + $user?->assets?->flatMap->components->count() + $user?->assets?->flatMap->licenses->count() + $user?->assets?->flatMap->assignedAccessories->count();
|
||||
|
||||
if ($user) {
|
||||
$this->authorize('view', $user);
|
||||
|
||||
return view('users.print')
|
||||
->with('users', [$user])
|
||||
->with('indirectItemsCount', $indirectItemsCount)
|
||||
->with('settings', Setting::getSettings());
|
||||
}
|
||||
|
||||
|
||||
@ -725,6 +725,10 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
{
|
||||
return $this->belongsToMany(License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id', 'created_at', 'updated_at');
|
||||
}
|
||||
public function directLicenses()
|
||||
{
|
||||
return $this->belongsToMany(\App\Models\License::class, 'license_seats', 'assigned_to', 'license_id')->withPivot('id', 'created_at', 'updated_at')->wherePivotNull('asset_id')->withTrashed();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establishes the user -> reportTemplates relationship
|
||||
@ -1389,7 +1393,47 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo
|
||||
->orwhereRaw('CONCAT(users.first_name," ",users.last_name) LIKE \''.$search.'%\'');
|
||||
|
||||
}
|
||||
|
||||
public function scopeWithInventoryRelations($query, int $id)
|
||||
{
|
||||
return $query->where('id', $id)
|
||||
->with([
|
||||
'assets.log' => fn ($query) => $query->withTrashed()
|
||||
->where('target_type', User::class)
|
||||
->where('target_id', $id)
|
||||
->where('action_type', 'accepted'),
|
||||
'assets.defaultLoc',
|
||||
'assets.location',
|
||||
'assets.model.category',
|
||||
'assets.assignedAssets.log' => fn ($query) => $query->withTrashed()
|
||||
->where('target_type', User::class)
|
||||
->where('target_id', $id)
|
||||
->where('action_type', 'accepted'),
|
||||
'assets.assignedAssets.assignedTo',
|
||||
'assets.assignedAssets.defaultLoc',
|
||||
'assets.assignedAssets.location',
|
||||
'assets.assignedAssets.model.category',
|
||||
'assets.components.category',
|
||||
'assets.licenses',
|
||||
'assets.licenses.category',
|
||||
'assets.assignedAccessories',
|
||||
'assets.assignedAccessories.accessory.category',
|
||||
'accessories.log' => fn ($query) => $query->withTrashed()
|
||||
->where('target_type', User::class)
|
||||
->where('target_id', $id)
|
||||
->where('action_type', 'accepted'),
|
||||
'accessories.category',
|
||||
'accessories.manufacturer',
|
||||
'consumables.log' => fn ($query) => $query->withTrashed()
|
||||
->where('target_type', User::class)
|
||||
->where('target_id', $id)
|
||||
->where('action_type', 'accepted'),
|
||||
'consumables.category',
|
||||
'consumables.manufacturer',
|
||||
'directLicenses.category',
|
||||
'licenses.category',
|
||||
])
|
||||
->withTrashed();
|
||||
}
|
||||
/**
|
||||
* Get all direct and indirect subordinates for this user.
|
||||
*
|
||||
|
||||
@ -48,6 +48,7 @@ return [
|
||||
'asset_tag' => 'Asset Tag',
|
||||
'assets_warrantee_alert' => 'There is :count asset with an expiring warranty or that are reaching their end of life in the next :threshold days.|There are :count assets with expiring warranties or that are reaching their end of life in the next :threshold days.',
|
||||
'assigned_to' => 'Assigned To',
|
||||
'assigned_to_assets' => 'Assignments to Assets',
|
||||
'eol' => 'EOL',
|
||||
'best_regards' => 'Best regards,',
|
||||
'canceled' => 'Canceled',
|
||||
|
||||
@ -168,39 +168,6 @@
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@if ($settings->show_assigned_assets)
|
||||
@php
|
||||
$assignedCounter = 1;
|
||||
@endphp
|
||||
@foreach ($asset->assignedAssets as $asset)
|
||||
<tr>
|
||||
<td>{{ $counter }}.{{ $assignedCounter }}</td>
|
||||
<td>
|
||||
@if ($asset->getImageUrl())
|
||||
<img src="{{ $asset->getImageUrl() }}" class="thumbnail" style="max-height: 50px;">
|
||||
@endif
|
||||
</td>
|
||||
<td>{{ $asset->asset_tag }}</td>
|
||||
<td>{{ $asset->name }}</td>
|
||||
<td>{{ (($asset->model) && ($asset->model->category)) ? $asset->model->category->name : trans('general.invalid_category') }}</td>
|
||||
<td>{{ ($asset->model) ? $asset->model->name : trans('general.invalid_model') }}</td>
|
||||
<td>{{ ($asset->defaultLoc) ? $asset->defaultLoc->name : '' }}</td>
|
||||
<td>{{ ($asset->location) ? $asset->location->name : '' }}</td>
|
||||
<td>{{ $asset->serial }}</td>
|
||||
<td>
|
||||
{{ Helper::getFormattedDateObject($asset->last_checkout, 'datetime', false) }}
|
||||
</td>
|
||||
<td>
|
||||
@if ($asset->getLatestSignedAcceptance($show_user))
|
||||
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $asset->getLatestSignedAcceptance($show_user)->accept_signature }}">
|
||||
@endif
|
||||
</td>
|
||||
</tr>
|
||||
@php
|
||||
$assignedCounter++
|
||||
@endphp
|
||||
@endforeach
|
||||
@endif
|
||||
@php
|
||||
$counter++
|
||||
@endphp
|
||||
@ -240,7 +207,7 @@
|
||||
$lcounter = 1;
|
||||
@endphp
|
||||
|
||||
@foreach ($show_user->licenses as $license)
|
||||
@foreach ($show_user->directLicenses as $license)
|
||||
@php
|
||||
if (($license->category) && ($license->category->getEula())) $eulas[] = $license->category->getEula()
|
||||
@endphp
|
||||
@ -398,7 +365,95 @@
|
||||
@endforeach
|
||||
</table>
|
||||
@endif
|
||||
@if($indirectItemsCount > 0 && $settings->show_assigned_assets)
|
||||
<div id="indirect-assignments-toolbar">
|
||||
<h4>{{ $indirectItemsCount.' '.trans('mail.assigned_to_assets') }}</h4>
|
||||
</div>
|
||||
<table
|
||||
class="snipe-table table table-striped inventory"
|
||||
id="indirect-assignments"
|
||||
data-pagination="false"
|
||||
data-toolbar="#indirect-assignments-toolbar"
|
||||
data-id-table="indirect-assignments"
|
||||
data-search="false"
|
||||
data-side-pagination="client"
|
||||
data-sortable="true"
|
||||
data-sort-order="desc"
|
||||
data-sort-name="name"
|
||||
data-show-columns="true"
|
||||
data-cookie-id-table="indirect-assignments">
|
||||
<thead>
|
||||
@php
|
||||
$indirectAssignmentsCounter = 1;
|
||||
@endphp
|
||||
<tr>
|
||||
<th style="width: 20px;" data-sortable="false" data-switchable="false">#</th>
|
||||
<th style="width: 40%;" data-sortable="true" data-switchable="false">{{ trans('mail.assigned_to') }}</th>
|
||||
<th style="width: 50%;" data-sortable="true">{{ trans('general.category') }}</th>
|
||||
<th style="width: 10%;" data-sortable="true">{{ trans('mail.item') }}</th>
|
||||
<th style="width: 10%;" data-sortable="true">{{ trans('general.quantity') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
@foreach ($show_user->assets as $asset)
|
||||
@foreach ($asset->assignedAssets as $indirectAsset)
|
||||
<tr>
|
||||
<td>{{ $indirectAssignmentsCounter }}</td>
|
||||
<td>{{ $asset->display_name ?? ''}}</td>
|
||||
<td>{{ (($indirectAsset->model) && ($indirectAsset->model->category)) ? $indirectAsset->model->category->name : trans('general.invalid_category') }}</td>
|
||||
<td>{{ $indirectAsset->display_name ?? '' }}</td>
|
||||
<td>1</td>
|
||||
|
||||
</tr>
|
||||
@php
|
||||
$indirectAssignmentsCounter++
|
||||
@endphp
|
||||
@endforeach
|
||||
@foreach ($asset->licenses as $indirectLicense)
|
||||
@if($indirectLicense)
|
||||
<tr>
|
||||
<td>{{$indirectAssignmentsCounter}}</td>
|
||||
<td>{{ $asset->display_name ?? ''}}</td>
|
||||
<td>{{ $indirectLicense->category?->name ?? '' }}</td>
|
||||
<td>{{ $indirectLicense->name ?? '' }}</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$indirectAssignmentsCounter ++
|
||||
@endphp
|
||||
@endforeach
|
||||
@foreach ($asset->components as $component)
|
||||
@if($component)
|
||||
<tr>
|
||||
<td>{{$indirectAssignmentsCounter}}</td>
|
||||
<td>{{ $asset->display_name ?? ''}}</td>
|
||||
<td>{{ $component->category?->name ?? '' }}</td>
|
||||
<td>{{ $component->name ?? '' }}</td>
|
||||
<td>{{ $component->pivot->assigned_qty }}</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$indirectAssignmentsCounter ++
|
||||
@endphp
|
||||
@endforeach
|
||||
@foreach ($asset->assignedAccessories as $indirectAccessory)
|
||||
@if($indirectAccessory)
|
||||
<tr>
|
||||
<td>{{$indirectAssignmentsCounter}}</td>
|
||||
<td>{{ $asset->display_name ?? '' }}</td>
|
||||
<td>{{ $indirectAccessory->accessory->category?->name ?? '' }}</td>
|
||||
<td>{{ $indirectAccessory->accessory->name ?? '' }}</td>
|
||||
<td>1</td>
|
||||
</tr>
|
||||
@endif
|
||||
@php
|
||||
$indirectAssignmentsCounter ++
|
||||
@endphp
|
||||
@endforeach
|
||||
@endforeach
|
||||
</table>
|
||||
@endif
|
||||
@php
|
||||
if (!empty($eulas)) $eulas = array_unique($eulas);
|
||||
@endphp
|
||||
|
||||
Reference in New Issue
Block a user