diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 761093911..613524d5c 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -594,18 +594,18 @@ class UsersController extends Controller $user = User::where('id', $id) ->with([ - 'assets.assetlog', - 'assets.assignedAssets.assetlog', + '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.assetlog', + 'accessories.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'), 'accessories.category', 'accessories.manufacturer', - 'consumables.assetlog', + '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', diff --git a/app/Models/Loggable.php b/app/Models/Loggable.php index 93b82f840..506eb116b 100644 --- a/app/Models/Loggable.php +++ b/app/Models/Loggable.php @@ -343,4 +343,24 @@ trait Loggable return $log; } + + /** + * Get latest signature from a specific user + * + * This just makes the print view a bit cleaner + * Returns the latest acceptance ActionLog that contains a signature + * from $user or null if there is none + * + * @param User $user + * @return null|Actionlog + **/ + public function getLatestSignedAcceptance(User $user) + { + return $this->log->where('target_type', User::class) + ->where('target_id', $user->id) + ->where('action_type', 'accepted') + ->where('accept_signature', '!=', null) + ->sortByDesc('created_at') + ->first(); + } } diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index d251d3c3d..8bc36ce97 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -147,8 +147,8 @@ {{ Helper::getFormattedDateObject($asset->last_checkout, 'datetime', false) }} - @if (($asset->assetlog->firstWhere('action_type', 'accepted')) && ($asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature!='')) - + @if ($asset->getLatestSignedAcceptance($show_user)) + @endif @@ -175,8 +175,8 @@ {{ Helper::getFormattedDateObject($asset->last_checkout, 'datetime', false) }} - @if (($asset->assetlog->firstWhere('action_type', 'accepted')) && ($asset->assetlog->firstWhere('action_type', 'accepted')->accept_signature!='')) - + @if ($asset->getLatestSignedAcceptance($show_user)) + @endif @@ -243,8 +243,8 @@ {{ Helper::getFormattedDateObject($license->pivot->updated_at, 'datetime', false) }} - @if (($license->assetlog->firstWhere('action_type', 'accepted')) && ($license->assetlog->firstWhere('action_type', 'accepted')->accept_signature!='')) - + @if ($license->getLatestSignedAcceptance($show_user)) + @endif @@ -308,8 +308,8 @@ - @if (($accessory->assetlog->first()) && ($accessory->assetlog->first()->accept_signature!='')) - + @if ($accessory->getLatestSignedAcceptance($show_user)) + @endif @@ -373,8 +373,8 @@ {{ Helper::getFormattedDateObject($consumable->pivot->created_at, 'datetime', false) }} - @if (($consumable->assetlog->first()) && ($consumable->assetlog->first()->accept_signature!='')) - + @if ($consumable->getLatestSignedAcceptance($show_user)) + @endif