Skip to content

Commit 5bae74b

Browse files
authored
Merge pull request #16688 from 36864/patch-1
Fixes #14734: Only show signatures for the printed user
2 parents 0259c91 + 3b31408 commit 5bae74b

File tree

3 files changed

+34
-14
lines changed

3 files changed

+34
-14
lines changed

app/Http/Controllers/Users/UsersController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -594,18 +594,18 @@ public function printInventory($id)
594594

595595
$user = User::where('id', $id)
596596
->with([
597-
'assets.assetlog',
598-
'assets.assignedAssets.assetlog',
597+
'assets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
598+
'assets.assignedAssets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
599599
'assets.assignedAssets.defaultLoc',
600600
'assets.assignedAssets.location',
601601
'assets.assignedAssets.model.category',
602602
'assets.defaultLoc',
603603
'assets.location',
604604
'assets.model.category',
605-
'accessories.assetlog',
605+
'accessories.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
606606
'accessories.category',
607607
'accessories.manufacturer',
608-
'consumables.assetlog',
608+
'consumables.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
609609
'consumables.category',
610610
'consumables.manufacturer',
611611
'licenses.category',

app/Models/Loggable.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,4 +343,24 @@ public function logUpload($filename, $note)
343343

344344
return $log;
345345
}
346+
347+
/**
348+
* Get latest signature from a specific user
349+
*
350+
* This just makes the print view a bit cleaner
351+
* Returns the latest acceptance ActionLog that contains a signature
352+
* from $user or null if there is none
353+
*
354+
* @param User $user
355+
* @return null|Actionlog
356+
**/
357+
public function getLatestSignedAcceptance(User $user)
358+
{
359+
return $this->log->where('target_type', User::class)
360+
->where('target_id', $user->id)
361+
->where('action_type', 'accepted')
362+
->where('accept_signature', '!=', null)
363+
->sortByDesc('created_at')
364+
->first();
365+
}
346366
}

resources/views/users/print.blade.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ class="snipe-table table table-striped inventory"
147147
<td>
148148
{{ Helper::getFormattedDateObject($asset->last_checkout, 'datetime', false) }}</td>
149149
<td>
150-
@if (($asset->assetlog->firstWhere('action_type', 'accepted')) && ($asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature!=''))
151-
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature }}">
150+
@if ($asset->getLatestSignedAcceptance($show_user))
151+
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $asset->getLatestSignedAcceptance($show_user)->accept_signature }}">
152152
@endif
153153
</td>
154154
</tr>
@@ -175,8 +175,8 @@ class="snipe-table table table-striped inventory"
175175
{{ Helper::getFormattedDateObject($asset->last_checkout, 'datetime', false) }}
176176
</td>
177177
<td>
178-
@if (($asset->assetlog->firstWhere('action_type', 'accepted')) && ($asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature!=''))
179-
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature }}">
178+
@if ($asset->getLatestSignedAcceptance($show_user))
179+
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $asset->getLatestSignedAcceptance($show_user)->accept_signature }}">
180180
@endif
181181
</td>
182182
</tr>
@@ -243,8 +243,8 @@ class="snipe-table table table-striped inventory"
243243
{{ Helper::getFormattedDateObject($license->pivot->updated_at, 'datetime', false) }}
244244
</td>
245245
<td>
246-
@if (($license->assetlog->firstWhere('action_type', 'accepted')) && ($license->assetlog->firstWhere('action_type', 'accepted')->accept_signature!=''))
247-
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $license->assetlog->firstWhere('action_type', 'accepted')->accept_signature }}">
246+
@if ($license->getLatestSignedAcceptance($show_user))
247+
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $license->getLatestSignedAcceptance($show_user)->accept_signature }}">
248248
@endif
249249
</td>
250250
</tr>
@@ -308,8 +308,8 @@ class="snipe-table table table-striped inventory"
308308
</td>
309309

310310
<td>
311-
@if (($accessory->assetlog->first()) && ($accessory->assetlog->first()->accept_signature!=''))
312-
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $accessory->assetlog->first()->accept_signature }}">
311+
@if ($accessory->getLatestSignedAcceptance($show_user))
312+
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $accessory->getLatestSignedAcceptance($show_user)->accept_signature }}">
313313
@endif
314314
</td>
315315
</tr>
@@ -373,8 +373,8 @@ class="snipe-table table table-striped inventory"
373373
{{ Helper::getFormattedDateObject($consumable->pivot->created_at, 'datetime', false) }}
374374
</td>
375375
<td>
376-
@if (($consumable->assetlog->first()) && ($consumable->assetlog->first()->accept_signature!=''))
377-
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $consumable->assetlog->first()->accept_signature }}">
376+
@if ($consumable->getLatestSignedAcceptance($show_user))
377+
<img style="width:auto;height:100px;" src="{{ asset('/') }}display-sig/{{ $consumable->getLatestSignedAcceptance($show_user)->accept_signature }}">
378378
@endif
379379
</td>
380380
</tr>

0 commit comments

Comments
 (0)